Closed timothee-bacri closed 1 year ago
Hi @timothee-bacri
Not sure to understand what the issue is really. It seems to me get what you are writing , but let me explain what happens as maybe the context is missing to you and this will be more clear.
but I now think this is more likely a knitr problem.
knitr is involved only in code computation so I don't think there is anything here related to knitr as you are just writing text. Anyhow, I'll keep explaining.
Strangely, the .rnw code (...) produces (via knitr::knit2pdf("mydocument.rnw")) a PDF with all correct quotation marks, without these strange errors.
When you are writing a Rnw
document, the text syntax you use is LaTeX. So writing LaTeX like ``abc"
is ok. So it will work the same as in overleaf where you are expected to write LaTeX I believe.
The following code in a .rmd (or .qmd) document
When you are writing Text in Qmd or Rmd document, the syntax used is Markdown, and specifically Pandoc's Markdown. This syntax accepts some raw LaTeX or parses some Markdown as raw LaTeX if no doubt about it, and I think that is why you get the result.
First, Pandoc's Markdown is a syntax so that you can express content the same, no matter the output. There is an option called smart that will produce the ``abc''
for you by just writing double quotes. It is activated by default with R Markdown and Quarto.
So try
---
format: latex
---
"abc" (123) "def"
"abc"
"def"
"abc"
"def"
and you'll get in LaTeX
``abc'' (123) ``def''
``abc'' ``def''
``abc''
``def''
So you can use regular double quotes to have the fancy LaTeX syntax in the output
Now why do you observe the result you have, by inserting LaTeX directly inside the document. For that we need to look at how Pandoc parses the LaTeX.
This Markdown code
<!-- Problem -->
``abc" \(123\) ``def"
<!-- Problem -->
``abc"
``def"
<!-- No problem -->
``abc"
``def"
is parsed as this. If you want to understand deeply, this is Abstract Syntax Tree (AST) representation internal to Pandoc that will be explained in this doc - but i'll give you the detail below
[ RawBlock (Format "html") "<!-- Problem -->"
, Para
[ Code ( "" , [] , [] ) "abc\" \\(123\\)" , Str "def\8221" ]
, RawBlock (Format "html") "<!-- Problem -->"
, Para [ Code ( "" , [] , [] ) "abc\"" , Str "def\8221" ]
, RawBlock (Format "html") "<!-- No problem -->"
, Para [ Str "``abc\8221" ]
, Para [ Str "``def\8221" ]
]
``abc" \(123\) ``def"
is seen as a Code block because first ``
matches the second ``
as backticks in Markdown means code syntax. So that is expected.
Now the following is aslo parsed the same
``abc"
``def"
because in Pandoc's markdown, going to newline does not create a paragraphe and the same applies - opening backticks matches the closing one on the other line.
Now the following is ok
``abc"
``def"
because adding a newline with space only will separate the paragraphs and no opening and closing backticks are matched.
I hope this explains why you observe the results you have.
If you want to write raw LaTex, and do not want parsing you need to explicitly tells pandoc to no parse. See how to write raw content using raw attributes
like this
---
format: latex
---
<!-- Problem -->
``` ``abc" \(123\) ``def" ```{=latex}
<!-- Problem -->
```{=latex}
``abc"
``def"
which gives this latex
```latex
``abc" \(123\) ``def"
``abc"
``def"
Pandoc parses the markdown like this
[ RawBlock (Format "html") "<!-- Problem -->"
, Para
[ RawInline (Format "latex") "``abc\" \\(123\\) ``def\"" ]
, RawBlock (Format "html") "<!-- Problem -->"
, RawBlock (Format "latex") "``abc\"\n``def\""
]
I hope this helps understand
@cderv Thank you very much for the detailed explanation and the solutions. I will likely need to come back here when I run into quotation mark problems again :)
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 originally posted my issue at https://github.com/quarto-dev/quarto-cli/issues/4857, but I now think this is more likely a
knitr
problem.I copy-paste here the important part from there.
Bug description
The following code in a .rmd (or .qmd) document
produces (when rendered with the R-code
rmarkdown::render("mydocument.Rmd")
(orquarto::quarto_render("mydocument.qmd")
) the following TeX codeand this in turn produces the following PDF
I have no idea what is happening, but Overleaf does not have this problem, so I think this is a
knitr
problem.Edit
Strangely, the .rnw code
produces (via
knitr::knit2pdf("mydocument.rnw")
) a PDF with all correct quotation marks, without these strange errors.Technical information
I have updated all my packages with
update.packages(ask = FALSE, checkBuilt = TRUE)
, and runremotes::install_github('yihui/knitr')
.By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.