Skip to content

Slightly refactor TeX source generation. #22359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,27 @@ def make_tex(self, tex, fontsize):
"""
basefile = self.get_basefile(tex, fontsize)
texfile = '%s.tex' % basefile
fontcmd = {'sans-serif': r'{\sffamily %s}',
'monospace': r'{\ttfamily %s}'}.get(self._font_family,
r'{\rmfamily %s}')

Path(texfile).write_text(
r"""
%s
fontcmd = (r'\sffamily' if self._font_family == 'sans-serif' else
r'\ttfamily' if self._font_family == 'monospace' else
r'\rmfamily')
tex_template = r"""
%(preamble)s
\pagestyle{empty}
\begin{document}
%% The empty hbox ensures that a page is printed even for empty inputs, except
%% when using psfrag which gets confused by it.
\fontsize{%f}{%f}%%
\fontsize{%(fontsize)f}{%(baselineskip)f}%%
\ifdefined\psfrag\else\hbox{}\fi%%
%s
{%(fontcmd)s %(tex)s}
\end{document}
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
encoding='utf-8')
"""
Path(texfile).write_text(tex_template % {
"preamble": self._get_preamble(),
"fontsize": fontsize,
"baselineskip": fontsize * 1.25,
"fontcmd": fontcmd,
"tex": tex,
}, encoding="utf-8")

return texfile

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy