Problem with cross-reference and citation using the visual editor.

Hi,

I have been working with bookdown to draft a report. I am using bookdown::pdf_document2 as output and using the last version of Rstudio (1.4.1103) with R 4.0.2.

In some sections I need to cross-reference figures and add citations in the same parenthesis but I encounter the following issue:

  1. When using the visual editor: [Figure @ref(fig:figure-1); @citation1; @citation2] will produce and output in the knitted pdf with square brackets [Figure 1; citation1; citation2] instead of round brackets (Figure 1; citation1; citation2).

  2. A way that I could make this work was not using the visual editor and escaping the first ; as: [Figure \@ref(fig:figure-1)\; @citation1; @citation2], which produce the reference with parenthesis. However, if I turn on the visual editor, the escaped \; is converted into a ; and causing the problem again.

is there any form to escape characters directly from the visual editor ?

Cheers.

Here is a reproducible example of this : The \; will be transformed to ; in canonical mode when activating visual editor.

---
title: "Untitled"
date: "17 2 2021"
output:   
  bookdown::pdf_document2: default
bibliography: packages.bib
---

```{r}
knitr::write_bib(c("knitr", "rmarkdown"), file = "packages.bib")
```

```{r mtcars, fig.cap="plot1"}
plot(mtcars)
```

See [Figure \@ref(fig:mtcars)\; @R-knitr; @R-rmarkdown]

See [@R-knitr; @R-rmarkdown]

# References

For now, the best way to have the visual editor handle this syntax is to use inline raw for example

See [Figure \@ref(fig:mtcars)`;`{=latex} @R-knitr; @R-rmarkdown]

In that case the visual editor will parse it as Pandoc as raw TeX, and it will appear correctly in the output.

1 Like

Thank you for your answer,
this will work in the meantime.

Cheers.

1 Like

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.