I’m writing a world-building document and need to add creative notes outside the main text. However, comments serve other purposes, and I want these creative notes to be flexibly selectable for display in the final output document based on settings.
For placing notes outside the main body of text, there are some packages that make it easy utilize the margins. For instance:
For optionally including them in your document you can do something simple like this:
#let include-all-comments = true
#let comment(comment-body) = if include-all-comments {
//Anything you want for formatting your comment (including using packages)
set text(red)
comment-body
}
//Your document where you may include as many comments as you want
#lorem(5)
#comment[Some text]
#lorem(5)
Changing include-all-comments from true to false will prevent any of the comments from rendering in the output document.
This code runs normally in the documentation, but the include-all-comments become invalid when imported from the template.
If you could share the structure of your document that would be very helpful.
I defined the function in the template using the following code:
#let include-note = false // 是否包含笔记
#let note(note-body) = if include-note {
//Anything you want for formatting your comment (including using packages) / 可以包括任何评论格式(包括使用包)
set text(red)
note-body
}
Then call it in the document like this:
#let include-note = false // 是否包含笔记
#note[note]
This is one way to do it:
template.typ
create-note() is a function that returns a function. The returned function will be used in main.typ.
#let create-note(visible) = (body) => if visible {body}
main.typ
Use the create function from the template to define a local note() function which can be used in this document.
#import "template.typ": create-note
#let note = create-note(true)
#lorem(10)
#note(text(red)[This is a note.])
#lorem(10)
One side benefit of doing it this way is you can have different types or categories of notes. You would define multiple functions within main.typ each with their own visibility setting, then it would be possible to select which category of notes are visible.
For instance if multiple people add notes they could each have their own function:
/*main.typ*/
//Only notes from Alice will be visible
#let note-alice = create-note(true)
#let note-bob = create-note(false)
#let note-claire = create-note(false)
I think these posts could also be relevant to you – if you need a single location inside your document where you can set note visibility:
Or if you want to configure the document from the command line: