[Tex/LaTex] insert code keywords inline


What is the command to insert inline code words into the text like this?
enter image description here

I know there are packages for inserting snippets into the code, but I need to insert keywords within the main text. I was wondering if there is a more convenient way to do that.

Best Answer

The package listings provides \lstinline for such short snippets. The advantage of such a package is its awareness of keywords etc.

In principle any formatting can be used for the 'code' -- as long as the syntax does not interfere with TeX/LaTeX syntax all is well.

The package xparse allows for verbatim arguments, it can be used as well.





\lstset{language=C,keywordstyle={\bfseries \color{blue}}}


\lstinline{for} or \lstinline{while} or \lstinline{main}

\codeword{Here} you \codeword{see} an \codeword{example} of \codeword{an} inline \codeword{code}


enter image description here

Related Question