On Sat, Feb 08, 2025 at 08:37:58PM +0100, onf wrote:
> I understand your use case, but it still seems simpler to me to use
> sp over strings. You could define registers which specify the ratio
> between the top and bottom space, so that instead of 1v:1v it becomes
> e.g. 0.4v:0.6v. Obviously the ratios could be defined without units,
> e.g. 40:60, and could be multiplied by the appropriate unit later;
> this would allow you to generalize the task of shifting the text.

The thing is that you can't generalize, that's why I went into detail on
my previous explanation.  What makes the difference is that the string
trick makes the displacement without altering *or being altered* by the
rest of the elements.  Let's take a generic case, a document with just
titles and paragraphs where titles has 1.2v vertical space at top and
.8v at bottom and paragraphs zero separation in both.  The following is
one of the special cases you'll bump against to:


  1.2v <- IF this lands at the top of the page it will be ignored.
  This is a Title
  0.8v <- THEN starting from this point, the rest of the base lines on
          this page will be 0.2v higher than the base lines in other pages.
  0
  paragraph
  0
  [...]


If you take a look to the code examples in my previous post you'll see:


  .       ne 2
  .       if (\\n[.h]/1v = 2) \{\
  .               rs
  .               sp \\n[\\$0_top]u-\\n[vertical_space]u
  .       \}

  (Notice that this has to go *after* '.ne 2')


With the string trick you don't have to worry about details like this.
And I'd be happy with this solution if it weren't for one drawback
(which motivated my original question): it doesn't work when the title
spans more than one line.  To cover this case, you have to disable
justification, apply the string to each line, and manually insert the
line break.  This way:

  .ds adjust \v'\\n[.v]u/5u'\Z'\\$*'
  .nf
  .
  \*[adjust "This is a very"]
  .br
  \*[adjust "long title"]


> 
> I don't have the time to study your approach in more depth, sorry.

You are a resourceful person, your ideas are always useful. :-)


> 
> ~ onf
> 

-- 
Walter

Reply via email to