Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
I think you need to add mathescape=true. –  Peter Grill Nov 20 '11 at 20:01

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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