This might be an edge case, but I'm trying to create a beamer presentation with knitr where I want to display a code chunk using different formulas as arguments for a function. I found that when using overlays, the tilde in the code chunks disappear. Is there a way to get them to display?
Here's a minimal reproducible example:
\documentclass{beamer}
\begin{document}
\begin{frame}[fragile]
\frametitle{Slide with overlay}
\only<1>{
<<notilde, eval = FALSE>>=
myfunction(data, formula = ~ x)
@
}
\only<2>{
<<notilde2, eval = FALSE>>=
myfunction(data, formula = y ~ x)
@
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Slide without overlay}
<<tilde, eval = FALSE>>=
myfunction(data, formula = ~ x)
@
\end{frame}
\end{document}
The first frame of the presentation looks like this:
Any help is appreciated.
EDIT:
The slide without overlay looks like this:
To clarify, the syntax of <<...>>
and @
is specific to the R package knitr. Anything between these symbols are interpreted by knitr as R code chunks and converted to latex to include syntax highlighting.
You can replace the ~ with the math mode $\sim$
If not in a special environment like verbatim, the tilde in latex is a protected space, i.e. a space at which no line break occurs.
It is not clear from your question: is it working for your second frame, without overlay? I don't know part of your syntax: is the << ... >>= ... @ equivalent to a verbatim or code environmet? It looks a bit, as your text is set in a fixed space font and has syntax highlihting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With