latex3 / tagging-project

Issues related to the tagging project
https://latex3.github.io/tagging-project/
LaTeX Project Public License v1.3c
42 stars 15 forks source link

math tagging incompatible with pgf's "matrix of math nodes" #30

Open mbertucci47 opened 1 year ago

mbertucci47 commented 1 year ago

The math tagging code is incompatible with the tikz library matrix's key matrix of math nodes:

\DocumentMetadata{testphase={phase-III,math}}
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}
\matrix[matrix of math nodes]
  {
    A & B \\
  };
\end{tikzpicture}

\end{document}

gives the error

! Argument of \__math_grab_dollar:w has an extra }.

A normal tikz \matrix or matrix of nodes like

\begin{tikzpicture}
\matrix[matrix of nodes]{A & B\\};
\end{tikzpicture}

works fine.

Originally I encountered this because I was trying to determine why the math tagging didn't work with tikz-cd (which uses matrix of math nodes, I think), however that gives a different error.

\DocumentMetadata{testphase={phase-III,math}}
\documentclass{article}

\usepackage{tikz-cd}

\begin{document}

\[\begin{tikzcd}
  A & B
\end{tikzcd}\]

\end{document}

produces

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options

and

! Package pgf Error: Single ampersand used with wrong catcode.

If the tikz-cd incompatibility is more appropriate as a separate issue I can make another.

u-fischer commented 1 year ago

hm yes. I think that counts as "currently incompatible". The tikz code hides the end dollar and so the grabbing code can't find it.

Your second error is a different issue: The problem is that tikzcd is a verbatim-like environment: it wants to change the catcode of &, and so can't be used as argument in another command. You would get the same error with

\documentclass{article}

\usepackage{tikz-cd}
\begin{document}
\newcommand\test{\[\begin{tikzcd}
  A & B
\end{tikzcd}\]}
\test
\end{document}

Use this instead (see the tikz-cd docu: Issues with active characters):

\DocumentMetadata{testphase={phase-III,math}}
\documentclass{article}

\usepackage{tikz-cd}
\begin{document}
\[\begin{tikzcd}[ampersand replacement=\&,]
  A \& B
\end{tikzcd}\]
\end{document}