From 3931de2b5e46feab4c04b61f83dc38df4545c5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Mon, 21 Jun 2021 16:18:16 +0200 Subject: [PATCH] In LuaTeX, ensure that empty paragraphs are empty --- base/changes.txt | 5 +++++ base/ltpara.dtx | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/base/changes.txt b/base/changes.txt index dfd7a9609..1b502936b 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -6,6 +6,11 @@ completeness or accuracy and it contains some references to files that are not part of the distribution. ================================================================================ +2021-06-21 Marcel Krüger + + * ltpara.dtx: + Don't print effectivly empty paragraphs in RTL contexts in LuaTeX + 2021-06-09 Frank Mittelbach * ltshipout.dtx: diff --git a/base/ltpara.dtx b/base/ltpara.dtx index 5ab52a5e9..978281cb6 100644 --- a/base/ltpara.dtx +++ b/base/ltpara.dtx @@ -14,8 +14,8 @@ %%% From File: ltpara.dtx % % \begin{macrocode} -\def\ltparaversion{v1.0g} -\def\ltparadate{2021/05/27} +\def\ltparaversion{v1.0h} +\def\ltparadate{2021/06/21} % \end{macrocode} %<*driver> \documentclass{l3doc} @@ -714,6 +714,37 @@ % % % +% \begin{macro}{\@@_end_empty_par:} +% For most engines, running \cs{tex_par:D} in an empty paragraph will drop +% the paragraph, but in Lua\TeX\ this sometimes leads to paragraphs which +% contain only direction nodes. Therefore we first make sure that the list +% is really empty when using Lua\TeX. +% \changes{v1.0h}{2021/06/21}{Ensure that empty paragraphs are really empty in Lua\TeX} +% \begin{macrocode} +\sys_if_engine_luatex:TF + { + \newluafunction \g_@@_end_empty_par_id_int + \exp_args:Nx \everyjob { + \exp_not:V \everyjob + \exp_not:N \lua_now:n { + local~texnest, flush_list, par_token = tex.nest, node.flush_list, token.create'tex_par:D'~ + lua.get_functions_table()[\int_use:N \g_@@_end_empty_par_id_int] = function() + local~nest_level = texnest.top~ + local~cur_head = nest_level.head~ + flush_list(cur_head.next) + nest_level.tail, cur_head.next = cur_head, nil~ + token.put_next(par_token) + end + } + } + \protected \luadef \@@_end_empty_par: \g_@@_end_empty_par_id_int + } { + \cs_set_eq:NN \@@_end_empty_par: \tex_par:D + } +% +% +% \end{macrocode} +% \end{macro} % \begin{macro}{\g_@@_standard_everypar_tl} % Whenever \TeX{} starts a paragraph it inserts first an % indentation box and then executes the tokens stored in @@ -746,7 +777,7 @@ % settings will not get lost as we need them for later. % \begin{macrocode} \group_begin: - \tex_par:D + \@@_end_empty_par: \group_end: % \end{macrocode} % We then change \cs{tex_everypar:D} to generate an error so that