rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.88k stars 975 forks source link

Can produce .tex file, but get "Undefined control sequence." Error #1523

Closed MCM-Math closed 5 years ago

MCM-Math commented 5 years ago

I've looked at other "Undefined control sequence" pages, but mine seems to be a different case:

Running R Markdown produces a .tex file, but I get the following error:

! Undefined control sequence. l.41 \DeclareRelease {v1}{2001-04-09}{parskip-2001-04-09.sty}

The pandoc command uses default-1.17.0.2.tex as the template. The .tex file can be compiled by TeXworks just fine, and the document seems to come out fine, so I don't know where the breakdown is occurring.

yihui commented 5 years ago

It would be hard to tell without a minimal reprex.

MCM-Math commented 5 years ago

The header alone causes the error:

---
documentclass: article
output:
  bookdown::pdf_document2:
    keep_tex: true
    fig_caption: true
    number_sections: true
    toc: no
header-includes:
- \usepackage{setspace}
- \usepackage{fancyhdr}
- \usepackage{lipsum}
- \usepackage{float}
- \usepackage[numbered]{bookmark}
- \floatstyle{plaintop}
- \restylefloat{figure}
- \floatplacement{figure}{H}
- \pagestyle{fancy}
---
MCM-Math commented 5 years ago

This is on a company computer for work, so there is only so much I can disclose or do.

These are the packages I am using:

                  Package             Version      
acepack           "acepack"           "1.4.1"      
askpass           "askpass"           "1.1"        
assertthat        "assertthat"        "0.2.0"      
backports         "backports"         "1.1.3"      
base64enc         "base64enc"         "0.1-3"      
BH                "BH"                "1.69.0-1"   
bindr             "bindr"             "0.1.1"      
bindrcpp          "bindrcpp"          "0.2.2"      
bit               "bit"               "1.1-14"     
bit64             "bit64"             "0.9-7"      
bitops            "bitops"            "1.0-6"      
blob              "blob"              "1.1.1"      
bookdown          "bookdown"          "0.9"        
Cairo             "Cairo"             "1.5-9"      
callr             "callr"             "3.1.1"      
caTools           "caTools"           "1.17.1.1"   
checkmate         "checkmate"         "1.9.1"      
chron             "chron"             "2.3-53"     
classInt          "classInt"          "0.3-1"      
cli               "cli"               "1.0.1"      
clipr             "clipr"             "0.5.0"      
clisymbols        "clisymbols"        "1.2.0"      
cmprsk            "cmprsk"            "2.2-7"      
colorspace        "colorspace"        "1.3-2"      
covr              "covr"              "3.2.1"      
crayon            "crayon"            "1.3.4"      
crosstalk         "crosstalk"         "1.0.0"      
curl              "curl"              "3.3"        
data.table        "data.table"        "1.12.0"     
DBI               "DBI"               "1.0.0"      
dbplyr            "dbplyr"            "1.3.0"      
desc              "desc"              "1.2.0"      
descr             "descr"             "1.1.4"      
devEMF            "devEMF"            "3.6-2"      
devtools          "devtools"          "2.0.1"      
diffobj           "diffobj"           "0.2.1"      
digest            "digest"            "0.6.18"     
docxtools         "docxtools"         "0.2.0"      
dplyr             "dplyr"             "0.7.8"      
dtplyr            "dtplyr"            "0.0.2"      
dygraphs          "dygraphs"          "1.1.1.6"    
e1071             "e1071"             "1.7-0"      
Epi               "Epi"               "2.32"       
etm               "etm"               "1.0.4"      
evaluate          "evaluate"          "0.12"       
fansi             "fansi"             "0.4.0"      
filehash          "filehash"          "2.4-1"      
flextable         "flextable"         "0.4.6"      
fontBitstreamVera "fontBitstreamVera" "0.1.1"      
fontLiberation    "fontLiberation"    "0.1.0"      
fontquiver        "fontquiver"        "0.2.1"      
forecast          "forecast"          "8.4"        
formatR           "formatR"           "1.5"        
formattable       "formattable"       "0.2.0.1"    
Formula           "Formula"           "1.2-3"      
fracdiff          "fracdiff"          "1.4-2"      
freetypeharfbuzz  "freetypeharfbuzz"  "0.2.5"      
fs                "fs"                "1.2.6"      
futile.logger     "futile.logger"     "1.4.3"      
futile.options    "futile.options"    "1.0.1"      
gapminder         "gapminder"         "0.3.0"      
gdtools           "gdtools"           "0.1.7"      
ggplot2           "ggplot2"           "3.1.0"      
ggplot2movies     "ggplot2movies"     "0.0.1"      
gh                "gh"                "1.0.1"      
gifski            "gifski"            "0.8.6"      
git2r             "git2r"             "0.23.0"     
glue              "glue"              "1.3.0"      
gridExtra         "gridExtra"         "2.3"        
gsubfn            "gsubfn"            "0.7"        
gtable            "gtable"            "0.2.0"      
gtools            "gtools"            "3.8.1"      
hexbin            "hexbin"            "1.27.2"     
highr             "highr"             "0.7"        
Hmisc             "Hmisc"             "4.1-1"      
hms               "hms"               "0.4.2"      
htmlTable         "htmlTable"         "1.12"       
htmltools         "htmltools"         "0.3.6"      
htmlwidgets       "htmlwidgets"       "1.3"        
httpuv            "httpuv"            "1.4.5"      
httr              "httr"              "1.4.0"      
ini               "ini"               "0.3.1"      
jpeg              "jpeg"              "0.1-8"      
jsonlite          "jsonlite"          "1.5"        
JuliaCall         "JuliaCall"         "0.16.1"     
kableExtra        "kableExtra"        "1.0.1"      
knitr             "knitr"             "1.21"       
labeling          "labeling"          "0.3"        
Lahman            "Lahman"            "6.0-0"      
lambda.r          "lambda.r"          "1.2.3"      
later             "later"             "0.7.5"      
latticeExtra      "latticeExtra"      "0.6-28"     
lazyeval          "lazyeval"          "0.2.1"      
lmtest            "lmtest"            "0.9-36"     
lubridate         "lubridate"         "1.7.4"      
magick            "magick"            "2.0"        
magrittr          "magrittr"          "1.5"        
manipulateWidget  "manipulateWidget"  "0.10.0"     
mapproj           "mapproj"           "1.2.6"      
maps              "maps"              "3.3.0"      
maptools          "maptools"          "0.9-4"      
markdown          "markdown"          "0.9"        
MatrixModels      "MatrixModels"      "0.4-1"      
memisc            "memisc"            "0.99.14.12" 
memoise           "memoise"           "1.1.0"      
microbenchmark    "microbenchmark"    "1.4-6"      
mime              "mime"              "0.6"        
miniUI            "miniUI"            "0.1.1.1"    
multcomp          "multcomp"          "1.4-8"      
munsell           "munsell"           "0.5.0"      
mvtnorm           "mvtnorm"           "1.0-8"      
numDeriv          "numDeriv"          "2016.8-1"   
nycflights13      "nycflights13"      "1.0.0"      
officer           "officer"           "0.3.2"      
openssl           "openssl"           "1.1"        
packrat           "packrat"           "0.5.0"      
pander            "pander"            "0.6.3"      
pillar            "pillar"            "1.3.0"      
pkgbuild          "pkgbuild"          "1.0.2"      
pkgconfig         "pkgconfig"         "2.0.2"      
pkgload           "pkgload"           "1.0.2"      
plogr             "plogr"             "0.2.0"      
plyr              "plyr"              "1.8.4"      
png               "png"               "0.1-7"      
polspline         "polspline"         "1.1.13"     
praise            "praise"            "1.0.0"      
prettyunits       "prettyunits"       "1.0.2"      
processx          "processx"          "3.2.1"      
promises          "promises"          "1.0.1"      
proto             "proto"             "1.0.0"      
ps                "ps"                "1.2.1"      
purrr             "purrr"             "0.2.5"      
quadprog          "quadprog"          "1.5-5"      
quantmod          "quantmod"          "0.4-13"     
quantreg          "quantreg"          "5.36"       
R6                "R6"                "2.3.0"      
randomForest      "randomForest"      "4.6-14"     
RColorBrewer      "RColorBrewer"      "1.1-2"      
Rcpp              "Rcpp"              "1.0.0"      
RcppArmadillo     "RcppArmadillo"     "0.9.200.5.0"
RCurl             "RCurl"             "1.95-4.11"  
readr             "readr"             "1.2.1"      
rematch2          "rematch2"          "2.0.1"      
remotes           "remotes"           "2.0.2"      
repr              "repr"              "0.18"       
reshape           "reshape"           "0.8.8"      
reshape2          "reshape2"          "1.4.3"      
reticulate        "reticulate"        "1.10"       
rex               "rex"               "1.1.2"      
rgeos             "rgeos"             "0.4-2"      
rgl               "rgl"               "0.99.16"    
RH2               "RH2"               "0.2.4"      
rJava             "rJava"             "0.9-10"     
RJDBC             "RJDBC"             "0.2-7.1"    
rlang             "rlang"             "0.3.0.1"    
rmarkdown         "rmarkdown"         "1.11"       
rms               "rms"               "5.1-2"      
RMySQL            "RMySQL"            "0.10.15"    
RPostgreSQL       "RPostgreSQL"       "0.6-2"      
rprojroot         "rprojroot"         "1.3-2"      
rsconnect         "rsconnect"         "0.8.12"     
RSQLite           "RSQLite"           "2.1.1"      
rstudioapi        "rstudioapi"        "0.8"        
RUnit             "RUnit"             "0.4.32"     
rvest             "rvest"             "0.3.2"      
sandwich          "sandwich"          "2.5-0"      
scales            "scales"            "1.0.0"      
selectr           "selectr"           "0.4-1"      
servr             "servr"             "0.11"       
sessioninfo       "sessioninfo"       "1.1.1"      
sf                "sf"                "0.7-1"      
shiny             "shiny"             "1.2.0"      
showtext          "showtext"          "0.5-1"      
showtextdb        "showtextdb"        "2.0"        
sourcetools       "sourcetools"       "0.1.7"      
sp                "sp"                "1.3-1"      
SparseM           "SparseM"           "1.77"       
spData            "spData"            "0.2.9.6"    
sqldf             "sqldf"             "0.4-11"     
stringi           "stringi"           "1.2.4"      
stringr           "stringr"           "1.3.1"      
styler            "styler"            "1.1.0"      
svglite           "svglite"           "1.2.1"      
svUnit            "svUnit"            "0.7-12"     
sylly             "sylly"             "0.1-5"      
sylly.en          "sylly.en"          "0.1-3"      
sys               "sys"               "2.1"        
sysfonts          "sysfonts"          "0.8"        
tables            "tables"            "0.8.7"      
testit            "testit"            "0.9"        
testthat          "testthat"          "2.0.1"      
TH.data           "TH.data"           "1.0-9"      
tibble            "tibble"            "1.4.2"      
tictoc            "tictoc"            "1.0"        
tidyr             "tidyr"             "0.8.2"      
tidyselect        "tidyselect"        "0.2.5"      
tikzDevice        "tikzDevice"        "0.12"       
timeDate          "timeDate"          "3043.102"   
tinytex           "tinytex"           "0.10"       
translations      "translations"      "3.5.0"      
tseries           "tseries"           "0.10-46"    
TTR               "TTR"               "0.23-4"     
tufte             "tufte"             "0.4"        
units             "units"             "0.6-2"      
urca              "urca"              "1.3-0"      
uroot             "uroot"             "2.0-9"      
usethis           "usethis"           "1.4.0"      
utf8              "utf8"              "1.1.4"      
uuid              "uuid"              "0.1-2"      
vdiffr            "vdiffr"            "0.2.3"      
viridis           "viridis"           "0.5.1"      
viridisLite       "viridisLite"       "0.3.0"      
webshot           "webshot"           "0.5.1"      
whisker           "whisker"           "0.3-2"      
withr             "withr"             "2.1.2"      
xfun              "xfun"              "0.4"        
XLConnect         "XLConnect"         "0.2-15"     
XLConnectJars     "XLConnectJars"     "0.2-15"     
xml2              "xml2"              "1.2.0"      
xopen             "xopen"             "1.0.0"      
xtable            "xtable"            "1.8-3"      
xts               "xts"               "0.11-2"     
yaml              "yaml"              "2.2.0"      
zip               "zip"               "1.0.0"      
zoo               "zoo"               "1.8-4" 
yihui commented 5 years ago

