# LaTeX/Packages/Listings and subindex

I am using LaTeX/Packages/Listings AND this code to make a rectangle with sql source code inside of it, but I would like to have the option to insert subindexes...

I try it using the following but had no success, any idea?

\begin{lstlisting}
SELECT  SUM($x_{1}$ *$x_{1}$ FROM X;
\end{lstlisting}

I would like to make the $x_1$ shows right

• I think you need to add mathescape=true. – Peter Grill Nov 20 '11 at 20:01

You need to add mathescape=true. Here is the output without and with this added:

\documentclass[border=2pt]{standalone}
\usepackage{xcolor}
\usepackage{listings}

\begin{document}
SELECT  SUM($x_{1}$ *$x_{1}$ FROM X;
SELECT  SUM($x_{1}$ *$x_{1}$ FROM X;