How to show all math as block equations by default?

Can I setup things to have all $...$ math show as block equations?

Use case: for CeTZ figures I need all math to have correct bounding boxes, otherwise things like fill: white don’t work as expected. But having to write always things like $ P $ instead of $P$ is annoying and easy to forget. So I’d like to change the default in particular files or scopes, to have $...$ produce block equations.

I tried #set math.equation(block: true) but the spacing in $...$ takes precedence.

Here’s an example of what I want to fix:

#import "@preview/cetz:0.2.2"

#let opaque(it) = block(fill: white, inset: 1pt, it)

#cetz.canvas({
  import cetz.draw: *
  line((-1, 1), (1, -1))
  content((-0.4, 0.4), opaque($|x|$))
  content((0.4, -0.4), opaque($ |x| $))
})

image

I’d like the $|x|$ (top-left) to render the same as $ |x| $.

I know only one solution for that, but it is quite hacky. See this chapter of Typstonomicon.

Note that would just make all math display size math, not center aligned block, but that seems okay for your usecase. Though it’s not hard to add alignment or anything to this snippet.

Thanks! Using display size is not enough: the equation is still inline so it still has the wrong bounding box. But your link gave me the idea for a solution that seems to work:

#show math.equation.where(block: false): math.equation.with(block: true)
1 Like

That’s cool, I was sure it wouldn’t work.

It seems it wasn’t working earlier, but is working after the update that fixed show rules. Good to know.

1 Like