2525# Loading the font directly here lead to FreeTypeAbstraction to fail with error
2626# code 35, because handles to fonts are C pointer that cannot be fully
2727# serialized at compile time
28- const _new_computer_modern_fonts = Dict(
29- :regular => joinpath(" NewComputerModern" , " NewCMMath-Regular.otf" ),
30- :italic => joinpath(" NewComputerModern" , " NewCM10-Italic.otf" ),
31- :bold => joinpath(" NewComputerModern" , " NewCM10-Bold.otf" ),
32- :bolditalic => joinpath(" NewComputerModern" , " NewCM10-BoldItalic.otf" ),
33- :math => joinpath(" NewComputerModern" , " NewCMMath-Regular.otf" )
34- )
3528
36- const _computer_modern_fonts = Dict(
37- :regular => joinpath(" ComputerModern" , " cmr10.ttf" ),
38- :italic => joinpath(" ComputerModern" , " cmmi10.ttf" ),
39- :bold => joinpath(" ComputerModern" , " cmb10.ttf" ),
40- :bolditalic => joinpath(" ComputerModern" , " cmmib10.ttf" ),
41- :math => joinpath(" ComputerModern" , " cmmi10.ttf" )
42- )
4329
4430const _default_font_mapping = Dict(
4531 :text => :regular,
@@ -58,20 +44,27 @@ const _default_font_modifiers = Dict(
5844)
5945
6046"""
61- FontFamily([ fonts, font_mapping, font_modifiers, slant_angle] )
47+ FontFamily(fonts ; font_mapping, font_modifiers, special_chars, slant_angle, thickness )
6248
6349A set of font for LaTeX rendering.
6450
65- # Fields
51+ # Required fields
52+ - `fonts` A with the path to 5 fonts (:regular, :italic, :bold, :bolditalic,
53+ and :math). The same font can be used for multiple entries, and unrelated
54+ fonts can be mixed.
55+
56+ # Optional fields
6657 - `font_mapping` a dict mapping the different character types (`:digit`,
6758 `:function`, `:punctuation`, `:symbol`, `:variable`) to a font identifier.
6859 Default to `MathTeXEngine._default_font_mapping`
69- - `fonts` a dict mapping font identifier to a font path. Default to
70- `MathTeXEngine._default_fonts` which represents the NewComputerModern font.
7160 - `font_modifiers` a dict of dict, one entry per font command supported in the
7261 font set. Each entry is a dict that maps a font identifier to another.
7362 Default to `MathTeXEngine._default_font_modifiers`.
74- - `slant_angle` the angle by which the italic fonts are slanted, in degree
63+ - `specail_chars` mapping for special characters that should not be
64+ represented by their default unicode glyph
65+ (for example necessary to access the big integral glyph).
66+ - `slant_angle` the angle by which the italic fonts are slanted, in degree.
67+ - `thickness` the thickness of the lines associated to the font.
7568"""
7669struct FontFamily
7770 fonts:: Dict{Symbol, String}
@@ -82,29 +75,64 @@ struct FontFamily
8275 thickness:: Float64
8376end
8477
78+ function FontFamily(fonts:: Dict ;
79+ font_mapping = _default_font_mapping,
80+ font_modifiers = _default_font_modifiers,
81+ special_chars = Dict{Char, Tuple{String, Int}}(),
82+ slant_angle = 13 ,
83+ thickness = 0.0375 )
84+
85+ return FontFamily(
86+ fonts,
87+ font_mapping,
88+ font_modifiers,
89+ special_chars,
90+ slant_angle,
91+ thickness
92+ )
93+ end
94+
95+ """
96+ FontFamily(name::String = "NewComputerModern")
97+
98+ One of the default set of font for LaTeX rendering.
99+
100+ Currently available are
101+ - NewComputerModern
102+ - TeXGyreHeros
103+
104+ These names can also be used in a LaTeXString directly,
105+ with the command `\\ fontfamily`,
106+ e.g. L"\\ fontfamily{TeXGyreHeros}x^2_3".
107+ """
85108FontFamily() = FontFamily(" NewComputerModern" )
86- FontFamily(fontname) = default_font_families[fontname]
109+ FontFamily(fontname:: AbstractString ) = default_font_families[fontname]
87110
88111# These two fonts internals are very different, despite their similar names
89112# We only try to fully support NewComputerModern, the other is here as it may
90113# sometime provide quickfix solution to bug
91114const default_font_families = Dict(
92115 " NewComputerModern" => FontFamily(
93- _new_computer_modern_fonts,
94- _default_font_mapping,
95- _default_font_modifiers,
96- _symbol_to_new_computer_modern,
97- 13 ,
98- 0.0375 ),
99- " ComputerModern" => FontFamily(
100- _computer_modern_fonts,
101- _default_font_mapping,
102- _default_font_modifiers,
103- _symbol_to_computer_modern,
104- 15 ,
105- 0.0375 )
116+ Dict(
117+ :regular => joinpath(" NewComputerModern" , " NewCMMath-Regular.otf" ),
118+ :italic => joinpath(" NewComputerModern" , " NewCM10-Italic.otf" ),
119+ :bold => joinpath(" NewComputerModern" , " NewCM10-Bold.otf" ),
120+ :bolditalic => joinpath(" NewComputerModern" , " NewCM10-BoldItalic.otf" ),
121+ :math => joinpath(" NewComputerModern" , " NewCMMath-Regular.otf" )
122+ ),
123+ special_chars = _symbol_to_new_computer_modern),
124+ " TeXGyreHeros" => FontFamily(
125+ Dict(
126+ :regular => joinpath(" TeXGyreHerosMakie" , " TeXGyreHerosMakie-Regular.otf" ),
127+ :italic => joinpath(" TeXGyreHerosMakie" , " TeXGyreHerosMakie-Italic.otf" ),
128+ :bold => joinpath(" TeXGyreHerosMakie" , " TeXGyreHerosMakie-Bold.otf" ),
129+ :bolditalic => joinpath(" TeXGyreHerosMakie" , " TeXGyreHerosMakie-BoldItalic.otf" ),
130+ :math => joinpath(" TeXGyreHerosMakie" , " TeXGyreHerosMakie-Regular.otf" )
131+ )
132+ )
106133)
107134
135+
108136"""
109137 get_font([font_family=FontFamily()], fontstyle)
110138
0 commit comments