I have a linear model in a code chunk that I want to display nicely in LaTeX. The model call takes the standard form with a tilde ~ which gets typeset horribly in LaTeX.
\documentclass{article}
\begin{document}
<<>>=
lm(Sepal.Width ~ Sepal.Length, data = iris)
@
\end{document}
The code is knitted knitr::knit(mwe.Rnw)
and then run through PDFLaTeX.
Making nice tildes is very annoying in LaTeX and getting knitr to make them doesn't seem entirely easy, easier. An inspection of the .tex file produced by knit
shows that the code is put into three environments, of which \begin{alltt} ... \end{alltt}
is the interesting one. But the package alltt
doesn't offer any quick fixes for special typesetting of special characters.