johanvx / typst-undergradmath

A Typst port of undergradmath
Creative Commons Attribution Share Alike 4.0 International
109 stars 7 forks source link

A few remarks #2

Open laurmaedje opened 1 year ago

laurmaedje commented 1 year ago

Hey, I'm one of the Typst developers. This is great!

A few remarks:

PS: Would you be fine with us posting this on Twitter with the Typst account?

johanvx commented 1 year ago

Thanks for your attention! Feel free to share and use this anywhere!

Reply on the remarks:

The thing with the script letters is interesting. Are they even part of Unicode?

I didn't think about this. ~So I've just search on Compart (https://www.compart.com/en/unicode/) and found that they are Unicode letters. For example, the letter $\mathscr{P}$ \mathscr{P} is actually Mathematical Script Capital P \u{1D4AB}.~ Script letters and calligraphic letters are the same (handwriting letters with different fonts?) according to this Chinese post on Zhihu. Need to check https://www.ctan.org/pkg/mathrsfs and https://ctan.org/pkg/unicode-math.

Widehat is available, it's automatic if you write $hat(x+y)$

Oh, nice! I didn't even try this. I'll update the document then.

doteq is $dot(eq)$ because the dot is an accent

I've tried this but didn't adopt it. I don't remember why though. Maybe the spacing is not identical with the LaTeX \doteq? I'll check this soon.

Maybe there can be an explanation for scaling: They scale by default if the symbol is entered directly as a codepoint, they don't scale automatically if you use symbol notation like $angle.l$.

Yeah, I think there should be some explanations. I'll add this comment by creating a co-authored commit.

The examples for the h function are missing a hashtag because the function consists only of a single letter

Oh yes, mentioning single letter functions without a hashtag may be ambiguous. Thanks for pointing this out.

The alignment example is a bit weird since it would look the same without alignment, but I guess that goes for the original LaTeX version, too

I just tried to mimic the original LaTeX version 😝 and didn't think much on this.

$"9.8" "m/s"^2$ would work for the units thing, but it's obviously hacky and not good. Typst needs to support this better.

I have no idea here because I'm not familiar with the ~ spacing in LaTeX. I'll add this (with a 💦 annotation as this is hacky) in a co-authored commit.

johanvx commented 1 year ago

I've tried this but didn't adopt it. I don't remember why though. Maybe the spacing is not identical with the LaTeX \doteq? I'll check this soon.

So here's a simple test.

LaTeX | Typst

`doteq` comparison between LaTeX and Typst (from left to right), the spacing between `dot` and `eq` in Typst is larger

with LaTeX code

\documentclass[10pt]{article}
\usepackage{mathtools, amssymb, amsthm}
\begin{document}
\[ \doteq \]
\end{document}

and Typst code

#set text(10pt)
$ dot(eq) $
user202729 commented 1 year ago

Remark on script characters: The font files are in a typical LaTeX distribution (CTAN: /tex-archive/fonts/rsfs), but they're postscript type 1 font, and I think Typst only support opentype font.

Maybe something in https://stackoverflow.com/questions/9322635/how-can-i-convert-postscript-type-1-font-to-otf-or-ttf can convert them to a Typst-compatible format.

https://tex.stackexchange.com/questions/659025/context-lmtx-how-to-use-the-rsfs-font?noredirect=1&lq=1#comment1640490_659025 also has some discussion but nothing too useful.


On the doteq issue, I attempt to build the symbol myself a bit but I still don't understand how the box model work in Typst (compared to that in TeX), as well as the issue of spacing between math symbols/mathstyle (mathchoice):

#let doteq1 = box(baseline: -0.5pt, align(center, stack(spacing: -2pt, sym.dot, sym.eq)))

$ a dot(eq) b, a = b, a doteq1 b $

$ 2^(a dot(eq) b, a = b, a doteq1 b) $

image

johanvx commented 1 year ago

I wrote something weird but maybe usable.

#let eqdot = $\u{2A66}$
#let doteq2 = style(styles => {
  let ex = measure("x", styles).height
  box(baseline: -ex, align(center, stack(spacing: (0.3455 - 1 + 0.1874 * 2) * ex, $dot$, $eq$)))
})

$ doteq2 = eqdot quad a doteq2 b, a = b, a eqdot b \
  2^(doteq2 = eqdot quad a doteq2 b, a = b, a eqdot b) $

Output of the above Typst code

Sad to find out that eqdot is a Unicode character (Equals Sign with Dot Below) while doteq is not.

user202729 commented 1 year ago

See, the problem is that your doteq2 does not respect mathstyle. In superscript doteq still keeps some spacing around it, while = and eqdot doesn't.

In TeX this would be solved with \mathchoice. Not sure about this, maybe there's some way to extract the information whether the current text is in superscript or not from the style?

Unfortunately repr(style) just return .., it's opaque.

johanvx commented 1 year ago

It turns out that doteq is \u{2250} (see #9). Here's a new demo with typst 0.1.0 (94e052b8):

#let eqdot = "\u{2A66}"
#let doteq = "\u{2250}"

Customized symbols defined with `"..."`:

$ doteq = eqdot quad a doteq b, a = b, a eqdot b \
  2^(doteq = eqdot quad a doteq b, a = b, a eqdot b) $

#let eqdot = $\u{2A66}$
#let doteq = $\u{2250}$

Customized symbols defined with `$...$`:

$ doteq = eqdot quad a doteq b, a = b, a eqdot b \
  2^(doteq = eqdot quad a doteq b, a = b, a eqdot b) $

Customized symbols defined with `"` and `$`, the former is good, while the latter contains trailing spacing


Update

With typst 0.4.0 (f692a5ef), there's no difference any more.

kokic commented 4 months ago

The width of hat is not always suitable e.g. hat(x_i) or hat(x y) . This has forced me to write hat(space x_i space).

johanvx commented 4 months ago

The width of hat is not always suitable e.g. hat(x_i) or hat(x y) . This has forced me to write hat(space x_i space).

Good point! I hope that readers can do this with the help of Section Spacing in mathematics.

Just out of curiosity: in what context are these use cases?

For me:

[^*]: actually, maybe something like paren.l hat(#h(0.1em) arrow(u)\, arrow(v) #h(0.1em)) paren.r is better.