# Left Quotation Marks when using RMarkdown and knitR

Normally when you want left quotation marks in LaTeX, you type the following:




However, in RMarkdown, you will trigger a block of R code to run when you type two pairs of backticks on the same line, causing the LaTeX to render incorrectly.

For example,

Sticks and stones may break my bones,'' he said. But words will never hurt me.''


Will be rendered incorrectly in the output document; specifically, the stuff enclosed by the backticks will be printed out by R, and everything after will be rendered properly by LaTeX. Here is a picture:

I then attempted to use backslashes in order to escape the R code, and this got me closer, but now the right quotation marks are now recognized as a pair of single quotes right next to each other:

\\Sticks and stones may break my bones,'' he said. \\But words will never hurt me.''


How can I properly obtain two left quotation marks on the same line using RMarkdown, without having these render issues?

First of all, you need to be aware of this fact:

Markdown is not LaTeX.

So in general you should not expect LaTeX syntax to work in Markdown documents. The correct way to write quotes in Markdown is to just write quotes literally, i.e., use " ". They will be converted to the correct LaTeX code (i.e.,  '') when Markdown is converted to LaTeX (via Pandoc). The same thing applies to single quotes.

Backticks have a special meaning in Markdown: they are used to write text verbatim. You can use any number of backticks (one, two, three, ...), as long as the backticks come in pairs. In your case, you have a pair of double backticks, which mark the text Sticks and stones may break my bones,'' he said. as verbatim.

I strongly recommend you to read the Pandoc's Markdown syntax at least once before using R Markdown. It will save you a lot of time in the future, and you probably won't have questions about the Markdown basics.

• @CoreyLevinson If you want it to be LaTeX in stead of Markdown, you could use the R-and-Weave (.Rnw)-format. I wrote a package includeRnw to make it even more LaTeX-convenient. – Andreas Storvik Strauman May 15 '18 at 17:34

### The R-side fix:

It's a bit hairy, because you could do escaped regex in R to redefine what is interpreted as R-code. However, there is an "easy" way out:

Redefining how knitr parses you file:

A little depending on how the file is knited. The idea here is to define the pattern right before it's knited.

If you're in RStudio then you can redefine what is the current -code chunk to, say, the default Rnw syntax. From the knitr docs. So in R:

library(knitr)
old_patterns = knit_patterns$get() # old pattern list (to restore later) all_patterns = all_patterns # a list of all built-in patterns str(all_oatterns) # See all the patterns knit_patterns$set(all_patterns[["rnw"]]) # set pattern list from
all_patterns\$rnw
knit("path/to/myR.Rmd")


However, there are some TeX alternatives:

### The quickTeX-fix

Make a new character, e.g. ", to represent a backtick, and use it like this:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
% Define " to be an active character
\catcode"\active
% Define " to be the backtick  like so
\let"
% Now use " as if it was a back
""Sticks and stones may break my bones,'' he said. ""But words will never hurt me.''
\end{document}


### Another (possibly) quick (possibly) fix:

use the package dirtytalk:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{dirtytalk}
\begin{document}
\say{Sticks and stones may break my bones,} he said. \say{But words will never hurt me.}
\end{document}


### Yet another (possibly) fix:

You can make your own external tex file that is not parsed by knitr:

%% quoteCommands.tex
\newcommand{\startQuote}{}
\newcommand{\endQuote}{''}


and then

\documentclass{article}
\usepackage[utf8]{inputenc}
\input{quoteCommands}
\begin{document}
\startQuote Sticks and stones may break my bones,\endQuote he said. \startQuote But words will never hurt me.\endQuote
\end{document}
`
• This is a great writeup of a number of ways to get the correct result, but I have marked the other answer correct because it is simpler (just use the quotation marks.) It was not obvious to me that I have been writing in Markdown instead of LaTeX, but now that I realize that I am writing in Markdown, I will begin to use Markdown notation. (Example: I was curious why \textbf{hey} wouldn't always work. Now I know just to use hey). – Corey Levinson May 17 '18 at 3:16
• @CoreyLevinson Also, the other post is written by the creator of Knitr. I would have done the same as you :) – Andreas Storvik Strauman May 17 '18 at 6:56