[luatex] Adding a callback before trailing spaces are removed from a line of input

Eduardo Ochs eduardoochs at gmail.com
Sun Aug 29 23:40:46 CEST 2021

On Sun, 29 Aug 2021 at 16:42, Vítek Novotný <witiko at mail.muni.cz> wrote:

> Dear Eduardo,
> ah, light begins to shine! I suppose you could register a
> process_line_buffer callback, which would `return ""` until it has
> matched "End of block" or until it has been called five times, at which
> point it would unregister itself.
Hi Vitek,

I've just uploaded the second prototype to github - in this one when
we call Foo with a second arguments, like this,

  \directlua{Foo("End of block", "skip")}

it skips the lines that are fake Markdown by making
"process_input_buffer" return "%". It is here,


and its test.tex file is just this, plus comments:



\directlua{dofile "minimalcore.lua"}

%L skiplinesuntil_ = 0
%L skiplinesuntil  = function (li)
%L     if tex.inputlineno <= skiplinesuntil_ then
%L       return "%"
%L     end
%L     return li
%L   end
%L luatexbase.add_to_callback("process_input_buffer",
%L    skiplinesuntil, "skiplinesuntil")
%L findlinewithre = function (firstline, re)
%L     for i=firstline,1000000 do
%L       if texlines[i] == nil then error("re not found") end
%L       if texlines[i]:match(re) then return i end
%L     end
%L   end
%L printlines = function (i, j)
%L     print("\n\n")
%L     for k=i,j do print(k..":", '"'..texlines[k]..'"') end
%L     print("\n\n")
%L   end
%L Foo = function (re, skip)
%L     local outerbeg = tex.inputlineno
%L     local innerbeg = outerbeg + 1
%L     local innerend = findlinewithre(innerbeg, re) - 1
%L     local outerend = innerend + 1
%L     printlines(innerbeg, innerend)
%L     if skip then skiplinesuntil_ = outerend end
%L   end

(Test 1)
\directlua{Foo("End of block")}%
End of block
(without skip, with \%)

(Test 2)
\directlua{Foo("End of block", "skip")}%
End of block
(with skip, with \%)

(Test 3)
\directlua{Foo("End of block", "skip")}
End of block
(with skip, without \%)



When we don't add a "%" after the \directlua line then a strange space
appears, and I don't know why. I also don't know how to handle in an
elegant way the cases in which we have a main .tex file that "\input"s
other .tex files that also have blocks of "%L" lines and blocks of
fake Markdown code... in Dednat6 I handle this by using this quick
hack in each of my sub-.tex files:


If you have any ideas for solving this, please let me know!

    Eduardo Ochs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/luatex/attachments/20210829/7d47a9e2/attachment-0001.html>

More information about the luatex mailing list.