`\lvert` `\rvert` 's space looks strange
Enter-tainer opened this issue · 13 comments
I've just sort oiwiki equations by length and check about top 10% of them. Most of them looks fine!
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.
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
$
Well, I have no idea why lr
has this behavior but maybe we could take advantage from which.
- 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 oflr
). - This certainly will be affected by
lr
, for example, theshow
rule of it, maybe this behavior is surprising since at first glance, {l,r}vert have nothing to do withlr
.
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:
- 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.
- In latex math mode, barely
|
belongs tomathord
and generally the math-spacing after it is related to the category of next char (see https://texdoc.org/serve/texbytopic/0, sec23.6)
- However for typst
|
belongs tofence
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 | $
aftersum
is ignored sincesum
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:
$
&a+class("normal",|) x class("normal",|)+y,\
&a+|x|+y,\
$