4

I've run into a problem where the usage of pgfplots seems to break tikz. A MWE is below. I get the error message that div is not yet implemented which is certainly not true. If I comment out the line I marked, everything is fine.

This is on MiKTeX 2.9 with all packages updated.

I've found this old article and this one which both seem to deal with the same problem, but I couldn't figure out how to adapt the solutions shown there to my problem. I'n not (at least not explicitly) using the FPU library anywhere, am I?

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}  % <- here's the culprit

\begin{document}
\begin{tikzpicture}[xscale=.8, yscale=-0.8]
  \foreach \n in {2, ..., 118} {
    \pgfmathsetmacro{\x}{mod(int(\n - 2),13)}
    \pgfmathsetmacro{\y}{div(int(\n - 2),13)}
    \pgfmathsetmacro{\c}{ifthenelse(isprime(\n),10,0)}
    \fill[black!\c!white] (\x,\y) rectangle +(.85cm,.6cm);
  }
\end{tikzpicture}
\end{document}
1
  • 4
    I'm voting to close this question because it reported a bug which is solved in PGFPlots v1.15. Jun 25 '17 at 6:24
4

Based upon this Q&A: Presence of 'pgfplots' package breaks 'forest' environment w/ 'folder' option enabled (due to FPU) I get the following solution:

Replace

\usepackage{pgfplots}

with

\makeatletter
\let\pgfmathdivX=\pgfmathdiv@
\let\pgfmathisprimeX=\pgfmathisprime@
\usepackage{pgfplots}
\let\pgfmathdiv@=\pgfmathdivX 
\let\pgfmathisprime@=\pgfmathisprimeX 
\makeatother

Actually, the div part can be omitted if the expression is written as int(\n - 2)/13 rather than div(int(\n - 2),13).

MWE:

\documentclass{article}

\usepackage{tikz}

\makeatletter
\let\pgfmathisprimeX=\pgfmathisprime@
\usepackage{pgfplots}
\let\pgfmathisprime@=\pgfmathisprimeX 
\makeatother

\begin{document}
\begin{tikzpicture}[xscale=.8, yscale=-0.8]
  \foreach \n in {2, ..., 118} {
    \pgfmathsetmacro{\x}{mod(int(\n - 2),13)}
    \pgfmathsetmacro{\y}{int(\n - 2)/13}
    \pgfmathsetmacro{\c}{ifthenelse(isprime(\n),10,0)}
    \fill[black!\c!white] (\x,\y) rectangle +(.85cm,.6cm);
  }
\end{tikzpicture}
\end{document}
2
  • Thanks, that did the trick (albeit it feels a bit clumsy). What not works is replacing div with / as that would be divide.
    – Frunobulax
    Nov 27 '16 at 14:29
  • Ah yes, I see. I forgot that. Nov 27 '16 at 14:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.