How to customize the style of equation numbering?

Hi,

For figures I use the following method:

#let SIZE_SMALL = 9pt
#show figure.caption: it => text(
  size: SIZE_SMALL, 
  [*#it.supplement #it.counter.display(it.numbering):* #it.body]
)

Is there a similar method to achieve bold equation numbering?

Thanks in advance!


EDIT:
If you are using the i-figured module: see here

For figure.caption you’ve missed the it.separator which is equal to : by default.

#let JF_FS_SMALL = 14pt
#set page(paper: "a6")
#let your-default-font = "Linux Libertine"
#set text(font: your-default-font)

#show figure.caption: it => context text(
  size: JF_FS_SMALL,
  [*#it.supplement #it.counter.display(it.numbering)#it.separator* #it.body],
)

// #set math.equation(numbering: "(1)") // not bold
#set math.equation(numbering: (..n) => {
  strong(text(font: your-default-font, numbering("(1)", ..n)))
})

#figure(caption: [caption], rect())
$ y = 2x $

image

The problem with equation is that it uses the default math font (which I didn’t really think/know about before), therefore strong() has no effect on it. To fix this, you have to use some other typeface that has a bold font.

Note that using a custom numbering function has a side effect that is described here: How to increase the spacing between the number and the title of a heading? - #2 by Andrew.


Typst 0.12 update

With Typst v0.12.0 you can use the built-in bold math font like this:

#set math.equation(numbering: (..n) => strong(numbering("(1)", ..n)))
$ y = 2x $

This means that the your-default-font stuff can be removed.

1 Like

Clever! This is a great solution.

I’d like to add an example of how I used this with the i-figured module:

#import "@preview/i-figured:0.2.4"

#set page(paper: "a7")
#set heading(numbering: "1")

#let custom-font = "Buenard"
#set text(font: custom-font)

#show heading: i-figured.reset-counters
#show math.equation: it => i-figured.show-equation(
  it, 
  numbering: (..n) => text(
    font: custom-font,
    strong(numbering("(1.1)", ..n))
  )
)

= Heading One 
$ y = x^2 + 1 $
$ y = x^2 + 2 $

= Heading Two
*#lorem(5)*
$ y = x^2 + 3 $

image

This can be optimized like this:

#show math.equation: i-figured.show-equation.with(
  numbering: (..n) => text(
    font: custom-font,
    strong(numbering("(1.1)", ..n))
  )
)

Because even though the it is the first positional argument, you still can use .with() with named arguments, which wouldn’t interfere with positional arguments. It won’t work if you set/pass positional arguments and first argument should be it. In other cases .with() nicely reduces code clutter.

1 Like

I expanded the post with a new solution for Typst 0.12. I also added the now missing context from the show figure.caption rule because counter.display should be used inside a context.

Careful with counter.display() now. First of all, it’s probably enough to just move the context only before counter.display() but more importantly this now won’t work anymore with 0.12 and floating figures, see Wrong counter value when accessed from inside floating figure · Issue #4966 · typst/typst · GitHub.

This is technically correct as, according to @laurmaedje, it was kind of more luck that it even worked at all and now it doesn’t anymore. The correct solution would be to pass the location of figure.caption to the counter with .at() but since .location() of figure.caption() returns none, the next best and (for now) correct way is to nest the figure.caption() show rule inside a figure show rule and use its location.

#show figure: fig => {
  show figure.caption: c => [
    #let fig-num = numbering(fig.numbering, ..c.counter.at(fig.location()))
    *#it.supplement #fig-num#it.separator* #it.body
  ]
  fig
}