[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,

  https://github.com/edrx/markdown-dednat6/

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

--snip--snip--

\documentclass{article}
\begin{document}

\catcode`\^^J=10
\directlua{dofile "minimalcore.lua"}
\directlua{texfile0(status.filename)}
\def\pu{\directlua{pu()}}

%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
%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
%L
\pu

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

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

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

\end{document}

--snip--snip--


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:

  http://angg.twu.net/LATEX/dednat6/block.lua.html#tf_push_and_tf_pop

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

  Cheers,
    Eduardo Ochs
    http://angg.twu.net/dednat6.html
    http://angg.twu.net/math-b.html
-------------- 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.