Skip to content

spurious enddir node #413

Description

@Udi-Fogiel

This is not a Babel bug, but a LuaTeX one. In some cases using \textdirection/\linedirection in a paragraph may produce a spurious enddir node.

The simplest example is

\textdirection=0
\leavevmode\textdirection=0
\bye

Usually this goes undetectable, but in some cases it can confuse Lua code which inspect direction nodes (such as babel-bidi-basic.lua), or even worse, corrupt LuaTeX's coordinate system during the pdf creation phase. Here is an example using babel with a noticeable effect (note the last "run" on the bottom left corner):

\documentclass{article}
\usepackage[hebrew,english,bidi=basic]{babel}
\begin{document}
run \selectlanguage{hebrew}run \selectlanguage{english}run

run {\selectlanguage{hebrew}run} run \selectlanguage{hebrew}run
\end{document}

It also might affects other packages if babel is used (lua-visual-debug for example).

I'm not sure when it will be fixed, so maybe a workaround should be added? A possible workaround:

\documentclass{article}
\usepackage[hebrew,english,bidi=basic]{babel}
\directlua{
luatexbase.add_to_callback("pre_linebreak_filter",
function(head)
  local stack = 0
  for n, sb in node.traverse_id(node.id('dir'),head) do
    stack = stack + 1-2*sb
    if stack == -1 then
      head, n = node.remove(head,n)
      return head
    end
  end
  return head
end, "Babel.remove_spurious_enddir",0)
}
\begin{document}
run \selectlanguage{hebrew}run \selectlanguage{english}run

run {\selectlanguage{hebrew}run} run \selectlanguage{hebrew}run
\end{document}

This function should be called early.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions