0

How can I make a text appear like code in Rmarkdown output? Like this: text formatted as code?

Putting my text between backticks is not producing this effect (like it has done above). Instead text is being formated verbatim.

Thanks

Gustavo Mirapalheta
  • 931
  • 2
  • 11
  • 25
  • see https://stackoverflow.com/questions/69438444/how-to-highlight-an-inline-code-snippet-in-latex/70658157#70658157 – samcarter_is_at_topanswers.xyz Jan 26 '22 at 13:35
  • I saw that this uses another Latex package (listings). I noticed that when I knit to HTML instead of PDF the highlighting works fine. Does this mean that the highlighting with backticks does not work in a PDF output? – Gustavo Mirapalheta Jan 26 '22 at 13:47

1 Answers1

0

It seems the backsticks are not working for pdf output (https://community.rstudio.com/t/highlighting-text-inline-in-rmarkdown-or-bookdown-pdf/35118/4).

I was able to solve this by using the soul and xcolor packages and by incluind the following line in my header:

\usepackage{soul, xcolor} 
\definecolor{codegray}{rgb}{0.95,0.95,0.95}
\sethlcolor{codegray}

Now I can use the tag hl{text} to produce the desired result. Although I still have to switch all my backticks by this tag in my document.

Gustavo Mirapalheta
  • 931
  • 2
  • 11
  • 25