You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature requestNew feature or requestmathRelated to math category, with its syntax, layout, etc.symbolsRelated to the symbols category, which gives names and shorthands to symbols
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!
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 $
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 $
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
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.
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.
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.
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)
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.
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:
feature requestNew feature or requestmathRelated to math category, with its syntax, layout, etc.symbolsRelated to the symbols category, which gives names and shorthands to symbols
Activity
Enivex commentedon Mar 27, 2023
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.Enivex commentedon Mar 27, 2023
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)
user202729 commentedon Mar 27, 2023
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:
\hbargives horizontal line by composing a line withh,\hslashundefined.unicode-mathpackage alone: both gives\hslash.unicode-mathandamsfonts:\hbargives horizontal line (not composed),\hslashgives slashed line.Leedehai commentedon Mar 27, 2023
Thanks @Enivex. But
hbardefined this way creates horizontal spaces around thehbarsymbol. I also tried thestrike()andoverline()function, but they have the same problem.Enivex commentedon Mar 27, 2023
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.reduceDisclaimer: No warranty 😂
Enivex commentedon Mar 27, 2023
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)
(Of course, this is just a disgusting hack job. I'm for instance not sure how this will interact with things like font size.)
Leedehai commentedon Mar 27, 2023
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 withmove(). The length units areem, which scales with the font size. As mentioned previously,h()is used to remove the unexpected spaces from both sides of the letter.I included this
hbarinto myphysicspackage: https://github.com/Leedehai/typst-physics.Enivex commentedon Mar 27, 2023
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.
Leedehai commentedon Mar 27, 2023
Agreed. Ideally Typst could provide a built-in
hbarsymbol, so we can get rid of these house-of-card hacks.Enivex commentedon Mar 27, 2023
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.
user202729 commentedon Mar 28, 2023
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.
We're still missing a lot of drawing primitives. (or maybe even better, allow the equivalent of
\pdfspecialin LaTeX, but this is a different feature request)Leedehai commentedon Apr 2, 2023
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.
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:Leedehai commentedon Dec 15, 2023
In summary, it depends on the font.. closing my issue.