rstudio / bookdown

Authoring Books and Technical Documents with R Markdown

Home Page:https://pkgs.rstudio.com/bookdown/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve error message for LaTeX document by adding line number

aaamini opened this issue · comments

Having a space at the beginning or at the end of an inline math (enclosed in $$) sometimes causes hard to trace errors.

For example, $ y = (y_1,\dots,y_n) \in \mathbb R^n$ causes the following

! LaTeX Error: \symbballowed only in math mode.

Error: LaTeX failed to compile _main.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See _main.log for more info.
Execution halted

Exited with status 1.

I have noticed it with space before the ending $ sign as well.

Thanks. This was helpful. It would be nice if there was a way to produce a more graceful error. For example, there is no line number associated with the error. Not sure if this is possible at bookdown level though.

I agree it will be nice to output the line number in the error message, but I guess it is not possible to have the line number of the Rmd source document, because Pandoc doesn't provide this information when converting .md to .tex.

It should be possible to print the line number of the .tex document, though. If anyone wants to try, here is the the place to implement it: https://github.com/rstudio/tinytex/blob/40217e53312bf696d62691223f75539972800df0/R/latex.R#L336-L358 Thanks!