# How to implement luabidi so that I can use luacode in XeLaTeX

I would like to use the following luacode (follow-up from this post):

\usepackage{luacode}
\begin{luacode*}

function replace_punc ( buff )
if string.find ( buff , "\\gla" ) then
buff = string.gsub ( buff , " ()" ,
"\\nogloss{%1} @ " )
buff = string.gsub ( buff, "([:.,;'!?]+)( )" ,
" @ \\nogloss{%1}%2" )

end
return ( buff )
end

luatexbase.add_to_callback ( "process_input_buffer", replace_punc, "replace_punc" )
\end{luacode*}


Its purpose is to automate \nogloss.

It works with LuaLaTeX, but my whole document is set up with polyglossia, which is incompatible with LuaLaTeX. @alanmunn mentioned that the above code could work with XeLaTeX if I use the luabidi package. I have played around with luabidi without success.

I would like the above code to work in XeLaTex with the following MWE:

\documentclass{book}

\usepackage{expex}
\usepackage{polyglossia}
\usepackage{fontenc}
\setdefaultlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{FrankRuehl}
\newfontfamily\englishfont{Linux Libertine O}

\lingset{everygla=\Large,glwordalign=center}

\begin{document}
\begin{hebrew}

\begingl
\gla "שלום {קוראים לי} דוד." //
\glb shalom \textenglish{korim li} david//
\glc Hello \textenglish{my name is} David//
\endgl

\begingl
\gla "מה נשמע דוד?" //
\glb ma nishma david //
\glc what \textenglish{is heard} David //
\endgl

\begingl
\gla "יום טוב!" //
\glb yom tov //
\glc day good //
\endgl

\end{hebrew}
\end{document}

• You've misinterpreted my comment about luabidi. That package is a designed to allow RTL typesetting with LuaTeX; it has nothing to do with allowing lua code to be used in XeTeX (which will not happen). So the question really is "How do I use luabidi as a replacement for the bidi package as loaded with polyglossia so that I can compile RTL documents with LuaTeX". – Alan Munn Jul 31 '17 at 13:34
• You may want to try the technique here: Media button in RTL which shows how to fool polyglossia into using luabidi instead. – Alan Munn Jul 31 '17 at 13:43
• I tried that with no success. That post and yours inspired my current post. – AML Jul 31 '17 at 13:49
• Alright, well between me misinterpreting @alanmunn's luabidi comment and my inability to get @ulrikefischer's code to work, I'm not sure this question is worth keeping around. Feel free to delete. Thanks all for your effort. – AML Aug 1 '17 at 12:05
• You can delete it yourself (there's a delete link next to the edit link for you.) – Alan Munn Aug 1 '17 at 12:38

Your question doesn't make much sense. The luacode will work only in luatex. There is absolutly no chance to get it working with xelatex.

Your document compiles for me with lualatex if I add some code to get \luatexpardir and \luatextextdir (see https://tex.stackexchange.com/a/273303/2388). I also had to change the font.

But I have no idea how good the bidi code works with lualatex as I can't read hebrew.

\directlua{
tex.enableprimitives("luatex",tex.extraprimitives("omega","luatex"))
}

\documentclass{book}

\usepackage{expex}
\usepackage{polyglossia}
\usepackage{fontenc}
\setdefaultlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{EzraSIL}
\newfontfamily\englishfont{Linux Libertine O}

\lingset{everygla=\Large,glwordalign=center}

\begin{document}
\begin{hebrew}

\begingl
\gla "שלום {קוראים לי} דוד." //
\glb shalom \textenglish{korim li} david//
\glc Hello \textenglish{my name is} David//
\endgl

\begingl
\gla "מה נשמע דוד?" //
\glb ma nishma david //
\glc what \textenglish{is heard} David //
\endgl

\begingl
\gla "יום טוב!" //
\glb yom tov //
\glc day good //
\endgl

\end{hebrew}
\end{document}

• Nice answer. What do the first three lines of your code do? – JPi Jul 31 '17 at 13:43
• @JPi They add the luatex prefix to some of the primitive commands (e.g. \textdir) see the linked answer. – Ulrike Fischer Jul 31 '17 at 13:44
• I'm trying to compile your example, but ever since running LuaTeX my system won't compile anything anymore (neither in XeTeX not LuaTeX). Does running LuaTeX do something strange to MiKTeX? This is odd. – AML Jul 31 '17 at 13:57
• Works fine for me in miktex. Compile on a command line to get a better error message. – Ulrike Fischer Jul 31 '17 at 14:00
• @UlrikeFischer It's not clear to me, did you also run the luacode code together with your modification, and did it work for you? – AML Jul 31 '17 at 14:10