Discussion:
Conflict between mathtools and pgfgantt
(too old to reply)
Scott Pakin
2017-07-20 16:26:20 UTC
Permalink
After wracking my brain trying to figure out why none of the examples
I found on the Web of pgfgantt's vgrid option worked, I finally
determined that there's a conflict between pgfgantt and mathtools.
Here's an MWE:

\documentclass{article}
\usepackage{mathtools}
\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[
vgrid={*2{red}, *1{green}, *{10}{blue, dashed}}
]{1}{20}
\gantttitle{Title 1}{20} \\
\ganttbar{}{1}{8} \\
\ganttbar{}{9}{20}
\end{ganttchart}
\end{document}

and here's what I get when I build that on an up-to-date TeX Live
2017:

$ pdflatex gantt
...
! Package pgfkeys Error: I do not know the key '/tikz/*1{green}' and I am going
to ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type H <return> for immediate help.
...

l.12 \end{ganttchart}

?

Any suggestions for a workaround would be welcome. My guess is that
my real document, which is 60 pages long and was written by a number
of authors, is not especially mathtools-heavy so I _might_ be able to
replace mathtools usage with raw LaTeX, but I haven't yet investigated
that option.

-- Scott
Scott Pakin
2017-07-20 16:34:06 UTC
Permalink
Post by Scott Pakin
After wracking my brain trying to figure out why none of the examples
I found on the Web of pgfgantt's vgrid option worked, I finally
determined that there's a conflict between pgfgantt and mathtools.
More information: It looks like the conflict is in fact between
pgfgantt and *amsmath* (which mathtools includes). This MWE also
breaks:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[
vgrid={*2{red}, *1{green}, *{10}{blue, dashed}}
]{1}{20}
\gantttitle{Title 1}{20} \\
\ganttbar{}{1}{8} \\
\ganttbar{}{9}{20}
\end{ganttchart}
\end{document}

-- Scott
Ulrike Fischer
2017-07-20 17:20:21 UTC
Permalink
Post by Scott Pakin
Post by Scott Pakin
After wracking my brain trying to figure out why none of the examples
I found on the Web of pgfgantt's vgrid option worked, I finally
determined that there's a conflict between pgfgantt and mathtools.
More information: It looks like the conflict is in fact between
pgfgantt and *amsmath* (which mathtools includes). This MWE also
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
vgrid={*2{red}, *1{green}, *{10}{blue, dashed}}
]{1}{20}
\gantttitle{Title 1}{20} \\
\ganttbar{}{1}{8} \\
\ganttbar{}{9}{20}
\end{ganttchart}
\end{document}
-- Scott
amsgen redefines \@ifstar and pgfgantt doesn't like this:

\documentclass{article}
%\RequirePackage{amsgen}
%relevant code from amsgen:
\makeatletter
\long\def\***@ifnextchar#1#2#3{%
\let\***@d= #1%
\def\***@a{#2}\def\***@b{#3}%
\futurelet\@***@token\***@ifnch
}
\def\***@ifnch{%
\ifx\@***@token\***@d \let\***@b\***@a \fi
\***@b
}
\def\@ifstar#1#2{\***@ifnextchar
*{\def\***@a*{#1}\***@a}{#2}}


\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[
vgrid={*2{red}, *1{green}, *{10}{blue, dashed}}
]{1}{20}
\gantttitle{Title 1}{20} \\
\ganttbar{}{1}{8} \\
\ganttbar{}{9}{20}
\end{ganttchart}
\end{document}

Probably one will have to patch the environment so that it restores
the original definition.
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Michael Shell
2017-07-20 20:05:37 UTC
Permalink
On Thu, 20 Jul 2017 19:20:21 +0200
Post by Scott Pakin
More information: It looks like the conflict is in fact between
pgfgantt and *amsmath* (which mathtools includes). This MWE also
I haven't looked much into this, but I would like to point out that the
problem is likely below pgfgantt because that does not even call \@ifstar
(at least not in the older version of my system), but it does load
tikz.sty which in turn at some point loads pgfkeys.code.tex where the
error actually occurs. pgfkeys.code.tex also loads
pgfkeysfiltered.code.tex.

If I had the time I would search all the loaded packages for any use of
\@ifstar. FWIW, on the unix command prompt one can search for all files
in or below a current directory that contain the string \@ifstar using:

find . -type f -print|sort|xargs grep \@ifstar

I also observe that the offending key '/tikz/*1{green}' does contain an *.

On my older system, none of the files in /tex/generic/pgf even call
\@ifstar. If the recent systems do have a file in there that does,
that would be an area to investigate.


Cheers,

Mike Shell
Ulrike Fischer
2017-07-20 20:52:11 UTC
Permalink
Post by Michael Shell
I haven't looked much into this, but I would like to point out that the
(at least not in the older version of my system),
pgfgantt uses in 4 place \@ifstar including in the vgrid code:

\def\***@vgrid@analyze{%
\@ifstar{\***@vgrid@draw}{\***@vgrid@draw1}%
}

Scotts example compiles again if one replace exactly this occurence:

\documentclass{article}
%\RequirePackage{amsgen}
%relevant code from amsgen:
\makeatletter
%save old ifstar:
\let\***@ifstar\@ifstar

\long\def\***@ifnextchar#1#2#3{%
\let\***@d= #1%
\def\***@a{#2}\def\***@b{#3}%
\futurelet\@***@token\***@ifnch
}
\def\***@ifnch{%
\ifx\@***@token\***@d \let\***@b\***@a \fi
\***@b
}
\def\@ifstar#1#2{\***@ifnextchar
*{\def\***@a*{#1}\***@a}{#2}}


\usepackage{pgfgantt}
\def\***@vgrid@analyze{%
\***@ifstar{\***@vgrid@draw}{\***@vgrid@draw1}%
}


\begin{document}
\begin{ganttchart}[
vgrid={*2{red}, *1{green}, *{10}{blue, dashed}}
]{1}{20}
\gantttitle{Title 1}{20} \\
\ganttbar{}{1}{8} \\
\ganttbar{}{9}{20}
\end{ganttchart}
\end{document}
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Scott Pakin
2017-07-21 21:22:30 UTC
Permalink
Thanks! Your code does indeed seem to do the trick.

I looked in amsgen.pdf to learn *why* it redefines \@ifstar. Here's
the associated code comment:

There will essentially never be a space before the *, so using
\@ifnextchar is unnecessarily slow.

Figuring that my modern desktop computer won't grind to a crawl if I
use LaTeX's more forgiving version of \@ifstar, I tried restoring the
original \@ifstar right after loading amsmath:

\documentclass{article}
\makeatletter
\let\***@ifstar=\@ifstar
\usepackage{amsmath}
\let\@ifstar=\***@ifstar
\makeatother
\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[
vgrid={*2{red}, *1{green}, *{10}{blue, dashed}}
]{1}{20}
\gantttitle{Title 1}{20} \\
\ganttbar{}{1}{8} \\
\ganttbar{}{9}{20}
\end{ganttchart}
\end{document}

Sure enough, that simpler solution also appears to work.

-- Scott
Ulrike Fischer
2017-07-21 23:01:04 UTC
Permalink
Post by Scott Pakin
Thanks! Your code does indeed seem to do the trick.
There will essentially never be a space before the *, so using
Figuring that my modern desktop computer won't grind to a crawl if I
The comment is misleading. Speed was not the main point of the
change. Compare:

\documentclass{article}
\makeatletter
\let\***@ifstar=\@ifstar
\usepackage{amsmath}

\begin{document}
\begin{align}
a &=b\\
* &=b
\end{align}

\let\@ifstar=\***@ifstar

\begin{align}
a &=b\\
* &=b
\end{align}


\end{document}

So it would be really better if pgfgantt wouldn't use \@ifstar but
\***@ifnextchar* instead.

(The question was discussed last year in the tex.sx chat:
https://chat.stackexchange.com/transcript/41?m=28926609#28926609)
--
Ulrike Fischer
http://www.troubleshooting-tex.de/
Michael Shell
2017-07-22 01:46:55 UTC
Permalink
On Sat, 22 Jul 2017 01:01:04 +0200
The comment is misleading. Speed was not the main point of the change.
Oh, so that was it! Interesting. Thanks Ulrike, I was curious about this
one. :) My own opinion here is that amsgen should not be changing such
kernel macros.

\\ * et al. should always be interpreted consistently in LaTeX.

Or perhaps the kernel should be changed to do it the amsgen way.

Or perhaps the kernel should even provide both types of \@ifstar,
selectable by ... well, dare I suggest it:

\@ifstar{star case}{nonstar case} % sees a * only if there isn't any space
\@ifstar*{star case}{nonstar case} % sees a * even after spaces

LOL! (And yes, I set the default to the amsgen way so that the
AMS math developers won't want to redefine \@ifstar.)

This said, given that amsgen redefines \@ifstar, and given the large
number of packages that rely on \@ifstar, packages should not assume
that constructs of macros with star forms (defined using \@ifstar) like:

\MYmacro *

are always treated as

\MYmacro*

So, doesn't pgfgantt not still have a problem in that it is relying
on \@ifstar to see an * even after spaces? Ditto for the KOMA class
issue Ulrike solved:

https://tex.stackexchange.com/questions/303623/weird-asterisk-in-toc-and-section-not-working-when-using-siunitx/

As Ulrike said, simply switching to \***@ifnextchar* is an easy fix,
but I wonder why pgfgantt and KOMA are creating and relying on constructs
of the form

\MYmacro *

in the first place.

Anyway, I'm surprised, and glad, this problem has not been more
commonly encountered.


Cheers,

Mike
d***@gmail.com
2017-07-22 09:20:21 UTC
Permalink
Post by Michael Shell
Oh, so that was it! Interesting. Thanks Ulrike, I was curious about this
one. :) My own opinion here is that amsgen should not be changing such
kernel macros.
well yes but it's tricky: amsmath.sty (or rather the earlier amstex.sty)
was already doing that before latex2e was designed.
Post by Michael Shell
\\ * et al. should always be interpreted consistently in LaTeX.
Or perhaps the kernel should be changed to do it the amsgen way.
we considered that, but already back in 1993 that broke too much stuff
Post by Michael Shell
LOL! (And yes, I set the default to the amsgen way so that the
\MYmacro *
are always treated as
\MYmacro*
for a macro use above they are treated the same as the space after the control name isn't tokenized. so it's pretty much only after \\ that this is an issue for *-forms of commands, but here it's being used in argument parsing so after , or { so again the space token becomes an issue
, *1{green}

David
Scott Pakin
2017-07-26 19:07:23 UTC
Permalink
Last night, I sent a patch to Wolfgang Skala, the pgfgantt developer,
to replace \@ifstar with \***@ifnextchar*. Let's hope he accepts
it...

Thanks to all for an informative thread,
-- Scott

Loading...