Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: undefined \mathdefault #27907

Open
@tobiasBora

Description

@tobiasBora

Bug summary

If we\input the pgf file created by matplotlib with pgf backend, it assumes\mathdefault to exist. But unfortunately, this command is not provided by any of the recommended packages as far as I see: to produce the actualpdf file, matplotlib seems to actually define it manually like:

\def\mathdefault#1{#1}

as can be read from the automatically generated .pgf file… Manually adding this line in the .tex file before the\input works as a workaround, but this seems like a dirty workaround as this is not documented as far as I can see.

Would it be possible to either document it or provide these commands in a properly packaged latex library?

See also this discussionleo-colisson/robust-externalize#31

Code for reproduction

importmatplotlib.pyplotaspltimportmatplotlibmatplotlib.use('pgf')plt.rcParams.update({"text.usetex":True, })plt.rcParams.update({"pgf.preamble":"\n".join([r"\usepackage{fontspec}",r"\usepackage{amsmath}",r"\usepackage{amssymb}",    ]),})plt.rcParams['text.latex.preamble']=r'\newcommand{\mathdefault}[1][]{}'# doesn't seem to work.year= [2014,2015,2016,2017,2018,2019]tutorial_count= [39,117,111,110,67,29]plt.plot(year,tutorial_count,color="#6c3376",linewidth=2)plt.title("Simple plot")plt.xlabel('Year')plt.ylabel('Number of futurestud.io Tutorials')plt.savefig("foo.pgf",bbox_inches="tight")

Actual outcome

I would expect\input of the pgf file to work, but it is not. Here is the full file I use to both compile the python and include it (using the recent robust-externalize library, you might need to copy the .sty from to install it and you might want to compile with-shell-escape for simplicity)

\documentclass{article} \usepackage{lipsum}\usepackage{tikz}\usepackage{robust-externalize}\robExtConfigure{enable fallback to manual mode} % prints a helpful message in the document if you forgot --shell-escape%% If you do not add this line, this will return an error:%\def\mathdefault#1{#1}\begin{document}\lipsum[1]\begin{figure}[ht]  \centering  \begin{CacheMeCode}{python, custom include command={\input{\robExtAddCachePathAndName{\robExtFinalHash.pgf}}}, set placeholder eval={__LINEWIDTH__}{\lenToCmNoUnit[in]{\linewidth}}}    import matplotlib.pyplot as plt    import matplotlib    from matplotlib.pyplot import figure    matplotlib.use("pgf")    # See this link for details on how to preview the image in jupyter    # https://matplotlib.org/stable/users/explain/text/pgf.html    matplotlib.rcParams.update({      "font.family": "serif",      "font.serif": [], # Use LaTeX default serif font.      "text.usetex": True, # use inline math for ticks    })    figure(figsize=(__LINEWIDTH__, 0.7*__LINEWIDTH__))    year = [2014, 2015, 2016, 2017, 2018, 2019]    tutorial_count = [39, 117, 111, 110, 67, 29]    plt.plot(year, tutorial_count, color="#6c3376", linewidth=2)    plt.title("Simple plot for $\delta = 2$")    plt.xlabel('Year')    plt.ylabel('Number of futurestud.io Tutorials')    print(get_filename_from_extension(".pgf"))    # https://stackoverflow.com/a/52587591/4987648    plt.savefig(get_filename_from_extension(".pgf"), bbox_inches="tight")  \end{CacheMeCode}  \caption{Test}%\end{figure}\end{document}% Local Variables:% TeX-command-extra-options: "--shell-escape -halt-on-error"% End:

Expected outcome

I expect the use of\def\mathdefault#1{#1} to be at least documented, ideally automatically defined in the.pgf file if the command does not already exist with something like:

\providecommand\mathdefault[1]{#1}

Additional information

This seems to be a regression, as it used not to be a problem on 3.7 I think.

Operating system

NixOs

Matplotlib Version

3.8.2

Matplotlib Backend

pgf

Python version

3.11.8

Jupyter version

Not using jupyter

Installation

Linux package manager

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp