Latex has “cancelto” in math mode. It’s similar to “cancel”, but it’s an arrow instead of a line, and it points to an additional parameter which is supposed to indicate what expression evaluates to. Most often, it’s 0 or 1 (see image). Ideally it would be implemented by the developers, but in the meantime, is there a way to reproduce this with a show rule or something? Thanks!
I’m not aware of an easy solution for this, you might as well create a new issue for this.
Here is my very rough solution:
#let cancelto(body, to) = {
let arrow = rotate(-55deg, scale(x: 170%, $-->$))
context {
let m = measure(body)
let (w, h) = (m.width, m.height * 2)
set place(center + horizon)
// block(height: h * 2.5, align(horizon, body)) // Add vertical margins.
body
place(dx: -w * 0.5, dy: -h * 0.1, arrow)
place(dx: w * 0.3, dy: -h * 1.1, $0$)
}
}
$(diff T)/(diff t) = k (diff^2 T)/(diff z^2) + v_z (diff T)/(diff z)$
$cancelto((diff T)/(diff t), 0) = k (diff^2 T)/(diff z^2) + v_z (diff T)/(diff z)$
$(diff T)/(diff t) = k (diff^2 T)/(diff z^2) + v_z (diff T)/(diff z)$
Awesome, thanks. I’ll try to find a way to determine the angle and scale automatically. And I’ll create the issue as well.
Be sure to link it here (both ways is even better). :)
A relevant issue would be this one probably Add arrow caps for stroke · Issue #1532 · typst/typst · GitHub.
Ideally, you would write
$
cancel(a x + b, stroke: #(cap: "arrow"))
$
or another syntax that is less verbose and more discoverable.
There’s another issue that was already created for this and was closed as not planned. The developers think it would be better as a package.
I had a feeling that this is more of a package-level functionality. And since it’s a part of a package in LaTeX, this further proves the point. You can make a package yourself at any point if you want, otherwise we’ll have to wait for someone else to do it.
Here is the Rust code for the cancel()
function, in case there’s something helpful there:
Now that Typst v0.12.0-rc1 is out, you can also use stretch
for long arrow:
// let arrow = math.stretch(sym.arrow.tr, size: 230%)
let arrow = rotate(-55deg, math.stretch(sym.arrow.r, size: 230%))
I also realized that if you are OK with 45 degree arrows, you can remove the rotate()
call and use a specific arrow glyph instead: https://typst.app/docs/reference/symbols/sym/?query=arrow.