Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/generic/pgf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Treat varargs for `min()` and `max()` in `luamath` pgf library pgf-tikz/pgfplots#492 #1359
- Fixed support for the `\tikz` command in the `dvisvgm4ht` driver for TeX4ht
- Wrong key name in unknown decoration option error #1082
- `gnuplot` was always run when the function contained leading or trailing spaces #1397

### Changed

Expand Down
7 changes: 4 additions & 3 deletions tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3365,7 +3365,8 @@
\def\tikz@plot@function unction#1{%
\def\tikz@plot@filename{\tikz@plot@prefix\tikz@plot@id}%
\iftikz@plot@raw@gnuplot%
\def\tikz@plot@data{\pgfplotgnuplot[\tikz@plot@filename]{#1}}%
\def\tikz@plot@data{%
\pgfplotgnuplot[\tikz@plot@filename]{\pgfutil@trimspaces@e{#1}}}%
\else%
\iftikz@plot@parametric%
\def\tikz@plot@data{\pgfplotgnuplot[\tikz@plot@filename]{%
Expand All @@ -3374,13 +3375,13 @@
plot [t=\tikz@plot@domain]
[\tikz@plot@xrange]
[\tikz@plot@range]
#1}}%
\pgfutil@trimspaces@e{#1}}}%
\else%
\def\tikz@plot@data{\pgfplotgnuplot[\tikz@plot@filename]{%
set samples \tikz@plot@samples;
plot [x=\tikz@plot@domain]
\ifx\tikz@plot@range\pgfutil@empty\else[\tikz@plot@range]\fi
#1}}%
\pgfutil@trimspaces@e{#1}}}%
\fi%
\fi%
\tikz@@@plot%
Expand Down
7 changes: 5 additions & 2 deletions tex/generic/pgf/modules/pgfmoduleplot.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,16 @@
\pgfutilpreparefilename{#1.table}%
\let\pgf@plottablefile=\pgfretval
\let\pgf@plottablefile@quoted=\pgfretvalquoted
\begingroup
\endlinechar=-1 % suppress white space at end
% Check, whether it is up-to-date
\openin\pgfutil@inputcheck=\pgf@plotgnuplotfile\relax
\ifeof\pgfutil@inputcheck%
\else%
\pgfutil@read\pgfutil@inputcheck to\pgf@temp% ignored
\pgfutil@read\pgfutil@inputcheck to\pgf@plot@line%
\closein\pgfutil@inputcheck
\edef\pgf@plot@code{#2\space}%
\edef\pgf@plot@code{\pgfutil@trimspaces@e{#2}}%
\ifx\pgf@plot@code\pgf@plot@line%
\openin\pgfutil@inputcheck=\pgfretval\relax
\ifeof\pgfutil@inputcheck%
Expand All @@ -501,11 +503,12 @@
\ifpgf@resample@plot%
\immediate\openout\pgf@plotwrite=\pgf@plotgnuplotfile\relax
\immediate\pgfutil@write\pgf@plotwrite{\pgf@gnuplot@head}%
\immediate\pgfutil@write\pgf@plotwrite{#2}%
\immediate\pgfutil@write\pgf@plotwrite{\pgf@plot@code}%
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was buggy.

By using \pgf@plot@code in replace of #2 in writing to .gnuplot, it has to be defined. But currently \pgf@plot@code is only defined if the .gnuplot exists.

A minimal reproducing example:

% copied from https://github.com/pgf-tikz/pgf/issues/1397
\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \draw plot[domain=-2:2] function{x**2};
\end{tikzpicture}
\end{document}

If the \jobname.pgf-plot.gnuplot doesn't exist before the compilation, an error is raised:

! Undefined control sequence.
<write> \pgf@plot@code 

Usually the error disappears in a following compilation, but the pgfplots manual building was broken because of the -halt-on-error option. See pgf-tikz/pgfplots#510 (comment).

The fix is simple, but I need some more time to setup a new l3build test suite which checks with shell escape, so .

diff --git a/tex/generic/pgf/modules/pgfmoduleplot.code.tex b/tex/generic/pgf/modules/pgfmoduleplot.code.tex
index 4dbaa14f..1b070a89 100644
--- a/tex/generic/pgf/modules/pgfmoduleplot.code.tex
+++ b/tex/generic/pgf/modules/pgfmoduleplot.code.tex
@@ -481,6 +481,7 @@
   \pgfutilpreparefilename{#1.table}%
   \let\pgf@plottablefile=\pgfretval
   \let\pgf@plottablefile@quoted=\pgfretvalquoted
+  \edef\pgf@plot@code{\pgfutil@trimspaces@e{#2}}%
   \begingroup
   \endlinechar=-1 % suppress white space at end
   % Check, whether it is up-to-date
@@ -490,7 +491,6 @@
     \pgfutil@read\pgfutil@inputcheck to\pgf@temp% ignored
     \pgfutil@read\pgfutil@inputcheck to\pgf@plot@line%
     \closein\pgfutil@inputcheck
-    \edef\pgf@plot@code{\pgfutil@trimspaces@e{#2}}%
     \ifx\pgf@plot@code\pgf@plot@line%
       \openin\pgfutil@inputcheck=\pgfretval\relax
       \ifeof\pgfutil@inputcheck%

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New PR #1412 is proposed. It comes with a set of tests.

\immediate\closeout\pgf@plotwrite%
\pgfutil@shellescape{%
\pgfkeysvalueof{/pgf/plot/gnuplot call} \pgf@plotgnuplotfile}%
\fi%
\endgroup
% \let\pgf@savedparsexyline=\pgf@parsexyline%
% \let\pgf@parsexyline=\pgf@parsegnuplotxyline%
\pgfplotxyfile{\pgf@plottablefile}%
Expand Down
4 changes: 4 additions & 0 deletions tex/generic/pgf/utilities/pgfutil-common.tex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
\def\pgfutil@trimspaces@@#1Q#2{#1}
\catcode`\Q=11

\def\pgfutil@trimspaces@e#1{%
\expandafter\pgfutil@trimspaces\expandafter{\pgfutil@expanded{#1}}%
}

% \pgfutil@ifx{<token 1>}{<token 2>}{<true code>}{<false code>}
%
% This macro is expandable.
Expand Down
Loading