[Tex/LaTex] lstinline – source code


I want to use \lstinline for displaying inline source code in text. This code can contain various characters from different programming languages. For example

while{$a || $b}

This text doesn't work in any of these forms because it contains start/end character of lstinline.



    % works
    \lstinline|while{$a && $b}|

    % doesn't work
    \lstlinline{while{$a || $b}}
    \lstlinline|while{$a || $b}|
    \lstlinline$while{$a || $b}$

I am looking for universal solution for multiple languages so there are many characters I can't use in this case (!, ^, ., {, |, etc…).

Is that possible with lstinline? If not, is there any good alternative? Thanks.

Best Answer

The command is \lstinline, not \lstlinline. If { and } pairs occur in the code, it's better to use the \lstinline[...]!some code! way.

The language etc. and other settings can be done in the optional argument. (the language=C setting is wrong for the given programming language -- it's not C, of course)




\lstinline[language=C]!while{$a || $b}!

enter image description here

Related Question