Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In ConTeXt mkiv, how do I register a callback? callback.register() does nothing (and IIRC most callbacks are frozen anyway) and somewhere I found tasks.appendaction, but this gives me an error that tasks is not defined (nil).

I'd like to add something to the post_linebreak_filter callback.


Edit: thanks to Khaled's answer and help from the Mailing list, I've got a solution now. The key is to create my own namespace:

moduledata.mystuff={}

and add my function:

moduledata.mystuff.show_hyph = show_hyph

and to register the function to the "finalizers" callbacks, which are the post_linebreak_filter equivalent in ConTeXt.

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

See my answer for a complete example

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

It should be nodes.tasks.appendaction(), I don't know the official way to use it, but after trial and error (and grepping through the source), I came up with:

bidi.handle_bidi = nodes.installattributehandler {
    name      = "bidi",
    namespace = bidi,
    processor = bidi.ctxprocess,
}
nodes.tasks.appendaction("processors", "characters",  "bidi.handle_bidi")

and:

nodes.tasks.enableaction("processors", "bidi.handle_bidi")
nodes.tasks.disableaction("processors", "bidi.handle_bidi")

(copied from my bidi module, and this is equivalent to pre_linepreak_filter)

Better ask Hans for a definite answer.

share|improve this answer
    
I have asked on the NTG ConTeXt list, waiting for an answer. –  topskip Feb 25 '11 at 11:30
    
I've got a reply from Hans, I'll post it as a separate answer. –  topskip Feb 25 '11 at 14:57
add comment

I have taken the example from the LuaTeX wiki and transformed it into ConTeXt code with the help of Khaled and Hans:

\mainlanguage[de]
\de
\startluacode
moduledata.mystuff={}
show_hyph = function(head)
  while head do
    if head.id == 0 or head.id == 1 then -- % hlist, vlist
      show_hyph(head.list)               -- % head.head in LuaTeX > 0.65
    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

moduledata.mystuff.show_hyph = show_hyph

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

\starttext
Seit zwei Jahren...
\stoptext

The "finalizer" is the ConTeXt equivalent of the post_linebreak_filter callback.

share|improve this answer
    
@Charles: Sorry for entering this discussion late. (I can't quite follow since parts are already deleted.) Just wanted to say: I usually strongly discourage people to include answers into the question. Just a pointer is OK, but I think we should keep answers to answers. What do you think? (@Patrick: In my opinion you've already got to much of an answer in the question now.) –  Hendrik Vogt Mar 2 '11 at 14:39
    
@Hendrik: Putting a summary at the end of questions is fairly well established on SO when there are several useful answers. E.g., stackoverflow.com/questions/9033/hidden-features-of-c Maybe this should be a meta qn? –  Charles Stewart Mar 2 '11 at 15:03
    
@Charles: Thanks for the feedback. Well, for a question with three hundred and two answers, a summary is somewhat necessary, but here we have two answers. But still it might be worth asking for other opinions on meta. –  Hendrik Vogt Mar 2 '11 at 15:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.