Skip to content
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

Heading counter is always zero until numbering is set #4061

Open
1 task done
mathrick opened this issue May 2, 2024 · 9 comments
Open
1 task done

Heading counter is always zero until numbering is set #4061

mathrick opened this issue May 2, 2024 · 9 comments
Labels
docs Improvements or additions to documentation model Related to structure and semantics.

Comments

@mathrick
Copy link

mathrick commented May 2, 2024

Description

Repro:

#let hnumber = context [#counter(heading).display("1. ")]
#show heading: (it) => [#context counter(heading).display("1. ") #it.body]

= First heading

#hnumber

== First subheading (but typst thinks it's #hnumber)

= Second heading

#set heading(numbering: "1. ")

= Third heading (but typst thinks it's #hnumber)

== another subheading

This renders as:
screenshot-typst app-2024 05 02-13_24_05

Tested on the web app (as of 2024-05-02), and locally on 0.11.0 (2bf9f95d)

Reproduction URL

No response

Operating system

Web app

Typst version

  • I am using the latest version of Typst
@mathrick mathrick added the bug Something isn't working label May 2, 2024
@Enivex
Copy link
Collaborator

Enivex commented May 2, 2024

This is intentional

@Enivex Enivex closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2024
@mathrick
Copy link
Author

mathrick commented May 2, 2024

Ok, in this case, this should be clearly documented and explained, because it's extremely confusing to stumble upon. Also, what is the reason for this behaviour?

@Enivex
Copy link
Collaborator

Enivex commented May 2, 2024

Ok, in this case, this should be clearly documented and explained, because it's extremely confusing to stumble upon. Also, what is the reason for this behaviour?

Let me ask the opposite question: Why would the counter step if numbering is not set? If it did, then I couldn't create unnumbered sections without manually decrementing the counter at the same time.

@Enivex Enivex added docs Improvements or additions to documentation model Related to structure and semantics. and removed bug Something isn't working labels May 2, 2024
@Enivex Enivex reopened this May 2, 2024
@Enivex
Copy link
Collaborator

Enivex commented May 2, 2024

I've reopened the issue, as I couldn't find this covered by the documentation. (Though I may have overlooked something)

@mathrick
Copy link
Author

mathrick commented May 2, 2024

Because the counter is defined to be counting things as they occur, not "counting things, but only if you also ask for the number afterwards":

Counts through pages, elements, and more.

With the counter function, you can access and modify counters for pages, headings, figures, and more. Moreover, you can define custom counters for other things you want to count.

Since counters change throughout the course of the document, their current value is contextual. It is recommended to read the chapter on context before continuing here.

No part of the docs mention the caveat, despite explaining when exactly the heading counter is stepped, and how to reset it. It's not at all clear to me that "I want to keep my unnumbered sections actually devoid of a number, not just not displaying the number" is the correct default, especially when resetting it explicitly covered and possible without any undue work.

@Enivex
Copy link
Collaborator

Enivex commented May 2, 2024

In what situation would you want the counter to keep going, but just not display it?

@mathrick
Copy link
Author

mathrick commented May 2, 2024

@Enivex: when the numbers are shown only for some of the counted items, or not a strict prefix of the heading content. That's how I originally stumbled upon it, I was writing a show rule for headings with the numbers conditionally embedded in the content being output, so it made no obvious sense to also enable numbering when it would just be redundant with what the show rule was generating.

@PgBiel
Copy link
Contributor

PgBiel commented May 8, 2024

You should step the counter before displaying it. You can check if it.numbering != none to avoid stepping twice.

@mathrick
Copy link
Author

mathrick commented May 8, 2024

@PgBiel: I don't really understand what you mean by that. If the numbering is none, then that will simply result in a counter that at best counts the times it's been displayed, which is not equivalent to having a counter that actually, y'know, counts the things it's supposed to count :). numbering: (..nums) => none is a much simpler workaround, but either way it's definitely a documentation bug at the very least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation model Related to structure and semantics.
Projects
None yet
Development

No branches or pull requests

3 participants