diff --git a/doc/generic/pgf/CHANGELOG.md b/doc/generic/pgf/CHANGELOG.md index 5b4cff84c..0aef99f64 100644 --- a/doc/generic/pgf/CHANGELOG.md +++ b/doc/generic/pgf/CHANGELOG.md @@ -81,6 +81,7 @@ lot of contributed changes. Thanks to everyone who volunteered their time! - Make `graphdrawing` work with `name prefix` and `name suffix` options #1087 - pgfkeys was a bit too relaxed around `\relax` #1132 - Remove spurious spaces for `3d view` #1151 +- Fix incorrectly placed matrix delimiters for implicitly positioned nodes #1102 ### Changed diff --git a/testfiles/gh-issue-1102.lvt b/testfiles/gh-issue-1102.lvt new file mode 100644 index 000000000..25aee24b1 --- /dev/null +++ b/testfiles/gh-issue-1102.lvt @@ -0,0 +1,76 @@ +\documentclass{minimal} +\input{pgf-regression-test} + +\RequirePackage{tikz} +\usetikzlibrary{calc, matrix} + +\begin{document} + +\setbox0=\hbox{$()$} % avoid logging font info cmex10 at test for "matrix delimiters" + +\START + +\SEPARATOR +\TYPE{Testing that special nodes are placed at expected position^^J% + when main nodes are implicitly positioned.} +\SEPARATOR + +\BEGINTEST{labels} +% adapted from https://github.com/pgf-tikz/pgf/issues/126 +\begin{tikzpicture}[L/.style={label={[name=#1]above:{.}}}] + \draw (0,4) -- (3,4) node[midway, L=a] (A) {A}; + \draw (0,3) -- node[L=b] (B) {B} (3,3); + + \draw (0,2) -- (3,2) node[near end, L=c] (C) {C}; + \draw (0,1) -- node[near end, L=d] (D) {D} (3,1); + + % `label distance` is initially 0pt + \AssertTikzPointEquals{(a.south)}{(A.north)} + \AssertTikzPointEquals{(b.south)}{(B.north)} + \AssertTikzPointEquals{(c.south)}{(C.north)} + \AssertTikzPointEquals{(d.south)}{(D.north)} +\end{tikzpicture} +\ENDTEST + +\BEGINTEST{pins} +\catcode`\@=11\relax +\def\distance{\tikz@pin@distance} +\catcode`\@=12\relax + +\begin{tikzpicture}[P/.style={pin={[name=#1]above:{.}}}] + \draw (0,4) -- (3,4) node[midway, P=a] (A) {A}; + \draw (0,3) -- node[P=b] (B) {B} (3,3); + + \draw (0,2) -- (3,2) node[near end, P=c] (C) {C}; + \draw (0,1) -- node[near end, P=d] (D) {D} (3,1); + + \AssertTikzPointEquals{(a.south)}{($ (A.north) + (0pt,\distance) $)} + \AssertTikzPointEquals{(b.south)}{($ (B.north) + (0pt,\distance) $)} + \AssertTikzPointEquals{(c.south)}{($ (C.north) + (0pt,\distance) $)} + \AssertTikzPointEquals{(d.south)}{($ (D.north) + (0pt,\distance) $)} +\end{tikzpicture} +\ENDTEST + +\BEGINTEST{matrix delimiters} +% adapted from https://github.com/pgf-tikz/pgf/issues/1102 +\begin{tikzpicture}[ampersand replacement=\&, + every left delimiter/.style={name=left}, + every right delimiter/.style={name=right}, + every above delimiter/.style={name=above}, + every below delimiter/.style={name=below}] + + \draw[->] (0, 0) -- + node[matrix of math nodes, anchor=north, + left delimiter=(, right delimiter=), + above delimiter=\{, below delimiter=\}] (M) + {0 \& -1 \\ 1 \& 0 \\} + (1, 0); + + \AssertTikzPointEquals{(M.south west)}{(left.south east)} + \AssertTikzPointEquals{(M.south east)}{(right.south west)} + \AssertTikzPointEquals{(M.north west)}{(above.south east)} + \AssertTikzPointEquals{(M.south west)}{(below.south west)} +\end{tikzpicture} +\ENDTEST + +\END diff --git a/testfiles/gh-issue-1102.tlg b/testfiles/gh-issue-1102.tlg new file mode 100644 index 000000000..230b48c4c --- /dev/null +++ b/testfiles/gh-issue-1102.tlg @@ -0,0 +1,30 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +============================================================ +Testing that special nodes are placed at expected position +when main nodes are implicitly positioned. +============================================================ +============================================================ +TEST 1: labels +============================================================ +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 2: pins +============================================================ +PASSED +PASSED +PASSED +PASSED +============================================================ +============================================================ +TEST 3: matrix delimiters +============================================================ +PASSED +PASSED +PASSED +PASSED +============================================================ diff --git a/testfiles/support/pgf-regression-test.tex b/testfiles/support/pgf-regression-test.tex index 9b2aa9573..10ac9bceb 100644 --- a/testfiles/support/pgf-regression-test.tex +++ b/testfiles/support/pgf-regression-test.tex @@ -1,6 +1,7 @@ \input regression-test.tex \OMIT +\catcode`\@=11\relax \newbox\PGFTESTBOX @@ -38,4 +39,100 @@ \ENDTEST } +% more typeout commands +\def\PASSED {\TYPE{PASSED}} +\def\FAILED {\TYPE{FAILED}} +\long\def\FAILEDAT#1{\TYPE{FAILED at #1}} + +% more assert commands, which if fails will typeout more diagnostic info +\newif\ifassert@return +\newdimen\assert@equals@tolerance + +% \AssertPointEquals[]{}{} +% [] omitted -> assert equiality within 0.001pt +% ::= | +\protected\long\def\AssertTikzPointEquals{% + \begingroup + \pgfutil@ifnextchar[%] + {\AssertTikzPointEquals@opt} + {\AssertTikzPointEquals@}% +} + +\protected\long\def\AssertTikzPointEquals@opt[#1]#2#3{% + \edef\assert@input{% + \string\AssertTikzPointEquals\unexpanded{[#1]{#2}{#3}}}% + \AssertTikzPointEquals@@[{#1}]{#2}{#3}% +} + +\protected\long\def\AssertTikzPointEquals@#1#2{% + \edef\assert@input{% + \string\AssertTikzPointEquals\unexpanded{{#1}{#2}}}% + \AssertTikzPointEquals@@[.001pt]{#1}{#2}% +} + +\protected\long\def\AssertTikzPointEquals@@[#1]#2#3{% + \assert@equals@tolerance=\dimexpr#1\relax + \ifdim\assert@equals@tolerance<0pt + \TYPE{\string\AssertTikzPointEquals: negative tolerance \the\assert@equals@tolerance}% + \fi + \expandafter\TikzGetOnePoint\expandafter{#2}\assert@tempa + \expandafter\TikzGetOnePoint\expandafter{#3}\assert@tempb + \assert@returntrue + \ifx\assert@tempa\assert@tempb + \else + \assert@tempa\pgf@xa=\pgf@x\pgf@ya=\pgf@y + \assert@tempb%\pgf@xb=\pgf@x\pgf@yb=\pgf@y + % + \ifdim\pgf@x>\dimexpr\pgf@xa+\assert@equals@tolerance\relax + \else + \ifdim\pgf@x<\dimexpr\pgf@xa-\assert@equals@tolerance\relax + \assert@returnfalse + \else + \ifdim\pgf@y>\dimexpr\pgf@ya+\assert@equals@tolerance\relax + \assert@returnfalse + \else + \ifdim\pgf@y<\dimexpr\pgf@ya-\assert@equals@tolerance\relax + \assert@returnfalse + \fi + \fi + \fi + \fi + \fi + \ifassert@return + \PASSED + \else + \FAILEDAT{\assert@input}% + \TYPE{% + - Expected: \detokenize\expandafter{#2} => (\the\pgf@xa, \the\pgf@ya)^^J% + - Actual: \space\space\detokenize\expandafter{#3} => (\the\pgf@x, \the\pgf@y)^^J% + - Tolerance: \the\assert@equals@tolerance + }% + \fi + \endgroup +} + +% pgf or tikz specific testing commands + +% \TikzGetOnePoint{}{} +% ::= | +\protected\long\def\TikzGetOnePoint#1#2{% + \pgfutil@ifnextchar\pgfqpoint + {\TikzGetOnePoint@{#2}} + {\def\assert@tempc{\TikzGetOnePoint@@{#2}}% + \tikz@scan@one@point\assert@tempc}% + #1% +} + +% \TikzGetOnePoint@{}\pgfqpoint{}{} +\protected\long\def\TikzGetOnePoint@#1#2#3#4{% + \TikzGetOnePoint@@{#1}{\pgfqpoint{#3}{#4}}% +} + +% \TikzGetOnePoint@@{}{} +\protected\long\def\TikzGetOnePoint@@#1#2{% + \pgf@process{#2}% + \edef#1{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% +} + +\catcode`\@=12\relax \TIMO diff --git a/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymatrix.code.tex b/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymatrix.code.tex index 507ac7a40..511818937 100644 --- a/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymatrix.code.tex +++ b/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymatrix.code.tex @@ -125,7 +125,7 @@ \def\tikz@delimiter#1#2#3#4#5#6#7#8{% \bgroup - \pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name}% + \pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name\tikz@node@is@a@labelfalse}% node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3] {% {\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}%