pgf icon indicating copy to clipboard operation
pgf copied to clipboard

[tl2021] TikZ coordinates like `([] {X}, {Y})` require excessive braces

Open ilyaza opened this issue 4 years ago • 10 comments

The syntax in the subject requires extra braces: ([] {{X}}, {{Y}}) works, but ([] {X}, {Y}) does not.

Minimal working example (MWE)

\documentclass{article}
\usepackage{tikz}

\begin{document}

  \tikz \path ([] {45+(45)}, 1);

\end{document}

gives ! Package pgf Error: No shape named 45+(45' is known.`

ilyaza avatar Dec 08 '21 10:12 ilyaza

Why do you need braces to start with?

ilayn avatar Dec 08 '21 10:12 ilayn

I'd argue that your placement of braces is wrong, i.e. I'd expect ([] {45+(45), 1}) but unfortunately that doesn't work either.

@muzimuzhi We have another brace-stripping problem.

@ilayn Nested parentheses. (For 45 + 45 you of course don't need extract parentheses)

hmenke avatar Dec 08 '21 10:12 hmenke

Nested parentheses need two braces since a decade but there is a strict usage for this. If you need coordinate manipulations you need calc. This has been also the case with https://tex.stackexchange.com/questions/29734/combining-and-5-in-tikz

ilayn avatar Dec 08 '21 10:12 ilayn

I use nested parentheses extensively for MANY years, and this is the first time I see a need for double braces. (But before I did not need ([] STUFF) syntax — this is only to work-around a bug in the plot subcommand.)

ilyaza avatar Dec 08 '21 11:12 ilyaza

Tests on overleaf's various texlive versions show this is a long-existing issue.

--- a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
+++ b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
@@ -5202,7 +5202,7 @@
 
 \def\tikz@scan@options[#1]#2{%
   \def\tikz@scan@point@options{#1}%
-  \tikz@@@scan@@absolute\tikz@scan@handle@options(#2%
+  \tikz@@@scan@@absolute\tikz@scan@handle@options({#2}%
 }%
 
 \def\tikz@scan@handle@options#1{%

The above proposal will make \tikz@scan@one@point accept ([] {45+(45)}, 1), but not ([] {45+(45), 1}). The pgfmanual reads (sec. 2.16 "Intersecting Paths"),

in general, you need to add braces around components of coordinates when these components contain parentheses

So it seems that fix is enough.

muzimuzhi avatar Dec 08 '21 12:12 muzimuzhi

After a second look, I question why \tikz@scan@options need its second parameter.

--- a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
+++ b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
@@ -5199,9 +5199,9 @@
   {\tikz@@@scan@@absolute#1(}%
 }%
 
-\def\tikz@scan@options[#1]#2{%
+\def\tikz@scan@options[#1]{%
   \def\tikz@scan@point@options{#1}%
-  \tikz@@@scan@@absolute\tikz@scan@handle@options(#2%
+  \tikz@@@scan@@absolute\tikz@scan@handle@options(%
 }%
 
 \def\tikz@scan@handle@options#1{%

muzimuzhi avatar Dec 08 '21 15:12 muzimuzhi

I use nested parentheses extensively for MANY years, and this is the first time I see a need for double braces.

Yes that's what I meant with strict usage that is coordinate syntax with options [] which @muzimuzhi is currently dissecting. Otherwise you can get away with it for some basic math. The issue I'm afraid is an XY problem that you are forcing one syntax too far to fix another. But I don't want to overreach

ilayn avatar Dec 08 '21 16:12 ilayn

Is this issue not fixed? I see @muzimuzhi already got a patch above.

That said, the patch would make

	\path ([] {45+(45), 1});

no longer work.

user202729 avatar Apr 26 '24 22:04 user202729

No, this issue is not fixed, as it still has an open state.

muzimuzhi avatar Apr 26 '24 22:04 muzimuzhi