!NuxCISwYQJuyWwNsEI:matrix.org

PGF/TikZ

52 Members
https://github.com/pgf-tikz11 Servers

Load older messages


SenderMessageTime
30 Jan 2022
@r_mano:matrix.orgRomano GiannettiSo, I was looking to a strange artifact in circuitikz, and I found this... which is clearly operator error (do not fill an open path), but it surprised me.21:29:19
@r_mano:matrix.orgRomano Giannetti
21:29:39
@r_mano:matrix.orgRomano Giannetti *
21:29:48
@r_mano:matrix.orgRomano Giannetti *
\documentclass[margin=1cm]{standalone}

\usepackage{tikz}
\pgfdeclareshape{what}{
     \anchor{center}{
        \pgfpointorigin
    }
    \foregroundpath{
        \pgfscope
            \pgfpathmoveto{\pgfpoint{-4pt}{0pt}}
            \pgfpathlineto{\pgfpoint{4pt}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{4pt}}
            \pgfpathlineto{\pgfpoint{-4pt}{0pt}}
            % \pgfpathclose
            \pgfusepath{draw,fill}
        \endpgfscope
    }
}

\begin{document}
\begin{tikzpicture}
    \draw[] (0,0) -- node[what] {} ++(0,-2);
    \draw[red, shorten <=.5cm] (1,0) -- node[what] {} ++(0,-2);
    \draw[blue,shorten <=.5cm] (2,0) -- node[draw] {} ++(0,-2);
\end{tikzpicture}

\end{document}
21:30:03
@r_mano:matrix.orgRomano Giannetti There is an artifact in the red line, which disappears if I uncomment the pgfpathclose or remove the shorten. This does not happen with the stock shapes, so there must be something I'm doing wrong that I miss. 21:32:27
@r_mano:matrix.orgRomano Giannettiksnip_20220130-223259.png
Download ksnip_20220130-223259.png
21:33:19
@r_mano:matrix.orgRomano Giannetti using backgroundpath or other layers does not change anything... 21:34:16
31 Jan 2022
@muzzi:matrix.orgmuzimuzhi
In reply to @r_mano:matrix.org
\documentclass[margin=1cm]{standalone}

\usepackage{tikz}
\pgfdeclareshape{what}{
     \anchor{center}{
        \pgfpointorigin
    }
    \foregroundpath{
        \pgfscope
            \pgfpathmoveto{\pgfpoint{-4pt}{0pt}}
            \pgfpathlineto{\pgfpoint{4pt}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{4pt}}
            \pgfpathlineto{\pgfpoint{-4pt}{0pt}}
            % \pgfpathclose
            \pgfusepath{draw,fill}
        \endpgfscope
    }
}

\begin{document}
\begin{tikzpicture}
    \draw[] (0,0) -- node[what] {} ++(0,-2);
    \draw[red, shorten <=.5cm] (1,0) -- node[what] {} ++(0,-2);
    \draw[blue,shorten <=.5cm] (2,0) -- node[draw] {} ++(0,-2);
\end{tikzpicture}

\end{document}

shorten <=.5cm is applied when the node shape is drawn. Yes this option (and shorten >) takes effect even when the path has no arrows. Without \pgfpathclose, you can also use \pgfsetshortenstart{0pt} \pgfsetshortenend{0pt} to do the resetting in pgf level.

PS: Commenting out the second \pgfpathlineto{\pgfpoint{-4pt}{0pt}} and using node[what, draw=black] help me figure out what's really wrong.

00:03:29
@muzzi:matrix.orgmuzimuzhi
In reply to @r_mano:matrix.org
\documentclass[margin=1cm]{standalone}

\usepackage{tikz}
\pgfdeclareshape{what}{
     \anchor{center}{
        \pgfpointorigin
    }
    \foregroundpath{
        \pgfscope
            \pgfpathmoveto{\pgfpoint{-4pt}{0pt}}
            \pgfpathlineto{\pgfpoint{4pt}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{4pt}}
            \pgfpathlineto{\pgfpoint{-4pt}{0pt}}
            % \pgfpathclose
            \pgfusepath{draw,fill}
        \endpgfscope
    }
}

\begin{document}
\begin{tikzpicture}
    \draw[] (0,0) -- node[what] {} ++(0,-2);
    \draw[red, shorten <=.5cm] (1,0) -- node[what] {} ++(0,-2);
    \draw[blue,shorten <=.5cm] (2,0) -- node[draw] {} ++(0,-2);
\end{tikzpicture}

\end{document}
*

shorten <=.5cm is applied when the node shape is drawn. Yes this option (and shorten >) takes effect even when the path has no arrows. Without \pgfpathclose, you can also use \pgfsetshortenstart{+0pt} \pgfsetshortenend{+0pt} to do the resetting in pgf level. The plus sign is a pgfmath trick so it knows the math-expr is only a simple value and the parsing will be quicker.

PS: Commenting out the second \pgfpathlineto{\pgfpoint{-4pt}{0pt}} and using node[what, draw=black] help me figure out what's really wrong.

00:06:29
@muzzi:matrix.orgmuzimuzhi

If the outer path has non-empty arrows, \pgfsetarrows{-} is also required.

It's a pity that there's no lists of options which are inherited, used, and reset inside a node/pic/matrix/graph.

00:29:09
@muzzi:matrix.orgmuzimuzhi *

If the outer path has non-empty arrows, \pgfsetarrows{-} is also required.

It's a pity that there's no documented lists of options which are inherited, used, and reset inside a node/pic/matrix/graph.

00:29:18
@r_mano:matrix.orgRomano Giannetti

If the outer path has non-empty arrows, \pgfsetarrows{-} is also required.

It's a pity that there's no documented lists of options which are inherited, used, and reset inside a node/pic/matrix/graph.

muzimuzhi thanks! So I should \pgfscope \pgfsetshortenstart{+0pt} \pgfsetshortenend{+0pt} \pgfsetarrows{-} ... \endpgfscope at the start of every shape backgroundpath which is supposed to be drawn independently from the outer path? Is the scoping sufficient to guarantee that the outer path is not disturbed?

06:31:43
@samcarter:matrix.orgsamcarter
In reply to @muzzi:matrix.org
hmenke: Since Conventional Commits has been applied for a while with a tacit agreement, maybe it's time to mention and require it in PR template. This could save us from reminding new contributors.
Random thought: maybe it would be interesting to have a talk about best practises in git at a future user group meeting?
10:27:07
@hmenke:matrix.orghmenke samcarter: That's a good idea. When and where will the next DANTE meeting take place? The website doesn't list anything yet. 11:12:17
@samcarter:matrix.orgsamcarter
In reply to @hmenke:matrix.org
samcarter: That's a good idea. When and where will the next DANTE meeting take place? The website doesn't list anything yet.
No idea! I did not yet hear about anything.
12:44:28
@muzzi:matrix.orgmuzimuzhi
In reply to @r_mano:matrix.org

If the outer path has non-empty arrows, \pgfsetarrows{-} is also required.

It's a pity that there's no documented lists of options which are inherited, used, and reset inside a node/pic/matrix/graph.

muzimuzhi thanks! So I should \pgfscope \pgfsetshortenstart{+0pt} \pgfsetshortenend{+0pt} \pgfsetarrows{-} ... \endpgfscope at the start of every shape backgroundpath which is supposed to be drawn independently from the outer path? Is the scoping sufficient to guarantee that the outer path is not disturbed?

There're more to be reset. What I can immediately think of is using \pgfsetcornersarced{\pgfpointorigin} to reset outer non-zero rounded corners.

Is the scoping sufficient to guarantee that the outer path is not disturbed?

Yes I think so.

13:32:11
@muzzi:matrix.orgmuzimuzhi
In reply to @r_mano:matrix.org

If the outer path has non-empty arrows, \pgfsetarrows{-} is also required.

It's a pity that there's no documented lists of options which are inherited, used, and reset inside a node/pic/matrix/graph.

muzimuzhi thanks! So I should \pgfscope \pgfsetshortenstart{+0pt} \pgfsetshortenend{+0pt} \pgfsetarrows{-} ... \endpgfscope at the start of every shape backgroundpath which is supposed to be drawn independently from the outer path? Is the scoping sufficient to guarantee that the outer path is not disturbed?

*

Depending on the design goal, there may be more to be reset. What I can immediately think of is using \pgfsetcornersarced{\pgfpointorigin} to reset outer non-zero rounded corners.

Is the scoping sufficient to guarantee that the outer path is not disturbed?

Yes I think so.

13:43:22
@hmenke:matrix.orghmenke
In reply to @muzzi:matrix.org

If the outer path has non-empty arrows, \pgfsetarrows{-} is also required.

It's a pity that there's no documented lists of options which are inherited, used, and reset inside a node/pic/matrix/graph.

Well, generally everything should be assumed to be inherited, because even if we can reset certain things in the graphics state, these changes will not propagate back into pgfkeys. To be sure that everything is in sync, all the (un)desired options should be reset manually.
14:11:10
@muzzi:matrix.orgmuzimuzhi Reminds me of tcolorbox' styles reset and internal initialize@reset: reset will reset all tcolorbox aspects on every box layer, and initialize@reset executes options and adds them to reset. This makes tcolorboxes nestable.
https://github.com/T-F-S/tcolorbox/blob/2573999ebc4453258d50124acaea05dc99a2850c/tex/latex/tcolorbox/tcolorbox.sty#L2324-L2325
17:13:15
1 Feb 2022
@muzzi:matrix.orgmuzimuzhi
In reply to @hmenke:matrix.org
Well, generally everything should be assumed to be inherited, because even if we can reset certain things in the graphics state, these changes will not propagate back into pgfkeys. To be sure that everything is in sync, all the (un)desired options should be reset manually.
Romano Giannetti: Resetting things in node shapes' foreground/background path may be too late and less flexible. For example, it will also overwrite <options> in ... node[<shape>, <options>]. I find resetting things in \tikz@node@reset@hook which is used in \tikz@normal@fig (in a local group) helpful, but it's a breaking change as Henri said "generally everything should be assumed to be inherited".
19:07:12
@muzzi:matrix.orgmuzimuzhi
19:07:16
@muzzi:matrix.orgmuzimuzhi *
\documentclass{article}
\usepackage{tikz}

\makeatletter
\pgfutil@g@addto@macro\tikz@node@reset@hook
  {\tikzset{shorten <=+0pt, shorten >=+0pt, arrows={-}, rounded corners=+0pt}}
\makeatother

\pgfdeclareshape{what}{
  \anchor{center}{
    \pgfpointorigin
  }
  \foregroundpath{
    \pgfpathmoveto{\pgfpoint{-4pt}{0pt}}
    \pgfpathlineto{\pgfpoint{4pt}{0pt}}
    \pgfpathlineto{\pgfpoint{0pt}{4pt}}
    \pgfpathlineto{\pgfpoint{-4pt}{0pt}}
    \pgfusepath{draw,fill}
  }
}

\begin{document}
\begin{tikzpicture}[back]
    \draw[] (0,0) -- node[what] {} ++(0,-2);
    
    \draw[fill=red, shorten <=.5cm] (1,0) -- node[what] {} ++(0,-2);
    \draw[fill=red, shorten <=.5cm] (2,0) -- node[what, shorten <=5pt] {} ++(0,-2);
    
    \draw[fill=blue,rounded corners=10pt] (3,0) -- node[what] {} ++(0,-2);
    \draw[fill=blue,rounded corners=10pt] (4,0) -- node[what, rounded corners=2pt] {} ++(0,-2);
    
    \draw[fill=green, <->] (5,0) -- node[what] {} ++(0,-2);
    \draw[fill=green, <->] (6,0) -- node[what, shorten <=3pt, <-] {} ++(0,-2);
\end{tikzpicture}
\end{document}
19:08:04
@muzzi:matrix.orgmuzimuzhiimage.png
Download image.png
19:08:10
@muzzi:matrix.orgmuzimuzhi Perhaps circuitikz could achieve similar effects by locally changing style every node? 19:13:26
@muzzi:matrix.orgmuzimuzhi * Perhaps circuitikz could achieve similar effects by locally changing style every node? Because in \tikz@normal@fig \tikzset{every node/.try} is used right after \tikz@node@reset@hook. 19:14:18
@r_mano:matrix.orgRomano Giannetti muzimuzhi: I see it is difficult... sometimes you want them to propagate, and sometimes no. So I think I will go for the minimal fix; really the user that noticed the problem was trying to do a very strange thing with the shape. 19:15:40
@r_mano:matrix.orgRomano Giannetti * muzimuzhi: I see it is difficult... sometimes you want them to propagate, and sometimes no. So I think I will go for the minimal fix; really the user that noticed the problem was trying to do a very strange thing with the shape. (See https://tex.stackexchange.com/questions/632051/tikz-shorten-with-circuitikz) 19:16:21
@muzzi:matrix.orgmuzimuzhi
In reply to @r_mano:matrix.org
muzimuzhi: I see it is difficult... sometimes you want them to propagate, and sometimes no. So I think I will go for the minimal fix; really the user that noticed the problem was trying to do a very strange thing with the shape. (See https://tex.stackexchange.com/questions/632051/tikz-shorten-with-circuitikz)

sometimes you want them to propagate, and sometimes no

true. Having every relation between any of tikz options and node/pic/matrix/graph documented is such a hard task, and it's even impossible to resort the inconsistencies when tikz's main features has been populated for such a long time.

Oh I've opened that tex-sx question, but didn't read through.

19:22:51
4 Feb 2022
@r_mano:matrix.orgRomano Giannetti Fast/dirty question: it is possible to access the name of a shape inside the back/fore/etc-ground part? I am thinking about a hook system for circuitikz... 09:20:26
@r_mano:matrix.orgRomano GiannettiI am thinking something similar to this, where #1 is the name of the shape --- but I'll prefer not to add it manually like it is now:10:00:35

Show newer messages


Back to Room ListRoom Version: 6