1

The following example works:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table{
0 0 
0.5 0.25
1 1
};
\end{axis}
\end{tikzpicture}
\end{document}

However, I cannot take the data from an external program. As a simulation let us say that

printf '0 0\n0.5 0.25\n1 1\n'

prints the desired

0 0
0.5 0.25
1 1

Now I would like to write instead

\addplot table{
\input|"printf '0 0\n0.5 0.25\n1 1'"
};

and compile it with pdflatex --shell-escape. I am quite sure that the newlines are the problem and catcode tables may be a solution but I was not able to find an appropriate solution.

Update: \string\n and expandable input via @@\input were suggested similar to something like:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\makeatletter
\let\zz\@@input
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table{
\zz|"printf '0 0\string\n0.5 0.25\string\n1 1'"
};
\end{axis}
\end{tikzpicture}
\end{document}

I think, I have tried all variations with \zz,\input,\n, \string\n, \string\n\string\n and none of them worked.

4
  • probably you want \string\n but it depends on whether you need another layer of quoting for the \ on your command shell, it is system dependent, but you need \string\n or it tries to expand the undefined tex command \n, but it could be you need \string\\n instead:-) Commented May 3, 2018 at 19:07
  • Your suggestion works outside a tikzpicture but unfortunately not inside a tikzpicture. (Doubling \string\ndid not work either, inputting with an expandable input did not work either.) Commented May 3, 2018 at 19:43
  • can you use a normal file input at that point or does the argument of \addplot table need to expand to its content (in which case you would need ``\@@input` not \input (and make @ a letter with \makeatletter ) Commented May 3, 2018 at 20:02
  • I would like to solve this problem without needing to write and read an extra file. I have updated the question (\@@input did not yet solve the problem). Commented May 3, 2018 at 20:26

1 Answer 1

0

According to Christian Feuersänger (the author of pgfplots), everything inside addplot{} is not expandable. Hence, a solution with the given conditions is not possible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .