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.
1 Answer
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}
\texttt{lavaan}
lavaan
in some way, it did not automatically become monospaced.\newcommand{\lavaan}{\texttt{lavaan}}
.