Skip to content
Merged
Show file tree
Hide file tree
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
97 changes: 97 additions & 0 deletions reference/data/basics.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
BASICS = Dict()

BASICS["accents"] = [
L"\dot{Q} \dot{q}",
L"\vec{A} \vec{a}",
L"\bar{L} \bar{l}",
L"\hat{\Phi} \bar{\varphi}"
]

BASICS["delimiters"] = [
L"(1 + 2) (\frac{1}{2})",
L"\left(1 + 2\right) \left(\frac{1}{2}\right)",
L"\left[a + b\right] \left[\frac{a}{b}\right]",
L"\left{A + B \right} + \left{\frac{A}{B}\right}",
L"\left{\alpha + \beta \right} + \left{\frac{\alpha}{\beta}\right}",
L"\left{1 + \left[2 + \left(3 + 4\right)\right]\right}"
]

BASICS["fonts"] = [
L"\mathrm{bonjour}",
L"\mathbb{R} \mathbb{Q} \mathbb{C}",
L"\mathcal{N} \mathcal{K}"
]

BASICS["fractions"] = [
L"\frac{a + b + c}{c + b + a}",
L"\frac{a}{A + B + C}",
L"\frac{j - f}{f - j}"
]

BASICS["functions"] = [
L"\sin{\omega} + \cos{\theta}",
L"\exp{\log{2}} = 2",
L"\inf_{x} \tan(x) \leq \sup_{x} \tan(x)"
]

BASICS["infix"] = [
L"T + V",
L"7 - 2",
L"v \cdot w",
L"E = m c^2"
]

BASICS["integrals"] = [
L"\int_a^b",
L"\int \int \int"
]

BASICS["linebreaks"] = [
L"we clearly see $x = 22$\\and $y > x^2$"
]

BASICS["punctuation"] = [
L"x!",
L"23.17",
L"10,000"
]

BASICS["spaces"] = [
L"a \! b",
L"a \; b",
L"a \quad b",
L"a \qquad b"
]

BASICS["square_roots"] = [
L"\sqrt{2}",
L"\sqrt{\frac{1}{2}}",
L"\sqrt{b^2 - 4ac}",
L"\sqrt{1 + \frac{A + B}{J + U}}"
]

BASICS["subsuper"] = [
L"V^1_2",
L"U_{ij}",
L"W^{(i + j)}",
L"x_L x_y x_{y \rightarrow 0}",
L"N_\nu L_\nu A_\nu J_\nu",
L"N^\nu L^\nu A^\nu J^\nu",
L"^{87} Rb"
]

BASICS["symbols"] = [
L"k\xi",
L"\alpha \beta \gamma \delta \epsilon \omega \theta \phi \varphi \psi",
L"\Gamma \Delta \Omega \Theta \Phi \Psi",
L"\nabla \rightarrow \neq \leq \hbar",
L"\text{phi} \rightarrow \phi \quad \text{varphi} \rightarrow \varphi",
L"\text{epsilon} \rightarrow \epsilon \quad \text{varepsilon} \rightarrow \varepsilon"
]

BASICS["underover"] = [
L"\sum_{n = 1}^{m^2}",
L"\sum_{N = 1}^{M^2}",
L"\prod_{n \neq m}",
L"\prod_{N \neq M}"
]
94 changes: 94 additions & 0 deletions reference/data/spacing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const SPACING = Dict(
"Issue #142 italic roman boundaries" => [
raw"f(t)",
raw"g(x)",
raw"(f)x",
raw"(t)",
raw"\eta(t)",
raw"\alpha(t)",
raw"g(f(x))",
raw"\mathrm{y}(x)",
raw"\mathrm{g}t",
],
"Issue #95 lower-case Greek and subscript spacing" => [
raw"\eta(t)",
raw"\alpha_k",
raw"\omega_k",
raw"k\xi",
raw"\nu(k)",
raw"N_\nu L_\nu A_\nu J_\nu",
raw"x_{\alpha(k)}",
raw"v_{(a + b)_k}^i",
raw"\partial_i u_j",
raw"\phi_\varphi \rho_\sigma",
],
"Subscript and superscript combinations" => [
raw"x_i",
raw"x^i",
raw"x_i^j",
raw"V^i_j",
raw"x_{i_j}",
raw"x^{i^j}",
raw"x_{(a+b)_k}^i",
raw"T_{\alpha\beta}^{ij}",
raw"\Gamma^\mu_{\nu\rho}",
raw"\psi^\dagger_i\psi_i",
],
"PR #151 primes and deep scripts" => [
raw"x' f'",
raw"x'' f''",
raw"x′ f′",
raw"x\prime f\prime",
raw"x^\prime f^\prime",
raw"x'_y f_g'",
raw"A^{B^{C^{D^E}}}_{F_{G_{H_I}}}",
raw"f^{A'}",
],
"Roman upright and capital boundaries" => [
raw"\mathrm{d}x",
raw"\mathrm{e}^{-x}",
raw"\mathrm{Re}\,z",
raw"\mathrm{Im}\,z",
raw"\mathrm{Tr}\,A_i^j",
raw"\mathrm{Cov}(X,Y)",
raw"A_\nu B_\nu C_\nu D_\nu",
raw"M\mathrm{M}M",
],
"Issue #129 math operator spacing" => [
raw"\log x",
raw"\log(x)",
raw"\sin x",
raw"\sin(x)",
raw"\exp t",
raw"\exp(t)",
raw"\max_{t \in \{1,...,5\}}",
],
"Operators, delimiters, and fractions" => [
raw"-1,\ 2-1,\ (-1)",
raw"\alpha^*",
raw"\psi^* \psi",
raw"\frac{1}{2}\pm\sqrt{3}",
raw"\frac{1}{2}{}\pm\sqrt{3}",
raw"\left(\frac{1}{2}\right)f(t)",
raw"\sqrt{x_i^2+y_i^2}",
raw"\sum_{k=0}^n a_k x^k",
raw"\int_0^{2\pi}\sin(x)\,dx",
],
"Script layout issues #93, #105, #110, #126" => [
raw"\left(\frac{dy}{dx}\right)_0",
raw"\left(\frac{A^{xy}}{B}\right)^{1/4}",
raw"(\frac{A^{xy}}{B})^{1/4}",
raw"\left\langle\left|\int\right|\right\rangle",
raw"\left\langle\left|\left\langle\left|\int\right|\right\rangle\right|\right\rangle",
raw"x^{\frac{1}{1+2}}",
raw"x_{\frac{1}{1+2}}",
],
"Nested expressions" => [
raw"\frac{\alpha_i+\beta_i}{\gamma_i+\delta_i}",
raw"\sqrt{\frac{1+\alpha_k}{1+\beta_k}}",
raw"F_{\mu\nu}F^{\mu\nu}",
raw"\overline{z}_i",
raw"\left(\alpha_{(i+j)_k}\right)^2",
raw"\frac{\partial^2 f}{\partial x_i\partial x_j}",
],
)
145 changes: 38 additions & 107 deletions reference/references.jl
Original file line number Diff line number Diff line change
@@ -1,128 +1,59 @@
using CairoMakie
using MathTeXEngine
using LaTeXStrings

inputs = Dict()
include("data/basics.jl")
include("data/spacing.jl")

inputs["accents"] = [
L"\dot{Q} \dot{q}",
L"\vec{A} \vec{a}",
L"\bar{L} \bar{l}",
L"\hat{\Phi} \bar{\varphi}"
]

inputs["delimiters"] = [
L"(1 + 2) (\frac{1}{2})",
L"\left(1 + 2\right) \left(\frac{1}{2}\right)",
L"\left[a + b\right] \left[\frac{a}{b}\right]",
L"\left{A + B \right} + \left{\frac{A}{B}\right}",
L"\left{\alpha + \beta \right} + \left{\frac{\alpha}{\beta}\right}",
L"\left{1 + \left[2 + \left(3 + 4\right)\right]\right}"
]
with_font(font_name, expr) = latexstring("\\fontfamily{$font_name}$expr")

inputs["fonts"] = [
L"\mathrm{bonjour}",
L"\mathbb{R} \mathbb{Q} \mathbb{C}",
L"\mathcal{N} \mathcal{K}"
]
const REFERENCES = Dict(
"basics" => BASICS,
"spacing" => SPACING
)

inputs["fractions"] = [
L"\frac{a + b + c}{c + b + a}",
L"\frac{a}{A + B + C}",
L"\frac{j - f}{f - j}"
const SUPPORTED_FONTS = [
"NewComputerModern",
"TeXGyreHeros",
"TeXGyrePagella",
"LucioleMath"
]

inputs["functions"] = [
L"\sin{\omega} + \cos{\theta}",
L"\exp{\log{2}} = 2",
L"\inf_{x} \tan(x) \leq \sup_{x} \tan(x)"
]

inputs["infix"] = [
L"T + V",
L"7 - 2",
L"v \cdot w",
L"E = m c^2"
]

inputs["integrals"] = [
L"\int_a^b",
L"\int \int \int"
]

inputs["linebreaks"] = [
L"we clearly see $x = 22$\\and $y > x^2$"
]

inputs["punctuation"] = [
L"x!",
L"23.17",
L"10,000"
]
function generate(destination_folder, references = REFERENCES, fonts = SUPPORTED_FONTS)
@info "Generating reference images in folder $destination_folder"

inputs["spaces"] = [
L"a \! b",
L"a \; b",
L"a \quad b",
L"a \qquad b"
]

inputs["square_roots"] = [
L"\sqrt{2}",
L"\sqrt{\frac{1}{2}}",
L"\sqrt{b^2 - 4ac}",
L"\sqrt{1 + \frac{A + B}{J + U}}"
]

inputs["subsuper"] = [
L"V^1_2",
L"U_{ij}",
L"W^{(i + j)}",
L"x_L x_y x_{y \rightarrow 0}",
L"N_\nu L_\nu A_\nu J_\nu",
L"N^\nu L^\nu A^\nu J^\nu",
L"^{87} Rb"
]

inputs["symbols"] = [
L"\alpha \beta \gamma \delta \epsilon \omega \theta \phi \varphi \psi",
L"\Gamma \Delta \Omega \Theta \Phi \Psi",
L"\nabla \rightarrow \neq \leq \hbar",
L"\text{phi} \rightarrow \phi \quad \text{varphi} \rightarrow \varphi",
L"\text{epsilon} \rightarrow \epsilon \quad \text{varepsilon} \rightarrow \varepsilon"
]
path = mkpath(destination_folder)
failures = Dict()
for (group, data) in references
if data isa AbstractDict
generate(joinpath(destination_folder, group), data)
else
fig, fails = reference_figure(data, fonts)

inputs["underover"] = [
L"\sum_{n = 1}^{m^2}",
L"\sum_{N = 1}^{M^2}",
L"\prod_{n \neq m}",
L"\prod_{N \neq M}"
]
if !isempty(fails)
failures[group] = fails
end

function generate(name)
@info "Generating reference image at $name"
path = mkpath(name)
failures = Dict()
for (group, exprs) in inputs
fig, fails = single_figure(exprs)
if !isempty(fails)
failures[group] = fails
save(joinpath(path, "$group.png"), fig, px_per_unit=3)
end

save(joinpath(path, "$group.png"), fig, px_per_unit=3)
end

return failures
end

function single_figure(exprs)
fig = Figure(size=(200, length(exprs)*60))
function reference_figure(exprs, fonts = SUPPORTED_FONTS)
fig = Figure()
failures = Dict()
for (i, expr) in enumerate(exprs)
try
Label(fig[i, 1], expr)
catch e
failures[expr] = e
end
for (j, font) in enumerate(fonts)
Label(fig[0, j], font)
for (i, expr) in enumerate(exprs)
try
Label(fig[i, j], with_font(font, expr))
catch e
failures[expr] = e
end
end
end
resize_to_layout!(fig)
return fig, failures
end
5 changes: 5 additions & 0 deletions src/MathTeXEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export glyph_index
# Reexport from LaTeXStrings
export @L_str

# Advanced layout/parser knobs. These are intentionally not exported, but may
# be toggled by qualified access when debugging regressions.
const italic_correction_enabled = Ref(true)
const unspace_binary_operators_heuristic_enabled = Ref(true)

include("parser/tokenizer.jl")
include("parser/texexpr.jl")
include("parser/commands_data.jl")
Expand Down
6 changes: 2 additions & 4 deletions src/engine/fonts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,8 @@ object.
get_fontpath(font_family::FontFamily, fontstyle::Symbol) = full_fontpath(font_family.fonts[fontstyle])
get_fontpath(fontstyle::Symbol) = get_fontpath(FontFamily(), fontstyle)

function is_slanted(font_family, char_type)
font_id = font_family.font_mapping[char_type]
return font_id == :italic
end
is_slanted_font(font_id) = font_id in (:italic, :bolditalic)
is_slanted(font_family, char_type) = is_slanted_font(font_family.font_mapping[char_type])

slant_angle(font_family) = font_family.slant_angle * π / 180

Expand Down
Loading
Loading