Recently, while creating summaries using Typst to help with my job search, I came across a somewhat troubling aspect of the language that I think might be worth discussing.
In practice, to make my Typst projects look better, I like to modify list markers and other objects using show rules and set commands. However, I’ve noticed that sometimes there’s no way to reset modified objects to their initial state without consulting the documentation. This is a natural part of learning a language, but I think having a default keyword could address this need to constantly consult the wiki. You can refer to this example :
== Je veux / J'aime
#set list(marker: emoji.checkmark)
#set text(fill: green)
- La conception de système et la réflexion associée
- La résolution de problème
- L'analyse de système et de code
- La variété offerte par le domaine, l'évolution constante et le changement de projet
- Ce qui est lié au Forensic, l'enquête, la réflexion ect
== Je veux pas
#set list(marker: emoji.crossmark)
#set text(fill: red)
- Un métier uniquement focus sur la "_compliance_"
- Un métier fixé sur un objectif très fixe sans grande différence dans les projets (par exemple analyse de logs)
- Consultance
= Objectifs
#set list(marker: ([•], [‣], [–])) // look up te docs to paste the symbol list
// #set list(marker:default) seems more intuitive
#set text(fill: luma(10))
// #set text(fill : default) no need to check that default color of text is ...
// default keyword change context based on the object it is attributed to
- a
- b
- c
Since I clearly don’t yet have the skills to contribute on GitHub, I figured it would be better to discuss it here and let the idea develop a bit before creating a GitHub issue.
In Typst, set rules are scoped, they only apply within the block where they are defined.
If you want them to be temporary, one possibility is to wrap them inside a #[ ... ] block so they don’t affect the rest of the document.
== Je veux / J'aime
#[
#set list(marker: emoji.checkmark)
#set text(fill: green)
- La conception de système et la réflexion associée
- La résolution de problème
- L'analyse de système et de code
- La variété offerte par le domaine, l'évolution constante et le changement de projet
- Ce qui est lié au Forensic, l'enquête, la réflexion ect
]
== Je veux pas
#[
#set list(marker: emoji.crossmark)
#set text(fill: red)
- Un métier uniquement focus sur la "_compliance_"
- Un métier fixé sur un objectif très fixe sans grande différence dans les projets (par exemple analyse de logs)
- Consultance
]
= Objectifs
- a
- b
- c
So the default keyword is not mandatory for this usecase.
A good approach will be in this case to create your own lists.
And if you want to re-use the rules, you can create a function:
#let check-list(body) = {
set list(marker: emoji.checkmark)
set text(fill: green)
body
}
#check-list[
- La conception de système et la réflexion associée
- La résolution de problème
- L'analyse de système et de code
- La variété offerte par le domaine, l'évolution constante et le changement de projet
- Ce qui est lié au Forensic, l'enquête, la réflexion ect
]
Hey @Alex!
You have run into a common issue that people run into when using Typst. Its also something that I’m not terribly fond of, and this is an openly discussed issue on GitHub (see the full discussion here).
As @Rumeau and @TheJanzap have already explained, you need to shift the the way you think about writing from a top-down approach to one of scoping.
To add to tools they have already provided you can also create custom display functions that apply style within a set scope. Something like the following:
#let pretty-grid(body) = {
show grid.cell.where(x: 0): strong
show grid.cell.where(y: 0): set text(fill: green)
body
}
// Scoped section of document
#{
show: pretty-grid
grid(
columns: 2,
[This],[Text],[Is],[Styled]
)
}
Hope this helps!