On Fri, Feb 07, 2025 at 08:33:20PM +0100, onf wrote:
> Hi Walter,
> 
> On Fri Feb 7, 2025 at 7:46 PM CET, Walter Alejandro Iglesias wrote:
> > [...]
> > Titles and subtitles (I'm referring to those in the body of the
> > document, not those in the header and footer) look better when they have
> > more space above than below.  I've recently been studying how to achieve
> > this without altering the line spacing.  So far I've been doing
> > something like this:
> >
> > .\" ------------------------------
> > .vs 15
> > .ds adjust \v'\\n[.v]u/5u'\Z'\\$*'
> > .de h1
> > .  br
> > .  ps 14
> > .  sp
> > .  ds prev \\$0
> > ..
> > .de pp
> > .  br
> > .  ps 12
> > .  if '\\*[prev]'h1' .sp
> > ..
> > .pp
> > This is a paragraph.
> > .h1
> > \*[adjust "This is a title"]
> > .pp
> > This is another paragraph.
> > .\" --------------------------------
> >
> > How can I achieve that trick (or alike) from the macro?  (Thus avoid
> > having to add the label to each title in the document.)
> 
> Your approach seems unnecessarily complicated. Unless I am missing
> something, what you are trying to do with
>   \v'\\n[.v]u/5u'
> can be achieved via
>   .sp 0.2v
> or its equivalent
>   .sp 0.2
> 
> ~ onf
> 

I'll go into detail with my explanation.  Veterans here will be bored,
but perhaps those like me who are just scratching the surface with Groff
can get something out of it.

My novels are more like textbooks than novels in style.  They are full
of titles and subtitles.  If I'd known that this would complicate my
life when editing them, I would've avoided doing it.  Beginner mistakes.
:-)

The following is the first chapter of one of them, published in my
website (sorry for the ad at the end):

  https://roquesor.com/en/pdf/ven_extract.pdf

As you can see, in addition to titles and subtitles, there are lines
that show dates that go below the titles, as well as verses, quotes,
etc.  All of these elements each have their own macro and the first
thing they define is the vertical separation with the preceding text
block.

To avoid confusion with units translations, before the macros, I first
define a global '.vs' value and right after (based on that global .vs) I
define in number variables top and bottom spaces of each element in 'v'
units.  Then, depending on the case, sometimes it's convenient to use
the bottom space of the previous element (for example, a paragraph that
follows a title), other times to use the top space of the current one (a
verse or quote that follows a paragraph), other times a combination of
both.  Some special cases require to define a new special value.  As a
result, I end up with a series of conditionals at the beginning of each
macro.  At bottom I paste two examples (in the next paragraph I explain
why) of the macro I use for titles[1].

Now I get to the part that made the story more complicated.  Please,
open the linked document with a PDF viewer that allows you to turn pages
without altering the vertical position of the pages, skip document
title, credits, etc., go forward to where the first chapter begins and
then position a second window over the viewer so that the top edge of
the window matches one of the paragraph base lines.  Hitting spacebar in
your PDF viewer you'll notice that the base lines on all the pages match
the guide perfectly (except for titles subtitles and dates, which are
the ones modified with the "adjust" string.)  I found that this feature,
in addition to making the vertical size of the text box more uniform
across the pages, serves to check the operation of the widow and orphan
automation (which we recently discussed in another thread[2].)  But to
achieve this uniformity you have to sit down and do the math with the
spaces so that they add up to round numbers in "v" units.  This is why I
found it easier and less prone to error to round all the spaces to 1v
and use the string trick I showed in the previous post only in those
cases that require different spacing above and below (titles, subtitles
and dates).  Well, this is the botch job I've come up with so far. :-)


[2] https://lists.gnu.org/archive/html/groff/2025-01/msg00123.html


[1] The PDF from the link can be generated with any of these two
    approaches:

.\" This is the option using the trick I suggested in my frist message.
.ds adjust \v'\\n[.v]u/5u'\Z'\\$*'
.de h1
.       if '\\*[prev]'pp' .ep
.       if '\\*[prev]'qu' .eq
.       br
.       ie '\\*[prev]'ct' .sp \n[ct_bot]u
.       el \{.ie '\\*[prev]'pg' .sp \n[pg_bot]u
.       el \{.ie '\\*[prev]'eg' .sp \n[eg_bot]u
.       el \{.ie '\\*[prev]'te' .sp \n[te_bot]u
.       el .sp \\n[\\$0_top]u
.       \}\}\}
.       ps \\n[\\$0_ps]u
.       vs \\n[\\$0_vs]u
.       ll \n[line_length]u-2m \" Shorter line lenght
.       fam \*[font_family]
.       ft \*[font_type]
.       in 0
.       nf
.       nh \" Disable hyphenation
.       ne 2
.       ds prev \\$0
..

.\" This is what the macro becomes without using the string trick
.de h1
.       if '\\*[prev]'pp' .ep
.       if '\\*[prev]'qu' .eq
.       br
.       ie '\\*[prev]'ct' \{\
.               sp \n[ct_bot]u
.               sp \\n[\\$0_top]u-\\n[vertical_space]u
.       \}
.       el \{.ie '\\*[prev]'pg' \{\
.               sp \n[pg_bot]u
.               sp \\n[\\$0_top]u-\\n[vertical_space]u
.       \}
.       el \{.ie '\\*[prev]'eg' \{\
.               sp \n[eg_bot]u
.               sp \\n[\\$0_top]u-\\n[vertical_space]u
.       \}
.       el \{.ie '\\*[prev]'te' \{\
.               sp \n[te_bot]u
.               sp \\n[\\$0_top]u-\\n[vertical_space]u
.       \}
.       el .sp \\n[\\$0_top]u
.       \}\}\}
.       ps \\n[\\$0_ps]u
.       vs \\n[\\$0_vs]u
.       ll \n[line_length]u-2m \" Shorter line lenght
.       fam \*[font_family]
.       ft \*[font_type]
.       in 0
.       fi
.       ad l
.       nh \" Disable hyphenation
.       ne 2
.       if (\\n[.h]/1v = 2) \{\
.               rs
.               sp \\n[\\$0_top]u-\\n[vertical_space]u
.       \} 
.       ds prev \\$0
..


-- 
Walter

Reply via email to