You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The str() function could accept content out of which it would extract the textual parts. For example: str([Hello _there_]) would be "Hello there".
Use Case
In a few projects I want to set the document (PDF) title but also display the title in the doc itself. However, the title might be content and not a string. That means that it needs to be duplicated:
set document(title: "This cool project")
align(center)[
#set text(size: 1.5em)
This _*cool*_ project
]
This is not a big deal but leads to these kinds of templates which feel weird because of the duplicity:
I acknowledge that there are many vague cases and lots of complexity -- I'm just putting this out. Maybe there's also an existing solution to this which I overlooked, such as iterating the children of the content and only collecting the textual yield.
Reacted by Armin Nabavi, Patrick Kunzmann, hurzl, Janosh Riebesell, Carl Kuhlemann, goyalyashpal, xelantro, Nicolai Weitkemper, Diego Miguel Lozano, Chaoses-Ib and 3 more
Thanks @EpicEricEE. That feels like should be the implementation of str(content) so I'll leave the issue open to keep this under consideration but anyone else feel free to close it.
Internally, there is already a plain text functionality (via the PlainText trait), which is used for instance for the PDF outline.
Since the issue mostly comes up with set document(title: _), I'm considering to just allow content there and do the plain-text conversion internally.
Long-term, with get rules, this would also mean that more "standard" metadata like title, author, etc. could be specified with document set rules instead of on the template and templates could read that. For that, the title would also need to be content.
Reacted by Vilém Zouhar, Sébastien d'Herbais de Thun, KOMOTO Kenta, Jan Romann, Rai, Pravin Bansal and sme
I have pushed a commit that allows arbitrary content as the document title. It will then be turned into a string internally. This should cover your use case. I will also update the web app templates to default to a content block instead of a string with the next release.
I'm not comfortable with exposing the internal plain-text functionality at the moment because it's very lossy for more complex content.
in Hebrew for example, I might write ' and use a show rule to turn it into a Geresh ׳, or someone might want smart quotes when entering their Name "nickname" Surname. It's mostly about simple conversions like that and about being able to reuse the same variable later in like the title page.
Unfortunately the plain text conversion employed to convert the title to a string is very naive, so it wouldn't be able to handle show rules. I think it also doesn't properly handle smartquotes, but that would be fixable.
I looked for this feature to have a convenient shortcut for inline code. I'm writing content with a lot of inline OCaml code, and instead of writing
... ```ocaml Foo``` ...
I would like to be able to write #code[Foo] or even #c[Foo]. This suggests the definition
#let code(s) = raw(s, lang: "ocaml")
but this does not work because s is content in #code[Foo], but raw expects a string argument. The current solutions are to call this like #c("Foo"), which is conceptually cleaner but also noticeably less convenient to type, or to assume that the caller will only pass string-like content (no nested structure) and call s.text:
#let code(s) = raw(s.text, lang: "ocaml")
Reacted by mobotsar, Marcel Rød, CrumblyLiquid, Tip ten Brink, Robertino, Aleksei Zobnin, Jincheng (Jeffrey) YANG, darshan, stefnotch, PaulMaget and 1 more
Activity
[-]Turning content into string with str(content)[/-][+]Turning content into string: `str(content)`[/+]EpicEricEE commentedon Sep 20, 2023
You can indeed iterate over the children and collect the text recursively. It's definitely not perfect, but it works for your case:
zouharvi commentedon Sep 20, 2023
Thanks @EpicEricEE. That feels like should be the implementation of
str(content)so I'll leave the issue open to keep this under consideration but anyone else feel free to close it.laurmaedje commentedon Sep 20, 2023
Internally, there is already a plain text functionality (via the
PlainTexttrait), which is used for instance for the PDF outline.Since the issue mostly comes up with
set document(title: _), I'm considering to just allow content there and do the plain-text conversion internally.Long-term, with get rules, this would also mean that more "standard" metadata like title, author, etc. could be specified with document set rules instead of on the template and templates could read that. For that, the title would also need to be content.
laurmaedje commentedon Nov 20, 2023
I have pushed a commit that allows arbitrary content as the document title. It will then be turned into a string internally. This should cover your use case. I will also update the web app templates to default to a content block instead of a string with the next release.
I'm not comfortable with exposing the internal plain-text functionality at the moment because it's very lossy for more complex content.
zouharvi commentedon Nov 20, 2023
Thank you for resolving this!
emilyyyylime commentedon Feb 27, 2024
@laurmaedje would it be possible to apply the same change for document author?
laurmaedje commentedon Feb 27, 2024
Does it really make sense for an author name to have markup?
emilyyyylime commentedon Feb 28, 2024
in Hebrew for example, I might write
'and use a show rule to turn it into a Geresh׳, or someone might want smart quotes when entering their Name "nickname" Surname. It's mostly about simple conversions like that and about being able to reuse the same variable later in like the title page.laurmaedje commentedon Feb 28, 2024
Unfortunately the plain text conversion employed to convert the title to a string is very naive, so it wouldn't be able to handle show rules. I think it also doesn't properly handle smartquotes, but that would be fixable.
Typst template: use content rather than string...
gasche commentedon Jan 21, 2025
I looked for this feature to have a convenient shortcut for inline code. I'm writing content with a lot of inline OCaml code, and instead of writing
I would like to be able to write
#code[Foo]or even#c[Foo]. This suggests the definitionbut this does not work because
sis content in#code[Foo], butrawexpects astringargument. The current solutions are to call this like#c("Foo"), which is conceptually cleaner but also noticeably less convenient to type, or to assume that the caller will only pass string-like content (no nested structure) and calls.text:goyalyashpal commentedon Jun 18, 2025
most of the time, i need this kind of functionality as the string concatenation with
. + " " + .becomes VERY ugly, very fast.i don't need to use content in place of strings, or even perform any conversion per say, but i just need some easy way to join strings.
think: the new f-strings in python, vs. doing via
+strcat operator in olden times.context:
let filecontents = if prependName == true { if type(comment) == str { comment + " " + filename + "\n" + read(file) } else if type(comment) == array [ #comment.at(0) #filename #comment.at(1) #read(file) ] // <~~~~ Intended easy way to concatenate strings. } else { read(file) }focussing in on the intended part:
some string templating construct akin to
typmarking content:versus current way to fight with
typcfeat: add `link.a()` and `util.to-string()`
NamorNiradnug commentedon Oct 12, 2026
This would actually be useful for keywords as well, especially in math, where some math stuff can be a part of a keyword