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'm using the package listings and came across a problem displaying an SQL statement within an java environment. This is the MWE.

\documentclass[]{report}
\usepackage{listings}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
 backgroundcolor=\color{lbcolor},
 tabsize=4,
 rulecolor=,
 language=matlab,
 basicstyle=\scriptsize,
 upquote=true,
 aboveskip={1.5\baselineskip},
 columns=fixed,
 showstringspaces=false,
 extendedchars=true,
 breaklines=true,
 prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
 frame=single,
 showtabs=false,
 showspaces=false,
 showstringspaces=false,
 identifierstyle=\ttfamily,
 keywordstyle=\color[rgb]{0,0,1},
 commentstyle=\color[rgb]{0.133,0.545,0.133},
 stringstyle=\color[rgb]{0.627,0.126,0.941},
}

\begin{document}
\begin{lstlisting}[language=java]
  Connection db = DriverManager.getConnection("jdbc:h2:rel.db", "user", "pass");
  Statement stmt = db.createStatement();
  stmt.execupdate("INSERT INTO CAMPAIGN VALUES ('C1R1R2R3R4R5R6', 1234, 1170, 1189, 1934)");
\end{lstlisting}
\end{document}

The problem is in the 4th line as the SQL statement is using single quotes within a string. I get the latex error (from log):

! Undefined control sequence.
\lst@um'@ ->\lst@ifupquote \textquotesingle 
                                        \else \char 39\relax \fi 
l.299 ...cupdate("INSERT INTO CAMPAIGN VALUES ('C
                                              1R1R2R3R4R5R6', 1234, 117...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

How to fix this? Is this a bug - I don't get what's wrong with using single quotes within double quotes?

Update: Solution seems to be adding \usepackage{textcomp} before modifying the listings styles.

share|improve this question
    
Your excerpt works fine for me. What version of the listings package do you use? Could you provide a complete code example that shows the issue? –  Martin May 9 '12 at 10:05
2  
Did you say \usepackage{textcomp}? You probably have some customizations that require this package. –  egreg May 9 '12 at 10:07
    
hi, thanks for the comments, i was just about to create a minimal working example while noticing that i need to add the package textcomp before modifying the listings styles. i will update the question in a minute. –  vertoe May 9 '12 at 10:17
    
You also need to add xcolor along with textcomp –  Harish Kumar May 9 '12 at 10:26
1  
A current listings shouldn't let you use upquote=true if the textcomp package has not been loaded. So if your complete, small example above still gives the error you should (beside loading textcomp) also check your package version. –  Ulrike Fischer May 9 '12 at 12:03
add comment

1 Answer

up vote 5 down vote accepted

Your example works well if you add the two packages to your preamble:

\usepackage{xcolor}
\usepackage{textcomp}

Tested with TeX Live 2012.

share|improve this answer
add comment

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.