Skip to content

Commit f514403

Browse files
cpp-nielClang Robot
andauthored
Add support for \matrix
* Add matrix parsing Matrices are parsed into a `matrix` struct that contains the matrix rows. Tests ensure that simple and more complex matrices are being parsed correctly as well as triggering the potential "missing closing brace error". * Add initial version of matrix noad layouting * Initial working version of arbitrarily sized assembled delimiters * Tidy up * Fit and finish for arbitrarily sized delimiters and matrices * Add assembled delimiters and matrices to docs * Fix unit tests * Additional unit tests * Add new approval test approved files * Finalize tests and update approval files - Correct algorithm for determining best auto sized glyph * 🎨 Committing clang-format changes --------- Co-authored-by: Clang Robot <robot@example.com>
1 parent 0ff59ad commit f514403

39 files changed

Lines changed: 2326 additions & 627 deletions

doc/features.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ of approval tests used to help test the library for regressions.
1414
- [Subscripts and Superscripts](#subscripts-and-superscripts)
1515
- [Fractions](#fractions)
1616
- [Radicals](#radicals)
17+
- [Matrices](#matrices)
1718
- [Big Operators](#big-operators)
1819
- [Accents](#accents)
1920
- [Overlining and Underlining](#overlining-and-underlining)
@@ -29,36 +30,49 @@ of approval tests used to help test the library for regressions.
2930
- [Punctuation](#punctuation)
3031
- [Others](#others)
3132
- [Spaces](#spaces)
32-
3333

3434
## Subscripts and Superscripts
3535

3636
Subscripts and superscripts including all levels of nesting are supported:
3737

3838
![](./../tests/approval_tests/approved_files/docs.subscripts_and_superscripts.approved.svg)
3939

40-
4140
## Fractions
4241

4342
There is full support for the standard `\frac` command - again, including all levels of nesting:
4443

4544
![](./../tests/approval_tests/approved_files/docs.fractions.approved.svg)
4645

47-
The `\binom` command is also supported and anything that is not covered by either `\frac` or
46+
The `\binom` command is also supported and anything that is not covered by either `\frac` or
4847
`\binom` can be achieved using the generalized fraction command `\genfrac`:
4948

5049
![](./../tests/approval_tests/approved_files/docs.genfrac.approved.svg)
5150

52-
Note that in generalized fractions the third argument - the line thickness - is always in points and that currently
51+
Note that in generalized fractions the third argument - the line thickness - is always in points and that currently
5352
the fourth argument - the style - is ignored and treated as if `\displaystyle` was set.
5453

55-
5654
## Radicals
5755

5856
*mfl* has full support for radicals, including the optional degree and unlimited nesting:
5957

6058
![](./../tests/approval_tests/approved_files/docs.radicals.approved.svg)
6159

60+
## Matrices
61+
62+
TeX-style matrices are supported via the `\matrix` command:
63+
64+
![](./../tests/approval_tests/approved_files/docs.matrix.approved.svg)
65+
66+
For example, *J* in the second row above is defined as follows:
67+
68+
```
69+
J = \left(\matrix{
70+
\frac{\partial f_1}{\partial x_1} & \frac{\partial f_1}{\partial x_2} & \cdots & \frac{\partial f_1}{\partial x_n} \cr
71+
\frac{\partial f_2}{\partial x_1} & \frac{\partial f_2}{\partial x_2} & \cdots & \frac{\partial f_2}{\partial x_n} \cr
72+
\vdots & \vdots & \ddots & \vdots \cr
73+
\frac{\partial f_m}{\partial x_1} & \frac{\partial f_m}{\partial x_2} & \cdots & \frac{\partial f_m}{\partial x_n}
74+
}\right)
75+
```
6276

6377
## Big Operators
6478

@@ -75,7 +89,6 @@ The extended integral symbols are also considered big operators:
7589

7690
![](./../tests/approval_tests/approved_files/docs.big_ops_integrals.approved.svg)
7791

78-
7992
## Accents
8093

8194
There is support for the common mathematical accents:
@@ -90,14 +103,12 @@ There is also support for some additional mathematical accents:
90103

91104
![](./../tests/approval_tests/approved_files/docs.additional_accents.approved.svg)
92105

93-
94106
## Overlining and Underlining
95107

96108
The automatic positioning and sizing of overlines and underlines is fully supported:
97109

98110
![](./../tests/approval_tests/approved_files/docs.lines.approved.svg)
99111

100-
101112
## Functions and User Defined Operators
102113

103114
Unlike variables, known functions are typeset in roman instead of italics. *mfl* also
@@ -110,7 +121,6 @@ behave like built-in functions:
110121

111122
![](./../tests/approval_tests/approved_files/docs.operatorname.approved.svg)
112123

113-
114124
## Delimiters
115125

116126
The following symbols are recognized as opening and closing delimiters:
@@ -122,17 +132,20 @@ available, and the dot variants `\left.` and `\right.` can be used to omit one o
122132

123133
![](./../tests/approval_tests/approved_files/docs.sized_delimiters.approved.svg)
124134

135+
If supported by the font, *mfl* will also assemble delimiters from "parts" allowing the use of
136+
oversized - and effectively arbitrarily sized - delimiters:
137+
138+
![](./../tests/approval_tests/approved_files/docs.extra_large_delimiters.approved.svg)
125139

126140
## Fonts
127141

128142
*mfl* only supports the scoped font switches (like `\mathrm`, `\mathit` etc.) and not the
129143
deprecated state switches (like `\rm`, `\it` etc.). *mfl* recognises the font
130-
commands in the examples below. Availability and appearance of glyphs will of course
144+
commands in the examples below. Availability and appearance of glyphs will of course
131145
depend on the actual fonts that are being used. This is what the *Stix2* fonts look like:
132146

133147
![](./../tests/approval_tests/approved_files/docs.fonts.approved.svg)
134148

135-
136149
## Symbols
137150

138151
*mfl* recognises most mathematical symbols. Here is an overview of the most important ones
@@ -142,12 +155,11 @@ for reference.
142155

143156
![](./../tests/approval_tests/approved_files/docs.greek_alphabet_lowercase.approved.svg)
144157

145-
As per mathematical convention, Greek capitals are automatically set in roman font and
158+
As per mathematical convention, Greek capitals are automatically set in roman font and
146159
not in italics.
147160

148161
![](./../tests/approval_tests/approved_files/docs.greek_alphabet_uppercase.approved.svg)
149162

150-
151163
### Binary Operators
152164

153165
*mfl* supports the basic TeX binary operators:
@@ -158,7 +170,6 @@ as well as various binary operators from additional packages like the AMS packag
158170

159171
![](./../tests/approval_tests/approved_files/docs.additional_binary_operators.approved.svg)
160172

161-
162173
### Relational Operators
163174

164175
Similarly to the binary operators, *mfl* supports the fundamental relational operators:
@@ -169,7 +180,6 @@ but also recognises many others:
169180

170181
![](./../tests/approval_tests/approved_files/docs.additional_relational_operators.approved.svg)
171182

172-
173183
#### Negations
174184

175185
Many relations can be negated by prepending `\not`:
@@ -180,7 +190,6 @@ and some further negated relational operators are also supported:
180190

181191
![](./../tests/approval_tests/approved_files/docs.additional_negations.approved.svg)
182192

183-
184193
### Arrows
185194

186195
The TeX arrow symbols are supported:
@@ -191,14 +200,12 @@ and *mfl* will also recognise the following extended set of arrow symbols:
191200

192201
![](./../tests/approval_tests/approved_files/docs.additional_arrows.approved.svg)
193202

194-
195203
### Punctuation
196204

197205
*mfl* recognises the following symbols as punctuation:
198206

199207
![](./../tests/approval_tests/approved_files/docs.punctuation.approved.svg)
200208

201-
202209
### Others
203210

204211
For completeness, the following tables show the remaining supported symbols:
@@ -207,7 +214,6 @@ For completeness, the following tables show the remaining supported symbols:
207214
![](./../tests/approval_tests/approved_files/docs.combining_symbols.approved.svg)
208215
![](./../tests/approval_tests/approved_files/docs.dots.approved.svg)
209216

210-
211217
## Spaces
212218

213219
The following mathematical spacing commands are recognized by *mfl*:

include/mfl/abstract_font_face.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#include "mfl/font_family.hpp"
55
#include "mfl/units.hpp"
66

7-
#include <cstddef>
8-
#include <cstdint>
97
#include <functional>
108
#include <memory>
9+
#include <optional>
1110
#include <vector>
1211

1312
namespace mfl
@@ -68,6 +67,21 @@ namespace mfl
6867
std::int32_t size = 0;
6968
};
7069

70+
struct glyph_part
71+
{
72+
size_t glyph_index = 0;
73+
std::int32_t start_connector_length = 0;
74+
std::int32_t end_connector_length = 0;
75+
std::int32_t full_advance = 0;
76+
bool is_extender;
77+
};
78+
79+
struct glyph_assembly
80+
{
81+
std::vector<glyph_part> parts;
82+
std::int32_t italic_correction;
83+
};
84+
7185
struct abstract_font_face
7286
{
7387
virtual ~abstract_font_face() = default;
@@ -77,6 +91,8 @@ namespace mfl
7791
const bool use_large_variant) const = 0;
7892
[[nodiscard]] virtual std::vector<size_variant> horizontal_size_variants(const code_point char_code) const = 0;
7993
[[nodiscard]] virtual std::vector<size_variant> vertical_size_variants(const code_point char_code) const = 0;
94+
[[nodiscard]] virtual std::optional<glyph_assembly> horizontal_assembly(const code_point char_code) const = 0;
95+
[[nodiscard]] virtual std::optional<glyph_assembly> vertical_assembly(const code_point char_code) const = 0;
8096
virtual void set_size(const points size) = 0;
8197
};
8298

include/mfl/detail/quantity.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ namespace mfl::detail
8585

8686
template <typename Tag>
8787
std::ostream& operator<<(std::ostream& os, const quantity<Tag>& p)
88-
{ return os << std::format("{}", p); }
88+
{
89+
return os << std::format("{}", p);
90+
}
8991
}

include/mfl/units.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ namespace mfl
2323

2424
constexpr dots_per_inch operator""_dpi(const long double x) { return dots_per_inch{static_cast<double>(x)}; }
2525
constexpr dots_per_inch operator""_dpi(const unsigned long long x)
26-
{ return dots_per_inch{static_cast<double>(x)}; }
26+
{
27+
return dots_per_inch{static_cast<double>(x)};
28+
}
2729

2830
constexpr pixels operator""_px(const long double x) { return pixels{static_cast<double>(x)}; }
2931
constexpr pixels operator""_px(const unsigned long long x) { return pixels{static_cast<double>(x)}; }

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_library(mfl
1111
noad/gen_script.cpp
1212
noad/left_right.cpp
1313
noad/math_char.cpp
14+
noad/matrix.cpp
1415
noad/noad.cpp
1516
noad/overline.cpp
1617
noad/radical.cpp
@@ -33,6 +34,7 @@ add_library(mfl
3334
parser/line.cpp
3435
parser/math_char.cpp
3536
parser/math_space.cpp
37+
parser/matrix.cpp
3638
parser/parse.cpp
3739
parser/parser_state.cpp
3840
parser/parser_utilities.cpp

0 commit comments

Comments
 (0)