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

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

Closed
ondohotola opened this issue May 21, 2023 · 6 comments
Closed

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

ondohotola opened this issue May 21, 2023 · 6 comments
Labels
feature request New feature or request model Related to structure and semantics.

Comments

@ondohotola
Copy link

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.

@ondohotola ondohotola added the feature request New feature or request label May 21, 2023
@Enivex
Copy link
Collaborator

Enivex commented May 21, 2023

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.

@ondohotola
Copy link
Author

Great,

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

@Enivex
Copy link
Collaborator

Enivex commented May 21, 2023

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

@reknih reknih added the meta label May 21, 2023
@laurmaedje
Copy link
Member

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

@Enivex
Copy link
Collaborator

Enivex commented May 21, 2023

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.

@ondohotola
Copy link
Author

ondohotola commented May 23, 2023

@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.

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

No branches or pull requests

4 participants