12

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.

q9f
  • 1,995
  • 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 09 '12 at 10:05
  • 2
    Did you say \usepackage{textcomp}? You probably have some customizations that require this package. – egreg May 09 '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. – q9f May 09 '12 at 10:17
  • You also need to add xcolor along with textcomp –  May 09 '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 09 '12 at 12:03
  • You might be interested in the matlab-prettifier package; see this answer. – jub0bs Apr 28 '14 at 15:52

1 Answers1

13

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

\usepackage{xcolor}
\usepackage{textcomp}

Tested with TeX Live 2012.

Marco Daniel
  • 95,681