insert code keywords inline

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.

\documentclass{article}

\usepackage{xcolor}
\usepackage{listings}

\usepackage{xparse}

\NewDocumentCommand{\codeword}{v}{%
\texttt{\textcolor{blue}{#1}}%
}

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

\begin{document}

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

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

\end{document}

enter image description here


This is also possible using the minted package and the highlighting tool pygmentize

The command for minted inline code is called \mintinline{language}{code}

The inline highlighting will only colorize keywords, that are defined for the language and colored properly according to the highlighting style you choose.

\documentclass{scrartcl}

\usepackage{minted}
\usemintedstyle{vs}

\begin{document}
    To create a table you could use the command \mintinline{MySQL}{ALTER TABLE}. 
    While  \mintinline{MySQL}{DROP TABLE} deletes a table,
    \mintinline{MySQL}{INSERT} enables you to insert something into a table.
\end{document}

Which gives you:

enter image description here

Note that the default highlighting style gives you green keywords and you need to use --shell-escape to get pygmentize to work.

Tags:

Inline

Code