1

Following this answer, I've tried to embed a listing with long lines into a beamer frame.

I'd like to have a nice red arrow at the line break (as show here).

The parameters prebreak and postbreak give an error while compiling it. As a matter of fact, it's the \textcolor that gives the error.

Here is the adapted MWE :

\documentclass[xcolor={svgnames,usenames,dvipsnames,table}]{beamer}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{listings}

\lstset{%
    xleftmargin=3.4pt,
    xrightmargin=3.4pt,
    %keepspaces=true,
    columns=fullflexible,   % Rasterize the columns
    frame=single,
    basicstyle=\ttfamily\small,
    inputencoding=utf8,
    extendedchars=\true,
    backgroundcolor=\color{black!10},
    breaklines=true,
% This works
    postbreak=\mbox{$\hookrightarrow$\space},
% This does not work
    postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
}


\begin{document}

\begin{frame}[fragile]{Test}
\begin{lstlisting}
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{frame}
\end{document}

Here is the output of the code, without the \textcolor obviously.

MWE output

If I uncomment the postbreak line, I get this error :

! Missing number, treated as zero.
<to be read again> 
                   \kern 
l.3 This 
         is a long line. This is a long line. This is a long line. This is a...
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

Any ideas on why does the textcolor makes things crash ?

  • 3
    It is probably a good idea to leave that postbreak line uncommented in the MWE. Then it would fail without the user having to do anything. Here we have to read the MWE to know that it only fails if you remove a % – daleif Oct 27 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.