[latex3-commits] [git/LaTeX3-latex3-latex2e] pre_shipout: Lua callback for shipout (294ad649)

Marcel Fabian Krüger tex at 2krueger.de
Fri Jan 22 14:00:51 CET 2021


Repository : https://github.com/latex3/latex2e
On branch  : pre_shipout
Link       : https://github.com/latex3/latex2e/commit/294ad6497cf215213cff4e76cbfd7cf2d2da2e73

>---------------------------------------------------------------

commit 294ad6497cf215213cff4e76cbfd7cf2d2da2e73
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Wed Sep 30 17:40:51 2020 +0200

    Lua callback for shipout


>---------------------------------------------------------------

294ad6497cf215213cff4e76cbfd7cf2d2da2e73
 base/ltshipout.dtx                   | 42 ++++++++++++++++++++++++++++++++++++
 base/testfiles/tlb-callbacks-001.lvt |  2 ++
 2 files changed, 44 insertions(+)

diff --git a/base/ltshipout.dtx b/base/ltshipout.dtx
index 4032caf6..7ef1de17 100644
--- a/base/ltshipout.dtx
+++ b/base/ltshipout.dtx
@@ -363,6 +363,20 @@
 %    names as given below.
 %
 %
+%
+% \subsection{Provided Lua\Tex\ callbacks}
+% 
+%  \begin{variable}{pre_shipout_filter}
+%    Under Lua\TeX, additionally the \texttt{pre_shipout_filter} callback is
+%    provided. The signature is
+%    \begin{verbatim}
+%     function(<node> head)
+%       return true | false | <node> newhead
+%     end
+%    \end{verbatim}
+%    This callback is invoked after all \TeX-level hooks described above.
+%  \end{variable}
+%
 % \subsection{Information counters}
 %
 %
@@ -691,6 +705,33 @@
 %  \end{macro}
 %
 %
+%  \begin{macro}{\@@_finalize_box:}
+%    For Lua\TeX{} invoke the \texttt{pre\_shipout\_filter} callback.
+%    \begin{macrocode}
+\sys_if_engine_luatex:TF
+  {
+    \newluafunction \@@_finalize_box:
+    \exp_args:Nx \everyjob {
+      \exp_not:V \everyjob
+      \exp_not:N \lua_now:n {
+        luatexbase.create_callback('pre_shipout_filter', 'list')
+        local~call, getbox, setbox = luatexbase.call_callback, tex.getbox, tex.setbox~
+        lua.get_functions_table()[\the \@@_finalize_box:] = function()
+          local~result = call('pre_shipout_filter', getbox(\the \l_shipout_box))
+          if~not (result == true) then~
+            setbox(\the \l_shipout_box, result~or~nil)
+          end~
+        end
+      }
+    }
+    \protected \luadef \@@_finalize_box: \the \@@_finalize_box:
+  } {
+    \cs_set_eq:NN \@@_finalize_box: \scan_stop:
+  }
+%    \end{macrocode}
+%  \end{macro}
+%
+%
 %  \begin{macro}{\@@_execute:}
 %    This is going to the be the code run by \cs{shipout}. The code
 %    follows closely the  ideas from \pkg{atbegshi}, so not
@@ -941,6 +982,7 @@
                     }
                     \bool_gset_true:N \g_@@_lastpage_handled_bool
                 }
+              \@@_finalize_box:
 %    \end{macrocode}
 %    Finally we run the actual \TeX{} primitive for shipout. As that will
 %    expand delayed \cs{write} statements inside the page in which
diff --git a/base/testfiles/tlb-callbacks-001.lvt b/base/testfiles/tlb-callbacks-001.lvt
index f96e1a9b..d4fbf5a2 100644
--- a/base/testfiles/tlb-callbacks-001.lvt
+++ b/base/testfiles/tlb-callbacks-001.lvt
@@ -15,6 +15,8 @@
 % current ltluatex user-callbacks
  expected_user_callbacks['pre_mlist_to_hlist_filter']=1
  expected_user_callbacks['post_mlist_to_hlist_filter']=1
+%
+ expected_user_callbacks['pre_shipout_filter']=1
 % curent luaotfload user-callbacks
  expected_user_callbacks['luaotfload.patch_font_unsafe']=1
  expected_user_callbacks['luaotfload.resolve_font']=1





More information about the latex3-commits mailing list.