5

I want to get colorful prebreak and postbreak tokens with listings package, but the following code doesn't work:

\documentclass{article}
\usepackage{xcolor,listings}
\begin{document}
\begin{lstlisting}[basicstyle=\ttfamily,breaklines,prebreak={\space\color{teal}!},postbreak={\color{blue}!\space}]
This is a long line. This is a long line. This is a long line. This is a long line. This is a long line.
This is another long line. This is another long line. This is another long line. This is another long line.
\end{lstlisting}
\end{document}

How could I resolve this problem?

0

1 Answer 1

5

enter image description here

\documentclass{article}
\usepackage{xcolor,listings}
\begin{document}
\begin{lstlisting}[basicstyle=\ttfamily,breaklines,prebreak={\space\hbox{\textcolor{teal}{!}}},postbreak={\hbox{\textcolor{blue}{!}}\space}]
This is a long line. This is a long line. This is a long line. This is a long line. This is a long line.
This is another long line. This is another long line. This is another long line. This is another long line.
\end{lstlisting}
\end{document}
2
  • Why is there a need to wrap the \textcolor in a \hbox, here? Why is this error occurring?
    – jub0bs
    Apr 19, 2015 at 9:57
  • 3
    @Jubobs because if you don't You get an error message from tex telling you to do it:-) Remove the \hbox and you get ! Improper discretionary list. which is a primitive error in a \discretionary texbook says: more precisely, the horizontal list formed by each discretionary general text must consist only of characters, ligatures, kerns, boxes, and rules; there should be no glue or penalty items, etc Apr 19, 2015 at 10:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .