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
I don't know if this is possible and if there is demand but:
Current line breaking behavior
source
compiled
\n
[ ]
\
linebreak()
>1 times \n
parbreak()
Want to be able to customize it to
source
compiled
\n
linebreak()
> 1 times \n
parbreak()
\\n
continue line
or maybe even
source
compiled
\n
[ ]
\n\n
linebreak()
>2 times \n
parbreak()
\
linebreak()
Bonus if this behavior can be changed depending on the context (e.g. in a paragraph vs table cell) and if rules for trimming line breaks in certain contexts can be defined.
Doing this in Typst code right now is almost impossible, mostly because
show rules like #show regex("\\s"): white_char => ... never capture line breaks in the source
\n gets compiled to [ ] (making it indistinguishable from many other things that generate [ ])
the content tree is currently not well traverseable and mutable.
Reacted by Savio Mak, Michał Moczulski, Michael Flaks, MatthiasJ1, iwkjosec, bluss, Giovanni Berti, KauriP, Adrian Hill, Chaoses-Ib and 9 more
Reacted by Chaoses-Ib, Rojan Kaya and Dimitri Kokkonis
Regarding the demand: one major use case would be typesetting poems. Those have manual line breaks by definition, and putting '\' at the end of every line quickly gets annoying. I'd gladly do something like
#let poem(
text
) = {
set par(join-lines: false)
text
}
Reacted by Miquel, ZZzzaaKK, Icaro, Erithax, Petr Nevyhoštěný, Erni, Gianluca Mondini, Michael Flaks, KauriP, Simone Ragusa and 3 more
I can imagine adding a set rule to respect line breaks in source and turn them into linebreak() instead of [ ].
Configurable \ for line continuation, in contrast, would in my opinion do more harm than good. It's really the opposite of what it does now and it would be hard to judge at a glance what a piece of code does. This problem already comes up a bit with the hard linebreaks, but there I see more of a use case.
I would also be interested in finding a solution to this. I expected that with the recent changes to the realisation subsystem, I could simply #show "\n": linebreak() but that doesn't work.
The show rule doesn't operate on the source text but on the realized text. In the case of your show rule, there are no "\n" in the realized text, so it doesn't match. (If it did match, it would replace a linebreak with a linebreak, to no real effect.)
Regarding the demand: one major use case would be typesetting poems. Those have manual line breaks by definition, and putting '' at the end of every line quickly gets annoying. I'd gladly do something like
#let poem(
text
) = {
set par(join-lines: false)
text
}
I wonder if any work could be done in this direction? I really enjoy using Typst and, in particular, would like to expand its usage to poetry. Such a feature would be of huge help, because so far editing a poem requires manually add a lot of line breaks.
Reacted by Gianluca Mondini, Victor Sannier, Chaoses-Ib, Bastien Voirin and Aitanuqui
#lorem(10)
#quote(block: true, attribution: link("https://en.wikisource.org/wiki/Shakespeare%27s_Songs/Blow,_Blow,_Thou_Winter_Wind")[_As You Like It_])[
```poem Blow, blow, thou winter wind, Thou art not so unkind, As man's ingratitude; Thy tooth is not so keen, Because thou art not seen, Although thy breath be rude. High-ho! sing, heigh-ho! unto the green holly: Most friendship is feigning, most loving mere folly: Then heigh-ho, the holly! This life is most jolly. Freeze, freeze, thou bitter sky, Thou dost not bite so nigh As benefits forgot: Though thou the waters warp, Thy sting is not so sharp As friend remembcr'd not. Heigh-ho! sing, heigh-ho! unto the green holly: Most friendship is feigning, most loving mere folly: Then heigh-ho, the holly! This life is most jolly. ```
]
#lorem(10)
Reacted by Philipp Niedermayer, Gianluca Mondini, bluss, Bastien Voirin and Ian
I am rendering a label for use in a laboratory and the users are not expected to be generally familiar with Typst, but may use some of its intuitive typesetting (bold, italics, etc). More advanced users will be able to input chemical equations using #ce from typsium or something similar.
My approach to this is to eval(..., mode="markup") an input string, but I would like for this to break on newlines without appending a \ to the end of each line. I have so far simply replaced newlines in the input string with #let input_str = input_str.replace("\n", "\\\n"), but this does not work for multiline code, since the resulting \ will be a syntax error in that case.
My current workaround is to instead do #let input_str = input_str.replace("\n", "\n\n") and add a set par(spacing: ...) to make paragraph breaks be similar size to line breaks. This is okay for my use case since there really isn't room for paragraphs on the labels anyway, but is admittedly a bit of a hack. A native solution would be preferable.
Edit: My workaround has an unfortunate limitation, which a solution to this issue would alleviate: The user cannot enter empty lines, as they simply are not rendered as linebreaks.
But that's at least as verbose as the first example.
Since the value proposition typst has for me is being less verbose and faster to type (for taking lecture notes), it's a shame that I have to type a backslash at the beginning of each line.
But of course with that hack I lose all of the LSP features, syntax highlighting, autocomplete, errors at the correct place etc. So it's not really a good solution..
I just discovered Typst three days ago. To get a feel for it, I've been manually converting a large LaTeX document I have, and just ran into a need to have "poetry" type lines, where a hard return in the source is actually rendered as a linebreak. My fave AI and I wrestled unsuccessfully with it for about an hour, and then I found this thread (and a similar one), and none of the solutions offered here are acceptable to me for one reason or another.
I had high hopes for Typst; was enjoying it. But something this simple (preserving newlines), made so hard (impossible), tells me that this is not a tool I can use. Disappointing.
If you can give more details, we'd appreciate it. I'm particularly curious what was hard when using raw blocks with a poem language tag? since that's what I fell back to when typesetting a poem and felt it worked alright.
I didn't know this one while looking at raw blocks, so this is also an interesting workaround:
#"While it's not intended to be a fix-it-all, Using a string actually preserves whitespace & and linebreaks too.It has the same limitations as raw blocks -- no markup"
If you can give more details, we'd appreciate it. I'm particularly curious what was hard when using raw blocks with a poem language tag? since that's what I fell back to when typesetting a poem and felt it worked alright.
I'm looking for a tool that I can give to writers that is better (for large multi-chaptered, complicated 500-page documents, at least) than the fragile WYSIWYG tools to which they're accustomed (MS-Word, LO Writer, etc).
LaTeX and most other TeX derivatives have too much of a learning curve, but Typst is really close to a tool I think they could use.
There's already enough friction in learning to use Typst; this is too big of a hurdle. For example, a section of poetry that quotes someone quoting, with indentations for each quoting, with an italicized underlying Greek word in parentheses mid-quote).
First off, the writers must have the mental power to remember, "Oh, yeah, poetry isn't done like all other formatted text, with something like #discuss[blah blah blah], but instead requires three backtics." That is putting the burden on the writer, where it does not belong, instead of on the tool, where it does belong.
Secondly, the raw format and the string format totally destroys that formatting I described, forcing the writers (or me) to do weird janky hacky kludges to make the poetry lines look the way they're supposed to look.
A simple switch that leaves newlines in the text is all that's needed to keep Typst on the "this may very well work for us" list.
Another way this could be customised which I don't think has been suggested yet would be to use separate elements for spaces, parbreaks, and linebreaks constructed by a single source newline, multiple source newlines, and a \ whitespace, which reduce to the usual space, parbreak, and linebreak elements using a show-rule which can then be overriden.
This is the same idea as from: https://forum.typst.app/t/syntax-overriding/9196/3
Activity
[-][Feature Request] Customizing default line break behavior[/-][+]Customizing default line break behavior[/+]michalmoc commentedon Mar 19, 2024
Regarding the demand: one major use case would be typesetting poems. Those have manual line breaks by definition, and putting '\' at the end of every line quickly gets annoying. I'd gladly do something like
laurmaedje commentedon Mar 19, 2024
I can imagine adding a set rule to respect line breaks in source and turn them into
linebreak()instead of[ ].Configurable
\for line continuation, in contrast, would in my opinion do more harm than good. It's really the opposite of what it does now and it would be hard to judge at a glance what a piece of code does. This problem already comes up a bit with the hard linebreaks, but there I see more of a use case.[-]Customizing default line break behavior[/-][+]Customizing source line break behavior[/+]fhilgers commentedon Jul 27, 2024
I really dislike overriding symbol behaviour if not necessary.
Could a field be added to the
Spacenode in the ast or just a new node be added? The source already has the commentMaybe it would be best to keep the information about the type of whitespace in the node?
laurmaedje commentedon Aug 4, 2024
AST nodes already contain their complete
text, so it's easy to find out the number of newlines in it.davystrong commentedon Oct 12, 2024
I would also be interested in finding a solution to this. I expected that with the recent changes to the realisation subsystem, I could simply
#show "\n": linebreak()but that doesn't work.laurmaedje commentedon Oct 13, 2024
The show rule doesn't operate on the source text but on the realized text. In the case of your show rule, there are no "\n" in the realized text, so it doesn't match. (If it did match, it would replace a linebreak with a linebreak, to no real effect.)
mikeonly commentedon Dec 12, 2024
I wonder if any work could be done in this direction? I really enjoy using Typst and, in particular, would like to expand its usage to poetry. Such a feature would be of huge help, because so far editing a poem requires manually add a lot of line breaks.
YDX-2147483647 commentedon Jan 26, 2025
Workaround
michalmoc commentedon Jan 26, 2025
@YDX-2147483647
Nice idea for simple cases, but it's not unusual to add some commands inside, like footnotes and markings.
bluss commentedon May 15, 2025
Here is another poem + raw block workaround that allows most inline markup: https://forum.typst.app/t/how-to-force-line-breaks-without-extra-spaces/4091/10 I think it still speaks for a native "environment" that works similar to this, i.e preserving linebreaks. It would have benefits like proper editor support for the embedded markup.
JeppeKlitgaard commentedon Jun 20, 2025
I have another use-case for this as well.
I am rendering a label for use in a laboratory and the users are not expected to be generally familiar with Typst, but may use some of its intuitive typesetting (bold, italics, etc). More advanced users will be able to input chemical equations using
#cefrom typsium or something similar.My approach to this is to
eval(..., mode="markup")an input string, but I would like for this to break on newlines without appending a\to the end of each line. I have so far simply replaced newlines in the input string with#let input_str = input_str.replace("\n", "\\\n"), but this does not work for multiline code, since the resulting\will be a syntax error in that case.My current workaround is to instead do
#let input_str = input_str.replace("\n", "\n\n")and add aset par(spacing: ...)to make paragraph breaks be similar size to line breaks. This is okay for my use case since there really isn't room for paragraphs on the labels anyway, but is admittedly a bit of a hack. A native solution would be preferable.Edit: My workaround has an unfortunate limitation, which a solution to this issue would alleviate: The user cannot enter empty lines, as they simply are not rendered as linebreaks.
discapes commentedon Apr 21, 2026
When I'm taking notes in math, I find myself writing a \ on almost every line. For example:
One might argue that I'm not supposed to put everything math mode and the proper way to get that same result would be
But that's at least as verbose as the first example.
Since the value proposition typst has for me is being less verbose and faster to type (for taking lecture notes), it's a shame that I have to type a backslash at the beginning of each line.
discapes commentedon Apr 21, 2026
Now I could as a workaround do the following to get my ideal version of how typst syntax should work:
But of course with that hack I lose all of the LSP features, syntax highlighting, autocomplete, errors at the correct place etc. So it's not really a good solution..
DebianFanatic commentedon May 25, 2026
I just discovered Typst three days ago. To get a feel for it, I've been manually converting a large LaTeX document I have, and just ran into a need to have "poetry" type lines, where a hard return in the source is actually rendered as a linebreak. My fave AI and I wrestled unsuccessfully with it for about an hour, and then I found this thread (and a similar one), and none of the solutions offered here are acceptable to me for one reason or another.
I had high hopes for Typst; was enjoying it. But something this simple (preserving newlines), made so hard (impossible), tells me that this is not a tool I can use. Disappointing.
isuffix commentedon May 26, 2026
If you can give more details, we'd appreciate it. I'm particularly curious what was hard when using raw blocks with a
poemlanguage tag? since that's what I fell back to when typesetting a poem and felt it worked alright.bluss commentedon May 26, 2026
I didn't know this one while looking at raw blocks, so this is also an interesting workaround:
DebianFanatic commentedon May 26, 2026
isuffix asks:
I'm looking for a tool that I can give to writers that is better (for large multi-chaptered, complicated 500-page documents, at least) than the fragile WYSIWYG tools to which they're accustomed (MS-Word, LO Writer, etc).
LaTeX and most other TeX derivatives have too much of a learning curve, but Typst is really close to a tool I think they could use.
There's already enough friction in learning to use Typst; this is too big of a hurdle. For example, a section of poetry that quotes someone quoting, with indentations for each quoting, with an italicized underlying Greek word in parentheses mid-quote).
First off, the writers must have the mental power to remember, "Oh, yeah, poetry isn't done like all other formatted text, with something like
#discuss[blah blah blah], but instead requires three backtics." That is putting the burden on the writer, where it does not belong, instead of on the tool, where it does belong.Secondly, the raw format and the string format totally destroys that formatting I described, forcing the writers (or me) to do weird janky hacky kludges to make the poetry lines look the way they're supposed to look.
A simple switch that leaves newlines in the text is all that's needed to keep Typst on the "this may very well work for us" list.
Aitanuqui commentedon Aug 20, 2026
I want to add that CommonMark, Obsidian and AsciiDoc acknowledge this use case of preserving source line breaks.
CommonMark
Obsidian

AsciiDoc per block
AsciiDoc per document
Lege19 commentedon Nov 24, 2026
Another way this could be customised which I don't think has been suggested yet would be to use separate elements for spaces, parbreaks, and linebreaks constructed by a single source newline, multiple source newlines, and a
\whitespace, which reduce to the usualspace,parbreak, andlinebreakelements using a show-rule which can then be overriden.This is the same idea as from: https://forum.typst.app/t/syntax-overriding/9196/3
This would avoid creating more weird set rules.