Skip to content

Make the lstlistings inside a node work again #1420

@AlMa1r

Description

@AlMa1r

Brief outline of the bug

Somewhere between the final TeX Live 2023 and the final TeX Live 2024, we can no longer place a program listing (the lstlisting environment) into a node. Discussion: https://tex.stackexchange.com/questions/751789/what-changed-between-the-final-texlive-2023-and-the-final-texlive-2024-concernin . LaTeX evolved, but TikZ (apparently and in this specific regard) did not. We kindly ask to restore the functionality (program listings inside nodes) without workarounds.

Minimal non-working example (MnWE)

\documentclass{article}% compile with latex or pdflatex from the final TeX Live 2024 or later
\usepackage{listings}
\usepackage{tikz}% 2023-01-15 v3.1.10 (3.1.10)
\begin{document}
\begin{tikzpicture}
\node {\begin{lstlisting}
\end{lstlisting}};
\end{tikzpicture}
\end{document}

Known workarounds (thx to @jlab, @cfr, and @ulrike-fischer)

\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node {\hbox{\begin{lstlisting}
\end{lstlisting}}};
\end{tikzpicture}
\end{document}

and

\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node {\begin{lstlisting}
\end{lstlisting}\par};
\end{tikzpicture}
\end{document}

and

\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node {\begin{lstlisting}
\end{lstlisting}

};
\end{tikzpicture}
\end{document}

and

\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\makeatletter
\AddToHook{env/lstlisting/after}{\@endpefalse}
\makeatother
\begin{document}
\begin{tikzpicture}
\node {\begin{lstlisting}
\end{lstlisting}};
\end{tikzpicture}
\end{document}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions