# Input from external program to tikz as a LaTeX command with several arguments

I am in need of a command \myprogram that takes 3 optional and 1 mandatory arguments. When using pdfLateX --shell-escape, \myprogram should call

echo '(#1,#2) parabola (#3,#4)'


(echo stands here as a replacement for an own external program) and should be combined with a \draw command from tikz such that

\tikz \draw \myprogram[-1][-1][1]{2};


gives the same output as

\tikz \draw (-1,-1) parabola (1,2);


I already have a WORKING solution with only 1 argument (with the help given here):

\documentclass{article}
\usepackage{tikz}
\makeatletter\let\zz\@@input\makeatother
\providecommand{\myprogram}[1]{\zz|"echo '(0,0) parabola (1,#1)'" }
\begin{document}
\tikz \draw \myprogram{2};
\end{document}


Also, I already have a WORKING solution with multiple arguments for LuaLaTeX (emulating my external program with tex.sprint instead of echo):

\documentclass{article}
\usepackage{tikz,xparse}
\DeclareExpandableDocumentCommand{\xmyprogram}{O{0} O{0} O{1} m}{\directlua{tex.sprint('(#1,#2) parabola (#3,#4)')}}
\providecommand\myprogram{\romannumeral\^^@\xmyprogram}
\begin{document}
\tikz \draw \myprogram[-1][-1][1]{2};
\end{document}


Combining your two existing pieces gives the working pdfLaTeX shell-escape solution:

\documentclass{article}
\usepackage{tikz,xparse}
\makeatletter\let\zz\@@input\makeatother
\DeclareExpandableDocumentCommand{\xmyprogram}{O{0} O{0} O{1} m}{%
\zz|"echo '(#1,#2) parabola (#3,#4)'"
}
\providecommand\myprogram{\romannumeral\^^@\xmyprogram}
\begin{document}
\tikz \draw \myprogram[-1][-1][1]{2};
\end{document}

• The small thing that I was missing was putting the } on a new line. I never thought that this could make a difference. – Linus Romer Apr 10 '18 at 15:58