How to replace a given String for an entire Typst file?

Hi, is possible to replace a given string with another one using the replace function for an entire document?

For example I have content1.typ and content2.typ which are included in a main.typ document. Now I want to replace all occurrences of a given string inside content1.typ and content2.typ. How can I do that?

1 Like

Maybe with the show rules mentioned in the tutorial?

#show "bla": "foo"

Have you tried that?
I don’t know if the importing from the other files poses a problem. But I don’t think so :)

as @Xodarap mentioned you can use #show for that.

Note that #show "bla": "foo" matches “bla” but not “Bla”

You could use regex to create other matches, for instance case-insensitive or other patterns you can create with a regex.

See the following example:

// changes every encountered dolor.
#show "dolor": [*EDITED*]
// this matches cases-sensitive, so ipsum (lowercase) does not match.
#show "Ipsum": "OOPS case does not match, thus not changed"

// this regex matches cases insensitive by enabling case-insensitive mode (?i)
#show regex("(?i)whatever"): {
  set text(red) 
  "whatEVAH"
}

= my main doc

some introduction dolor Whatever.

#include "ch1.typ"

#include "ch2.typ"

results in:

the included files were:

== Chapter 1

#lorem(30)

=== Some sub named Whatever.
#lorem(60)

and

== Chapter 2

#lorem(30)
2 Likes

Thank you, very well explained, I couldn’t remember about the #show command. That seems to be the solution.

Thanks to all.

Hey @Jacopo, welcome to the forum! I’ve changed your question post’s title to better fit our guidelines: How to post in the Questions category

For future posts, please make sure your title is a question you’d ask to a friend about Typst. :wink:

1 Like