Skip to content
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

spath/transform={current}{...} doesn't work in postaction #31

Open
muzimuzhi opened this issue Jul 17, 2024 · 1 comment
Open

spath/transform={current}{...} doesn't work in postaction #31

muzimuzhi opened this issue Jul 17, 2024 · 1 comment

Comments

@muzimuzhi
Copy link

But it works in preaction.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spath3}

\begin{document}
Pre-action
\begin{tikzpicture}[line width=1pt]
  \path[draw=red, draw opacity=.5]
       [preaction ={draw=blue,
                    spath/transform={current}{xshift=10pt}}]
    (0,0) rectangle (1,.8);
\end{tikzpicture}

Post-action
\begin{tikzpicture}[line width=1pt]
  \path[draw=red, draw opacity=.5]
       [postaction={draw=blue,
                    spath/transform={current}{xshift=10pt}}]
    (0,0) rectangle (1,.8);
\end{tikzpicture}
\end{document}

image

@loopspace
Copy link
Owner

This is a "feature" of how pre- and post-actions are done and how they differ. It's subtle, so I think it definitely warrants a clear example in the documentation.

Because a pre-action is enacted before the main action, the path that's been oh-so-carefully constructed is already in position for the pre-action. Therefore, when the options of the pre-action are parsed, the current path is the expected path.

However, when a post-action is enacted then the main action has already happened, clearing the current path. Therefore it needs to restore the defined path to the current path at some point. The code that does this and that parses the options does it in the "usual" order: parse the options then set the path (this is what happens on a normal path). This means that when the spath/transform=... key is parsed then there is no current path.

The solution is the same as wanting to set an option on the main path that affects the whole path, but needing to specify it in the options before the path is constructed: to use the key spath/at end path construction.

Here's your example:

Pre-action
\begin{tikzpicture}[line width=1pt]
  \path[draw=red, draw opacity=.5]
       [preaction ={draw=blue,
                    spath/transform={current}{xshift=10pt}}]
    (0,0) rectangle (1,.8);
\end{tikzpicture}

Post-action
\begin{tikzpicture}[line width=1pt]
  \path[draw=red, draw opacity=.5]
[postaction={draw=blue,
    spath/at end path construction={
      \tikzset{
        spath/transform={current}{xshift=10pt}
      }
    }
  }
]
    (0,0) rectangle (1,.8);
\end{tikzpicture}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants