0

I have the following latex code

\begin{lstlisting}[escapechar=\%]
begin
  begin
    \alpha;
    i = 5

  ...
\end{lstlisting}

and I would like to have the \alpha be rendered as a but it seems to still render as \alpha. How can I get it to render as a

Thanks in advance

  • 4
    Look up Escaping to LaTeX in the listings manual – daleif Jun 12 '20 at 8:39
  • 1
    Welcome to TeX - LaTeX! Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem. – Alessandro Cuttin Jun 12 '20 at 9:43
0

You can typeset maths using LaTeX code in a lstlisting environment when setting the key mathescape as true.

\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[escapechar=\%, mathescape=true]
begin
  begin
    $\alpha$;
    i = 5

  ...
\end{lstlisting}
\end{document}

There are other ways to achieve similar results. As said by @daleif in the comments, it is described in more details in the section Escaping to LaTeX of listings's documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.