Skip to content

Commit 594caad

Browse files
committed
Add Latin Modern support for mathtext
1 parent 6eeede6 commit 594caad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+78
-6
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,43 @@ class DejaVuSerifFonts(DejaVuFonts):
640640
}
641641

642642

643+
class LatinModernFonts(UnicodeFonts):
644+
"""
645+
A font handling class for the Latin Modern fonts
646+
647+
"""
648+
_fontmap = {
649+
'rm': 'Latin Modern Roman',
650+
'it': 'Latin Modern Roman:italic',
651+
'bf': 'Latin Modern Roman:weight=bold',
652+
'bfit': 'Latin Modern Roman:italic:bold',
653+
'tt': 'Latin Modern Mono',
654+
'sf': 'Latin Modern Sans',
655+
'ex': 'Latin Modern Math'
656+
}
657+
_fallback_font = False
658+
_sans = False
659+
660+
def __init__(self, *args, **kwargs):
661+
# This must come first so the backend's owner is set correctly
662+
self.fontmap = {}
663+
TruetypeFonts.__init__(self, *args, **kwargs)
664+
665+
for key, name in self._fontmap.items():
666+
fullpath = findfont(name)
667+
self.fontmap[key] = fullpath
668+
self.fontmap[name] = fullpath
669+
670+
def _get_glyph(self, fontname, font_class, sym):
671+
uniindex = get_unicode_index(sym)
672+
font = self._get_font(fontname)
673+
if font is not None:
674+
glyphindex = font.get_char_index(uniindex)
675+
if glyphindex != 0:
676+
return super()._get_glyph(fontname, font_class, sym)
677+
return super()._get_glyph('ex', font_class, sym)
678+
679+
643680
class DejaVuSansFonts(DejaVuFonts):
644681
"""
645682
A font handling class for the DejaVu Sans fonts
@@ -841,6 +878,10 @@ class FontConstantsBase:
841878
delta_integral = 0.1
842879

843880

881+
class LatinModernFontConstants(FontConstantsBase):
882+
pass
883+
884+
844885
class ComputerModernFontConstants(FontConstantsBase):
845886
script_space = 0.075
846887
subdrop = 0.2
@@ -888,6 +929,8 @@ class DejaVuSansFontConstants(FontConstantsBase):
888929
'cmss10': ComputerModernFontConstants,
889930
'cmsy10': ComputerModernFontConstants,
890931
'cmtt10': ComputerModernFontConstants,
932+
'Latin Modern Roman': LatinModernFontConstants,
933+
'Latin Modern Math': LatinModernFontConstants,
891934
'STIXGeneral': STIXFontConstants,
892935
'STIXNonUnicode': STIXFontConstants,
893936
'STIXSizeFiveSym': STIXFontConstants,

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class FontProperties:
562562
absolute font size, e.g., 10. Default: :rc:`font.size`
563563
564564
- math_fontfamily: The family of fonts used to render math text.
565-
Supported values are: 'dejavusans', 'dejavuserif', 'cm',
565+
Supported values are: 'lm', 'dejavusans', 'dejavuserif', 'cm',
566566
'stix', 'stixsans' and 'custom'. Default: :rc:`mathtext.fontset`
567567
568568
Alternatively, a font may be specified using the absolute path to a font

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MathTextParser:
4141
'dejavusans': _mathtext.DejaVuSansFonts,
4242
'stix': _mathtext.StixFonts,
4343
'stixsans': _mathtext.StixSansFonts,
44+
'lm': _mathtext.LatinModernFonts,
4445
'custom': _mathtext.UnicodeFonts,
4546
}
4647

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
% This is version 1.0, dated 22 June 2009, of the GUST Font License.
2+
% (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
3+
%
4+
% For the most recent version of this license see
5+
% http://www.gust.org.pl/fonts/licenses/GUST-FONT-LICENSE.txt
6+
% or
7+
% http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt
8+
%
9+
% This work may be distributed and/or modified under the conditions
10+
% of the LaTeX Project Public License, either version 1.3c of this
11+
% license or (at your option) any later version.
12+
%
13+
% Please also observe the following clause:
14+
% 1) it is requested, but not legally required, that derived works be
15+
% distributed only after changing the names of the fonts comprising this
16+
% work and given in an accompanying "manifest", and that the
17+
% files comprising the Work, as listed in the manifest, also be given
18+
% new names. Any exceptions to this request are also given in the
19+
% manifest.
20+
%
21+
% We recommend the manifest be given in a separate file named
22+
% MANIFEST-<fontid>.txt, where <fontid> is some unique identification
23+
% of the font family. If a separate "readme" file accompanies the Work,
24+
% we recommend a name of the form README-<fontid>.txt.
25+
%
26+
% The latest version of the LaTeX Project Public License is in
27+
% http://www.latex-project.org/lppl.txt and version 1.3c or later
28+
% is part of all distributions of LaTeX version 2006/05/20 or later.
Binary file not shown.
109 KB
Binary file not shown.
115 KB
Binary file not shown.
109 KB
Binary file not shown.
116 KB
Binary file not shown.
92.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)