# Help defining PDF syntax with listings package

I'm trying to make a pdf language definition for the listings package, but I can't get the string definition to work correctly. This is what I have defined:

\lstdefinelanguage{pdf}{
alsoletter={/,(,)},
morekeywords={/Type,/Outlines, /Count, /Kids, /Page,
/Parent, /Resources, /MediaBox, /Contents, /Length, /ProcSet, /PDF, /Size,
/Root, /Pages, /Catalog, /Font, /F1, /F2, /Text, /Subtype, /Type1, /Name,
/BaseFont, /Helvetica-Bold, /Encoding, /MacRomanEncoding, /Helvetica},
morecomment=[l]{\%},
morestring=[s]{(}{)}
}


Here you can see the result:

It should either go from ( to ), or maybe from BT to ET (which is what vim does).

Okay. So I figured it out. For some reasons using breaklines=true creates this error.

Here is a minimal working example that produces the error:

\documentclass[a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel, listings, color}
\definecolor{darkviolet}{rgb}{0.5,0,0.4}
\definecolor{darkgreen}{rgb}{0,0.4,0.2}
\definecolor{darkblue}{rgb}{0.1,0.1,0.9}

\lstset{ %
keywordstyle=\color{darkviolet},
stringstyle=\color{darkblue},
breaklines=true,% Produces the error in the highlighting
}

\lstdefinelanguage{pdf}{
alsoletter={/},
morekeywords={/Length, /F1},
morecomment=[l]{\%},
morestring=[s]{(}{)}
}

\begin{document}
\begin{lstlisting}[language=pdf]
%PDF-1.0

5 0 obj
<< /Length 44 >>
stream
BT
/F1 27 Tf
100 100 Td (Hello World) Tj
ET
endstream
endobj

%%EOF
\end{lstlisting}
\end{document}


But I need to have breaklines set to true. So anybody know a reason why this is happening? Or is it just a bug in the listings package?

-
Unfortunately I have no solution. Maybe you are interested in minted with the language postscript: pygments.org/demo/82411 –  Marco Daniel May 25 '13 at 9:56
–  Jubobs Mar 11 '14 at 21:18
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 18 '14 at 16:03

There appears top be special code "currently only for )" when breakline is active (listings.dtx 1.4, l. 12576):

% \begin{macro}{\lst@breakProcessOther}
% is the same as |\lst@ProcessOther| except that it also outputs the current
% token string. This inserts a potential linebreak point.
% Only the closing parenthesis uses this macro yet.
%    \begin{macrocode}
\gdef\lst@breakProcessOther#1{\lst@ProcessOther#1\lst@OutputOther}
{\lst@ifbreaklines \lst@Def{)}{\lst@breakProcessOther)}\fi}
%    \end{macrocode}


There are probably better ways to remove that from the hook again, but this seems to do, when put in the preamble:

\makeatletter
\def\uglypatch #1\lst@ifbreaklines#2\fi#3\uglypatch{%
\long\def\lsthk@SelectCharTable{#1#3}%
}
\lst@ifbreaklines
\expandafter\uglypatch\lsthk@SelectCharTable\uglypatch
\fi
\makeatother
`
-