Skip to content

Conversation

@manuelbb-upb
Copy link
Contributor

Concerning #9

In horizontal_layout, implement a heuristic for italic correction.
Inspecting elements pairwise. For pairs of TeXChar, look at is_slanted property to determine rules and add Space similar to what sile does.
There is an additional rule for transition from upright to italic: NewComputerModern has large positile bearing for some italic glyphs that don't go under the baseline. We reduce this bearing, but don't set it to zero, which could make some letter combinations look too squished.

For this to work, TeXChar constructor now sets .is_slanted based on font_id, otherwise changes due to \mathrm & similar are not propagated correctly.

With some trickery the correction seems to work in :delimited groups as well :)
BTW, I changed the y-position computation for :delimited to better center parentheses.
To test #110 I made the changes in e66cce5 and it looks good:

image

This pull request is a bit all over the place, but if you want to I can separate the italic correction heuristic from the parentheses computations...

using GLMakie
using LaTeXStrings
import MathTeXEngine as MTE

function test_fig(it_corr=true)
    global Z
    MTE.ITALIC_CORRECTION[] = it_corr
    fig = Figure()
    Label(fig[0,1], "it_corr=$(it_corr)"; fontsize=20)
    s = L"$
        \eta(t), 
        \eta_1(t), 
        \eta_1^2(t),
        $ \\ \\ $
        (f), (t), (t+f),
        \left(\frac{1}{2}\right)
        \left(f\right),
        \left(t\right),
        \left(t+f\right),
        $ \\ \\ $
        \mathrm{y}(x), 
        g(f(x)), 
        \mathrm{g}t, 
        \mathrm{x}x,
        \mathrm{t}t,
        \mathrm{g}g,
        $ \\ $
        \mathrm{op}t, 
        \mathrm{o}\mathrm{p}t,
        $ \\ $
        lll,
        \mathrm{lll},
        l\mathrm{l}l,
        MMM,
        \mathrm{MMM},
        M\mathrm{M}M,
        $"
    Label(fig[1,1], s; fontsize=40)
    return fig    
end

fig1 = test_fig(true)
save(joinpath(@__DIR__, "fig_it_corr.png"), fig1)
fig2 = test_fig(false)
save(joinpath(@__DIR__, "fig_not_corr.png"), fig2)
fig_not_corr fig_it_corr

Enable a heuristic to create extra spaces whenever
italic and upright characters mingle.

* new global const `ITALIC_CORRECTION = Ref(true)` to enable or
  disable correction heuristic.
* changes in `TeXChar` constructor to correctly set `is_slanted`.
* heuristic algorithm in `horizontal_layout` inspired by
  [sile](https://github.com/sile-typesetter/sile) (MIT license).
@manuelbb-upb manuelbb-upb marked this pull request as draft October 7, 2025 07:19
@manuelbb-upb manuelbb-upb marked this pull request as ready for review October 7, 2025 11:25
@manuelbb-upb manuelbb-upb changed the title Italic correction heuristics + \left \right vertical centering Italic correction heuristics (mainly for text fontfaces in math) Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant