Skip to content

references to labels in #include documents bomb on standalone #1276

Closed

Description

@ondohotola

Description

I am re-doing a largeish handbook from LaTeX/LyX in typst.

In LyX the concept of “child document” allows referencing labels in other (child) documents even when compiling a (child) document standalone (for speed).

When I try to do this in typst it generates errors when the labels are missing (standalone). It works very well when doing the master document (with the required) #includes.

I would not mind a warning on compilation and perhaps an obvious text being inserted, ie bold and uppercase MISSINGLABEL in the PDF, perhaps even in red or something.

Use Case

This would allow to generate #include’d files to be compiled standalone.

Activity

  1. added
    feature request
    on May 21, 2023
  2. Enivex commented on May 21, 2023

    @Enivex
    Collaborator

    This should be achievable right now by creating a custom ref function that uses https://typst.app/docs/reference/meta/query/ to check for the existence of the label. Though I haven't actually tried.

    It wouldn't be a bad idea to have an optional fallback value for #ref so it fails more gracefully.

  3. ondohotola commented on May 21, 2023

    @ondohotola
    Author

    Great,

    could you perhaps do that? It’s way beyond my capabilities.

  4. Enivex commented on May 21, 2023

    @Enivex
    Collaborator

    Proof of concept:

    main.typ

    #set heading(numbering: "1.")
    
    = First <test>
    
    @test2
    
    #include "child.typ"
    

    child.typ

    #set heading(numbering: "1.")
    
    #let myref(label) = locate(loc =>{
        if query(label,loc).len() != 0 {
            ref(label)
        } else {
            text(fill: red)[?]
        }
    })
    
    = Second <test2>
    
    #myref(<test>)
    

    Compiled main.typ
    image

    Compiled child.typ
    image

  5. laurmaedje commented on May 21, 2023

    @laurmaedje
    Member

    Could probably also use a ref show rule instead of a custom ref function.

  6. Enivex commented on May 21, 2023

    @Enivex
    Collaborator

    Could probably also use a ref show rule instead of a custom ref function.

    I considered the possibility, but I didn't know exactly how to make it work.

  7. ondohotola commented on May 23, 2023

    @ondohotola
    Author

    @Enivex posted the solution to the Discord (which I have slightly adapted:

    main.typ

    #set heading(numbering: "1.")
    #show ref: it =>{
      if it.element == none{
        text(fill: red)[(?)]
      } else {
        it
      }
    }
    
    = First <test>
    
    @test2
    
    #include "child.typ"
    

    child.typ

    #set heading(numbering: "1.")
    
    #show ref: it =>{
      if it.element == none{
        text(fill: red)[(?)]
      } else {
        it
      }
    }
    
    = Second <test2>
    
    @test

    which does the trick very nicely indeed.

    Thank you very much.

  8. added
    model
    and removed on Nov 24, 2023
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

    feature requestmodel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions