ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* post_linebreak_filter in context
@ 2011-02-25 11:28 Patrick Gundlach
  2011-02-25 12:46 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Gundlach @ 2011-02-25 11:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

how do I install a custom post_linebreak_filter in ConTeXt? I have this LaTeX file:

------------------------------------------------------------------------------------
\documentclass[12pt,a4paper]{scrartcl}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{fontspec}
\directlua{
show_hyph = function(head)
  while head do
    if head.id == 0 or head.id == 1 then % hlist, vlist
      show_hyph(head.list) % should be head.head in a newer luatex than 0.64
    elseif head.id == 7 then             % disc
      local n = node.new("whatsit","pdf_literal")
      n.mode = 0
      n.data = "q 0.3 w 0 2 m 0 7 l S Q"
      n.next = head.next
      n.prev = head
      head.next = n
      head = n
    end
  head = head.next
  end
  return true
end
luatexbase.add_to_callback("post_linebreak_filter",show_hyph,"show_hyph")

}

\begin{document}
\begin{minipage}{5cm}
\blindtext
\end{minipage}
\end{document}
------------------------------------------------------------------------------------

which registers a function "show_hyph" as the post_linebreak_filter (the rest is not really interesting). How would I do this in ConTeXt?

(also asked on tex.se: http://tex.stackexchange.com/questions/11960/how-to-register-a-callback-in-context)

Thanks

Patrick

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: post_linebreak_filter in context
  2011-02-25 11:28 post_linebreak_filter in context Patrick Gundlach
@ 2011-02-25 12:46 ` Hans Hagen
  2011-02-25 15:14   ` Patrick Gundlach
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2011-02-25 12:46 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Patrick Gundlach

On 25-2-2011 12:28, Patrick Gundlach wrote:
> Hi,
>
> how do I install a custom post_linebreak_filter in ConTeXt? I have this LaTeX file:
>
> ------------------------------------------------------------------------------------
> \documentclass[12pt,a4paper]{scrartcl}
> \usepackage[english]{babel}
> \usepackage{blindtext}
> \usepackage{fontspec}
> \directlua{
> show_hyph = function(head)
>    while head do
>      if head.id == 0 or head.id == 1 then % hlist, vlist
>        show_hyph(head.list) % should be head.head in a newer luatex than 0.64
>      elseif head.id == 7 then             % disc
>        local n = node.new("whatsit","pdf_literal")
>        n.mode = 0
>        n.data = "q 0.3 w 0 2 m 0 7 l S Q"
>        n.next = head.next
>        n.prev = head
>        head.next = n
>        head = n
>      end
>    head = head.next
>    end
>    return true
> end
> luatexbase.add_to_callback("post_linebreak_filter",show_hyph,"show_hyph")
>
> }
>
> \begin{document}
> \begin{minipage}{5cm}
> \blindtext
> \end{minipage}
> \end{document}
> ------------------------------------------------------------------------------------
>
> which registers a function "show_hyph" as the post_linebreak_filter (the rest is not really interesting). How would I do this in ConTeXt?

first put the function in some namespace, like:

moduledata.mystuff = { }
moduledata.mystuff.show_hyph = show_hyph

then register it in the finalizer group (which is the post_linebreak stuff)

nodes.tasks.appendaction("finalizers","after","moduledata.mystuff.show_hyph")

(before and after are subgroups that can be used by users if needed; of 
course one never know to what extent it will influence other processes, 
so "shipouts","after" might be a better choice)

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: post_linebreak_filter in context
  2011-02-25 12:46 ` Hans Hagen
@ 2011-02-25 15:14   ` Patrick Gundlach
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Gundlach @ 2011-02-25 15:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello Hans,

> 
> first put the function in some namespace, like:
> 
> moduledata.mystuff = { }
> moduledata.mystuff.show_hyph = show_hyph
> 
> then register it in the finalizer group (which is the post_linebreak stuff)
> 
> nodes.tasks.appendaction("finalizers","after","moduledata.mystuff.show_hyph")

Works perfectly.

> (before and after are subgroups that can be used by users if needed; of course one never know to what extent it will influence other processes, so "shipouts","after" might be a better choice)

Ok. In this case it works for me but I'l remember that.

Thanks!

Patrick

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-25 15:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-25 11:28 post_linebreak_filter in context Patrick Gundlach
2011-02-25 12:46 ` Hans Hagen
2011-02-25 15:14   ` Patrick Gundlach

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).