I'm trying to compile a R Markdown file that uses exam::tex2image to generate an image from a Latex equation.
Unfortunately the compilation fails, the error message talks about a log file which doesn't exist.
Source code:
---
output:
pdf_document:
keep_tex: true
---
```{r 2sls, echo=FALSE, results="hide"}
exams::tex2image("2+2=4")
```
stdout:
❯ R -e "options(tinytex.verbose = TRUE);rmarkdown::render('README.Rmd', clean=F)"
> options(tinytex.verbose = TRUE);rmarkdown::render('README.Rmd', clean=F)
processing file: README.Rmd
|.......................................... | 67% (2sls)This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/Arch Linux) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
Quitting from lines 8-9 (README.Rmd)
Error: LaTeX failed to compile tex2image.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See tex2image.log for more info.
Execution halted
Your code works correctly for me (with TeX Live 2022/Debian) so it is likely something in your LaTeX setup that is causing the problem, possibly a missing style file or something like that.
To debug the issue I would run the example interactively and set the tdir
argument for the temporary directory:
exams::tex2image("2 + 2 = 4", tdir = "/path/to/tempdir/")
Note that the temporary directory should be empty before. Then tex2image()
will create a temporary LaTeX file in the temporary directory and then run tinytex::latexmk()
(or tools::texi2dvi()
) on it. If there are problems you can also run LaTeX manually to produce the .log file or apply other debugging strategies.