Closed IndrajeetPatil closed 3 years ago
Yes this is a currently expected behavior as fig.cap
option can't really take Markdown syntax. In fact, it depends on the output format and type of image inclusion that will be produce.
However, this is kind of hidden and advanced but you should see the difference in the intermediary md file (set keep_md: TRUE
in your YAML)
Without out.width
, Markdown syntax will be used to insert the plot. This means caption will be processed by Pandoc to be converted to LaTeX. Code generated by knitr in .md
file for Pandoc to process:
![To read more: https://en.wikipedia.org/wiki/Ggplot2](Untitled_files/figure-latex/empty-1.pdf)
When you set out.width
, knitr will produce a figure environment and caption will be written as is in LaTeX - it won't be processed as Markdown by Pandoc. Code generated by knitr in .md
file for Pandoc to process:
\begin{figure}
\includegraphics[width=1\linewidth]{Untitled_files/figure-latex/empty-1} \caption{To read more: https://en.wikipedia.org/wiki/Ggplot2}\label{fig:empty}
\end{figure}
So you see the difference.
If you want url in LaTeX, you should use the corresponding command (and escaping because R)
```{r empty, fig.cap="To read more: \\url{https://en.wikipedia.org/wiki/Ggplot2}", out.width = "100%"}
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) + geom_point()
This work well when you produce only LaTeX output but don't if you want also HTML from the same code. That is why there is a trick in **bookdown** to allow using `fig.cap` with Text Reference: https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references
So this is not a **rticles** specificity but a current **knitr** behavior because Pandoc Markdown can't by default handle all latex case.
We may revisit that in the future if Pandoc Figures syntax evolve.
Thanks a ton for your kind and detailed response, Christophe! :)
If you want url in LaTeX, you should use the corresponding command (and escaping because R)
This solved the issue for me 🎉
I will let you decide if you want to close this or keep it open.
I don't think there is anything we can do in rticles sides directly. It should be in other packages.
however, we currently have some solutions so I guess it is fine.
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.
I noticed this behavior while using
rticles
template for a JOSS paper.Minimal
YAML
for the document:rmarkdown
code to generate a figure with a caption:Created on 2021-04-01 by the reprex package (v1.0.0)