2

My issue is to include verbatim output from knitr Sweave code chunks in footnotes. The BVerbatim environment (fancyvrb) gives me the formatting that I want. (NB: one needs to put \VerbatimFootnotes somewhere following the preamble.) With the chunk option results='asis' the code is delimited with \begin{Sinput} ... \end{Sinput}. Is there a way to ensure that these do not appear, or to omit them? An example is at the end of the post.

If I include the output directly in the footnote, whether with results='asis' or results='markup', the formatting is untidy and the code appears normalsize, even if I have size='footnotesize' as a chunk option. I can of course admit defeat and include the code directly in a BVerbatim environment, with the concurrent risk that the code that is printed is not guaranteed to be the code that is executed.

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\VerbatimFootnotes
<<setup, echo=FALSE>>=
render_listings()
@

<<install-pkg, echo=FALSE, eval=FALSE>>=
repos <- "http://cran.csiro.au"
install.packages('httr', repos=repos)}
@ 

To install the package {\em httr}, execute
the code in the footnote.\footnote{
\begin{BVerbatim}[baseline=t]
<<install-pkg, eval=FALSE, echo=TRUE, results="asis">>=
@ 
\end{BVerbatim}
}
\end{document}
  • 2
    Welcome to TeX.SX! This is question number 100000, hurray! – egreg Nov 13 '15 at 20:53
  • Could you post a minimal example to make it easier for us to get started on diagnosing the problem? – Yihui Xie Nov 14 '15 at 6:20
1

The following is clumsy, but achieves what I want

    \documentclass{article}
    \usepackage{fancyvrb}
    \begin{document}
    \VerbatimFootnotes
    \newcommand*\FancyVerbStopString{'zzz'}
    <<setup, echo=FALSE>>=
    render_listings()
    @

    <<install-pkg, echo=FALSE, eval=FALSE>>=
    repos <- "http://cran.csiro.au"
    install.packages('httr', repos=repos)}
    @ 

    To install the package {\em httr}, execute
    the code in the footnote.\footnote{
    \begin{BVerbatim}[baseline=t, firstline=2, lastline=3] 
    <<install-pkg-fn, eval=FALSE, echo=TRUE, highlight=FALSE, results="asis">>=
    <<install-pkg>>
    'zzz'
    @ 
    \end{BVerbatim}
    }
    \end{document}

The effect of firstline=2 is to drop off the \begin{Sinput}. One could specify lastline=3 to drop off the \end{Sinput}. However, for automatic use, this requires a mechanism for counting the number of lines of code. Hence the use of

        \newcommand*\FancyVerbStopString{'zzz'}

Of course, any alphanumeric character string will do in place of 'zzz'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.