ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: Re: [NTG-context] Protect the lettrine
Date: Fri, 16 Jun 2023 20:25:20 +0200	[thread overview]
Message-ID: <1d86aeb8-5009-e9e1-18e2-e5e1440b43d3@freedom.nl> (raw)
In-Reply-To: <fa205ec1b8ddb44af91b492534f2007b369529bc.camel@telus.net>

On 6/15/2023 8:35 AM, Max Chernoff via ntg-context wrote:
> Hi Dave,
> 
>> How would you instruct ConTeXt to "protect" the lettrine such that
>> regardless of whether the first paragraph spans multiple lines, a short
>> first paragraph will still prevent the second paragraph from overlapping
>> the lettrine?
> 
>> Here's the output I'm looking to achieve:
>>
>> https://i.stack.imgur.com/XeZQS.png
>>
>> Note how the second line honours the lettrine's width and padding, in the
>> same way that the second line of the first paragraph in Knuth's quote
>> respects the width and padding.
> 
> Here's a questionable Lua-based solution:
> 
>     \startluacode
>     userdata.hangindent = 0
>     function userdata.post_lettrine(head)
>         nodes.tasks.disableaction("finalizers", "userdata.post_lettrine")
>     
>         if tex.prevgraf < math.abs(tex.hangafter) then
>             userdata.hangindent = tex.hangindent
>             nodes.tasks.enableaction("processors", "userdata.next_par")
>         end
>     
>         return head
>     end
>     nodes.tasks.appendaction("finalizers", "before", "userdata.post_lettrine")
>     nodes.tasks.disableaction("finalizers", "userdata.post_lettrine")
>     
>     
>     function userdata.next_par(head)
>         nodes.tasks.disableaction("processors", "userdata.next_par")
>     
>         if head.next.id == node.id("glue") and
>            head.next.subtype == 20
>         then
>             head.next.width = userdata.hangindent
>         end
>     
>         return head
>     end
>     nodes.tasks.appendaction("processors", "before", "userdata.next_par")
>     nodes.tasks.disableaction("processors", "userdata.next_par")
>     
>     
>     local default = typesetters.initials.actions.default
>     function typesetters.initials.actions.default(...)
>         nodes.tasks.enableaction("finalizers", "userdata.post_lettrine")
>         return default(...)
>     end
>     \stopluacode
>     
>     \setupinitial[n=2]
>     
>     [...]
> 
> Normally manipulating nodes inside the callbacks is the wrong way to do
> something, but in this case, that's exactly how the standard initial
> code works.
> 
> We need to modify the "default" alternative since "\setupinitial"
> provides no way for us to set a different alternative. A better solution
> would be to provide a new alternative so we wouldn't need to make
> questionable overrides to the base code.
Indeed, and it might also sort of fragile due to the prevgraf although 
we can assume sane usage. All this stuff is also a bit order sensitive.

I'll added this:

\setupinitial[n=2,continue=yes]

But I'll also cheat a bit by adding a prevdepth field to the parstate 
that remembers the previous one (as it gets lost otherwise).

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2023-06-16 18:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13  2:43 Thangalin via ntg-context
2023-06-13  8:29 ` Otared Kavian via ntg-context
2023-06-13 21:01   ` Thangalin via ntg-context
2023-06-13 21:11     ` Thangalin via ntg-context
2023-06-14  2:32     ` linguafalsa--- via ntg-context
2023-06-14  3:46       ` Thangalin via ntg-context
2023-06-14 17:43         ` linguafalsa--- via ntg-context
2023-06-14 21:32           ` Thangalin via ntg-context
2023-06-15  6:35             ` Max Chernoff via ntg-context
2023-06-16 18:25               ` Hans Hagen via ntg-context [this message]
2023-06-26  1:52                 ` Thangalin via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d86aeb8-5009-e9e1-18e2-e5e1440b43d3@freedom.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@freedom.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).