So I've been researching making own shapes in TikZ. As most things in LaTeX, I've come to learn, it seems to have an extremely deep rabbit hole.
So I was wondering - is there an easy way out?
Is it possible to define a new shape that can be used "between two coordinates" (i.e. \draw (A) open box (B)) in e.g. \path and \draw, which use familiar notation when defining?
For example, one could do something like this; As a minimal example I'm making a rectangle that has no top:
\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit}
\tikzset{
% When open box is called via edge, draw a rectangle with no top:
open box/.code={%
\pgfkeysalso{%
to path={%
let
\p{start}=(\tikztostart),
\p{end}=(\tikztotarget)
in
(\tikztostart) -| (\tikztotarget)
(\x{start},\y{start}) -- (\x{start},\y{end})
% Make a fitted node to get good anchors
node[fit={(\tikztostart)(\tikztotarget)}, inner sep=0pt](#1){}
}
}
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0) edge[open box={therect}] (2,2);
% How can this be switched with e.g: %<---
% \draw (0,0) open box[name=therect] (2,2) %<---
\node at (therect.center){RECT!};
\end{tikzpicture}
\end{document}
The result is:

I don't find this syntax half bad, actually, but I was wondering if there is something simpler that is made for this kind of thing, but I just haven't stumbled across?
Thanks! :)


style 2 argsis better, I agree :) – Andreas Storvik Strauman May 27 '19 at 12:58to[open box=...]instead of, say,open box[...]. Of course, if I knew what you really want to do then there may be a way without changing the parser. See e.g. here what changing the parser may mean. You may also use pgf keys instead of many arguments. – May 27 '19 at 13:02to[open box]oredge[open box]is fine, really. Its' mostly out of curiosity :) – Andreas Storvik Strauman May 27 '19 at 13:08\usepgfmodule{parser}that allows you to parse stuff. This can be used to translate stuff to styles that insert some paths, an explicit example can be found here. (No, I do not know why one user wants to write three different answers to one question or downvote an existing accepted answer just because one wants to add another answer, but my suspicion is that our site is a big experiment in sociology. ;-)) – May 27 '19 at 17:13