Skip to content

A normal hbar #355

Closed
Closed

Description

@Leedehai

Hi, I think the built-in symbol planck.reduce is a bit off [1], as the line is slant. In fact, this is Latex's \hslash.

However, the majority of papers use \hbar, where the "bar" above the letter "h" is horizontal [2]. That's what gives the reduced Planck constant symbol its colloquial name "h-bar".

It'd be awesome if Typst could provide an hbar symbol we are familiar with. Thanks!

[1] Screenshot 2023-03-26 at 20 58 03
[2] example: https://i.stack.imgur.com/VtYnw.png

Activity

  1. Enivex commented on Mar 27, 2023

    @Enivex
    Collaborator

    U+0127 (ħ) has a horizontal bar.

    Edit: You can make the symbol in text mode using _\u{0127}_, but every attempt I made at doing it in math mode failed.

  2. Enivex commented on Mar 27, 2023

    @Enivex
    Collaborator

    Here's a workaround:

    #let hbar = text(font: "Linux Libertine", style: "italic")[\u{0127}]

    (Setting the font explicitly seems to be necessary, at least with the math font used in the web app)

  3. user202729 commented on Mar 27, 2023

    @user202729
    Contributor

    Essentially at the moment only support "modern" font formats and the character in Latin Modern Math font has the slash diagonal.

    I try in LaTeX:

    • default: \hbar gives horizontal line by composing a line with h, \hslash undefined.
    • with unicode-math package alone: both gives \hslash.
    • With unicode-math and amsfonts: \hbar gives horizontal line (not composed), \hslash gives slashed line.
    • Inspecting the case above LaTeX uses font "MSBM10".
    • Looks like MSBM10 is only available in metafont, but fonts - Script for using metatype to convert metafont to TTF? - TeX - LaTeX Stack Exchange can probably be used to convert it to TTF that can be used.
  4. Leedehai commented on Mar 27, 2023

    @Leedehai
    ContributorAuthor

    Thanks @Enivex. But hbar defined this way creates horizontal spaces around the hbar symbol. I also tried the strike() and overline() function, but they have the same problem.

    #let hbar = text(font: "Linux Libertine", style: "italic")[\u{0127}]
    
    $ E = planck.reduce omega, E = hbar omega $
    

    Screenshot 2023-03-27 at 12 58 35

  5. Enivex commented on Mar 27, 2023

    @Enivex
    Collaborator

    Thanks @Enivex. But hbar defined this way creates horizontal spaces around the hbar symbol. I also tried the strike() and overline() function, but they have the same problem.

    #let hbar = text(font: "Linux Libertine", style: "italic")[\u{0127}]
    
    $ E = planck.reduce omega, E = hbar omega $
    
    Screenshot 2023-03-27 at 12 58 35

    Okay, new attempt, using New Computer Modern since it matches the default math font better.

    #let hbar = $text(font: "New Computer Modern", style: "italic","\u{0127}") #h(0.02cm)$

    I chose 0.02cm since that seemed to fit the spacing with planck.reduce

    Disclaimer: No warranty 😂

    image

  6. Enivex commented on Mar 27, 2023

    @Enivex
    Collaborator

    It annoyed me that it was slightly narrower. You may maybe prefer

    #let hbar = $text(font: "New Computer Modern", style: "italic",#scale(x: 108%,"\u{0127}")) #h(0.025cm)$

    The width then matches the planck.reduce in the math font (though the slant isn't exactly the same angle)

    image

    (Of course, this is just a disgusting hack job. I'm for instance not sure how this will interact with things like font size.)

  7. Leedehai commented on Mar 27, 2023

    @Leedehai
    ContributorAuthor

    Thank you!

    I fiddled around a bit in my doc and arrived at this solution. It appears to be work well with scaling (e.g. in a superscript's denominator), and the shape of the letter "h" is the same as the current font's Planck symbol.

    However, applying function strike() on the symbol unexpectedly shifted the letter a bit downward in the math mode, so I had to move it back up with move(). The length units are em, which scales with the font size. As mentioned previously, h() is used to remove the unexpected spaces from both sides of the letter.

    #let hbar = $#h(0em) #move(dy: -0.08em, strike(offset: -0.55em, extent: -0.03em, sym.planck)) #h(0em)$
    

    Screenshot 2023-03-27 at 17 52 06

    I included this hbar into my physics package: https://github.com/Leedehai/typst-physics.

  8. Enivex commented on Mar 27, 2023

    @Enivex
    Collaborator

    However, applying function strike() on the symbol unexpectedly shifted the letter a bit downward in the math mode,

    I ran into something similar when first trying to scale() outside the text() instead of inside. Seems like a bug of some kind.

    The only thing missing from the strike() solution is that the rectangle has sharp edges. It would be more aesthetically pleasing if it was possible to set a radius for it.

  9. Leedehai commented on Mar 27, 2023

    @Leedehai
    ContributorAuthor

    Agreed. Ideally Typst could provide a built-in hbar symbol, so we can get rid of these house-of-card hacks.

  10. Enivex commented on Mar 27, 2023

    @Enivex
    Collaborator

    Agreed. Ideally Typst could provide a built-in hbar symbol, so we can get rid of these house-of-card hacks.

    Your idea for a solution is basically the best possible for math fonts that do not have an italic version of \u{0127} (all of them?). Though I'm sure it could be made less janky (without the move etc).

    Ultimately Typst is just providing shorthands for symbols in the font. If the font literally doesn't have the symbol, then you either have to settle for a symbol from a different font, or create one like you did.

  11. user202729 commented on Mar 28, 2023

    @user202729
    Contributor

    I ran into something similar when first trying to scale() outside the text() instead of inside. Seems like a bug of some kind.

    I think rather than a bug I'd say it's more of "currently Typst does not explain clearly how the 'box and glue' model work
    (here it's called something like 'block box and space') unlike in TeX so we're left with trying random combination of parameters".

    TeX's box has a property "where the baseline is" apart from just width and (total) height.

    The only thing missing from the strike() solution is that the rectangle has sharp edges. It would be more aesthetically pleasing if it was possible to set a radius for it.

    We're still missing a lot of drawing primitives. (or maybe even better, allow the equivalent of \pdfspecial in LaTeX, but this is a different feature request)

  12. added
    feature request
    math
    symbols
    on Apr 1, 2023
  13. Leedehai commented on Apr 2, 2023

    @Leedehai
    ContributorAuthor

    After a few more attempts, I arrived at this new solution for my physics package. It fixes the horizontal spacing problem well, though it still used a hacky workaround with move() to fix the unexpected vertical shift problem, which I think is unrelated to this symbol but a broader issue when calling text functions in math code (e.g. $ "text"#strike("text")"text" $, $"text"#box[$#box[$#box[$#box[$#box[$"text"$]$]$]$]$]$).

    Basically it adds a bar to the existing Planck symbol, so the underlying letter "h" definitely has the same shape as the Planck symbol, regardless of the font.

    #let hbar = (sym.wj, move(dy: -0.08em, strike(offset: -0.55em, extent: -0.05em, sym.planck)), sym.wj).join()
    

    The previous solution with #h(0em) fixes the horizontal spacing problem for most cases, but unexpectedly collapses spacing when placing near an equality sign =, addition +, etc. See the screenshot for a comparison:
    Screenshot 2023-04-01 at 23 05 18

  14. Leedehai commented on Dec 15, 2023

    @Leedehai
    ContributorAuthor

    In summary, it depends on the font.. closing my issue.

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

    feature requestmathsymbols

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions