# Why is \NewDocumentCommand or else Hobby (partly) ignoring this argument? [closed]

I am trying to write a command that will draw an outline (called a cloudoutline in my file) so that I can position a couple of copies of it in one graphic. Further I prefer to avoid defining a command in the preamble to the document, because I want to use different versions of it in different chapters of a book, where the chapters are "included" into one master file with one preamble. I'd like to be able to edit the command in the same file that uses it, rather then the master file.

The file below draws an outline of the desired shape, and indeed draws it all based on points located in fixed relations to a specified point called #2. However, changing the value of #2 only partly changes the relative positions of the copies. Specifically, different values of #2 give different placements of the node A relative to the curve even though all of the coordinates for the node and the curve are specified by relation to the single value #2. Different values of #2 do not give different placements of the curve.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,cd}
\usetikzlibrary{calc,intersections,through}
\usetikzlibrary{external,hobby}
\usetikzlibrary{arrows,trees}
\usetikzlibrary{shapes,backgrounds,patterns}

\usepackage{xparse}

\begin{document}
\NewDocumentCommand\Cloudoutline{ O{} r()}{\begin{tikzpicture}[use Hobby shortcut]
\node at (#2) (A) {A};
\draw[#1] (#2) to[curve through={($(#2)+(4,.5)$)..($(#2)+(8,0)$)..($(#2)+(8,-8)$)..($(#2)+(4,-8)$)..($(#2)+(0,-8)$) }] (#2);
\end{tikzpicture}}
\Cloudoutline[scale=.33](0,0)
\Cloudoutline[scale=.33](8,-2)
\end{document}


How can I rewrite this so that I can choose the placements of the two outlines relative to one another?

Maybe the better solution would be to have some kind of local preamble in each included file. Right now I know nothing about that.

## closed as unclear what you're asking by David Carlisle, Stefan Pinnow, TeXnician, egreg, TroyJan 11 '18 at 11:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• This has nothing to do with xparse. You are building two tikzpicture environments. For each one, the bounding box of the curve is calculated by tikz and then the picture is just treated as if you put that box in the output. The origin of the coordinate system in each picture does not matter from outside the picture. – Bruno Le Floch Jan 11 '18 at 1:19
• @egreg Yes, that is what I get. The "A"s move when the argument is changed, but the outlines do not move with them. – Colin McLarty Jan 11 '18 at 1:22
• @BrunoLeFloch The two tikzpicture environments do not look alike. The nodes "A" move when #2 is changed, as i said and you can see in the link in egreg's comment. Why does the argument affect the node but not the curve? – Colin McLarty Jan 11 '18 at 1:30

It isn't clear what you expect to happen or why you think xparse is involved. the tex macro does not interpret the tikzcode at all, it just replaces the placeholders by the supplied values. The output that you get from the commands is the same output that you get if you call tikz directly, the arguments are not ignored:

This document does not use xparse at all:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,cd}
\usetikzlibrary{calc,intersections,through}
\usetikzlibrary{external,hobby}
\usetikzlibrary{arrows,trees}
\usetikzlibrary{shapes,backgrounds,patterns}

\begin{document}

\begin{tikzpicture}[use Hobby shortcut]
\node at (0,0) (A) {A};
\draw[scale=.33] (0,0) to[curve through={($(0,0)+(4,.5)$)..($(0,0)+(8,0)$)..($(0,0)+(8,-8)$)..($(0,0)+(4,-8)$)..($(0,0)+(0,-8)$) }] (0,0);
\end{tikzpicture}
\begin{tikzpicture}[use Hobby shortcut]
\node at (8,-2) (A) {A};
\draw[scale=.33] (8,-2) to[curve through={($(8,-2)+(4,.5)$)..($(8,-2)+(8,0)$)..($(8,-2)+(8,-8)$)..($(8,-2)+(4,-8)$)..($(8,-2)+(0,-8)$) }] (8,-2);
\end{tikzpicture}
\end{document}

• note that if you use scale=1 the two versions look the same, as you scale the curve down it increasingly offsets away from A as you are scaling its coordinates. – David Carlisle Jan 11 '18 at 2:23
• As to xparse, my original MWE used it but I stripped it down farther without realizing I has getting rid of xparse. – Colin McLarty Jan 11 '18 at 9:29
• @ColinMcLarty no, your example uses xparse (\NewDocumentCommand) to define a command but what I meant is that your question is misplaced you ask why the command you define is dropping arguments and producing the result it does, but the command (however you define it) is not involved at all, it just expands to its definition. Your question is (as far as I can tell) just about tikz not about command arguments. As I show here the result you get is the result of those two tikzpicture, the command syntax just makes them shorter to write. – David Carlisle Jan 11 '18 at 9:32

Sorry I was not clearer. The answer I actually wanted did use xparse, and i figured out the problem. This file does what i wanted.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,cd}
\usetikzlibrary{calc,intersections,through}
\usetikzlibrary{external,hobby}
\usetikzlibrary{arrows,trees}
\usetikzlibrary{shapes,backgrounds,patterns}
\usepackage{xparse}
\begin{document}
\NewDocumentCommand\Cloudoutline{ O{} r()}{
\draw[#1] (#2) to[curve through={($(#2)+(4,.5)$)..($(#2)+(8,0)$)..($(#2)+(8,-8)$)..($(#2)+(4,-8)$)..($(#2)+(0,-8)$) }] (#2);}
\begin{tikzpicture}[use Hobby shortcut]
\Cloudoutline[scale=.25,rotate=20](0,0)
\Cloudoutline[scale=.25,rotate=10](18,-2)
\Cloudoutline[scale=.25,rotate=-20](9,12)
\end{tikzpicture}
\end{document}


I would not mind at all if the mods delete this question as being too confused.