[R-pkg-devel] Vignettes from LaTeX files.

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Sun Mar 7 01:18:50 CET 2021

On 7 March 2021 at 12:54, Rolf Turner wrote:
| Dirk Eddelbuettel <edd using debian.org> wrote:
| By "in base R" do you mean that one can do this *without* invoking
| the R.rsp package?

Exactly. Zero added dependencies. 

| What I understand you to be saying is that you can add four or five
| lines to a *.tex file in your vignettes directory (or does the file
| need to have a .Rnw extension?) and then the vignette will get built,
| when you build the package, without any recourse to the R.rsp package.
| (And there is then no need for any reference to R.rsp in your
| Is this correct?
| Can you be more explicit about the "four or five lines"?

See below.
| If my understanding is correct, it would be nice to see this all set
| out in simple terms in WRE.  Currently what is said in WRE is over my
| head, and think would be over the heads of many of us ordinary mortals.

Here is concrete example of a minimal latex file (I had in /tmp from showing
a colleague newer to plain latex the effects of setting/not-setting \date{})
   \author{Lennon and McCartney}
   \date{The Sixties}
   \title{Lots of stuff}


As you can see, no bells, no whistles, no limits. You could add whatever you
wanted.  Now as probably documented in several places, used in numerous
examples and many packages, _all it takes_ is adding four lines as a Sweave
vignette only needs the vignette headers:

   \author{Lennon and McCartney}
   \date{The Sixties}
   \title{Lots of stuff}
   %\VignetteKeywords{lennon, mccartney, harrison, starr}
Just how you can 'pdflatex demo.tex' (if the former is saved as 'demo.tex')
you can 'sweave demo.Rnw' (if the latter is saved as 'demo.tex') where sweave
is the helper script below wrapping what would happen inside a package build.

And that's all there is. Give it a try. Should also work if thrown into a package.


PS sweave script below. It's old and local... I should add xdg-open at the end.

#!/bin/bash -e

function errorexit () {
    echo "Error: $1"
    exit 1

function filetest () {
    if [ ! -f $1 ]; then
       errorexit "File $1 not found"
    return 0
if [ "$#" -lt 1 ]; then
    errorexit "Need to specify argument file"
BASENAME=$(basename $1 .Rnw)
filetest $RNWFILE
echo "library(tools); Sweave(\"$RNWFILE\")" \
      | R --no-save --no-restore --slave
filetest $LATEXFILE && pdflatex $LATEXFILE
#filetest $PDFFILE && acroread $PDFFILE &
#filetest $PDFFILE && xpdf $PDFFILE &
#filetest $PDFFILE && kpdf $PDFFILE &

https://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org

More information about the R-package-devel mailing list