I try to play with the callback function process_input_buffer provided by LuaTeX, but unluckily I don't get what I expect.

The manual said that

This callback allows you to change the contents of the line input buffer just before LuaTeX actually starts looking at it.

function (<string> buffer)
  return <string> adjusted_buffer

If you return nil, LuaTeX will pretend like your callback never happened. You can gain a small amount of processing time from that.

I try to use this callback to process my input. Firstly, I must register it

-- a.lua
-- the function appendSomething will append the \TeX command to end of the input lines
-- and return the adjusted string later
local function appendSomething(str)
  str = str .. " \\TeX{}"
  return str

callback.register("process_input_buffer", appendSomething)

% a.tex
\directlua{dofile 'a.lua'}

the output is as follows

hello T.5exEX world T.5exEX

I don't get the TeX with lower E. Since process_input_buffer process the input lines before TeX actually looks at it, the \TeX command should be appended to the end of the input lines. After that, TeX will do the actual typesetting work and read the \TeX, converting it into a token, replacing it with its replacement texts.

But, this don't happen. Why? Why I can't get the output lines with TeX (lower E) at the end of each line?

closed as too localized by egreg, mafp, Loop Space, lockstep, diabonas Apr 24 '13 at 11:07

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Works here. i.imgur.com/ItrCPKu.png – topskip Apr 24 '13 at 9:26
  • @topskip could you tell me why I am wrong? – Lucas Li Apr 24 '13 at 9:31
  • No, sorry. You can try to verify your input by writing print(string.format("TeX reads: %q",str)) as the first statement of the function appendSomething() in your Lua file. This will output the buffer on the terminal. – topskip Apr 24 '13 at 9:38
  • what does your log file say? – user2478 Apr 24 '13 at 9:40
  • @Herbert weird, it works in another file. I must have done something wrong. – Lucas Li Apr 24 '13 at 9:50

The codes given above can work well. I get a mistake because the careless redefinition of \lower in the privious part of my tex source file.

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