Skip to content

\addplot gnuplot {...}; always calls gnuplot #1413

@muzimuzhi

Description

@muzimuzhi

Brief outline of the bug

When using \addplot gnuplot {<gnuplot code>} from pgfplots, the gnuplot command is always executed.

Similar to #1397, but this time the cause is different.

In the .gnuplot file created by \addplot gnuplot, the second line starts with set format "%.7e";;, which contains the special % character. When reading it using \read/\pgfutil@read, current catcode scheme is used thus anything after % on the same line are ignored. This way, \pgfplotgnuplot always thinks the .gnuplot file outdated, so gnuplot command is executed in every compilation.

We need \readline here.

Minimal working example (MWE)

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
% this is the 2nd example in sec. 4.3 "The \addplot Command: Coordinate Input"
% https://github.com/pgf-tikz/pgfplots/blob/f40faa5864936890736461a2b410dcef8968e97f/doc/latex/pgfplots/pgfplots.reference.axis-addplot.tex#L108-L119
\begin{axis}
    \addplot+ [
        id=parable,
        domain=-5:5,
    ] gnuplot {4*x**2 - 5}
        node [pin=180:{$4x^2-5$}]{}
    ;
\end{axis}
\end{tikzpicture}

.gnuplot file

set table "gnuplot/pgfplots_parable.table"; set format "%.5f"
set format "%.7e";; set samples 25; set dummy x; plot [x=-5:5] 4*x**2 - 5;

As \pgfplotgnuplot only compares the second line of .gnuplot with what to be written, the % on the first line doesn't affect the result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pgfplotsRelated to package pgfplots

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions