matze / mtheme

A modern LaTeX Beamer theme
6.43k stars 846 forks source link

Failed to compile when using `evaluate` custom math functions with `pgfplots` #366

Open xiehao opened 4 years ago

xiehao commented 4 years ago

The following MWE shows this case:

\documentclass[]{beamer}
\usetheme{metropolis}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{pgfplots}
\begin{document}
    \begin{frame}
        \frametitle{MWE}
        \centering
        \begin{tikzpicture}[
            >=stealth,
            evaluate={
                function f(\x) {
                    return cos(2*\x);
                };
            },
            declare function={
                g(\x) = cos(2*\x);
            }
            ]
            \begin{axis}[
                axis lines=middle,
                xtick=\empty,
                ytick=\empty,
                xmin=-200,
                xmax=200,
                ymin=-1.5,
                ymax=1.5
                ]
                \addplot[
                    domain=-180:180,
                    samples=361
                    ]{f(x)};
                \node[coordinate,pin=above right:{$\cos 2x$}] at (axis cs:45,{f(45)}) {}; % ERROR when using metropolis theme
                \node[coordinate,pin=above right:{$\cos 2x$}] at (axis cs:45,{g(45)}) {};
            \end{axis}
        \end{tikzpicture}
    \end{frame}
\end{document}

As shown in the comment, the function declared by evaluate (say, function f) cannot pass and shows errors; while the function declared by declare function (say, function g) works fine.

The error output:

xelatex: unrecognized option '-pdf'
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019/Arch Linux) (preloaded format=xelatex)
 \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2019-10-01> patch level 1
(/usr/share/texmf-dist/tex/latex/beamer/beamer.cls
Document Class: beamer 2019/09/29 v3.57 A class for typesetting presentations
(/usr/share/texmf-dist/tex/latex/beamer/beamerbasemodes.sty (/usr/share/texmf-dist/tex/latex/etoolbox/etoolbox.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasedecode.sty)) (/usr/share/texmf-dist/tex/generic/oberdiek/ifpdf.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseoptions.sty (/usr/share/texmf-dist/tex/latex/graphics/keyval.sty)) (/usr/share/texmf-dist/tex/latex/geometry/geometry.sty (/usr/share/texmf-dist/tex/generic/oberdiek/ifvtex.sty) (/usr/share/texmf-dist/tex/generic/ifxetex/ifxetex.sty)) (/usr/share/texmf-dist/tex/latex/base/size11.clo) (/usr/share/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty (/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/share/texmf-dist/tex/latex/graphics/graphics.sty (/usr/share/texmf-dist/tex/latex/graphics/trig.sty) (/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg) (/usr/share/texmf-dist/tex/latex/graphics-def/xetex.def))) (/usr/share/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty (/usr/share/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.tex (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-lists.tex)) (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def (/usr/share/texmf-dist/tex/latex/ms/everyshi.sty)) (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex (/usr/share/texmf-dist/tex/generic/pgf/pgf.revision.tex))) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.code.tex)) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-xetex.def (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-dvipdfmx.def (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-pdf.def)))) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.code.tex)) (/usr/share/texmf-dist/tex/latex/xcolor/xcolor.sty (/usr/share/texmf-dist/tex/latex/graphics-cfg/color.cfg)) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.comparison.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integerarithmetics.code.tex))) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfint.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconstruct.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicstate.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransformations.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathprocessing.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.code.tex (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.code.tex)) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransparency.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code.tex))) (/usr/share/texmf-dist/tex/latex/pgf/utilities/xxcolor.sty) (/usr/share/texmf-dist/tex/generic/oberdiek/atbegshi.sty (/usr/share/texmf-dist/tex/generic/oberdiek/infwarerr.sty) (/usr/share/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)) (/usr/share/texmf-dist/tex/latex/hyperref/hyperref.sty (/usr/share/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty (/usr/share/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty)) (/usr/share/texmf-dist/tex/latex/oberdiek/auxhook.sty) (/usr/share/texmf-dist/tex/latex/oberdiek/kvoptions.sty) (/usr/share/texmf-dist/tex/latex/hyperref/pd1enc.def) (/usr/share/texmf-dist/tex/latex/latexconfig/hyperref.cfg) (/usr/share/texmf-dist/tex/latex/url/url.sty)

Package hyperref Message: Stopped early.

) (/usr/share/texmf-dist/tex/latex/hyperref/hxetex.def (/usr/share/texmf-dist/tex/latex/hyperref/puenc.def) (/usr/share/texmf-dist/tex/generic/oberdiek/stringenc.sty) (/usr/share/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty)) (/usr/share/texmf-dist/tex/generic/oberdiek/se-ascii-print.def) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaserequires.sty (/usr/share/texmf-dist/tex/latex/beamer/beamerbasecompatibility.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasefont.sty (/usr/share/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texmf-dist/tex/latex/sansmathaccent/sansmathaccent.sty (/usr/share/texmf-dist/tex/latex/filehook/filehook.sty))) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasetranslator.sty (/usr/share/texmf-dist/tex/latex/translator/translator.sty)) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasemisc.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasetwoscreens.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseoverlay.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasetitle.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasesection.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseframe.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseverbatim.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseframesize.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseframecomponents.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasecolor.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasenotes.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasetoc.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasetemplates.sty (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseauxtemplates.sty (/usr/share/texmf-dist/tex/latex/beamer/beamerbaseboxes.sty))) (/usr/share/texmf-dist/tex/latex/beamer/beamerbaselocalstructure.sty (/usr/share/texmf-dist/tex/latex/tools/enumerate.sty)) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasenavigation.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasetheorems.sty (/usr/share/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/share/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texmf-dist/tex/latex/amscls/amsthm.sty)) (/usr/share/texmf-dist/tex/latex/beamer/beamerbasethemes.sty)) (/usr/share/texmf-dist/tex/latex/beamer/beamerthemedefault.sty (/usr/share/texmf-dist/tex/latex/beamer/beamerfontthemedefault.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamercolorthemedefault.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerinnerthemedefault.sty) (/usr/share/texmf-dist/tex/latex/beamer/beamerouterthemedefault.sty))) (/usr/share/texmf-dist/tex/latex/beamertheme-metropolis/beamerthememetropolis.sty (/usr/share/texmf-dist/tex/latex/pgfopts/pgfopts.sty (/usr/share/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex))) (/usr/share/texmf-dist/tex/latex/beamertheme-metropolis/beamerinnerthememetropolis.sty (/usr/share/texmf-dist/tex/latex/tools/calc.sty) (/usr/share/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty (/usr/share/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty (/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex) (/usr/share/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version-0-65.sty) (/usr/share/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version-1-18.sty)) (/usr/share/texmf-dist/tex/latex/pgf/utilities/pgffor.sty (/usr/share/texmf-dist/tex/latex/pgf/math/pgfmath.sty (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex)) (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex))) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex (/usr/share/texmf-dist/tex/generic/pgf/libraries/pgflibraryplothandlers.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmodulematrix.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarytopaths.code.tex)))) (/usr/share/texmf-dist/tex/latex/beamertheme-metropolis/beamerouterthememetropolis.sty) (/usr/share/texmf-dist/tex/latex/beamertheme-metropolis/beamercolorthememetropolis.sty) (/usr/share/texmf-dist/tex/latex/beamertheme-metropolis/beamerfontthememetropolis.sty (/usr/share/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/share/texmf-dist/tex/latex/l3packages/xparse/xparse.sty (/usr/share/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/share/texmf-dist/tex/latex/l3kernel/expl3-code.tex (/usr/share/texmf-dist/tex/latex/l3kernel/l3deprecation.def)) (/usr/share/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def))) (/usr/share/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty (/usr/share/texmf-dist/tex/latex/base/fontenc.sty (/usr/share/texmf-dist/tex/latex/base/tuenc.def)) (/usr/share/texmf-dist/tex/latex/fontspec/fontspec.cfg))))) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymath.code.tex (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfpu.code.tex (/usr/share/texmf-dist/tex/generic/pgf/libraries/pgflibraryfpu.code.tex))) (/usr/share/texmf-dist/tex/latex/pgfplots/pgfplots.sty (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplots.revision.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplots.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotscore.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/sys/pgfplotssysgeneric.code.tex)) (/usr/share/texmf-dist/tex/generic/pgfplots/libs/pgfplotslibrary.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_loader.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructureext.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsmatrix.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/numtable/pgfplotstableshared.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsdeque.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/util/pgfplotsbinary.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/util/pgfplotsbinary.data.code.tex)) (/usr/share/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.verb.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/libs/pgflibrarypgfplots.surfshading.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-xetex.def (/usr/share/texmf-dist/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-dvipdfmx.def)))) (/usr/share/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/util/pgfplotscolor.code.tex)) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotsstackedplots.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotsmeshplotimage.code.tex))) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplots.scaling.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotscoordprocessing.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplots.errorbars.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplots.markers.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplotsticks.code.tex) (/usr/share/texmf-dist/tex/generic/pgfplots/pgfplots.paths.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecorations.code.tex (/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduledecorations.code.tex)) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecorations.pathmorphing.code.tex (/usr/share/texmf-dist/tex/generic/pgf/libraries/decorations/pgflibrarydecorations.pathmorphing.code.tex)) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecorations.pathreplacing.code.tex (/usr/share/texmf-dist/tex/generic/pgf/libraries/decorations/pgflibrarydecorations.pathreplacing.code.tex))) (/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryplotmarks.code.tex (/usr/share/texmf-dist/tex/generic/pgf/libraries/pgflibraryplotmarks.code.tex))) (/usr/share/texmf-dist/tex/latex/beamertheme-metropolis/pgfplotsthemetol.sty)
No file test.aux.
*geometry* driver: auto-detecting
*geometry* detected driver: xetex
ABD: EveryShipout initializing macros (/usr/share/texmf-dist/tex/latex/hyperref/nameref.sty (/usr/share/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))

Package hyperref Warning: Rerun to get /PageLabels entry.

(/usr/share/texmf-dist/tex/latex/translator/translator-basic-dictionary-English.dict) (/usr/share/texmf-dist/tex/latex/translator/translator-bibliography-dictionary-English.dict) (/usr/share/texmf-dist/tex/latex/translator/translator-environment-dictionary-English.dict) (/usr/share/texmf-dist/tex/latex/translator/translator-months-dictionary-English.dict) (/usr/share/texmf-dist/tex/latex/translator/translator-numbers-dictionary-English.dict) (/usr/share/texmf-dist/tex/latex/translator/translator-theorem-dictionary-English.dict)
Package pgfplots notification 'compat/show suggested version=true': you might benefit from \pgfplotsset{compat=1.16} (current compat level: 1.9).

No file test.nav.
./test.tex:38: Missing \endcsname inserted.
<to be read again> 
                   \x 
l.38     \end{frame}

./test.tex:38: Missing \endcsname inserted.
<to be read again> 
                   \x 
l.38     \end{frame}

./test.tex:38: Extra \endcsname.
\tikz@math@next ...yword@ \x =1Y4.5e1];\endcsname 

l.38     \end{frame}

(/usr/share/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texmf-dist/tex/latex/amsfonts/umsb.fd) [1] (./test.aux)

Package rerunfilecheck Warning: File `test.out' has changed.
(rerunfilecheck)                Rerun to get outlines right
(rerunfilecheck)                or use package `bookmark'.

 )
(see the transcript file for additional information)
Output written on test.pdf (1 page).
SyncTeX written on test.synctex.gz.
Transcript written on test.log.

Once the line using metropolis theme (line 2) is commented, it works fine.

u-fischer commented 4 years ago

The theme defines internally a font \x for testing purpose, and the math library chokes on it. But imho this is a tikz problem: https://github.com/pgf-tikz/pgf/issues/847

hmenke commented 4 years ago

I agree that this is a bug in PGF, but I'd also argue that using public names like \x for internal testing macros is really bad practice. Surely there will be more packages and user macros where this breaks.

muzimuzhi commented 4 years ago

Related source lines are https://github.com/matze/mtheme/blob/3e1381f83c8ea64fbb6a7db9643849fbce3d3ee6/doc/metropolistheme.dtx#L30-L38

A quick workaround is to un-defefine \x after theme metropolis is loaded:

\documentclass{beamer}
\usetheme{metropolis}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{pgfplots}

% \undef is defined in etoolbox package, which is loaded by beamer
\undef\x

\begin{document}
...
\end{document}