7

Problem description

I have a LaTeX project that relies on both, \usepackage{pgfplots} and \usepackage{forest}.

Since upgrading to TeX Live 2016, the presence of the pgfplots package breaks compilation if the document contains a \begin{forest} environment that has the folder option enabled.

The error message suggests this is because pgfplots wants to use the FPU, but the folder option in the forest environment relies on a Mod operation that is not (yet) implemented in the FPU:

! Package PGF Math Error: Sorry, the operation 'Mod' has not yet been implemented in the floating point unit.

Because I require both packages in my project, I would like to find a solution for this problem. I suspect that deactivating the FPU via \pgfkeys{/pgf/fpu=false} might be an option, but I'm not sure how I would apply this to the MWE below.

Minimal Working Example

Save the following MWE to main.tex and compile with pdflatex main. Then, uncomment the line marked TODO and try to recompile (which will fail).

\documentclass{standalone}

% NOTE: [edges] option required to enable 'folder' option in
% 'forest' environment below.
\usepackage[edges]{forest}%

% TODO: Uncomment the line below to break compilation
%\usepackage{pgfplots}%

\begin{document}

\begin{forest}%
  for tree={folder}% NOTE: Problem only occurs with this option enabled
  [foo%
    [bla]%
    [moo]%
  ]%
\end{forest}%

\end{document}
6
  • you can stick \pgfkeys{/pgf/fpu=false} somewhere before forest starts parsing but seems it doesn't accept options. – percusse Sep 10 '16 at 21:29
  • 1
    I don't think this really has anything to do with Forest. The fpu library does not appear to provide an effective reverse option. (@percusse 's suggestion doesn't work for me.) Hence, the only way to deal with this would be for pgfplots to enable it locally. I would think this would be best practice anyway, to be honest. If you are changing stuff from the defaults, you have a responsibility to ensure the changes are local unless they are designed to be global (e.g. that's the point of the package), which doesn't apply here. – cfr Sep 11 '16 at 1:13
  • 1
    Really, pgfplots should keep the use of fpu local. Other packages cannot be expected to pre-emptively check for possible disruption to the defaults. However, I think there is a further problem here which is independent of pgfplots and forest: see tex.stackexchange.com/questions/328996/…. In any case, I don't see any reason to think that Forest is at fault in this case. – cfr Sep 11 '16 at 1:35
  • 1
    I suspect this is a bug in pgfplots and another in the fpu library. The former can't intend to enable this globally, given how often it enables it within groups and how frequently it checks whether it is active. And the former can't intend the reversal option to not do what it says on the tin. – cfr Sep 11 '16 at 1:51
  • 4
    I'm voting to close this question because it is solved by updating PGFPlots to v1.15 – Stefan Pinnow Jun 25 '17 at 6:16
7

For a very crude temporary hack, you can redirect the meaning of Mod to mod and accept the risk of getting a negative number out of mod

Hence add

\let\pgfmathMod=\pgfmathmod\relax

But if I could find where to uninstall the fpu version of Mod, I guess adding this would fix that issue. That requires a fpu library change though.

\def\pgfmathfloatMod@#1#2{%
    \begingroup%
    \pgfmathfloatmod@{#1}{#2}%
    \let\pgfmathfloat@loc@TMPa=\pgfmathresult%
    \pgfmathfloatifflags{\pgfmathresult}{-}{\pgfmathfloatadd@{\pgfmathfloat@loc@TMPa}{#2}%
    \pgfmath@smuggleone\pgfmathresult%
    \endgroup%
}

However, Christian Feuersänger is the one that can resolve this.

1
  • The first line works as the quick workaround that I was looking for - thanks! – Florian H. Sep 11 '16 at 14:26
7

The root cause is an old bug in the FPU library: it fails to uninstall those commands for which it comes with an error message "this is not implemented".

The problem became apparent with the latest stable of pgfplots which calls "activate fpu ... deactivate fpu" at global scope -- and the deactivation fails.

I will take care of it.

A workaround for the problem at hand is

\documentclass{standalone}

% NOTE: [edges] option required to enable 'folder' option in
% 'forest' environment below.
\usepackage[edges]{forest}%

\makeatletter
\let\pgfmathModX=\pgfmathMod@
\usepackage{pgfplots}%
\let\pgfmathMod@=\pgfmathModX
\makeatother

\begin{document}

\begin{forest}%
  for tree={folder}% NOTE: Problem only occurs with this option enabled
  [foo%
    [bla]%
    [moo]%
  ]%
\end{forest}%

\end{document}

Note that this affects the following operations:

isprime iseven gcd frac random setseed Mod div real

5
  • What exactly needs to be changed in the case of "random"? – Dan Apr 25 '17 at 13:33
  • copy-paste the lines containing pgfmathMod and replace pgfmathMod by pgfmathrandom (case sensitive) – Christian Feuersänger Apr 25 '17 at 19:54
  • Having the same problem with random on Overleaf (my local texlive installation works perfectly fine). Any hint? – petrux Sep 2 '18 at 9:55
  • Same problem but with "random" function. What should the workaround be? Thanks! – petrux Sep 19 '18 at 15:05

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