# How can I use commands in a listlisting

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 ⍺

• Look up Escaping to LaTeX in the listings manual – daleif Jun 12 '20 at 8:39
• 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

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.