I'd like to combine different plots which I generate by some algorithms to some long path (which may be used for clippings). I am lacking an understanding of the \noexpand, \expandafter and so on magic. Here is my MWE:
\documentclass{article}
\usepackage{tikz}
\newcommand{\myparabola}[2]{
\pgfmathsetmacro{\myxmin}{min(2*sin(#1),-1)}
\pgfmathsetmacro{\myxmax}{max(2*sin(#1),1)}
plot[domain=\myxmin:\myxmax,variable=#2] ({#2},{#2*#2})
}
\begin{document}
This, of course, works:
\begin{center}
\begin{tikzpicture}
\pgfmathsetmacro{\myxmin}{min(2*sin(100),-1)}
\pgfmathsetmacro{\myxmax}{max(2*sin(100),1)}
\draw plot[domain=\myxmin:\myxmax,variable=\x] ({\x},{\x*\x});
\draw[clip] plot[domain=0:180,variable=\x] ({\x/100},{sin(\x)})
plot[domain=0:180,variable=\x] ({\x/100},{-sin(\x)});
\fill[red] circle (1.1);
\end{tikzpicture}
\end{center}
I want the result here be the same as above:
\begin{center}
\begin{tikzpicture}
% \draw \myparabola{100}{\x} ; % DOES NOT WORK
\end{tikzpicture}
\end{center}
Ultimately I'd like to plot several of those and/or use them in some clippings:
\begin{center}
\begin{tikzpicture} %DOES NOT WORK
% \clip \myparabola{100}{\x} \myparabola{200}{\x} \myparabola{-100}{\x};
\end{tikzpicture}
\end{center}
And of course I'm not really interested in parabolae, but more general functions
which I construct with an analogue of \verb|\myparabola|.
\end{document}
Is it possible to define the \myparabola command and use it in such a way that I can just insert it into some \draw or \clip command?
ADDENDUM: I made a tiny bit of progress and am now stuck at a much more basic question. Look at this MWE:
\documentclass{article}
\usepackage{tikz}
\newcommand{\myparabola}[1]{%
%\pgfmathsetmacro{\myxmin}{1}% IF I UNCOMMENT THIS LINES, THERE IS AN ERROR
plot[domain=-1:1] ({\noexpand\x},{#1*\noexpand\x*\noexpand\x})
}
\begin{document}
\begin{tikzpicture}
\draw[variable=\x] \myparabola{1} \myparabola{-1};
\end{tikzpicture}
\end{document}
It produces what is expected. However, if I dare to uncomment the line \pgfmathsetmacro{\myxmin}{1}, there is an error ! Package tikz Error: Giving up on this path. Did you forget a semicolon?.. Why is that? Any partial answer would be highly appreciated.


\pgfmathsetmacroin a path. You could perhaps use\pgfextra{\pgfsetmacro..}, see section 14.20 The PGF-extra Operation in the manual. But note the warning in the first paragraph of that section. – Torbjørn T. Jan 15 '18 at 22:52