typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
32.23k stars 863 forks source link

Multiple underbrace text not on the same height resp. horizontally aligned #3784

Open Fabioni opened 5 months ago

Fabioni commented 5 months ago

Description

I think it would be nicer if the text of the underbraces would be on the same height. Notice that the word "distributional" is slightly higher than "aleatoric" and "epistemic"

This is from Typst:

image

using:

$ p(y^*|x^*, cal(D)) = integral_theta integral_mu underbrace(p(y^*|mu), "aleatoric") thick underbrace(p(mu|x^*, theta), "distributional") thick underbrace(p(theta|cal(D)), "epistemic") thick d mu thin d theta $ 

This is from Latex:

image

Reproduction URL

No response

Operating system

Web app

Typst version

Leedehai commented 5 months ago

TL;DR: it looks quite contrived.


It appears this is the result of the different glyph renderings of the underbraces. If one looks at it closely, one can notice the underbraces all look a bit differently.

In fact, if I make the middle term narrower, the middle underbrace will use nearly the same glyph as the other two, and then the heights of all three look aligned:

// Fig 1 (original)
$ underbrace(p(y^*|mu), "aleatoric") thick underbrace(p(mu|x^*, theta), "distributional") thick underbrace(p(theta|cal(D)), "epistemic") $ 
// Fig 2 (modified)
$ underbrace(p(y^*|mu), "aleatoric") thick underbrace(p(mu|x^*), "distributional") thick underbrace(p(theta|cal(D)), "epistemic") $ 

Fig 1: Fig 2:

Each term is made of three frames stacked vertically downward: the term itself, the underbrace, and the annotation text. In Fig 1, typst::math::stretch::stretch_glyph() used a glyph that was "assemble from parts" for the middle underbrace, and "pre-made variant" for the other two. In Fig 2, all three underbraces are "pre-made variant". Note that though the stretching is horizontal, for some reasons (due to the font?) the resulting underbrace frames differ vertically, too:

From left to right, the underbrace frames' height()s are:

It's not all. From left to right, the underbrace frames' baseline()s are:

Leedehai commented 5 months ago

In light of this, a sensible solution could be: instead of vertically stacking the frames freely according to their heights, we define a "quantumized" ladder of heights. For example, if the underbrace is 2pt ~ 4pt in height, we wrap the underbrace inside a frame that is 4pt in height; if the underbrace is 4pt ~ 6pt in height, we wrap the underbrace inside a frame that is 6pt in height, etc. The specific numbers are TBD.

Enivex commented 5 months ago

This seems to be a font issue. Here's the same thing using Stix Two Math

image

Not exactly aligned, but close enough.

Fabioni commented 5 months ago

The font I am using is "New Computer Modern", probably a font many people use, especially in math heavy writings

Enivex commented 5 months ago

The font I am using is "New Computer Modern", probably a font many people use, especially in math heavy writings

Doesn't change the fact that the font has several issues. Though it has improved significantly over time.

Are your images from latex rendered using the same font through luatex/xetex?

Fabioni commented 5 months ago

It is even a used font in the Typst documentation, I think many people start from the guide for latex users: https://typst.app/docs/guides/guide-for-latex-users/.

You say this font has many problems, what alternative do you suggest?

The image from latex was just screenshotted from another paper, so I can't tell.

Enivex commented 5 months ago

It is even a used font in the Typst documentation, I think many people start from the guide for latex users: https://typst.app/docs/guides/guide-for-latex-users/.

You say this font has many problems, what alternative do you suggest?

I mentioned Stix Two Math as one alternative

The image from latex was just screenshotted from another paper, so I can't tell.

Then it's not really a fair comparison, because it's likely the Type 1 font Computer Modern rendered through pdftex. A proper one would involve using New Computer Modern Math through the unicode-math package with luatex or xetex.

Leedehai commented 5 months ago

Though it's a font issue, I still wish to fix it in Typst [1] by changing how the typst::math::underover::stack() stacks up the frames - for example, we can add a param to this function that tells it whether (and how large) the frame heights should be "quantumized" as mentioned above.

Thoughts?

[1] Because we don't know whether this font, or other possible fonts, can fix this.

Fabioni commented 5 months ago

Then it's not really a fair comparison

@Enivex, it is not about comparing against Latex, it is just about making Typst a good product. The screenshot from Latex was just to explain how I think the formula should look like. Next time I give you a hand made drawing if you wish...

Enivex commented 5 months ago

Then it's not really a fair comparison

@Enivex, it is not about comparing against Latex, it is just about making Typst a good product. The screenshot from Latex was just to explain how I think the formula should look like. Next time I give you a hand made drawing if you wish...

There was never any confusion as to what you meant. I don't think it looks great either.

My point is simply that we have to separate typst issues from font issues that have to be fixed upstream.

I've gone through the effort of comparing them:

LuaTeX + NCMM

luatex_ncm

LuaTeX + STM

luatex_stix

Typst + NCMM

typst_ncm

Typst + STM typst_stix

As you can see, NCMM is wonky in Typst, but it's also wonky to a lesser extent in LuaTeX. In comparison, Stix is only slightly off in Typst, and seemingly perfect in LuaTeX.

It may be a bit from column A and some from column B.