Skip to content

listings package and misparsed strings #795

@teepeemm

Description

@teepeemm

I wanted to roll up my sleeves and attempt a contribution. I thought an easy first step would be the odd formatting in the trivial examples at http://dlmf.nist.gov/LaTeXML/manual/customization/customization.latexml.html#SS3. Surely it would just be a misplaced space.

I eventually figured out that it's actually a bug in listings.sty.ltxml. The \\' on the previous line gets misinterpreted and doesn't close the quote. Because the next two lines supposedly begin inside a quotation, spaces are represented incorrectly. This can be seen in the following:

\documentclass{article}

\usepackage{listings}

\begin{document}

\lstinline[language=Perl]!confused  '\\'  quotes;!

\begin{lstlisting}[language=Perl]
 confused  '\\'  quotes;
\end{lstlisting}

\end{document}

which results in an xml snippet of

<text class="ltx_lst_identifier">confused</text>
<text class="ltx_lst_space">  </text>
<text class="ltx_lst_string">’\\’<text class="ltx_lst_space">␣␣</text>quotes;’</text>

and an output of confused ’\\’␣␣quotes;’ both times. The latter two spaces become open boxes because latexml thinks we're still inside the quote, and then needs to add a third quote at the end of the line to make sure to close it.

It turns out that removing [language=Perl] from either command causes the spaces to render correctly. I think this is because without a language, there is nothing to say that strings should be formatted differently.

Unfortunately, digging into listings.sty.ltxml is beyond my current capabilities. If someone else is able to, great. If we can't track down where this is coming from, then would we want to at least paper over the bug showing up in the manual by switching the last two examples? That would put the misparsed quote at the end, so that no spaces come after.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions