In typst, how can I achieve the same like with `subequation` in LaTeX?

333 views Asked by At

Consider the following LaTeX code:

\begin{subequations}
\begin{align}
a = b\\
b = c\\
c = d
\end{align}
\end{subequations}

It results in:

screenshot of a LaTeX-formula with three lines, where each line has its own unique number: (1a), (1b), (1c)

How can I achive the same result in typst?

In particular I need:

  • every equation has its own number
  • the equation numbers are enumerated by digit + letters
1

There are 1 answers

0
platlas On

I am not sure if {subequations} command have direct equivalent in Typst but something similar can be made with counter 0.

Here is custom function in Typst:

// initialize new counter with custom key
#let c = counter("myequations")
// counter starts at 0, this will push it to 1
#c.step() 

// define function with sub-equation block
#let subequation(it) = block[
    // increase value of counter at sub-level
    #c.step(level: 2)

    // `#it` is content
    // `#h(1fr)` will move rest to the righ. 
    // `#c.display(pattern)` will render current counter based on provided pattern
    #it #h(1fr) (#c.display("1a"))
]

// use sub-equation block
#subequation[$a = b$]
#subequation[$b = c$]
#subequation[$c = d$]

Note: #h(1fr) 1 is used instead of \begin{align}, for more advanced aligning check the layout section of reference 2 if needed.