How to typeset quotients (e.g. quotient groups) in typst?

tl;dr:
There are multiple methods to typeset something like a quotient, but nothing I am aware of satisfies me. Ideally, I would write

$ G over N $

and get something like
image,
where the size of the fraction increases according to the size of the two quotients.

Detailed explanation:

First you can just use a regular fraction

$ ker(H^n) / ker(H^(n-1)) $

which results in

.
This is the imo worst method.

Second, there is

$ ker(H^n) slash ker(H^(n-1)) $

which results in
image.
This is the method widely used in the internet and many LaTeX users, but it does not satisfy me, because if you would write it per hand, you would write the second right ker a bit more under the first and not on the same level. Also the size of the slash does not increase automatically, and e.g. here it lools off:
image.

Is there a good way to typeset quotiens in Typst?

I’m not sure what’s the best you can do in the current version, but in the next release (0.14) you will be able to set the style of fractions (see merged PR here):

#set math.frac(style: "horizontal")

$ ker(H^n) / ker(H^(n-1)) $

// Or the same with a local switch:
$ frac(style: "horizontal", ker(H^n), ker(H^(n-1))) $

image

This looks the same as a \/ b or a slash b though. Maybe you want the skewed style:

#set math.frac(style: "skewed")

$ ker(H^n) / ker(H^(n-1)) $

image

2 Likes

This can be relatively easily fixed by using lr—here some examples baseline vs. lr vs. lr with manual size:

$
ker(H^n) slash ker(H^(n-1)) \
lr(ker(H^n) mid(slash) ker(H^(n-1))) \
lr(ker(H^n) mid(slash) ker(H^(n-1)), size: #125%) \
$

$
a^2 slash sum b \
lr(a^2 mid(slash) sum b) \
lr(a^2 mid(slash) sum b, size: #125%) \
$

You can automatically replace fractions with lr using a show rule:

#show math.frac: it => $lr(it.num mid(slash) it.denom, size: #125%)$

This one is a bit harder; I have a solution for your use case, but it affects sizing of math in general. I guess the general-purpose solution is waiting for 0.14.

Anyway, here 's my imperfect approach using move for skewed fractions:

#show math.frac: it => {
  let offset = 2pt
  let num = move(dy: -offset, it.num)
  let denom = move(dy: offset, it.denom)
  $lr(num mid(slash) denom, size: #(125% + 2*offset))$
}

$
ker(H^n) / ker(H^(n-1)) \
a^2/(sum b) \
$

Note how the sum is smaller than the original version.

3 Likes

Thank you both for your solutions!

One question regarding the 0.14 release solution:
Is it possible to define an over such that

$ ker(H^n) over ker(H^(n-1)) $

expands automatically to

$ frac(style: "skewed", ker(H^n), ker(H^(n-1))) $

?

With other words, to “in between functions”, f(a,b) that can be written as a f bexist? If not, is it planned to include them?
Or alternatively, since the / case is special even today, if it is possible to define multiple /s with different default settings?

For this use case the benefit over defining let over(a,b)=frac(style: "skewed", a, b) is small, but indeed notable.

1 Like

In the meanwhile, this syntax will definitely be available:

#let skewed(expr) = {  // pick your name
  set math.frac(style: "skewed")
  expr
}
$ skewed(G / H) $