Re: listings fails in certain corner cases

Lars Madsen via texhax <[email protected]> Fri, 21 Nov 2025 09:45:14 +0000
Newsgroups gmane.comp.tex.texhax
Message-ID <GV2PR01MB12098D97D6B20EBE830CAF91FF2D5A@GV2PR01MB12098.eurprd01.prod.exchangelabs.com>
Using a \lstinline inside a \section seems like a very big no-no to me. Without it the document compiles just fine.



Lars Madsen
Programmør

Institut for Matematik
Aarhus Universitet

person.au.dk/daleif@math<https://person.au.dk/daleif@math>

________________________________
From: texhax <[email protected]> on behalf of Boylan, Ross via texhax <[email protected]>
Sent: 21 November 2025 10:06
To: '[email protected]' <[email protected]>; '[email protected]' <[email protected]>
Cc: Ross Boylan <[email protected]>; Boylan, Ross <[email protected]>
Subject: listings fails in certain corner cases


I was unable to latex my input file in some cases, getting the following error on a line inside of a lstlisting environment from the listings package:



ERROR: Extra }, or forgotten \endgroup.



--- TeX said ---

<recently read> \egroup



l.68   and

           I go on



I have attached a MWE, which is not so small.  There seem to be at least 2 necessary ingredients:

  1.  The \begin{lstlisting} starts at or near the bottom of one page, but the output it produces ends up on the next page.
  2.  The page header and footer (fancyhdr package) contains some text that uses \lstinline.



The first, alone, is insufficient.  This is with listings 1.11a (r76857), but I was getting the same problem with 1.10c.  After generating the attachments I upgraded listings to 1.11b; it made no difference.

Possibly the problem depends on some peculiarities of shipping the section title around for extramarks.



I think I have seen the problem even when the first line of the listing does end up on the bottom of the page before the rest continues on the next.



Papersize is default, which should be US Letter for me.



In some cases I’ve found putting a conditional break just before the listing (e.g., with the needspace package) is enough to clear up the problem.  Removing the \lstinline from the section name also “solves” it.



Even in  simple cases, i.e., 1 but not 2, I still get strange behavior: later sections of the listing switch to showing spaces explicitly.



It would be great if this just worked.



By the way, the listings manual doesn’t say anything explicitly that I could find about how or if it handles material that crosses pages, though there is some discussion of float behavior.



Thanks.

Ross Boylan