I’ve now nearly completed the mark-up on my first document, an academic article. Typst is amazing! Much, much easier to use than LaTeX.
First question:
I’ve inserted the instruction '#set heading(numbering: “1.”). I first put it right at the beginning of my document, and as a result the section numbers came out as “1.1”, “1.2”, etc. Then I moved it after the main heading and before the Introduction. The numbers came out as “0.1”, 0.2", etc. I want the main sections to be simply numbered “1”, “2”, etc. How do I do this?
Second question: how can I number examples automatically? I see there’s a way of numbering maths equations, but my examples are not equations. I’d like them to be simply numbered “1”, “2”, etc., and when referenced, they should just appear as a number in parenthesis, as in this example: “See (23)”; not “See Example (23)”.
for question 1, if i’ve understood correctly you should set heading numbering to numbering: "1.1". If you want something more complex, you can also set it to your own function, numbering((..nums) => {...})
For question 2, you can follow the advice from the docs, " To create a custom referenceable element like a theorem, you can create a figure of a custom kind and write a show rule for it. In the future, there might be a more direct way to define a custom referenceable element."
Thanks, aarnent!
Your answer to question 1 unfortunately doesn’t work. I’m still getting “Section 0.1, Section 0.2” instead of “Section 1, Section 2”.
Your answer to question 2 works nicely except for one problem: the Example numbering comes out as “Example 1”, “Example 2”, etc., and the references are like that too. What I’m wanting is just “(1), (2)”, etc., without the word “Example”. Can this be done?
Thanks again for your help so far!
1: Do you mean by “main heading” the title of the document? If yes use #text(size: 123pt)[Document Title] and = Section for your chapters/sections.
2: You have to modify how the reference gets displayed:
#show ref: it => {
let el = it.element
if el != none and el.func() == figure and el.kind == "example" {
// Override example figure
link(el.location(),
numbering(
"(1)",
..counter(figure.where(kind: "example")).at(el.location())
)
)
} else {
// Other references as usual.
it
}
}
Hi flokl, thanks for your help. Your solution to my first question works perfectly, but unfortunately the following is happening with your solution to question 2:
The “@label” tags are coming out numbered correctly, and in the correct format (Example “see (2) above”, but the numbers are not appearing next to the actual examples; and also, the examples are being centered, whereas they should ideally be in a 'hanging indent format against the left margin, e.g.:
(7) …dat hij Cecilia een boom hielp vellen
… that he Cecilia a tree helped cut.down
“that he helped Cecilia cut down a tree”
Is there a way of achieving this?
Thanks!
I see the post won’t accept my formatting:
the first line of the example should be against the left margin, but the second and third lines should start under the “_…dat”
Okay, my brain skipped half of the second question. So if you want both the numbering of your example and the reference to it in the same format “(1)” there is no need for my #show ref: posted above.
With @aarnent’s code the examples should be left aligned and the numbering in the correct spot, here is a full example with the modified code from @aarnent :
#let example(content) = figure(
kind: "example",
supplement: none,
numbering: (num) => numbering("(1)", num),
content
)
#show figure.where(kind: "example"): it => align(left,{
grid(columns: 2,
{
it.supplement
sym.space
counter(figure.where(kind:"example")).display(it.numbering)
sym.space
},
it.body
)
})
#example[
…dat hij Cecilia een boom hielp vellen\
…that he Cecilia a tree helped cut.down\
“that he helped Cecilia cut down a tree”
]<example>
#example[And another\
example
]<example2>
as seen in @example and @example2