How to correctly strike through a mixed text+equation passage?

I’m trying to strike through a passage that mixes prose and a display equation, e.g.:

  #strike[The relation
  $ E = m c^2 $
  holds in general.]

The prose gets struck correctly, but the equation itself shows no strikethrough at all: strike()/underline() seem to only decorate real text runs, not math glyphs (variables, digits, operators). Even a quoted string used as a subscript (X_“foo”) gets struck, but bare symbols never do, whether the equation is inline ($…$) or display ($ … $).

Is there a way to strike through this kind of mixed content (prose and equations) that:

  1. reflows normally when the struck text is long, and
  2. actually shows a line through the equation’s symbols, not just any quoted-string subscripts?

Happy to share more of what I’ve tried if useful.

There is an open issue about this: Text decoration functions not working with inline equations · Issue #2200 · typst/typst · GitHub

For the math portion, you can use math.cancel (probably better if accessibility is important).

#strike([The relation $ cancel(E = m c^2, angle: #90deg) $ holds in general.])

As an alternative, you can also use a custom function:

#let st(content) = context {
  let width = measure(content).width
  box[
    #content
    #place(
      dy: -3pt,
      line(stroke: .5pt, length: width),
    )
  ]
}

#strike([The relation $ st(E = m c^2) $ holds in general.])

Semantically, the first option is better IMO.

1 Like