Skip to content
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

Sanitise latex captions of kable() and figures #1418

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ThierryO
Copy link

Using % and _ in captions with kable() or fig.cap were problematic when rendered to pdf. These are now sanitised with escape_latex()

@yihui
Copy link
Owner

yihui commented Jul 20, 2017

The problem is that if I forcibly sanitize them, they may be problematic in other types of output if the source document format is R Markdown, because a character that is special to LaTeX is not necessarily special to another output format.

If your source document format is R Markdown, you may consider the feature of text references in bookdown for maximum portability: https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references

@ThierryO
Copy link
Author

The format of our source files is R Markdown/bookdown. We have been bitten by the examples below when rendering to pdf

```{r my-plot, fig.cap = "Estimate and 95% confidence interval}
my.plot()
```

```{r my-table}
kable(mtcars, caption = "Caption with some _ underscore")
```

The format is taken into account when sanitising the kable caption. That might not be the case for the fig.cap.

Could you explain why the Travis build fails? Because R CMD Check --as-cran passes on my machine.

@ThierryO
Copy link
Author

Here is a minimal bookdown example that works with this PR. The Travis errors seem unrelated to me.

---
title: "Caption test"
author: "Thierry Onkelinx"
date: "24 juli 2017"
output: 
  bookdown::pdf_book: default
  bookdown::epub_book: default
  bookdown::html_document2: default
---

```{r load, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
```

```{r pressure, echo=FALSE, fig.cap = "Pressure with percent % and underscore_"}
plot(pressure)
```

```{r cars}
kable(mtcars, caption = "mtcars with percent % and underscore_")
```

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants