-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support & in matrices without catcode change #1081
base: master
Are you sure you want to change the base?
Conversation
This is an interesting proposal but it needs very careful testing because there are a lot of downstream consumers of this code like Please also sign-off on your commits. It can be done in batch using git remote update
git rebase --exec 'git commit --amend --no-edit -n -s' @{upstream} |
1b3b602
to
6887d3f
Compare
All commits should be signed off now. (Done with The manual of I understand that lot more testing is necessary. |
Column separation is handled by modifying the bounding box of cells. Adjust this to handle the case when [between origins] is specified in later rows, like \begin{tikzpicture} \matrix[column sep={5mm,between origins}, nodes=draw]{ \node{1}; & \node(2){2}; \\ \node{3}; & \node{4}; & \node(5){5}; \\ }; \draw (5) -- (2); \end{tikzpicture} Signed-off-by: Gábor Braun <[email protected]>
Signed-off-by: Gábor Braun <[email protected]>
Upcoming changes require that \pgfmatrixendrow start with &, and column separation will need to be saved as well, as it will be processed later outside the cell group. These are to support constructs like (see bug pgf-tikz#503) \matrix[every odd row/.style={row sep=1cm}] {...}; Signed-off-by: Gábor Braun <[email protected]>
This is a step towards supporting & in place of \pgfmatrixnextcell, as & is not able to immediately process any argument. Move code from \pgf@matrix@endcell to \pgfmatrixnextcell. Remove \pgf@matrix@process@nextcell@options, no longer used. Notable aspects of the move needing care: 1) The test \ifpgf@matrix@last@cell@in@row has been omitted, as no longer necessary, and no longer guaranteed to be correct. 2) The test \pgfmatrixcurrentcolumn < \pgf@matrix@numberofcolumns still yields the correct result, even though \pgf@matrix@numberofcolumns might have a different value. 3) \pgf@matrix@maxx might have a different value, but needs no change in code. Signed-off-by: Gábor Braun <[email protected]>
Last commit made it a noop code. Signed-off-by: Gábor Braun <[email protected]>
Signed-off-by: Gábor Braun <[email protected]>
Signed-off-by: Gábor Braun <[email protected]>
Detect it by the single token \pgf@matrix@endcell (brought in by & starting a new cell), which is easier to check than the two tokens \let\pgf@matrix@signal@cell@end. Signed-off-by: Gábor Braun <[email protected]>
Think of "\pgfmatrixnextcell &" or "\pgfmatrixendrow &". The usual trick for this is surround looking ahead of next character by "\ifnum\iffalse{\fi0=`}\fi" and "\ifnum`{=0}\fi", but here we use variants. \pgfmatrixnextcell: As the look ahead does not occur in math mode, do it in a TeX group. This defends again & or \cr ending up in a (hidden) temporary control sequence for a long time. \pgfmatrixendrow: Look for an optional argument in the \noalign group, where the trick is not necessary. Signed-off-by: Gábor Braun <[email protected]>
Signed-off-by: Gábor Braun <[email protected]>
There is no longer an ampersand "wrong catcode". In documentation promote & as cell separator, use it in all examples, and remove limitation due to catcode of ampersand. Still document \pgfmatrixnextcell, which is now simply &. The main technical idea is adding "\aftergroup\pgf@matrix@nextcell" to the \halign preamble. The macro \pgf@matrix@nextcell will be added after the cell group, i.e., right after "&" in user input, so TeX will see \pgf@matrix@nextcell as the first token of the next table cell. Now \pgf@matrix@nextcell does what \pgfmatricnextcell did before. Signed-off-by: Gábor Braun <[email protected]>
Signed-off-by: Gábor Braun <[email protected]>
Use \pgf@matrix@maxxCOLUMN instead, which might have a different value but doesn't need extra global assignments. Signed-off-by: Gábor Braun <[email protected]>
Temporarily redefine \pgfmatrixendcode in empty cells, which is a much simpler way to omit end code. Signed-off-by: Gábor Braun <[email protected]>
Since one part is extremely short. Signed-off-by: Gábor Braun <[email protected]>
This is to simplify code without changing functionality. Move \pgfmatrix@init@row out of halign header to this end. Signed-off-by: Gábor Braun <[email protected]>
Make less dimension calculations, glue insertions, assignments for the same result. Signed-off-by: Gábor Braun <[email protected]>
Simplify code to handle column separation in pgf matrices: change \pgf@picminx only once per matrix cell for this purpose. Signed-off-by: Gábor Braun <[email protected]>
6887d3f
to
30295a0
Compare
Include tests for packages: tikz-cd, tikz-dependency, beamer (deliberately ignoring advice to not use & as cell separator). Omit dvisvgm result for beamer: it contains complicated dvips specials. Signed-off-by: Gábor Braun <[email protected]>
30295a0
to
10a77b1
Compare
I have added some tests. On my machine they run successfully, but some fail on GitHub. How to access the directory build/test on GitHub, where l3build puts test results? |
I've opened PR #1114 to upload From the content of
|
Thank you for the diffs, they have helped. For dvisvgm, the font numbers differ, e.g., lualatex --output-format=dvi '\documentclass{article}\showoutput \begin{document} abc \end{document}' Other egines seem to print TeX names instead: |
|\pgfmatrixendrow| inside the \meta{matrix cells}. It suffices that | ||
the macros inside \meta{matrix cells} expand to these macros | ||
the macros inside \meta{matrix cells} expand to these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that the row is changed anyway, we can directly remove one of the remaining "double space" instances :)
the macros inside \meta{matrix cells} expand to these | |
the macros inside \meta{matrix cells} expand to these |
This PR is blocked by #1116. |
\halign\bgroup% | ||
\pgf@matrix@init@row% | ||
\halign\bgroup% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong. Why is \pgf@matrix@init@row
called outside of the \halign
?
{% | ||
\catcode`\&=13 | ||
\gdef\tikz@matrix@make@active@ampersand{% | ||
\def\tikz@matrix@make@active@ampersand{% | ||
\ifx\tikz@ampersand@replacement\pgfutil@empty% | ||
\catcode`\&=13% | ||
\let&=\pgfmatrixnextcell% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to set up \let&=\pgfmatrixnextcell
in case someone set &
active outside of the matrix. Existing code might do this to work around tokenization problems. That way an active &
will expand to non-active &
inside the matrix.
{%
\catcode`\&=13
\gdef\tikz@matrix@make@active@ampersand{%
\ifx\tikz@ampersand@replacement\pgfutil@empty%
%\catcode`\&=13% <--- removed
\let&=\pgfmatrixnextcell%
\else%
\expandafter\let\tikz@ampersand@replacement=\pgfmatrixnextcell%
\fi%
}%
}%
Sorry, I had already reviewed this a year ago, but forgot to hit send. |
and no longer change the catcode in TikZ
between origins
between columns not specified in the first row.The documentation has been adjusted to not promote anything else as & as cell separator. All examples now use &, except for style
/tikz/ampersand replacment
.The macro
\pgfmatrixnextcell
is still documented.Two examples have been slightly altered to showcase that
between origins
work between columns not specified in the first row.Motivation for this change
Supporting & gets rid of the documented problems when matrices appear at less common places or have content with &.
The optional argument of & is not available immediately, so
the code for column spacing needs changing anyway.
It was easier not to reproduce an undocumented, unexpected behavior. For explicitness, this change occurs early in the branch.
Simplification are mostly taking the opportunity, and not necessary for the changes above, and appear near end of the branch. Empty cell handling needed change anyway to work correctly for empy cells ending with &.
Testing performed
The commits have been tested with som TikZ pictures, mostly from the documentation. With the last commit the LuaTeX version of the PGF documentation compiles succesfully.
It has not been built for intermediate versions.
Checklist