Skip to content

Make function supplement return the number as well #2990

Open

Description

@MDLC01

Description

Many elements have a supplement parameter. While it is useful, the fact that it only lets you customize what is displayed before a number is limiting.

We should allow supplements to be functions that accept the formatted number (as content), and return some content that contains the number with its supplement. For example, x => [Before #x after.].

#figure(
  supplement: n => [The #n#super[th] figure],
  caption: [A circle.],
  circle(),
)

A circle with the legend "The 8th figure: A circle."

Use Case

Easier customization. This also makes it possible to remove the space between the supplement and the number.

Current alternative

This can already be done by adding the content you want to have after the number within the numbering format, but this is far from optimal.

#figure(
  supplement: [],
  numbering: n => [The #n#super[th] figure],
  caption: [A circle.],
  circle(),
)

Activity

  1. added
    feature request
    on Dec 17, 2023
  2. added
    change request
    model
    and removed
    feature request
    on Dec 17, 2023
  3. Dherse commented on Dec 17, 2023

    @Dherse
    Contributor

    Be careful with just th as the super otherwise you'll get 21th or 103th which just looks weird!

  4. changed the title [-]Proposal: Function as `supplement`[/-] [+]Function as `supplement`[/+] on Dec 17, 2023
  5. MDLC01 commented on Dec 17, 2023

    @MDLC01
    CollaboratorAuthor

    Be careful with just th as the super otherwise you'll get 21th or 103th which just looks weird!

    Yes of course. This was just the first example I could think of. In practice, I guess the "th" would be part of the numbering pattern.

  6. MDLC01 commented on Dec 17, 2023

    @MDLC01
    CollaboratorAuthor

    I just realized that this proposal can't be implemented this way, because supplements can already be functions that accept the element's body.

    I think the underlying feature request is still interesting, though.

  7. wrzian commented on Nov 11, 2024

    @wrzian
    Contributor

    What if we allowed an extension to the supplement syntax: if you type @label[custom supp] then we allow you to use <label> as though it were a variable in the inner markup block? So you could write: @thm:A[Theorem <thm:A> by Author].

    If you don't include <label> then we can make the supplement default to prefix of the reference, or add a set rule that changes it to postfix.

  8. laurmaedje commented on Nov 11, 2024

    @laurmaedje
    Member

    Making the label suddenly evaluate to content seems strange to me, to be honest. It's not really the principle of least surprise.

  9. wrzian commented on Nov 11, 2024

    @wrzian
    Contributor

    Fair. I chose that because placing the label again doesn't have any current meaning. Some alternatives if this is desirable might be repeating @label or maybe using just a raw @ or #@.
    I do think this style has potential to solve the context-dependent supplement problem.

  10. laurmaedje commented on Nov 11, 2024

    @laurmaedje
    Member

    Is the need for this single-ref context-dependance really that common that it deserves custom syntax? I'd imagine that you'd typically either rather want to configure this in a set rule (as a function), not ad-hoc for a single reference.

  11. YDX-2147483647 commented on Dec 1, 2025

    @YDX-2147483647
    Contributor

    I just realized that this proposal can't be implemented this way, because supplements can already be functions that accept the element's body. (#2990 (comment))

    Could the issue title be modified for future reference? For example:

    Change the return value of supplement functions from Figure to Figure 1.

    • Current: (a figure element) ↦ [Figure].
    • Possible changes:
      • (1,) ↦ [Figure 1]
      • (a figure element,) ↦ [Figure 1]
      • (a figure element, 1) ↦ [Figure 1]
      • (a figure element, supplement: [Fig.]) ↦ [Fig. 1], where [Fig.] is given by writing @key[Fig.].
      • …

    Update on 2026-04-17

    The proposed {figure,heading,…}.supplement function API has an advantage over show ref: it => {…} customization:

    In a show ref function, we have to recreate a link.
    If link and ref have different styles (e.g., different text color), then the style for the created link will override the style for ref, which is not desired.

    Example:

    #show link: set text(blue.darken(20%))
    #show ref: set text(green.darken(30%))
    
    #figure(rect[Image], caption: [Caption]) <a>
    
    = Default
    / `ref`: @a
    / `link`: https://example.com
    
    = Customized
    #show ref: it => {
      let el = it.element
      if el != none and el.func() == figure {
        link(el.location(), {
          set text(green.darken(30%))
          // 👆 Without this, the `ref` will become blue.
          [第~]
          numbering(el.numbering, ..el.counter.at(el.location()))
          [~图]
        })
      } else {
        it
      }
    }
    / `ref`: @a
    / `link`: https://example.com
    Image
  12. changed the title [-]Function as `supplement`[/-] [+]Make function `supplement` return the number as well[/+] on Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestmodel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions