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.
\usepackage{textcomp}? You probably have some customizations that require this package. – egreg May 09 '12 at 10:07textcompbefore modifying the listings styles. i will update the question in a minute. – q9f May 09 '12 at 10:17xcoloralong withtextcomp– May 09 '12 at 10:26listingsshouldn't let you useupquote=trueif thetextcomppackage has not been loaded. So if your complete, small example above still gives the error you should (beside loadingtextcomp) also check your package version. – Ulrike Fischer May 09 '12 at 12:03matlab-prettifierpackage; see this answer. – jub0bs Apr 28 '14 at 15:52