2

using an up-to-date MiKTeX installation I'm trying to plot a graph in TikZ, where the \draw command with the coordinates is input from an external file. The \draw command is not closed by a semicolon inside the file though, because its options like [-latex] should be assignable within the main file. When I insert the file contents directly into the main file, everything works fine, but when I use \input{myfilename} to insert the file contents, I get the error

Package tikz Error: Giving up on this path. Did you forget a semicolon?. \input{myfilename}

Here are the MWEs:

This works fine:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} \begin{scope} \draw plot[smooth] coordinates { % ( 1, 0) % ( 0.5, -0.5) % ( 0, 0) % }% [-latex]; \end{scope} \end{tikzpicture}

\end{document}

But this produces the error:

\begin{filecontents}{genplot}
\draw plot[smooth] coordinates { %
    (           1,            0) %
    (         0.5,         -0.5) %
    (           0,            0) %
}
\end{filecontents}

\documentclass{article} \usepackage{tikz}

\begin{document}

\begin{tikzpicture} \begin{scope} \input{genplot}% [-latex]; \end{scope} \end{tikzpicture}

\end{document}

Strangely this was working fine until at least a year ago (when I last compiled the document). So something in the behaviour of using \input inside a TikZ picture must have changed since then. Can someone enlighten me or does anyone have a solution where I don't need to edit the content of the external file?

1 Answers1

2

This is more or less the same issue as this one caused by the change described here, and can be solved using the same workaround; add this to your preamble:

\ExplSyntaxOn
\cs_new:Npn \expandableinput #1
  { \use:c { @@input } { \file_full_name:n {#1} } }
\AddToHook{env/tikzpicture/begin}
  { \cs_set_eq:NN \input \expandableinput }
\ExplSyntaxOff

The code above will replace LaTeX's \input by \expandableinput inside the tikzpicture environment.

enter image description here

\begin{filecontents}{genplot}
\draw plot[smooth] coordinates { %
    (           1,            0) %
    (         0.5,         -0.5) %
    (           0,            0) %
}
\end{filecontents}

\documentclass{article} \usepackage{tikz}

\ExplSyntaxOn \cs_new:Npn \expandableinput #1 { \use:c { @@input } { \file_full_name:n {#1} } } \AddToHook{env/tikzpicture/begin} { \cs_set_eq:NN \input \expandableinput } \ExplSyntaxOff

\begin{document}

\begin{tikzpicture} \begin{scope} \input{genplot}% [-latex]; \end{scope} \end{tikzpicture}

\end{document}