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
{{ message }}
Repository navigation
Behavior of first line indentation in paragraphs seems limiting #311
bugSomething isn't workinglayoutRelated to the layout category, which is about composing, positioning, etc.textRelated to the text category, which is all about text handling, shaping, etc.
As I gathered from the docs (as seen on the reference for the first-line-indent argument), the first paragraph on a page is special-cased to never have it's first line indented.
If I understand this correctly, that means not all paragraphs will have indentation applied, just like LaTeX does by default. If this is correct, then some styles will not be able to be represented with Typst. For example, in Brazilian Portuguese documents we are used to apply indentation to every paragraph, regardless of it's length or position in the text, and as such we use the LaTeX package indentfirst pervasively.
Did I understand it correctly?
Reacted by 椰格, Mikajlo, Michael Pfaff, 5721309, Jean, Andrew Voynov, Vihan, Pēteris Pakalns , Luis Molon, Dixon Sean Low Yan Feng and 52 more
Reacted by Pēteris Pakalns , André Willyan and Arcstur
We'll add some configuration for this, so that both ways are possible.
Reacted by Pedro Fedricci, Johannes Wolf, Arthur Araruna, teenjuna, Sébastien d'Herbais de Thun, Lyova Potyomkin, Michael Pfaff, Jean, viocha, cfgrw and 21 more
Possibly related, paragraphs starting with something other than unformatted text don’t get indented (e.g. #super[x]). All of this makes the feature feel temperamental.
The bug with unformatted text not being indented should be fixed since the last release. Can you still reproduce it? More generally, I tried to fix the first line indent, but its not as simple as it seems. As currently all text is layouted as a paragraph in Typst, removing the rule would indent everything. That includes headings, code blocks, captions, words in boxes, etc. Since paragraphs are not clearly demarked (as they would be in, say HTML), we first need some automatic way to distinguish these two kinds of texts (possibly through the context they appear in).
Yes, I know. As mentioned in my previous response, the overall issue is difficult to fix. The only thing that was fixed so far is that formatted text wasn't even indented when it wasn't in the first paragraph.
As a work-around, I found that setting an horizontal spacing before the start of the paragraph works for my case.
something like
#let annotation(body)={
par(
[#h(3em)#body]
)
}
Where body is the paragraph. This could be set as a show rule so you wouldn't have to use it in a function every time. Again, I'm not sure if it works in every case but for something quick and dirty it's something!
@DawnEver oh wow, I never thought if using a negative hanging indent, great idea! Though if you have a border around the text you'd have to adjust the the block's padding so it wouldn't clip out of it. However it looks like you got around that by setting the first-line-indent to be 2em already! I'll try it out sometime, thanks for sharing :)
// Add more elements below as necessary, e.g. list#showselector.or(heading, table, grid, figure): it=> {
it""contextv(-par.spacing-measure("").height)
}
It's worth noting that you can unify the show rules by using selector.or as above. Also, for consistency with the original heading spacing, you should exclude the spacing for "".
Are there any known or potential issues with this particular method? Perhaps if some set of settings is changed, meaning the state is nothing like default settings? I'm thinking of a fuzzy testing of sorts. All because it's so simple yet so powerful/robust (unlike all others), at least on the paper. I'll put it to the test with my next documents.
But I think it's OK to manually handle those specific cases for the time being.
#show "〜": h(indent) is like:
Reacted by WanxuanL, Christopher Marín, SandaruKasa, Juntong Chen, Diamondtroller, Bryan Hoang, Giovanni Berti, woojiq, liinyun, Dimitri Tabatadze and 1 more
I started a new project which is a good reason to finally try and stop using 〜 as a manual intent after every heading, list, figure etc. and instead test workarounds that were posted here. Maybe I missed something, but the only good one was posted by @HPDell, because other workarounds mess up the layout with vertical or horizontal spacing.
I initially used it as is, and it was already very nice to have automatic indentation everywhere. But soon I faced my first problem: when inserting medium [] it is not flattened and therefore adds a nested structure ("subdocument"). But thankfully by adding 2 lines of code I was able to fix it using a recursive show rule function.
And soon enough, some places started misbehaving. In the end, one place where I can test several situations started to work as expected no matter what I did. But I still don't have anything besides paragraphs and headings, so my current solution will probably break again in the future. But for now this looks robust enough:
snippet
P.S. There is little logic to it: I was just checking the output and trying to make a bunch of conditions, so that there will be just one indentation at a single place in a document (paragraph).
Are you sure this code works? It looks strange when element type is sequence or styled. My friend used this solution with @preview/codelst:2.0.2 and that led to an error text does not have field "children" at the cycle declaration line (for (i, elem) in doc.children.enumerate()). It looks like when something element was styled, its child was text and recursion call of turn-on-first-line-indentation led to this error.
That workaround is very cursed and highly depends on your document structure. It uses a brute-force like approach of checking every scenario in a document. Just don't use it, or create your own from scratch for your document. Or good luck fixing my mess! ;)
For now, I switched to the superior in most ways solution: #311 (comment). Although I do still need my regular solution in some rare cases: #311 (comment). Now my setting preamble and document content are both much more clean: the show rule is super short and almost never need to prefix any paragraph.
Thanks for reply. I think it would be nice to have more than one solution so I'll try to do something with your code anyway. #311 (comment) looks sad, but I liked #311 (comment)
Returning to this in 2025. Just curious, if the new layout engine released in 0.12 simplifies implementing this feature? I assume many non-English users are anticipating this(The hack of appending a fake paragraph under the headings could lead to orphan headings).
There is progress on the feature. I can't make promises, but we are optimistic that this should be fixed this soon.
Reacted by Blue Rose, Adam Erickson, TymanWasTaken, azazo1 and Stefane Fermigier
Reacted by qujihan, Mikhail Kravets, Christopher Marín, Kin Yat Koo, Roberto Nobrega, Quan, Chen Linxuan, kya8, Blue Rose, Lord-Valen and 5 more
Reacted by mangkoran, Zhuoren Ye, Shawn Yim, Juntong Chen, Cesar, AKIMOTO Takumi, qujihan, Mikhail Kravets, Rafael Villar Burke (Pachi), White-Green and 11 more
Reacted by Ivan Molodetskikh, Narukara, qujihan, Mikhail Kravets, Jens Tinggaard, Pedro Fedricci, Chen Linxuan, Blue Rose, Adam Erickson, blokyk and 2 more
Reacted by itt828, ryota2357, Songpol Anannetikul, Pēteris Pakalns , Gabriel Dahia, Ivan Molodetskikh, Daniel Bershatsky, Arcstur, mangkoran, Rafael Villar Burke (Pachi) and 30 more
Reacted by Y.D.X., Daniel Bershatsky, Arcstur, mangkoran, Pedro Fedricci, Juntong Chen, Ernesto Martínez García, Blue Rose, Mark Bundschuh and N-yam-my
bugSomething isn't workinglayoutRelated to the layout category, which is about composing, positioning, etc.textRelated to the text category, which is all about text handling, shaping, etc.
Activity
laurmaedje commentedon Mar 25, 2023
We'll add some configuration for this, so that both ways are possible.
chris-morgan commentedon Apr 7, 2023
Possibly related, paragraphs starting with something other than unformatted text don’t get indented (e.g.
#super[x]). All of this makes the feature feel temperamental.laurmaedje commentedon Apr 10, 2023
The bug with unformatted text not being indented should be fixed since the last release. Can you still reproduce it? More generally, I tried to fix the first line indent, but its not as simple as it seems. As currently all text is layouted as a paragraph in Typst, removing the rule would indent everything. That includes headings, code blocks, captions, words in boxes, etc. Since paragraphs are not clearly demarked (as they would be in, say HTML), we first need some automatic way to distinguish these two kinds of texts (possibly through the context they appear in).
zhonghes commentedon Apr 11, 2023
this problem is still exist

laurmaedje commentedon Apr 11, 2023
Yes, I know. As mentioned in my previous response, the overall issue is difficult to fix. The only thing that was fixed so far is that formatted text wasn't even indented when it wasn't in the first paragraph.
wychwitch commentedon May 3, 2023
As a work-around, I found that setting an horizontal spacing before the start of the paragraph works for my case.
something like
Where body is the paragraph. This could be set as a show rule so you wouldn't have to use it in a function every time. Again, I'm not sure if it works in every case but for something quick and dirty it's something!
DawnEver commentedon May 21, 2023
I found another para
hanging-indentif you want to indent first line in 1 em
you can do like this:
wychwitch commentedon May 24, 2023
@DawnEver oh wow, I never thought if using a negative hanging indent, great idea! Though if you have a border around the text you'd have to adjust the the block's padding so it wouldn't clip out of it. However it looks like you got around that by setting the first-line-indent to be 2em already! I'll try it out sometime, thanks for sharing :)
pdcxs commentedon Jul 26, 2023
This works anyway. But it will also affect the raw texts/code blocks.
quantrung9 commentedon Aug 5, 2023
This one also does the trick (thanks shuosc/SHU-Bachelor-Thesis-Typst#12 (comment))
tcztzy commentedon Aug 15, 2023
so quick and so dirty, but I like it 👍
teenjuna commentedon Aug 15, 2023
@laurmaedje sorry for bothering, but do you know if there are plans to resolve this?
48 remaining items
Merge pull request typst#311 from tatsuyafw/patch-1
SandaruKasa commentedon Dec 27, 2024
Let me add my two cents of a workaround as well
PgBiel commentedon Dec 28, 2024
For future reference, I've posted a similar solution in the forum as well, with examples: https://forum.typst.app/t/how-to-indent-every-paragraph-excluding-headings/2137/4
It boils down to:
It's worth noting that you can unify the show rules by using
selector.oras above. Also, for consistency with the original heading spacing, you should exclude the spacing for"".Andrew15-5 commentedon Dec 28, 2024
Are there any known or potential issues with this particular method? Perhaps if some set of settings is changed, meaning the state is nothing like default settings? I'm thinking of a fuzzy testing of sorts. All because it's so simple yet so powerful/robust (unlike all others), at least on the paper. I'll put it to the test with my next documents.
fruzitent commentedon Dec 29, 2024
I had to wrap the figure in a
#block[](#box[]prevents breakable tables) because large image can create an extra blank page.Andrew15-5 commentedon Dec 30, 2024
I found that it doesn't work after
#pagebreak():PgBiel commentedon Dec 30, 2024
Correct; in general, it requires something to be before the paragraph.
It isn't very easy to solve that without a native implementation. But I think it's OK to manually handle those specific cases for the time being.
Andrew15-5 commentedon Dec 30, 2024
#show "〜": h(indent)is like:danilasar commentedon Jan 4, 2025
Are you sure this code works? It looks strange when element type is sequence or styled. My friend used this solution with @preview/codelst:2.0.2 and that led to an error
text does not have field "children"at the cycle declaration line (for (i, elem) in doc.children.enumerate()). It looks like when something element was styled, its child was text and recursion call of turn-on-first-line-indentation led to this error.Andrew15-5 commentedon Jan 4, 2025
That workaround is very cursed and highly depends on your document structure. It uses a brute-force like approach of checking every scenario in a document. Just don't use it, or create your own from scratch for your document. Or good luck fixing my mess! ;)
For now, I switched to the superior in most ways solution: #311 (comment). Although I do still need my regular solution in some rare cases: #311 (comment). Now my setting preamble and document content are both much more clean: the show rule is super short and almost never need to prefix any paragraph.
danilasar commentedon Jan 5, 2025
Thanks for reply. I think it would be nice to have more than one solution so I'll try to do something with your code anyway. #311 (comment) looks sad, but I liked #311 (comment)
jtchen2k commentedon Jan 14, 2025
Returning to this in 2025. Just curious, if the new layout engine released in 0.12 simplifies implementing this feature? I assume many non-English users are anticipating this(The hack of appending a fake paragraph under the headings could lead to orphan headings).
laurmaedje commentedon Jan 14, 2025
There is progress on the feature. I can't make promises, but we are optimistic that this should be fixed this soon.
Enivex commentedon Jan 27, 2025
Closed by #5768