Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use over-/underline() with any space symbol or h() #1716

Open
1 task done
Andrew15-5 opened this issue Jul 13, 2023 · 8 comments
Open
1 task done

Can't use over-/underline() with any space symbol or h() #1716

Andrew15-5 opened this issue Jul 13, 2023 · 8 comments
Labels
bug Something isn't working text Text layout, shaping, internationalization, etc.

Comments

@Andrew15-5
Copy link
Contributor

Andrew15-5 commented Jul 13, 2023

Description

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.

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst
@Andrew15-5 Andrew15-5 added the bug Something isn't working label Jul 13, 2023
@Andrew15-5
Copy link
Contributor Author

Andrew15-5 commented Jul 13, 2023

My current workaround is:

#let H(n) = {
  for value in range(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.

@adriandelgado
Copy link
Contributor

adriandelgado commented Jul 14, 2023

Try using this:

Text or no text #box(width: 1fr, stroke: (bottom: 0.5pt), none)

or

Text or no text #box(width: 1fr, line(length: 100%, stroke: 0.5pt))

underline skips whitespace I think.

@Andrew15-5
Copy link
Contributor Author

// #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))

image

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:

image

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)?

@Andrew15-5
Copy link
Contributor Author

I've come up with the next setup:

#let underline_thickness = 0.5pt
#set underline(stroke: underline_thickness)
#let ubox(..) = box(
  width: 1fr,
  stroke: (bottom: underline_thickness),
  outset: (bottom: 1.3pt), // Font dependant
  ..
)

Text or no text #underline[test]#ubox()

image

@laurmaedje laurmaedje added the text Text layout, shaping, internationalization, etc. label Jul 17, 2023
@Andrew15-5
Copy link
Contributor Author

Andrew15-5 commented 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).

#let underline-thickness = 0.5pt
#let underline-offset = 1pt
#set underline(stroke: underline-thickness, offset: underline-offset)
// Underline box
#let ubox(..box_args) = box(
  width: 1fr,
  stroke: (bottom: underline-thickness),
  outset: (bottom: underline-offset),
  ..box_args,
)

You can (re)define any box() arguments, including default width: 1fr (#ubox(width: 4cm)) and others.

@Andrew15-5
Copy link
Contributor Author

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().

@OrangeX4
Copy link

And the current underline does not support mixed Chinese-English typography, there are breaks here.

dbc23453e8b798889cc6dc4c11b49967

@Myriad-Dreamin
Copy link
Contributor

I have made a workaround helper today, hopefully useful for you:

#let long-underline(left: 0, right: 0, stroke: black, fake-text: "a ", content, ..args) = {
  let lspace(n) = {
    set text(fill: rgb("00000000"))
    underline(stroke: stroke, evade: false, fake-text * n, ..args)
  }
  if left > 0 {
    lspace(left)
  }
  underline(..args, content)
  if right > 0 {
    lspace(right)
  }
}

Usage:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working text Text layout, shaping, internationalization, etc.
Projects
None yet
Development

No branches or pull requests

5 participants