[texhax] RE: [listing.sty] \item[lstinline{foo}] howto?
Morten Høgholm
moho01ab at student.cbs.dk
Fri Nov 19 14:14:04 CET 2004
On Thu, 18 Nov 2004 08:50:16 +0100, Morten Høgholm
<moho01ab at student.cbs.dk> wrote:
> On Thu, 18 Nov 2004 07:31:16 +0100, Goebel, Juergen, OPE26
> <juergen.goebel at eads.com> wrote:
>
>>> Pavel Minev Penev [mailto:pavpen at berkeley.edu] wrote:
>>
>>> I don't have time to look at this, but as far as I remember, listings
>>> plays with the catcodes of characters at input (what mostly
>>> all verbatim
>>> environments do), thus, if you are trying to use a listing
>>> anywhere, but
>>> at the top level of macro expansion, it will not work
>>> (because catcodes
>>> will already have been defined for the characters to input).
>>
>> Thanks for the explanation. I'm going to see whether
>> the author thinks there is a solution ...
>
> What you can do is something like
>
> \newsavebox\JGbox
>
> \sbox\JGbox{\lstinline!ze_def.h!}
> \item[\usebox\JGbox]
I have now pinpointed the problem. The function \lst at Init contains many
lines of which the following are important to our problem:
\def\lst at Init#1{%
[...]
\ifhmode\ifinner \lst at boxtrue \fi\fi
\lst at ifbox
\lsthk at BoxUnsafe% check
\hbox to\z@\bgroup
$\if t\lst at boxpos \vtop
\else \if b\lst at boxpos \vbox
\else \vcenter \fi\fi
\bgroup \par\noindent
\else
[...]
}
The \par near the bottom of this snippet performs the action stored in the
current \everypar, which means that this special \everypar sets some
switches globally so that when \everypar is restored by listings later on,
it already thinks everything was done! The end result is missing output.
However the fix is quite easy, as one just have to add
\def\lst at Init#1{%
[...]
\ifhmode\ifinner \lst at boxtrue \fi\fi
\lst at ifbox
\lsthk at BoxUnsafe% check
\hbox to\z@\bgroup
$\if t\lst at boxpos \vtop
\else \if b\lst at boxpos \vbox
\else \vcenter \fi\fi
\bgroup \everypar{}%% <- This single |\everypar{}|.
\par\noindent
\else
[...]
}
Voila!
I'm cc'ing Carsten Heinz just in case.
--
Morten Høgholm
More information about the texhax
mailing list