Small backtick bug in R Markdown to pdf

There appears to be a small bug in rendering backticks to PDFs in R Markdown. This mostly only matters when trying to show how to write R Markdown. The bug is that backticks show as single quotes instead.

The bible, https://bookdown.org/yihui/rmarkdown-cookbook/verbatim-code-chunks.html, says to do this:

image

But when I do exactly that I get
image

1 Like

I don't get the same result

Something specific must be set somehow for LaTeX to change it.

Which format are you using ? rmarkdown::pdf_document ?
Which pandoc version is in used ? rmarkdown::pandoc_version() ?

Can you share a full reproducible example ?

Thanks

I am copy-and-pasting the code, as pushing the reprex button in RStudio didn't work. (I'm sure there's a way around that, but it doesn't seem necessary here.)

The website is only allowing one picture to be pasted in, so I will paste in a picture of the beginning of the pdf.

Unfortunately, reproducing backticks doesn't work well here. There are some missing even though I have marked the paste as code. So I am also uploading a picture.

I can't upload .RMD or .pdf files, but I am happy to provide them if it would be helpful.

image

If it matters, I am running on Windows 10 with the most recent version of R and RStudio as well as all packages up-to-date as of yesterday.

---
title: "Untitled"
author: "Dick Startz"
date: "`r Sys.Date()`"
output: pdf_document
---

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

```{r, eval=TRUE}`r ''`
1 + 1
```
````

```{r}
rmarkdown::pandoc_version()
rmarkdown::pdf_document()
```

@cderv I see you did something magical to make my post look better. Thanks!

  1. Could you explain what you did, so I can do it right next time?
  2. Would something more from me be helpful in figuring out the underlying backtick issue?

Yes sorry I should have shared: It is all in the FAQ

FAQ: How to Format R Markdown Source

There is an option somewhere that show the backticks in this font.
@yihui do you remember what could cause the backtick to be shown this way in LaTeX ?
I know this could happen with quotation mark and smart extension but I can't remember for this case.

Also @startz can you share xfun::session_info("rmarkdown") ? thanks

R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044), RStudio 2022.2.2.485

Locale:
LC_COLLATE=English_United States.utf8
LC_CTYPE=English_United States.utf8
LC_MONETARY=English_United States.utf8
LC_NUMERIC=C
LC_TIME=English_United States.utf8

Package version:
base64enc_0.1.3 bslib_0.3.1 digest_0.6.29 evaluate_0.15
fastmap_1.1.0 fs_1.5.2 glue_1.6.2 graphics_4.2.0
grDevices_4.2.0 highr_0.9 htmltools_0.5.2 jquerylib_0.1.4
jsonlite_1.8.0 knitr_1.39 magrittr_2.0.3 methods_4.2.0
R6_2.5.1 rappdirs_0.3.3 rlang_1.0.2 rmarkdown_2.14
sass_0.4.1 stats_4.2.0 stringi_1.7.6 stringr_1.4.0
tinytex_0.39 tools_4.2.0 utils_4.2.0 xfun_0.31
yaml_2.3.5

Pandoc version: 2.17.1.1

Could you also provide xfun::session_info('tinytex')? My current guess is that your LaTeX installation doesn't have the upquote package. If you are using TinyTeX as your LaTeX distribution, you may run tinytex::tlmgr_install('upquote').

Thank you @yihui. tinytex::tlmgr_install('upquote') solves the problem. (Also, thank you for all the wonderful software you've built.)

It would probably be a minor good thing if the default installation of RStudio included this. :slight_smile:

1 Like

I tend to agree. This is where to add LaTeX package names to the default TinyTeX bundle: tinytex/tools/pkgs-custom.txt at main · rstudio/tinytex · GitHub The upquote package is relatively small in size, so it won't hurt much. However, I'm not sure how frequently users could run into this problem. You are the first one who has reported this problem over the last few years. I guess an average user is unlikely to output backticks verbatim, but I know that this is very useful for writing tutorials to teach R Markdown. Perhaps I'll wait for a longer time and see if anyone else will be affected by this problem in the future. Thanks for the suggestion!

1 Like

Thanks @yihui ! I learnt about this one.
It is hidden in the Pandoc Manual :

The following packages will be used to improve output quality if present, but pandoc does not require them to be present: upquote (for straight quotes in verbatim environments)

Using a clean TinyTeX installation, I can reproduce this. I'll try that next time!
Thank you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.