latex3 / tagpdf

Tagging support code for LaTeX
59 stars 7 forks source link

`\color` (even deeply nested) at start of an item leaks to the label (but not `\textcolor`) #80

Closed jfbu closed 8 months ago

jfbu commented 1 year ago
\DocumentMetadata{testphase={block-tagging}}
\documentclass{article}
\usepackage{color}

\newcommand\blueit[1]{\textcolor{blue}{#1}}
\newcommand\redit[1]{{{{{{{\color{red}#1}}}}}}}

\begin{document}
\begin{itemize}
\item \blueit{blue}
\item \redit{red}
\item bla \redit{red}
\end{itemize}

Text:
\blueit{blue}
\redit{red}
black
\end{document}

produces

Capture d’écran 2023-05-18 à 14 02 45

test_tagging_item.log

u-fischer commented 1 year ago

You really shouldn't use \color without starting a paragraph first. Think at the known problems with tabulars:

\begin{tabular}{p{1cm}p{1cm}}
\blueit{blue} & \redit{red}
\end{tabular}

image

And it is also not a good idea to start a paragraph in a group, even more with tagging which relies a lot on the para-hooks.

So do \newcommand\redit[1]{\leavevmode{{{{{{\color{red}#1}}}}}}} (\textcolor contains a \leavevmode, that's why it is not affected).

jfbu commented 1 year ago

Original context was a bit complex and the macro (actually via an active char doing verb-like stuff) was redefined mid-way in the document and only then started using \color in one branch of an (expandable) test. A priori it was not probable it would be used at start of paragraph but with list items it is exactly what happened. The original had simply \begingroup...\endgroup. I have prefixed it all with \leavevmode.

With this (and item-label in place of label to get my bullet's) the color leaks seen there are gone.