0

I'm new to latex and trying to put my R codes in latex, which I have done in the following way:

\lstset{language=R,
    basicstyle=\small\ttfamily,
    stringstyle=\color{DarkGreen},
    otherkeywords={0,1,2,3,4,5,6,7,8,9},
    morekeywords={TRUE,FALSE},
    deletekeywords={data,frame,length,as,character},
    keywordstyle=\color{blue},
    commentstyle=\color{DarkGreen},
}

To add a block of code I use start\lstset and end\lstset. But to give an explanation of the codes in a sentence, I want to include some text written in R language. For example in the following sentence, I want sapply dflapop function(x) to appear in R language also in color. How can I do this?

The function sapply calls the dataframe of the corresponding dataset, which is dflapop in this case, and returns a vector conditioned by function(x) that sums up all values that are missing.

3
  • 2
    I am not sure if I understand your question; but I t seems to me that you would be best off with packages minted and fancyvrb. I this there are more suited to your needs. Oct 5, 2020 at 8:23
  • Do you know R the package knitr ? it can execute the R code in a LaTeX file (with .Rnw extension) , or show it with a highlight syntax, or both things. There are many examples of use in this site.
    – Fran
    Oct 5, 2020 at 8:40
  • In addition to Fran's comment: overleaf.com/learn/latex/Knitr
    – Nico
    Oct 5, 2020 at 11:19

1 Answer 1

2

If you want use \verb+monofont+ like snippets in text you can use \lstinline!function(x)!.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .