1

The question was originated from the previous question and the comment:

The offset implementation of A763043 would shift the path before decorations which means yshifting in the markings wouldn't be necessary, they would however be moved towards the postactions of the offsetting.

However, when I just copied the following patched-offset-trick:

% https://tex.stackexchange.com/a/763043
\makeatletter % see Code B in https://tex.stackexchange.com/a/728379
\let\nfold@orig@tikz@finish\tikz@finish
\def\tikz@finish{\tikz@nfold@do\nfold@orig@tikz@finish}
\let\tikz@nfold@do\relax
\tikzset{offset/.code=%
  \edef\tikz@temp{#1}\ifx\tikz@temp\tikz@nonetext \let\tikz@nfold@do\relax
  \else\def\tikz@nfold@do{\pgfgetpath\tikz@temp\pgfsetpath\pgfutil@empty\pgfoffsetpath\tikz@temp{#1}}%
  \fi}
\makeatother

and the complete code:

% https://tex.stackexchange.com/a/96970
% https://tex.stackexchange.com/a/762399
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{arrows.meta,bending,nfold,ext.nodes,decorations.markings}
% https://tex.stackexchange.com/a/763043
% https://tex.stackexchange.com/questions/764317/how-to-better-design-the-binary-switch-option-in-tikz-case#comment1907525_764317
\makeatletter % see Code B in https://tex.stackexchange.com/a/728379
\let\nfold@orig@tikz@finish\tikz@finish
\def\tikz@finish{\tikz@nfold@do\nfold@orig@tikz@finish}
\let\tikz@nfold@do\relax
\tikzset{offset/.code=%
  \edef\tikz@temp{#1}\ifx\tikz@temp\tikz@nonetext \let\tikz@nfold@do\relax
  \else\def\tikz@nfold@do{\pgfgetpath\tikz@temp\pgfsetpath\pgfutil@empty\pgfoffsetpath\tikz@temp{#1}}%
  \fi}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{
  foo/.tip={Straight Barb[harpoon,swap,length=5pt]},
  shrink/.style={thick,shorten >=2pt,shorten <=2pt},
  dualharpoon/.style={%
    draw=none,
    postaction={path only,draw,-foo,shrink,offset=-#1ex},
    postaction={path only,draw,foo-,shrink,offset=+#1ex,
        decorate, decoration={markings, mark=at position 0.5 with {
            \draw[-,line cap=round,thick] ++ (-.15cm,-.15cm) -- (+.15cm,+.15cm);
        }},
    },
  },
  dualharpoon/.default=.75,
}
\begin{document}
\begin{tikzpicture}[
    Qstyle/.style={
        dualharpoon,
        % ext/auto with offset, % default true
        ext/auto offset=1ex,
        auto,
    }]
    \node[draw,circle,fill=teal] (A) at (0,1) {A};
    \node[draw,circle,fill=magenta] (B) at (0,-1) {B};
    \node[draw,circle,fill=cyan] (C) at (2.5,.5) {C};
    \draw[magenta,Qstyle] (A) to[bend right] node {$\Delta$} node[swap]{$\nabla$} (B);
    \draw[teal,Qstyle] (B) to[bend right] node {$f(x)$} node[swap]{$g(x)$} (C);
    \draw[orange,Qstyle] (A) -- node {$x$} node[swap]{$y$} (C);
\end{tikzpicture}
\end{document}

gives not the ideal result(?)

res

Possibly I missed some important...

2
  • 1
    The inner decoration still needs to be inside a postaction since markings destroys the original path. However, this postaction also needs offset=none now because the offset=+#1ex gets inherited, oops. Commented 9 hours ago
  • @Qrrbrbirlbel Oh my goodness, I completely lost my mind just now. A large number of pgf commands with @ are somewhat intimidating. Many thanks! Commented 8 hours ago

1 Answer 1

2

Thanks to Qrrbrbirlbel's comment:

The inner decoration still needs to be inside a postaction since markings destroys the original path. However, this postaction also needs offset=none now because the offset=+#1ex gets inherited.


% https://tex.stackexchange.com/a/96970
% https://tex.stackexchange.com/a/762399
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{arrows.meta,bending,nfold,ext.nodes,decorations.markings}
% https://tex.stackexchange.com/a/763043
% https://tex.stackexchange.com/questions/764317/how-to-better-design-the-binary-switch-option-in-tikz-case#comment1907525_764317
\makeatletter % see Code B in https://tex.stackexchange.com/a/728379
\let\nfold@orig@tikz@finish\tikz@finish
\def\tikz@finish{\tikz@nfold@do\nfold@orig@tikz@finish}
\let\tikz@nfold@do\relax
\tikzset{offset/.code=%
  \edef\tikz@temp{#1}\ifx\tikz@temp\tikz@nonetext \let\tikz@nfold@do\relax
  \else\def\tikz@nfold@do{\pgfgetpath\tikz@temp\pgfsetpath\pgfutil@empty\pgfoffsetpath\tikz@temp{#1}}%
  \fi}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\tikzset{
  foo/.tip={Straight Barb[harpoon,swap,length=5pt]},
  shrink/.style={thick,shorten >=2pt,shorten <=2pt},
  dualharpoon/.style={%
    draw=none,
    postaction={path only,draw,-foo,shrink,offset=-#1ex},
    postaction={path only,draw,foo-,shrink,offset=+#1ex,
        postaction={
            decorate,offset=none,
            decoration={markings, mark=at position 0.5 with {
                \draw[-,line cap=round,thick] ++ (-.15cm,-.15cm) -- (+.15cm,+.15cm);
                }
            },
        }, 
    },
  },
  dualharpoon/.default=.75,
}
\makeatother
\begin{document}
\begin{tikzpicture}[
    Qstyle/.style={
        dualharpoon,
        ext/auto with offset, % default true
        ext/auto offset=1ex,
        auto,
    }]
    \node[draw,circle,fill=teal] (A) at (0,1) {A};
    \node[draw,circle,fill=magenta] (B) at (0,-1) {B};
    \node[draw,circle,fill=cyan] (C) at (2.5,.5) {C};
    \draw[magenta,Qstyle] (A) to[bend right] 
        node {$\Delta$} 
        node[swap,inner sep=0pt]{$\nabla$} 
    (B);
    \draw[teal,Qstyle] (B) to[bend right] 
        node[inner sep=0pt] {$f(x)$} 
        node[swap,inner sep=0pt]{$g(x)$} 
    (C);
    \draw[orange,Qstyle] (A) -- 
        node {$x$} 
        node[swap,inner sep=0pt]{$y$} 
    (C);
\end{tikzpicture}
\end{document}

res

1
  • \def\tikz@finish{\tikz@nfold@do\let\tikz@nfold@do\relax\nfold@orig@tikz@finish} would make preactions and postactions not being offset but that won't help with \draw[offset=1ex] (0,0) -- node[draw]{node} (1,1); which also offsets the path of the node. Though, I don't know how likely something like this would be. Maybe offset=none would be a good default for the every node style? There is unfortunately not a good hook for this but it wouldn't also be the first setting that gets passed down to nodes on a path. Commented 6 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.