-
-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resumable enum numbering #325
Comments
I have a different use case, but I believe this is relevant here. I feel that we should be able to provide a counter for an enum, or be able to retrieve the value of a counter from an enum. *My use case: * I'm trying to create a link to a particular step of an enum. I found a solution, but it feels very hacky...#[
// create a counter
#let s = counter("number")
#{ s.update(c => 1) } // start at 1
// ensure all enums (in this block?) update the counter before rendering
#set enum(numbering: it => {
s.update(number => it)
numbering("1.", it) // can't seem to find out what numbering the enum is using
})
This
Is
a numbered <step-link>
list
below
is a link to a numbered step
See #link(<step-link>)[#locate(loc => {
let item = query(<step-link>, before: loc).first();
[Step #{numbering("1.",..s.at(item.location()))}] // can't work out numbering of enum, but render number
})] for further information
] I can use a link successfully with a label, but I wondered if I can auto-generate the text from the enum's counter, e.g. See #link()[...]. I tried using a I tried to use locate() and query() to display a counter value, but when trying to use counter(enum), I get From looking at the typst source, it appears See also:
I'd be happy to attempt a PR, making the enums use counters, but I'm new to the codebase - I don't know what architectural decisions have led to the current code. |
Better integration between enums and counters seems very reasonable. One big difference though is that counters are always global to the document whereas enums are generally counted locally. |
I ended up here by searching how to skip a number when using a numbered list. The idea is that something like this: #set enum(start: 2)
Bla
Bla bla
#counter(enum).step()
Bla bla bla Should be printed as: |
I had a very similar problem to the one of @lingo, but my workaround didn't work perfectly: source
#locate(loc => counter("source").final(loc).first())
#show enum.item: it => {
counter("source").step()
it
}
item
item
item Using source
#locate(loc => counter("source").final(loc).first())
#set enum(full: false, numbering: (n) => {
counter("source").update(n)
numbering("1.", n)
})
item
item
item |
I can't seem to be able to adapt @Andrew15-5 's workaround to both manage multi-leveled numbered lists (such as "1)a)") and reuse the saved counter in a new list. Does anyone have an idea ? |
Yeah, multi-level numbering is not as simple. I haven't tried it with that, but it might work with some improved version. For that, the argument must be |
This part of @lingo's example currently gives the error "missing argument: location". How should one write this with the current syntax? I'm trying to figure out if the above examples from lingo and @Andrew15-5 will work with the solution given here to allow enums to be referenced later in the document (that solution works, but only if you number your numbered list manually as in the example
because the ...which makes that solution a lot less useful, and also seems to make it impossible to reference those items in a way not using numbers (roman numerals, letters, etc.) |
The 0.10 (currently released) syntax is |
Will the current usage/syntax be deprecated or removed completely? |
@laurmaedje, thank you, that works. I've put @lingo's solution into a function, so that it's not so wordy for every reference to a label:
Ultimately it would be nice to use |
Having a way to provide a counter for an
enum
to use would be great for one use case I have right now, which involves defining a custom numbered list, but it would also enable resuming the counting of oneenum
from another, like when you "suspend" the list with some text in between items.Replicating this idea on other numbered entities would also easen customization, like defining separate numbering on front matter / main matter / back matter, or continuous numbering for Theorems, Lemmas, etc.
The text was updated successfully, but these errors were encountered: