Skip to content

Prime symbol broken with Libertinus Math #2860

Closed

Description

@schuelermine

Description

The prime symbol seems incorrectly set in superscript when using Libertinus Math.

#show math.equation: set text(font: "Libertinus Math")

$
f(x) &= x^2 + 1 \
f'(x) &= 2 x
$

This happens in both the Web App and the command-line interface.

Web App:
Screenshot 2023-12-04 at 21-38-53 scratchpad – Typst

Local:
Screenshot from 2023-12-04 21-38-27

Reproduction URL

No response

Operating system

Web app, Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Dec 4, 2023
  2. alerque commented on Dec 4, 2023

    @alerque
    Contributor

    This is probably a font issue not a typesetting engine one. Whether it is a bug or a style choice I'm not actually sure. I'm the maintainer of Libertinus fonts project but was not the original author of the Math companion font. Either way please feel free to file an issue over here.

  3. added
    math
    upstream
    and removed
    upstream
    on Dec 4, 2023
  4. schuelermine commented on Dec 5, 2023

    @schuelermine
    ContributorAuthor

    I am fairly sure this is a typst-specific issue. I have recreated this equation in MathML and it looks fine.
    image

    Perhaps this is a version difference?

  5. alerque commented on Dec 5, 2023

    @alerque
    Contributor

    Can you post the MathML version here so I can experiment with this in SILE? I can experiment with a couple different versions of the font at once that way.

  6. schuelermine commented on Dec 5, 2023

    @schuelermine
    ContributorAuthor

    I made the MathML with MathJax and got the CSS link from MDN/Frédéric Wang
    MathMLLibertinus.txt

  7. schuelermine commented on Dec 5, 2023

    @schuelermine
    ContributorAuthor

    However I opened it with a Chromium browser and a similar issue appears.
    Screenshot_20231205-133254~2

  8. alerque commented on Dec 5, 2023

    @alerque
    Contributor

    I'm not much of a math expert, but I'm pretty sure that MathML is kindo of borked. In any case I think I got a working example in SILE's math variant syntax (an alternative to having it work on MathML directly). The result is that Libertinus Math looks differently there than in Typst. Here are my inputs comparing STIX Two Math with Libertinus Math in both SILE and Typst:

    SILE source (prime.sil):
    Details
    \begin[papersize=a7]{document}
    \use[module=packages.math]
    
    \set[parameter=math.font.family,value=STIX Two Math]
    \begin[mode=display]{math}
    	\table[columnalign=right left]{
    		f(x) &= x^2 + 1 \\
    		f\prime(x) &= 2x
    	}
    \end{math}
    
    \set[parameter=math.font.family,value=Libertinus Math]
    \begin[mode=display]{math}
    	\table[columnalign=right left]{
    		f(x) &= x^2 + 1 \\
    		f\prime(x) &= 2x
    	}
    \end{math}
    
    \end{document}
    
    Typst source (main.typ):
    Details
    #set page("a7")
    
    #[
        #show math.equation: set text(font: "STIX Two Math")
        $
            f(x) &= x^2 + 1 \
            f'(x) &= 2 x
        $
    ]
    
    #[
        #show math.equation: set text(font: "Libertinus Math")
        $
            f(x) &= x^2 + 1 \
            f'(x) &= 2 x
        $
    ]

    20231205_16h53m15s_grim

    Using the SILE side of things to check font versions:

    $ sile -d versions prime.sil
    SILE v0.14.13 (LuaJIT 2.1.1696562864)
    <prime.sil> as sil
    [1]
    Harfbuzz version: 8.3.0
    Shapers enabled: graphite2, ot, fallback
    ICU support enabled
    
    Fonts used:
    /usr/share/fonts/OTF/STIXTwoMath-Regular.otf:0  Version 2.13 b170
    /usr/share/fonts/gentium/GentiumPlus-Regular.ttf:0      Version 6.200
    /usr/share/fonts/OTF/STIXTwoMath-Regular.otf:0  Version 2.13 b170
    /usr/share/fonts/libertinus/LibertinusMath-Regular.otf:0        Version 7.040;RELEASE
    /usr/share/fonts/libertinus/LibertinusMath-Regular.otf:0        Version 7.040;RELEASE

    Presumably the Typst example being compiled locally is also picking up the same fonts from my system. I'm honestly not sure if perhaps it is preferring an embedded version or not. Assuming not, that's an interesting difference that suggests you might be right and this is Typst related and not the font.

  9. Enivex commented on Dec 5, 2023

    @Enivex
    Collaborator

    Even in SILE it looks smaller than I expect, even if the position is more correct. The MathML rendering looks right.

    I suspect this is an issue with how the prime is implemented in the font. The same thing is present with Noto Sans Math. There's some info in this issue @alerque

    notofonts/math#42

    Specifically this comment notofonts/math#42 (comment)

  10. khaledhosny commented on Dec 6, 2023

    @khaledhosny

    This usually happens when the ssty feature is not applied as appropriate.

  11. Zeta611 commented on May 19, 2024

    @Zeta611

    I stumbled upon this issue as I use Libertinus Math as my primary math font (in LaTeX). It worked fine in LaTeX (with unicode-math), but is broke in Typst.

    I suspect it's an issue in the typst side because directly using the prime unicode character U+2032 ′ fixes the issue.

    Comparing all different variations, only x prime and directly using the prime unicode without ^ works:

    $x'$ $x^'$ $x prime$ $x^prime$ $x′$ $x^′$
    
    #show math.equation: set text(font: "Libertinus Math")
    $x'$ $x^'$ $x prime$ $x^prime$ $x′$ $x^′$
    Screenshot 2024-05-19 at 13 17 21
  12. lumi-a commented on May 23, 2024

    @lumi-a

    Following @khaledhosny's comment, using

    #show math.equation: set text(font: "Libertinus Math", features: ("ssty",))

    seems to render primes correctly for me in Typst 0.11.1.

  13. Zeta611 commented on May 24, 2024

    @Zeta611

    @lumi-a Well, it now works well for $x'$, but not anymore for $x '$--it is the opposite now. But the shape & size of the prime is now "normal."

  14. pnkfelix commented on Jun 25, 2024

    @pnkfelix

    On Polytype, the self-proclaimed "Rosetta stone for typesetting engines", I think this issue is manifesting itself.

    The second item in their "Sample Gallery" shows Typst output for:

    #[
        #show math.equation: set text(font: "Libertinus Math", size: 16pt)
        $
            f(x) &= a' + b'' + c''' \
            f'(x) &= x^2 + 1
        $
    ]
    

    and it really highlights how "bad" the f'(x) looks when compared to the rendering for sile and xelatex.

    I don't know if the best response is to suggest to Polytype that they use the "ssty" mentioned above (or write f prime instead of f'), or if effort should be spent identifying some alternative fix

    But since this seems like it might be presenting Typst in a poor light in a fairly visible website (Polytype was recently featured on hackernews), it might be worth looking into.

  15. khaledhosny commented on Jun 25, 2024

    @khaledhosny

    Looking into the code, it seems that Typst expects ssty lookup to be an alternate substitution lookup:

    pub ssty_table: Option<ttf_parser::gsub::AlternateSubstitution<'a>>,

    While in Libertinus Math it is a single substitution lookup. I don’t know why Typst is accessing the raw lookup from ttf_parser, instead of enabling the feature through rustybuzz which should be more bullet-proof.

  16. laurmaedje commented on Jun 26, 2024

    @laurmaedje
    Member

    Typst doesn't currently pass single chars in math through rustybuzz and this was patched on top. Maybe we should always go through RB.

  17. khaledhosny commented on Jun 26, 2024

    @khaledhosny

    Yes, I think all text should go through the shaper for consistency.

  18. memeplex commented on Aug 12, 2024

    @memeplex

    Related discussion for ConTeXT https://mailman.ntg.nl/archives/list/[email protected]/thread/274EKUHM5JW3Z7Q25SLIF5OLUND4YRN2/

    OTOH in pdflatex and xelatex, with or without newtx, it renders fine. I took a look at libertinus-otf and libertinus-type1 package sources and was unable to find anything ssty related.

    I'm not sure whether you're planning switching to Libertinus Math alongside #1257 but in that case it would be better to fix this OTB.

  19. Enivex commented on Aug 12, 2024

    @Enivex
    Collaborator

    Related discussion for ConTeXT https://mailman.ntg.nl/archives/list/[email protected]/thread/274EKUHM5JW3Z7Q25SLIF5OLUND4YRN2/

    OTOH in pdflatex and xelatex, with or without newtx, it renders fine. I took a look at libertinus-otf and libertinus-type1 package sources and was unable to find anything ssty related.

    I'm not sure whether you're planning switching to Libertinus Math alongside #1257 but in that case it would be better to fix this OTB.

    I don't think there's any plan to change the math font.

  20. schuelermine commented on Dec 14, 2024

    @schuelermine
    Author
  21. mkorje commented on Dec 15, 2024

    @mkorje
    Collaborator

    @schuelermine Could you share the Typst code and compiler version you used to produce that image?

  22. schuelermine commented on Dec 16, 2024

    @schuelermine
    Author
  23. mkorje commented on Dec 16, 2024

    @mkorje
    Collaborator

    @schuelermine The changes that fixed this are currently only on the development version. When the next release is made it will be available. You can, in the web app, change the compiler version to the development version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmath

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions