Search code examples
latex

Writing code in a line without starting new line


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"


Solution

  • You can use the \lstinline macro:

    \documentclass{jarticle}
    
    \usepackage{amsmath,amsfonts}
    
    \usepackage{listings}
    
    \begin{document}
    
    
    test \lstinline|code| test
    
    \end{document}