From 08ac15181110e9d6f69583f024ecb6b408a86868 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 29 Jan 2022 13:51:45 +0100 Subject: [PATCH] Slightly refactor TeX source generation. - Don't use a nested format string (`fontcmd % tex`); simply pass `fontcmd` and `tex` separately. - Use named formats to make things easier to track. --- lib/matplotlib/texmanager.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index c9960c8c14cd..88ac43bad56e 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -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 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