Last active
April 30, 2024 04:04
-
-
Save PgBiel/3fcac20c8a1673ac8056b4b230a63a99 to your computer and use it in GitHub Desktop.
Typst - Only number labeled equations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MIT No Attribution | |
// | |
// Copyright (c) 2023 Pg Biel | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | |
// software and associated documentation files (the "Software"), to deal in the Software | |
// without restriction, including without limitation the rights to use, copy, modify, | |
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | |
// permit persons to whom the Software is furnished to do so. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
#let labeled-counter = counter("labeled-eq") | |
#let should-number = state("should-number-eq", (:)) | |
#show math.equation: it => { | |
if it.has("label") { | |
let eq-number = counter(math.equation).get().first() | |
let number = labeled-counter.get().first() | |
should-number.update(numbered => { | |
// Associate this equation number with a new labeled-only number | |
numbered.insert(str(eq-number), number + 1) | |
numbered | |
}) | |
labeled-counter.step() | |
} | |
it | |
} | |
#set math.equation(numbering: n => { | |
let num = should-number.final().at(str(n), default: none) | |
if num != none { | |
numbering("(1)", num) | |
} | |
}) | |
$ a $ <a> | |
$ b $ | |
$ c $ <c> | |
$ d $ | |
$ e $ <e> | |
Hello tfhe @a | |
Hello the @c | |
the @e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment