// keep string indented by making it into seperate strings inside a list, that will be joines with linebreaks
#raw(block: true, (
"fn main() {",
" println!(\"Hello World!\");",
"}").join("\n")
)
//keep string indented by manually appending linebreaks and joining strings with + operator
#raw(block: true,
"fn main() {\n" +
" println!(\"Hello World!\");\n" +
"}"
)
//use a custom show rule, that trims the first two leading spaces of each line of any raw block
#show raw: it => it.text.split("\n").map(line => line.trim(" ", at: start, repeat: false)).join("\n")
#raw(block: true,
"fn main() {
println!(\"Hello World!\");
}"
)
The last solution is similar to the proposed solution of @gezepi
EDIT: actually, my last proposal is somewhat flawed, because inside the show rule only the text ist returned and syntax styling gets lost.
A custom function applied to the string before handing it to a raw block would work better here.
All spaces before the indent level of the ``` are trimmed (this feature seems to be undocumented).
Of course this is going a bit in circles so I wonder why you want to avoid the ``` syntax for literal raw blocks? Is it to use escape sequences in the string?
Well, currently I simply try to improve my understanding how the plain Typst functions work, because they provide more options to customize the output and thus are very useful. E.g., using plain ‘raw’, I can change the color theme of a specific code block, or maybe to highlight a line there. As far as I know, these things are not possible if I simply use something like
```
// fenced code block
```
I didn’t try your solution yet, because I’m currently not near my laptop.
I can’t try it either right now but if all you want to do is change some options on raw for a single code block you could enclose a set or show rule and the literal raw block in a content block. Like
[
#set raw(..set some option)
// Or
#show raw: set some styling
```
//Some code
```
]