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

Marcel Fabian Krüger tex at 2krueger.de
Wed Sep 30 17:40:51 CEST 2020


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

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

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

    Lua callback for shipout


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

cc14752190ba14a4c1d609dc278928c83e206b09
 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 8f0422c8..d7a0b525 100644
--- a/base/ltshipout.dtx
+++ b/base/ltshipout.dtx
@@ -279,6 +279,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}
 %
 %
@@ -542,6 +556,33 @@
 %
 %
 %
+%  \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
@@ -724,6 +765,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.