# Why does loading multiple pgfplotslibraries in the same command sometime break the libraries?

I'm making some boxplots with the pgf statistics library. And I found the following.

This:

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}

%\usepgfplotslibrary{fillbetween}
%\usepgfplotslibrary{statistics}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
boxplot/draw direction = y,
]
\addplot [boxplot] table [col sep=comma,y index=0] {datatest.txt};
\end{axis}
\end{tikzpicture}
\end{document}


produces this:

But this (I'm now including fillbetween and statistics in the same \usepgfplotslibrary command):

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\usepgfplotslibrary{fillbetween,statistics}

%\usepgfplotslibrary{statistics,fillbetween}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
boxplot/draw direction = y,
]
\addplot [boxplot] table [col sep=comma,y index=0] {datatest.txt};
\end{axis}
\end{tikzpicture}
\end{document}


produces this:

Where the outlier is not marked.

Why does loading two libraries in the same statement break one? Thx for the help ;-)

edit, sorry I forgot the test file:

datatest.txt:

1
1
2
1
1
3
5


I also did test this both with \usepgfplotslibrary{statistics,fillbetween} and \usepgfplotslibrary{fillbetween,statistics} both produce the wrong result. At the same time, both

\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}


and

\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{statistics}


produce the right result.

• what is in the datatest.txt? – Ulrike Fischer Oct 29 '20 at 14:23
• btw: the problem is quite probably the order how you load the libraries, but without a test file it is difficult to test. – Ulrike Fischer Oct 29 '20 at 14:53
• @UlrikeFischer, I'm really sorry I forgot the datafile, it's there now ;-) I did test with loading the libraries in both orders (both with them in the same command and in seperate commands), the result was the same – Thorbjørn E. K. Christensen Oct 29 '20 at 15:39

The definition \use@@pgfplotslibrary has at the end this piece of code

    \expandafter\ifx\csname pgfp@library@#1@loadoptions\endcsname\relax
\else
\expandafter\pgfplotsset\expandafter{\pgfplots@glob@TMPa}%
\fi


Its purpose is to load "library hook code". In the case of the statistic library it should execute \csname pgfp@library@statistics@loadoptions\endcsname which basically does

/pgfplots/compat/library hook={statistics}{/pgfplots/boxplot/estimator=Excel,/pgfplots/boxplot/ensure mark=true},


where the ensure mark=true gives your mark.

The problem is that #1 is statistics,fillbetween or fillbetween,statistics if you combine both in one command, and so the test is always false.

So it is a bug but simply replacing #1 by \pgf@temp does not work, as these library calls can be nested and so the value is not correct in all cases.

• So this means that any pgfplotslibrary that needs a hook would fail if you load them at once? this seems like a fairly big problem, but I see that it's already been reported, thanks for the help 8-) – Thorbjørn E. K. Christensen Oct 29 '20 at 20:54

I do not have the reputation to comment. So I am writing an "answer". The difference is that different files get loaded. When you say

\usepgfplotslibrary{fillbetween,statistics}


/usr/local/texlive/2020/texmf-dist/tex/generic/pgfplots/pgfcontrib/tikzlibraryfillbetween.code.tex


whereas with

\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}


/usr/local/texlive/2020/texmf-dist/tex/generic/pgfplots/libs/tikzlibrarypgfplots.fillbetween.code.tex

As far as I can see this has to do with \pgfplots@iffileexists, which gets called by \use@@pgfplotslibrary. It appears that you are in a "wrong" subdirectory when this check is performed.