sile-typesetter / sile

The SILE Typesetter — Simon’s Improved Layout Engine
https://sile-typesetter.org
MIT License
1.61k stars 97 forks source link

Math module not working! #2066

Closed jodros closed 2 weeks ago

jodros commented 2 weeks ago

I simply can't render anything with math, always get:

Error: runtime error: ./packages/math/base-elements.lua:119: attempt to index a nil value
stack traceback:
    [C]: in function '__index'
    ./packages/math/base-elements.lua:119: in function 'getMathMetrics'
    ./packages/math/base-elements.lua:305: in function 'getScaleDown'
    ./packages/math/base-elements.lua:934: in function 'shape'
    ./packages/math/base-elements.lua:337: in function 'shapeTree'
    ./packages/math/base-elements.lua:334: in function 'shapeTree'
    ./packages/math/base-elements.lua:334: in function 'shapeTree'
    ./packages/math/typesetter.lua:157: in function 'handleMath'
    ./packages/math/init.lua:70: in function <./packages/math/init.lua:62>
    ./core/sile.lua:605: in function 'call'
    ./core/sile.lua:396: in function 'process'
    ./core/sile.lua:475: in function 'processString'
    ./core/sile.lua:525: in function <./core/sile.lua:488>

Both in my own files and those in tests.

leorosa commented 2 weeks ago

Have you installed a math font? From the documentation, "By default, this package uses Libertinus Math, so it will fail if Libertinus Math can’t be found."

jodros commented 2 weeks ago

Have you installed a math font?

Yes, I have this and other math fonts installed.

alerque commented 2 weeks ago

Can you Try with sile -d math -d fonts to get some debug info from the math and font subsystems. Also your sile --version would be good to know at this point.

jodros commented 2 weeks ago

Here is the output:

$ sile -d math -d fonts index.sil

SILE v0.15.3 (LuaJIT 2.1.ROLLING) [Rust]
<index.sil> as sil
<test.sil> as sil

[math] Resulting mbox: VBox(HBox(UnderOver(Text(atom=1, kind=operator, script=1, largeop, text="∑"), Text(atom=0, kind=identifier, script=3, text="i"), nil), Text(atom=3, kind=operator, script=1, text="="), Superscript(Text(atom=0, kind=number, script=1, text="1"), nil), Fraction(HBox(HBox(Superscript(Text(atom=0, kind=identifier, script=3, text="x"), nil))), HBox(HBox(Text(atom=0, kind=identifier, script=3, text="n"))))))
[math] Loading math font Libertinus Math;10;400;Regular;normal;;;LTR
[fonts] Looking for Libertinus Math;10;400;Regular;normal;;;LTR
[fonts] Resolved font family Libertinus Math -> /usr/share/fonts/Libertinus/LibertinusMath-Regular.woff2Error: runtime error: /usr/local/share/sile/packages/math/base-elements.lua:119: attempt to index a nil value
stack traceback:
    [C]: in function '__index'
    /usr/local/share/sile/packages/math/base-elements.lua:119: in function 'getMathMetrics'
    /usr/local/share/sile/packages/math/base-elements.lua:305: in function 'getScaleDown'
    /usr/local/share/sile/packages/math/base-elements.lua:934: in function 'shape'
    /usr/local/share/sile/packages/math/base-elements.lua:337: in function 'shapeTree'
    /usr/local/share/sile/packages/math/base-elements.lua:334: in function 'shapeTree'
    /usr/local/share/sile/packages/math/base-elements.lua:334: in function 'shapeTree'
    /usr/local/share/sile/packages/math/base-elements.lua:334: in function 'shapeTree'
    /usr/local/share/sile/packages/math/typesetter.lua:157: in function 'handleMath'
    /usr/local/share/sile/packages/math/init.lua:81: in function </usr/local/share/sile/packages/math/init.lua:73>
    /usr/local/share/sile/core/sile.lua:605: in function 'call'
    /usr/local/share/sile/core/sile.lua:396: in function 'process'
    /usr/local/share/sile/core/sile.lua:475: in function 'processString'
    /usr/local/share/sile/core/sile.lua:525: in function </usr/local/share/sile/core/sile.lua:488>
    /usr/local/share/sile/core/sile.lua:605: in function 'call'
    /usr/local/share/sile/core/sile.lua:396: in function 'process'
    /usr/local/share/sile/core/sile.lua:475: in function 'processString'
    /usr/local/share/sile/core/sile.lua:525: in function </usr/local/share/sile/core/sile.lua:488>
jodros commented 2 weeks ago

I just realized that despite I had all of the .otf fonts in /usr/share/fonts/otf, I had another folder /usr/share/fonts/Libertinus with only .woff fonts

and SILE was looking firstly in the later...

alerque commented 2 weeks ago

I don't think we can fault SILE for finding that font (especially since it's just following fontconfig's cues) but we can probably do a better job of erroring out at this point if we're asked to do something with a font that it doesn't support.