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
Can't use over-/underline() with any space symbol or h() #1716
I need to extend underline to the end of the line like this:
\documentclass{article}
\usepackage{ulem}
\begin{document}
Text or no text \uline{\hfill}
\end{document}
But neither #underline(h(100%)) (or 1fr) nor #underline(sym.space) is working. I didn't find any of the settings that can replicate the same behavior, and #line() ignores any text + it is drawn automatically on the next line (not inline).
I consider this a bug, since it should work in theory, and it does work in LaTeX.
Update (v0.12.0)
Now #underline(sym.space) does work and as was pointed out in #1716 (comment)#underline(box(width: 1fr, repeat(sym.space))) now also works. I tried pretty much all fonts that I use, and they all work. I think this should simplify some of my underline util functions.
Reproduction URL
No response
Operating system
Linux
Typst version
I am using the latest version of Typst
Reacted by Andrew Voynov, OrangeX4, InAnYan, Kirill Lukashev, raldone01, Wu Haotian, John Wang and Jan
#letH(n) = {
forvalueinrange(n) {
sym.space.hair
}
// I think I can write endless number of '0's, but the number must be more than '0.0'h(0.000000000000000000000000000000001pt)
}
#box[some text #underline[#H(1000)]] // Add n spaces to fill the whole line
I don't know why having h() with any non-zero length causes the spaces before it to show underlining, but without h() nothing is shown. And AFAIK, right now there are no getters, so I can't calculate the precise number of spaces.
P.S. I should try and use table, I think I can simplify this.
// #set box(outset: (bottom: 1.29pt))
Text or no text #underline[test]#box(width: 1fr, stroke: (bottom: 0.5pt))
Text or no text #underline[test]#box(width: 1fr, line(length: 100%, stroke: 0.5pt))
This solution is much better than mine, but it still tries to mimic the "underline until EOL". Typst was created to be more intuitive than LaTeX, you can create documents faster. And the fact that underline() ignores/skips any whitespace is just wrong, why is this the case?
Also, there can be default or custom settings for underline() and by using stroke of box() or line() you have to replicate/copy the settings of the underline() which is unnatural and just bad UX and bad practice, IMO.
One more thing. The underline stroke thickness is determined by the font? W-why is that? In the example above, the fake stroke is a bit thicker than the real one:
This is a different topic, but this makes it more difficult to use above workarounds. Sure, you can set underline thickness to 0.5pt in every single document, where you want to use underlining (or use template), but why not use some default value in the first place? Why thickness must be related to font (itself or boldness, I don't remember)?
#letunderline_thickness= 0.5pt#setunderline(stroke: underline_thickness)
#letubox(..) = box(
width: 1fr,
stroke: (bottom: underline_thickness),
outset: (bottom: 1.3pt), // Font dependant..
)
Text or no text #underline[test]#ubox()
I forgot to mention that this is the one most heavily used thing in blanks/forms making. Whenever I need to make a form with/without filling in information/details, I have to import a whole bag of hacky underline functions that otherwise would be much simpler/slimmer if h() were to work in underline().
changed the title [-]Can't use over-/underline() with any space symbol or h()[/-][+]Can't use `over-/underline()` with any space symbol or `h()`[/+]on Jul 16, 2024
As of Typst 0.12.0 underline(repeat(" ")) now works, kinda.
Interesting.
This is better than before:
Indeed.
For some reason not all space symbols work though, and what worse is that which symbols work seems to depend on the specific font used.
Oh...no...
I'm still using the same ubox() hack, but with different wrapper functions on top of it to be useful in different cases (in most cases you also want to use underline instead to use the evade feature). A solid workaround.
This is better than not working at all, but you shouldn't use it, as I found out (accidentally) that it has some repeat() downsides.
As you can see, in the best case scenario, the gap between spaces is barely noticeable, but in the worst: you either see the gap or justify: false will make the EOF shorter. I didn't test this with other spaces, but they all probably have the tiny gaps anyway. So I'm back to using the old hack.
BTW, previously I used ubox[~] in order to keep the line height correct, but a bunch of these will add visible spaces. Instead, the zero-width space should be used, i.e., ubox(sym.zws).
I tried, and it looks good for any length, so I guess it's precise. The main advantage over the old one is that the lines not only look uniform and as continuous lines on any zoom level (in Okular/MuPDF), but also you don't have to fiddle with default offset/thickness anymore. And evasion obviously works. I also already changed one of my templates to this and it looks better, I guess basically like it supposed to.
You can use it like #underline[ipsum]#ubox(width: ...), or make a wrapper like this:
Why do you have context? It will slow down compilation with each use.
Just to be absolutely sure it is safe enough. Being a new user or Typst, I am not exactly informed about how context works, and I observed situations where it was required. Coming from LaTeX means that I am super tolerant with compilation time. I will be happy to remove it when I fully understand context.
I recently bumped into a similar issue, essentially needing working #underline(h(<width>)), and all solutions above gave some artifacts(the underline had gaps) or layout issues(I'm recreating a page from Microsoft Word, hence the need for wacky text layout). Here's the workaround that worked for me:
I just guess the problem is that the underline function does not work on #h() element, thus the solution might be to find some chars to take space in the text flow. But unfortunately continuous multiple spaces are not allowed in typst and are treated as only a single space.
Today I happen to find that the space symbol \u{0020} is allowed to be repeated continuously in typst.
So for anyone who wants a simpler solution, the following works:
#letaddspace(number) = foriinrange(number){[\u{0020}]}
#underline(stroke: 2pt, offset: 0.4em)[#addspace(5)have a #addspace(20) try#addspace(5)]
Activity
Andrew15-5 commentedon Jul 13, 2023
My current workaround is:
I don't know why having
h()with any non-zero length causes the spaces before it to show underlining, but withouth()nothing is shown. And AFAIK, right now there are no getters, so I can't calculate the precise number of spaces.P.S. I should try and use table, I think I can simplify this.
adriandelgado commentedon Jul 14, 2023
Try using this:
or
underlineskips whitespace I think.Andrew15-5 commentedon Jul 14, 2023
This solution is much better than mine, but it still tries to mimic the "underline until EOL". Typst was created to be more intuitive than LaTeX, you can create documents faster. And the fact that
underline()ignores/skips any whitespace is just wrong, why is this the case?Also, there can be default or custom settings for
underline()and by using stroke ofbox()orline()you have to replicate/copy the settings of theunderline()which is unnatural and just bad UX and bad practice, IMO.One more thing. The underline stroke thickness is determined by the font? W-why is that? In the example above, the fake stroke is a bit thicker than the real one:
This is a different topic, but this makes it more difficult to use above workarounds. Sure, you can set underline thickness to
0.5ptin every single document, where you want to use underlining (or use template), but why not use some default value in the first place? Why thickness must be related to font (itself or boldness, I don't remember)?Andrew15-5 commentedon Jul 14, 2023
I've come up with the next setup:
Andrew15-5 commentedon Aug 24, 2023
I think this is a more universal version and all underlines (real/artificial) are on the same level (and have the same thickness).
You can (re)define any
box()arguments, including defaultwidth: 1fr(#ubox(width: 4cm)) and others.Andrew15-5 commentedon Nov 22, 2023
I forgot to mention that this is the one most heavily used thing in blanks/forms making. Whenever I need to make a form with/without filling in information/details, I have to import a whole bag of hacky underline functions that otherwise would be much simpler/slimmer if
h()were to work inunderline().OrangeX4 commentedon Dec 14, 2023
And the current underline does not support mixed Chinese-English typography, there are breaks here.
Myriad-Dreamin commentedon Feb 27, 2024
I have made a workaround helper today, hopefully useful for you:
Usage:
[-]Can't use over-/underline() with any space symbol or h()[/-][+]Can't use `over-/underline()` with any space symbol or `h()`[/+]kanashimia commentedon Oct 24, 2024
As of Typst 0.12.0
underline(repeat(" "))now works, kinda.You still can't use
hbecause it isn't counted as text and isn't underlined, for exampleunderline[foo #h(1cm) bar]will produce something likeThis is better than before:
For some reason not all space symbols work though, and what worse is that which symbols work seems to depend on the specific font used.
Andrew15-5 commentedon Oct 24, 2024
Interesting.
Indeed.
Oh...no...
I'm still using the same
ubox()hack, but with different wrapper functions on top of it to be useful in different cases (in most cases you also want to useunderlineinstead to use theevadefeature). A solid workaround.Andrew15-5 commentedon Nov 10, 2024
This is better than not working at all, but you shouldn't use it, as I found out (accidentally) that it has some
repeat()downsides.As you can see, in the best case scenario, the gap between spaces is barely noticeable, but in the worst: you either see the gap or
justify: falsewill make the EOF shorter. I didn't test this with other spaces, but they all probably have the tiny gaps anyway. So I'm back to using the old hack.BTW, previously I used
ubox[~]in order to keep the line height correct, but a bunch of these will add visible spaces. Instead, the zero-width space should be used, i.e.,ubox(sym.zws).mattfbacon commentedon Jun 6, 2025
Andrew15-5 commentedon Jun 6, 2025
Workaround by @bluss from here:
I've changed #1716 (comment) to something like this:
I tried, and it looks good for any length, so I guess it's precise. The main advantage over the old one is that the lines not only look uniform and as continuous lines on any zoom level (in Okular/MuPDF), but also you don't have to fiddle with default offset/thickness anymore. And evasion obviously works. I also already changed one of my templates to this and it looks better, I guess basically like it supposed to.
You can use it like
#underline[ipsum]#ubox(width: ...), or make a wrapper like this:neruthes commentedon Jul 11, 2025
After studying the comments above, I now have a
#hspacefunction in my latexcompat package. Thanks all.Andrew15-5 commentedon Jul 15, 2025
Why do you have
context? It will slow down compilation with each use.neruthes commentedon Jul 15, 2025
Just to be absolutely sure it is safe enough. Being a new user or Typst, I am not exactly informed about how context works, and I observed situations where it was required. Coming from LaTeX means that I am super tolerant with compilation time. I will be happy to remove it when I fully understand context.
Andrew15-5 commentedon Jul 15, 2025
Basically, if there is no error, and everything works correctly, don't use context blindly.
https://typst.app/docs/reference/context
Kogfill commentedon Dec 3, 2025
I recently bumped into a similar issue, essentially needing working #underline(h(<width>)), and all solutions above gave some artifacts(the underline had gaps) or layout issues(I'm recreating a page from Microsoft Word, hence the need for wacky text layout). Here's the workaround that worked for me:
phidiascheng commentedon Sep 24, 2026
I just guess the problem is that the underline function does not work on #h() element, thus the solution might be to find some chars to take space in the text flow. But unfortunately continuous multiple spaces are not allowed in typst and are treated as only a single space.
Today I happen to find that the space symbol \u{0020} is allowed to be repeated continuously in typst.
So for anyone who wants a simpler solution, the following works: