zauguin / luaul

5 stars 3 forks source link

Extension of the macro `\underLine` #11

Open pablgonz opened 2 years ago

pablgonz commented 2 years ago

Hi, I'm moving old files to LuaLaTeX and many of the soul capabilities can be done directly with fontspec and lua-ul. I think it would be nice to have an extension like key=val for \undeLine, something like:

\underLine[ul-color=some color, ul-width = some width, ul-depth = some dim]{awesome}

(don't take into account the names of the keys, I'm not very witty)

That is, to be able to better control the colour, width and depth (or vertical spacing) of \underLine. Something like this will be possible?

Saludos

zauguin commented 2 years ago

I pushed an experimental version of this: The (unreleased) version in the repo has a new macro \genericUnderLine to be used as

\genericUnderLine[color = red, top = -1pt, bottom = -2pt]{Some text comes here}

Supported keys are color (defaults to the current color), top (the height of the upper edge of the line), bottom (the height of the lower edge) and height (equal to top - bottom, indicating the line width. height feels more fitting than width here IMO, but I could be convinced otherwise). Normally at most two of the three keys top/bottom/height should be set (the third is determined automatically), but setting all three is supported as long as they are consistent (Exactly consistent, respecting TeX's rounding rules... You really don't want to rely on that).

Anyways, please test :smiley_cat:

pablgonz commented 2 years ago

Supported keys are color (defaults to the current color), top (the height of the upper edge of the line), bottom (the height of the lower edge) and height (equal to top - bottom, indicating the line width. height feels more fitting than width here IMO, but I could be convinced otherwise). Normally at most two of the three keys top/bottom/height should be set (the third is determined automatically), but setting all three is supported as long as they are consistent (Exactly consistent, respecting TeX's rounding rules... You really don't want to rely on that).

Anyways, please test

The name of the keys is correct (I'm not very clever for that) and it works perfect, now I can imitate (more or less) the output that Acrobat DC produces.

You can add a couple of things:

  1. Double line
  2. Offset, i.e. be able to extend (or shorten) a little bit to the left and right.
zauguin commented 2 years ago

Sorry for the long delay :see_no_evil:

1. Double line

Not really planned since it can be emulated by nesting two \underLines. That gives the advantage that both lines can be automized with all options without needing to duplicate all keys. Also it allows an arbitrary number of lines. Do you have an example where having support for this with requiring nesting would be useful?

2\. Offset, i.e. be able to extend (or shorten)  a little bit to the left and right.

That's ... complicated. Extending is relatively easy, but when it's possible to shorten than it becomes very obvious if the line stops somewhere and a new line starts. That makes it rather fragile. Also it could be argued that abc\underLine[shortened]{def}\underLine[shortened]{ghi}jkl would be supposed to leave a gap in the underline. That's hard to implement since lua-ul treats underlines as a character property and has o notion of where the different commands started or ended.

pablgonz commented 2 years ago

Not really planned since it can be emulated by nesting two \underLines. That gives the advantage that both lines can be automized with all options without needing to duplicate all keys. Also it allows an arbitrary number of lines. Do you have an example where having support for this with requiring nesting would be useful?

I had completely forgotten that you can nest :D The specific example is of the type by hand (I don't know how to translate this into English), one of the study techniques taught in my country consists of underlining text (yes there are colors, but students usually carry only one pencil) and "double underlining" is something that is frequently used, in collegial terms you pass the printed material to the students, not the PDF with the nice colors :(

2\. Offset, i.e. be able to extend (or shorten)  a little bit to the left and right.

That's ... complicated. Extending is relatively easy, but when it's possible to shorten than it becomes very obvious if the line stops somewhere and a new line starts. That makes it rather fragile. Also it could be argued that abc\underLine[shortened]{def}\underLine[shortened]{ghi}jkl would be supposed to leave a gap in the underline. That's hard to implement since lua-ul treats underlines as a character property and has o notion of where the different commands started or ended.

Ops, in my mind it looked a bit easier, I didn't think in paragraphs as such but in sentences or headings (nothing multiline) ...snif

zauguin commented 2 years ago

Not really planned since it can be emulated by nesting two \underLines. That gives the advantage that both lines can be automized with all options without needing to duplicate all keys. Also it allows an arbitrary number of lines. Do you have an example where having support for this with requiring nesting would be useful?

I had completely forgotten that you can nest :D

Allowing nesting is not really one of the most common features for LaTeX underlining packages ;) Do you think that it should be made clearer that it is supported (and, for this kind of usage, even recommended).

The specific example is of the type by hand (I don't know how to translate this into English), one of the study techniques taught in my country consists of underlining text (yes there are colors, but students usually carry only one pencil) and "double underlining" is something that is frequently used, in collegial terms you pass the printed material to the students, not the PDF with the nice colors :(

Thanks. I certainly can identify with the students carrying only one pencil. Also in PDF files this allows you to print without requiring color printing, so I think there is some value to it.

In your opinion is this something for which the nesting based implementation is appropriate or do you still think it needs explicit support?

2\. Offset, i.e. be able to extend (or shorten)  a little bit to the left and right.

That's ... complicated. Extending is relatively easy, but when it's possible to shorten than it becomes very obvious if the line stops somewhere and a new line starts. That makes it rather fragile. Also it could be argued that abc\underLine[shortened]{def}\underLine[shortened]{ghi}jkl would be supposed to leave a gap in the underline. That's hard to implement since lua-ul treats underlines as a character property and has o notion of where the different commands started or ended.

Ops, in my mind it looked a bit easier, I didn't think in paragraphs as such but in sentences or headings (nothing multiline) ...snif

I'll keep this in mind as a potential future extension.

pablgonz commented 2 years ago

Thanks. I certainly can identify with the students carrying only one pencil. Also in PDF files this allows you to print without requiring color printing, so I think there is some value to it.

In my school world it is very common to work only in black and white (someday we will be able to print in color, but I see it as a long way off :)

In your opinion is this something for which the nesting based implementation is appropriate or do you still think it needs explicit support?

I think that will depend more on your opinion and what you want to do with lua-ul in the future. I see two scenarios:

  1. A key option (this one is to my liking) and is justified by the second scenario.

  2. Nesting the macro, I still like it, but you may want to implement (in the future) something similar to the \emph behavior for nesting and this could hinder the development of the package.

I'll keep this in mind as a potential future extension.

That would be great.

I know the focus of the package is on color, but these details are very cool, sometimes you try to imitate the usual handwriting techniques in PDF (just for illustrative purposes) and I find in lua-ul a tremendous potential, around here where I live everything is printed on paper and photocopied (yes many sheets) and on screen the colors look great, but in print they don`t look so nice :D.

jan-glx commented 4 days ago

I came here because I thought I needed offset/extend too – I use lua-ul to add gray background to (wrapped) inline code – but I realized that I actually just want to add some space around my highlighted text & that, of course, works like a charm already :)