With the header you provided above, I cannot reproduce your problem.

It might be caused by your (old) LaTeX distribution. I'd recommend using TinyTeX instead: https://bookdown.org/yihui/rmarkdown/installation.html

MCM-Math commented 5 years ago

I have the TinyTeX package installed, and the MiKTeX distribution is pretty up-to-date (2.9.6753), as well as pandoc. Also, I am able to compile the .tex file generated by R Markdown, as stated above; the error appears after the pandoc command in R.

It might be useful to note that both the pandoc and the MiKTeX distribution are downloaded as part of the Anaconda distribution. Also, I can create Word and PowerPoint files from R Markdown code without difficulty.

yihui commented 5 years ago

Then I don't have an idea. As I said, I cannot reproduce the issue. What's your rmarkdown::pandoc_version()? I guess it doesn't matter, though.

MCM-Math commented 5 years ago

2.5

MCM-Math commented 5 years ago

Is it possible to have R Markdown just create the .tex file, and then stop? It seems to produce the .tex file, and the problems seem to come after that. I can finish creating the PDF from the .tex with TeXworks, but now R Markdown just seems to hang at the pandoc command part.

yihui commented 5 years ago

rmarkdown::render('foo.Rmd', 'foo.tex') gives you the .tex file, or use latex_document instead of pdf_document as the output format. I hope to figure out the reason for the failure, though, in case other people run into the same issue in the future... FWIW, I tested on both macOS and Windows (with TinyTeX instead of MikTeX), and was unable to reproduce the issue with the YAML header you provided.

jacob-long commented 5 years ago

I'm having an issue that may have the same cause. It's not the most minimal reprex — hard for me to slim down the template/style without breaking things in other ways — but it's a reprex: https://github.com/jacob-long/rmd-reprex

I'm using Windows 10, MikTeX, newest (CRAN) version of rmarkdown.

When running rmarkdown::render("reprex.Rmd"), I get:

"C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS reprex.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output reprex.tex --template cv-simple.tex --highlight-style tango --pdf-engine xelatex
! Argument of \label has an extra }.
<inserted text>
                \par
l.77 \section{Heading}\label{heading}}

Error: Failed to compile reprex.tex. See reprex.log for more info.

Despite the error, if I simply run xelatex reprex.tex (with reprex.tex generated using the keep_tex argument) from the command line, I don't get any errors.

yihui commented 5 years ago

@jacob-long If you run xelatex reprex.tex, you do get the PDF, but there actually exists the same error in the log file, and the exit status of xelatex is not zero (indicating failure of the execution). I'm not familiar with the LaTeX document class that you used in this example, and I cannot offer further help here. Sorry.

antaldaniel commented 5 years ago

I am getting this error, and it is related to the custom blocks that I tried to copy from the example, i.e. the bookdown book in the package.

The block2 {rmdblock}{caution} etc block create a weird error, i.e. A number should have been here; I inserted0'.` This usually stops the builder, but the .tex file is created, and it is usually possible to build a PDF from it.

I do not know what may cause Latex to think that a parameter is missing from here, but this is what is created from the Rmd to tex conversion.

\BeginKnitrBlock{rmdwarning}
\begin{itemize}
My warning text. 
\end{itemize}
\EndKnitrBlock{rmdwarning}
yihui commented 5 years ago

@antaldaniel Would you please file a new issue since your error seems to be different?

antaldaniel commented 5 years ago

My apologies, I thought it was the same, but it is not, and I also understand what happened. I saw a similar issue somewhere, but maybe on stackoverflow. I will look it up.

github-actions[bot] commented 4 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.