Hey there,
I am currently trying to switch my set up for writing scientific articles from Latex to Typst (because Typst is so much cooler
).
I have some troubles with setting up the file structure. Usually I have 3 (stereo-typical) files:
- main.typ : The file where the main manuscript including references and text goes in.
- appendix.typ : a separate file that is usually for publication online-only. This file needs to be rendered separately, but the sections in the appendix (or supplementary materials; wording depends on the journal) should be referencable from the main document, e.g, “see Appendix B.3 for further details”.
- response_letter.typ : Usually, scientific articles undergo a review process where they have to be changed at least once. If reviewers suggest changes or additions, it is common to implement them and then write a separate “letter” in which one summarizes all changes. To do that, I would need to be able to reference page number from the main document (and potentially from the appendix). For example, I would write: “Thank you reviewer 1 for your valuable comment on XX, we adapted the methods section on page 12 in the manuscript to include this additional information and added appendix F to include the requested robustness checks”.
Example:
main.typ
#set heading(numbering: "1.")
= Section 1 <sec:1>
This is my main document.
This is changed. <resp:change1>
For more information, see _Appendix A.1_.
appendix.typ
#set heading(numbering: "A.1")
= Data Description
== Main Dataset Descriptives <ap:descriptives>
Important main dataset descriptives.
response_letter.typ
Dear editors,
...
= Reviewer 1
We implemented your changes on page _page 1_ of the manuscript according to your suggestions.
So far, I could not come up with any solutions that work for this. In Latex, I use the xr-package to do this.
Question: Is there any way to cross-reference the documents, so that:
- referencing sections like Appendix A.1 (in main.typ, referencing
<ap:descriptives>
) works?
- referencing page numbers like page 1 (in response_letter.typ, referencing
<resp:change1>
) works?
I would be very thankful for any help and suggestions! (and great project!)
You could include the file(s) while resetting page and heading numbers. This would of course add those pages to the main PDF, but it should be easy to split them off afterwards, or just export the first couple pages using the page range setting during export from the webapp.
main.typ
#set heading(numbering: "1.")
#set page(numbering: "1")
= Section 1 <sec:1>
This is my main document.
This is changed. <resp:change1>
For more information, see @ap:descriptives on #ref(<ap:descriptives>, form: "page")
#pagebreak()
#counter(page).update(1)
#counter(heading).update(0)
#include "appendix.typ"
appendix.typ
#set heading(numbering: "A.1", supplement: "Appendix")
#set page(numbering: (..i) => "A-"+str(i.at(0)))
= Data Description
== Main Dataset Descriptives <ap:descriptives>
Important main dataset descriptives.
Output
1 Like
Hello @Lukas_Erhard, a related question was asked at How to cross-reference labels defined in external typst projects? - #2 by Andrew.
As was suggested, you can save the result of typst query "heading" main.typ
to a file, and parse the results in your response review.
Unfortunately, I am not aware of ways to get the specific page numbers without compiling the document. In which case, you’d need either save them from the main.typ
, or import main.typ
in another document specifically to get page numbers.
I agree that this would be the simplest option, however not the most elegant, I feel. It would force me to split the PDF in multiple parts by hand (I don’t use the webapp).
If I may, I would have a couple of follow up questions:
- Do you know how clickable references behave in the PDF once it is split? Will they all just break?
- Do you know if there is an option to set some custom “split-points” in the Typst code to automate the generation of multiple PDFs?
Hi @quachpas, thank you for your response! I found the other related question but probably did not understand it correctly. I will look into the typst query command a bit deeper and try to understand the code.
I would be totally ok with importing main.typ and/or appendix.typ in another document to get the page numbers and references.
Could you point me to some example code on how I would reference a appendix section / pagenumber in main.typ once I have imported appendix.typ in main.typ? I am still quite new to Typst and not very used to a lot of the concepts.
Not that I knew of, but you can pass a page range to the typst CLI.
To get the page number, you could use something like this:
#pagebreak()
#context[#here().page() <split>]
#counter(page).update(1)
#counter(heading).update(0)
#include "appendix.typ"
and query the page to split at with
typst query main.typ "<split>" --field text --one
which will give you 2 in my example. Then you can compile your document only to the previous page, i.e. compile pages 1 to (2-1=1):
typst compile main.typ --pages 1-1
typst compile appendix.typ
These steps you can easily automate with a bash script.