mitex-rs/mitex

`\lvert` `\rvert` 's space looks strange

Enter-tainer opened this issue · 13 comments

#mitex(`
\lvert a \rvert
`
) $ abs(a) $

image

might be hard to handle

I've just sort oiwiki equations by length and check about top 10% of them. Most of them looks fine!

btw, it is the output of texmath

image

This is the perfect solution

image

This issue is a bit difficult to deal with, and I need to take into account the spaces before and after the symbols, and I'll see if there's any way to improve it later.

How about something like:

#let vert = math.class("closing", sym.bar.v)

$ z + vert x vert + y $

image

But this results in a slight asymmetry.

this is not optimal because vert can be used for other purpose

Yes, it's hard to deal with

Consider:

#let vert = math.class("closing", sym.bar.v)

$
"lr":& a+lr(bar.v"",size:#0%) x lr(""bar.v,size:#0%) + b\
"verb":&a + vert x vert + b \
"abs":&a + abs(x) + b
$

image

Well, I have no idea why lr has this behavior but maybe we could take advantage from which.

  1. This will not affect $\left\lvert x \right\rvert$ since $ lr(lr(|"",size:#0%) x/y lr(""|,size:#0%)) $ works as expected. (Another weird feature of lr).
  2. This certainly will be affected by lr, for example, the show rule of it, maybe this behavior is surprising since at first glance, {l,r}vert have nothing to do with lr.

How about something like:

#let vert = math.class("closing", sym.bar.v)
$ z + vert x vert + y $

Why not just keep class("opening", bar.v) (for \lvert) and class("closing", bar.v) (for \rvert)?

This is a bit lengthy though, but its results corresponding to the correct categories of atoms of latex formula.

This looks correct

how does tex determine which vert is opening and which vert is close?

how does tex determine which vert is opening and which vert is close?

I miss read. for lvert and rvert, it is easy to determine open and close. The hard thing is something like $|a+b|$

The hard thing is something like $|a+b|$

Well, tex also does not check whether | is open or close here, | belongs to mathord here.

However, tex and typst handle spaces and math-spacings differently:

  1. In latex math mode (if not do some tricky changes), spaces are ignored. However, it seems that typst handles spaces and math-spacing at the same time.
  2. In latex math mode, barely | belongs to mathord and generally the math-spacing after it is related to the category of next char (see https://texdoc.org/serve/texbytopic/0, sec23.6)
    image
  3. However for typst | belongs to fence and typst will respect the space around it unless in some certain cases, see:
    https://github.com/typst/typst/blob/0d93ccd4bfc814534c106d3f78eef16b06b3cc70/crates/typst/src/math/spacing.rs#L23-L66
    For example, spaces in $ sum | $ after sum is ignored since sum is defaulted to be large.

Hence, for bare | in | x |, I think maybe we should interpreted it as class("normal",|) (although this is not correct class that typst expects | to be) and the result still looks good:

image

$
&a+class("normal",|) x class("normal",|)+y,\
&a+|x|+y,\
$