pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
199 stars 33 forks source link

Regression? Incorrect rendering on LuaTeX with compat set to 1.12 or later #492

Closed cfr42 closed 1 month ago

cfr42 commented 1 month ago

Ref. https://tex.stackexchange.com/q/726281/ and https://tex.stackexchange.com/a/726304/

The example from Jasper's question renders incorrectly if compiled with LuaTeX if compat=1.18. Experimentation shows the cutoff is between 1.11 and 1.12 as demonstrated by the example below. Compiled as-is, the image is only partially rendered. If the current compat line is commented and the one below uncommented, the output is correct.

This appears to be engine-specific as the regression does not affect pdfTeX. compat=1.18 renders the image completely on this engine.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
% \pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[%
      enlargelimits = true,
      axis lines = none, ticks = none,
      cyl/.style = {%
        surf,
        black!30!,
        variable = \u,
        variable y = \v,
        z buffer = sort,
        faceted color=black!70!,
      },
    ]

    \addplot3[%         (-) Z-SEMIAXIS
      cyl,
      domain = -3:3,
      y domain = 0:360,
    ] ({cos(v)}, {sin(v)}, {min(u,abs(cos(v)),abs(sin(v)))});

    \addplot3[%         (-) X-SEMIAXIS
      cyl,
      domain = -3:3,
      y domain = 0:360,
    ] ({min(u,-abs(cos(v)),-abs(sin(v)))}, {cos(v)}, {sin(v)});

    \addplot3[%         (+) Y-SEMIAXIS
      cyl,
      domain = 0:360,
      y domain = -3:3,
    ] ({cos(u)}, {max(v,abs(cos(u)),abs(sin(u)))}, {sin(u)});

    \addplot3[%         (+) X-SEMIAXIS
      cyl,
      domain = -3:3,
      y domain = 0:360,
    ] ({max(u,abs(cos(v)),abs(sin(v)))}, {cos(v)}, {sin(v)});

    \addplot3[%         (+) X-SEMIAXIS
      cyl,
      domain = -3:3,
      y domain = 0:360,
    ] ({cos(v)}, {sin(v)}, {max(u,abs(cos(v)),abs(sin(v)))});

    \addplot3[%         (-) Y-SEMIAXIS
      cyl,
      domain = 0:360,
      y domain = -3:3,
    ] ({cos(u)}, {min(-abs(cos(u)),-abs(sin(u)),v)}, {sin(u)});

  \end{axis}
\end{tikzpicture}
\end{document}
Mo-Gul commented 1 month ago

The problem seems to be that the Lua functions min and max do only handle the first two arguments, see

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        domain=0:3,
        samples=4,
    ]
        \addplot {min(1,x)};
        \addplot {min(1,2,x)};
%        \addplot {min(1,min(2,x))};     % <-- workaround

%        \addplot {max(2,x)};
%        \addplot {max(1,2,x)};
    \end{axis}
\end{tikzpicture}
\end{document}

grafik

(I did not test other functions that might show the current bug.)

cfr42 commented 1 month ago

So what changed in 1.12? Did pgfplots or pgf switch to using the Lua functions?

hmenke commented 1 month ago

image

cfr42 commented 1 month ago

Sorry. I don't use pgfplots very much and I probably shouldn't be submitting anything on GitHub. But does that mean the bug is in the lua backend and should be reported elsewhere, that it isn't considered a bug or neither?

hmenke commented 1 month ago
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
% Workaround for https://github.com/pgf-tikz/pgfplots/issues/492
\directlua{
  pgfluamathfunctions.stringToFunctionMap["max"] = math.max
  pgfluamathfunctions.stringToFunctionMap["min"] = math.min
}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain=0:3, samples=4]
    \addplot {min(1,x)};
    \addplot {min(1,2,x)};
  \end{axis}
\end{tikzpicture}
\end{document}
Mo-Gul commented 1 month ago

Awesome. Your (@hmenke) workaround as well as the fix work perfectly fine.

cfr42 commented 1 month ago

Thank you for fixing this so rapidly.