Writing code in a line without starting new line

Viewed 2049

When I write code in platex using {lstlisting}

\begin{lstlisting}
if True:
   print("latex")
\end{lstlisting}

However how can I put the code in the sentence??

like the ` in stackoverflow.

I want to show like below

"Please look at this code print("latex") ,this code is nice"

2 Answers

Also, the core macro verb:

\documentclass{article}

\begin{document}

Text text text \verb|code \ @ } code| text text.

\end{document}

Not only braces and vertical bars | can delimit the content or argument here (see the comments below) but any other character, as long as it is the same before and after and not part of the the inline code. For example \verb!code \ @ } code! will work just as well.

As you can see, special characters need no escape within verb.

You can use the \lstinline macro:

\documentclass{jarticle}

\usepackage{amsmath,amsfonts}

\usepackage{listings}

\begin{document}


test \lstinline|code| test

\end{document}
Related