-
-
Notifications
You must be signed in to change notification settings - Fork 872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Figure code may generate wrong LaTeX code (when rendering Rmd to tex) if the fig.cap is not TeX-safe #2302
Comments
I've adopted the second solution you proposed. Thanks! |
Thanks for your prompt reply! Much appreciated! I can confirm that this fixes the issue (LaTeX will correctly fail with "runaway argument" for the above example). |
Sorry, I just discovered that the above fix would break some reverse dependencies. I'll investigate and may consider switching to the first solution (but one tricky thing is to avoid escaping |
What about |
Yes, that's what I was thinking. |
Just committed the new fix. Thanks! |
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. |
Reproducible and illustrative example (
test.Rmd
):then render with
rmarkdown::render("test.Rmd","pdf_document")
.The figure output will be offset and followed with verbatim text
\begin{figure}
in the PDF document.Analysis:
When special options are needed in
hook_plot_md
for LaTeX output (here triggered byout.width
), it will callhook_plot_tex
and pass its output verbatim into the.md
file - here (test.knit.md
):That works in most cases, because pandoc will detect valid LaTeX and simply copy that content. However, in the above case, the caption is not TeX-safe (the
%
needs escaping) so pandoc will detect invalid LaTeX and treat it as simple text - escaping all the commands - (fromtest.tex
):The cause is really hard to detect. The user may not be aware that the caption contained an unescaped
%
sign that caused the problem.Solutions
There are really two related issues with possible solutions:
fig.cap
could possibly escape naked%
characters when producing LaTeX code for the figure (partly to make it both html-target and PDF-target consistent). This would at least avoid the arguably most common cause of this problem (which is really hard to debug!).hook_plot_md
might wrap the LaTeX code fromhook_plot_tex
in a=latex
block to prevent pandoc from falling back to regular text rendering. This will make the LaTeX processing fail, but at least it is clear what happened at that point.Note that pandoc may fail on complex LaTeX code beyond the simple issue above, so one might argue that using
=latex
bock is a way to go.By filing an issue to this repo, I promise that
I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: