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 via email to