How do I make the axis tick scale work as expected?

I was following the example in the wiki to try to format my ticks in terms of pi/a

Sadly that didn’t work. Here is a rather minimal example of what I am trying to do:

#let a = 10
#lq.diagram(
  xlim: (0, calc.pi/a),
  ylim: (0, auto),
  xaxis: (
    ticks: (0, calc.pi/a),
    locate-ticks: lq.locate-ticks-linear.with(unit: calc.pi/a),
    format-ticks: lq.format-ticks-linear.with(suffix: $pi/a$)
  ),
  yaxis: (ticks: (0, )),
)

Does anyone have an idea why this doesn’t work? I would expect that it just says pi/a at the tick on the right. I mean pi/a is 0.314… It might be a rounding error

Hi @Murphy and welcome!

If you specify ticks manually through the ticks parameter, the manual tick locator is chosen. This overrides the setting for the tick locator, so that the unit that you set with the linear tick locator has no effect.

If you want to get rid of fractional ticks, instead of ticks: (0,1) you can set the tick distance to 1 or to (min: 0).

Does that help?

1 Like

Thanks! Replaced ticks: (0,1) with tick-distance: 1. It worked perfectly :)

PS: It might be a good idea to tweak the docs that you can find lq.tick-locate.linear (docs) also under locate-ticks-linear with the search. That confused me a bit before looking at the source.

1 Like

Great!

Actually format-ticks-linear has been sort of replaced by tick-format.linear in the latest release (but the former is kept for backwards compatibility for some time). This change goes towards when tick becomes a type and the formatters (hopefully) part of it’s namespace like tick.format.linear (currently this is not possible with Typst).

My idea is that the new scheme will improve discoverability: users can type tick. and get the suggestion tick.format. and then get the individual tick formatters as suggestions.

Edit: I just noticed that the docs accidentally still mention the old aliases in some places and guess that this led to the confusion?

Yeah exactly. The example with Pi I shared used the old version. That was confusing.

I have now updated the tutorials.

4 Likes