2

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?

\lstset{language=SQL, caption=SQL, label=SQL, frame=shadowbox, rulesepcolor=\color{blue}}
\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
2

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

enter image description here

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

\begin{document}
\lstset{language=SQL, caption=SQL, label=SQL, frame=shadowbox, rulesepcolor=\color{blue}}
\begin{lstlisting}
       SELECT  SUM($x_{1}$ *$x_{1}$ FROM X;
\end{lstlisting}

\begin{lstlisting}[mathescape=true]
       SELECT  SUM($x_{1}$ *$x_{1}$ FROM X;
\end{lstlisting}
\end{document}
  • One more question, Is it possible to change the title "Listing 1", "Listing 2".... "Listing n"? to a different title? – cMinor Nov 20 '11 at 20:08
  • @cMinor \renewcommand{\lstlistingname}{Code} will change Listing n to Code n. – Torbjørn T. Nov 20 '11 at 20:21

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.