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.

Asked
Active
Viewed 149 times
1
1 Answers
2
This list the packages of a R session automatically, with the required format:
test.Rnw in Rstudio (or test.Rtex in Overleaf):
\documentclass{article}
\begin{document}
<<foo,echo=F>>=
library(xtable) # loaded only for test
library(ggplot2) # loaded only for test
@
\subsection*{A hard R work}
<<morefoo,echo=T>>=
2+3
@
\subsection*{Materials and Methods}
<<info,echo=F>>=
a <- knitr::combine_words(.packages(),
before = "\texttt{", after ="}")
@
For this hard work we used the
\Sexpr{sessionInfo()$R.version$version.string}
with the packages \Sexpr{a}.
\end{document}
Fran
- 80,769

\texttt{lavaan}– David Carlisle Aug 23 '22 at 17:41lavaanin some way, it did not automatically become monospaced. – David Carlisle Aug 23 '22 at 18:30\newcommand{\lavaan}{\texttt{lavaan}}. – murray Aug 23 '22 at 19:29