ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Max Chernoff via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Max Chernoff <mseven@telus.net>
Subject: Re: [NTG-context] Protect the lettrine
Date: Thu, 15 Jun 2023 00:35:10 -0600	[thread overview]
Message-ID: <fa205ec1b8ddb44af91b492534f2007b369529bc.camel@telus.net> (raw)
In-Reply-To: <CAANrE7qgmMy3tDuSMWtyJZOCAkUVjSTATS21Ak4ieDm2APazBg@mail.gmail.com>

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.

-- Max
___________________________________________________________________________________
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-15  6:36 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 [this message]
2023-06-16 18:25               ` Hans Hagen via ntg-context
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=fa205ec1b8ddb44af91b492534f2007b369529bc.camel@telus.net \
    --to=ntg-context@ntg.nl \
    --cc=mseven@telus.net \
    /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).