I'm an extreme beginner. I would like to write the names of R packages like "lavaan" in the screenshot attached, but I really don't know how to achieve that. Can anyone help? I would only format one word at a time like this. enter image description here

  • 3
    \texttt{lavaan} Aug 23, 2022 at 17:41
  • Thank you so much! Do you think there's a way to automatically format just like R code? Aug 23, 2022 at 17:53
  • Welcome to TeX.SE. Please clarify what you mean by "a way to automatically format just like R code".
    – Mico
    Aug 23, 2022 at 18:00
  • sorry I do not understand your question. LaTeX has to be told which font to use. Just as in R markdown you must have marked lavaan in some way, it did not automatically become monospaced. Aug 23, 2022 at 18:30
  • 2
    If you're going to use a particular name like that a lot in your document, then in the preamble you could include a macro for it: \newcommand{\lavaan}{\texttt{lavaan}}.
    – murray
    Aug 23, 2022 at 19:29

1 Answer 1


This list the packages of a R session automatically, with the required format:


test.Rnw in Rstudio (or test.Rtex in Overleaf):



library(xtable)   # loaded only for test
library(ggplot2)  # loaded only for test


\subsection*{A hard R work} 


\subsection*{Materials and Methods} 

a <- knitr::combine_words(.packages(), 
before = "\\texttt{", after ="}")

For this hard work we used the 
with  the  packages \Sexpr{a}.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.