# How to use mathematical symbols in listing?

I want to use math mode in lstlisting. How do I do that? How to put tab in this mode?

\begin{document}

module main()
enumerated States {$S_0$,$S_1$,$S_2$,$S_3$}
integer c;
initial : c = 0 and States = $S_0$;
endmodule
\end{lstlisting}


\end{document}

-
See 4.14 Escaping to LATEX of the documentation of listings. –  Ulrike Fischer Jul 18 '12 at 10:36

The escapeinside option allows you to define how to escape from verbaitm. Here's an example:

\begin{lstlisting}[escapeinside={(*}{*)}]
if foo
list= { (*$S_1,S_2,S_3$*) }
\end{lstlisting}


I've used escapeinside to define an opening (* and closing *) escape commands. Things between (* and *) will be typeset normally. Obviously, if (* or *) are common in whatever language you're using, you should pick something else.

In fact, if all you want to do is escape maths, you can use the mathescape option:

\begin{lstlisting}[mathescape=true]
if foo
list= { $S_1,S_2,S_3$ }
\end{lstlisting}

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9063401818275452, "perplexity": 4900.684618323198}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-49/segments/1416400378047.50/warc/CC-MAIN-20141119123258-00033-ip-10-235-23-156.ec2.internal.warc.gz"}