For example, I have an equation that is printed repeatedly on a presentation. When I want to reference it, the compiler says that the label occurs multiple times in the document. This is understandable, since the presentation subslides must be printed repeatedly. So I want to remove all of the label after the first subslide is printed, how I can do that?
I have tried using show math.equation: it => { .. }
but it cannot remove the label without reconstructing the equation. Is there any suggestion?
I just created a minimal example based on the Touying docs and had no problem with an equation (or a reference to one) appearing more than once:
#import "@preview/touying:0.5.5": *
#import themes.simple: *
#show: simple-theme.with(aspect-ratio: "16-9")
#set math.equation(numbering: "(1)")
= Title
== First Slide
$ a = b $ <foo>
#pause
Hello @foo!
#pause
More!
So I reproduced the problem manually:
#set math.equation(numbering: "(1)")
#let eq = [$ a = b $ <foo>]
#eq
#eq
Hello @foo!
When should an equation be labelled? If it is the first appearance of that label in the document, i.e. when there are no occurrences of the label earlier. We can write that like this:
#let eq = context {
let raw-eq = $ a = b $
let lbl = <foo>
if query(selector(lbl).before(here())).len() == 0 {
[#raw-eq #lbl]
} else {
raw-eq
}
}
Since you probably want that for multiple equations, it would be nice to put that in a function. In the course of that, I also solve the “it cannot remove the label without reconstructing the equation” problem:
#let uniquify(body) = {
// content functions for validation
let sequence = [a ].func()
let space = [ ].func()
// validate the body to avoid misuse
assert.eq(type(body), content, message: "body is not content but must be an equation")
if body.func() == sequence {
// extract the single non-space child, if there is only one
let children = body.children.filter(it => it.func() != space)
assert.eq(children.len(), 1, message: "body is a sequence but must be a single equation")
body = children.first()
}
assert.eq(body.func(), math.equation, message: "body is not an equation")
let (body: eq-body, ..fields) = body.fields()
// not labelled, just return the original equation
if "label" not in fields {
return body
}
// we remove the label, so the rest of the fields
// can now be used to reconstruct the equation (if needed)
let lbl = fields.remove("label")
context if query(selector(lbl).before(here())).len() == 0 {
// return the original labelled equation
body
} else {
// make a new equation with all the same settings, but without label
math.equation(eq-body, ..fields)
}
}
#let eq = uniquify[$ a = b $ <foo>]
This does not fix other issues with displaying the same equation multiple times (especially increasing equation numbers) which Touying also handles, but the narrow subject of the question is solved.