0

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}
AML
  • 2,265
  • 1
    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 01 '17 at 12:05
  • You can delete it yourself (there's a delete link next to the edit link for you.) – Alan Munn Aug 01 '17 at 12:38

1 Answers1

3

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}
Ulrike Fischer
  • 327,261
  • Nice answer. What do the first three lines of your code do? – JPi Jul 31 '17 at 13:43
  • 1
    @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
  • I did run exactly the code I show in my question. I now added the luacode, it doesn't give error but I can't say if it works or not as I have no idea what it should do in this left-right-mix. Before trying to inject callbacks you should better test if expex handles the languages, spaces, directions etc correctly when you use the commands directly. – Ulrike Fischer Jul 31 '17 at 14:34
  • @AML The lua code does work with this example, but with two caveats. First, if you want to replace the " characters you need to escape them with a backslash in the lua code. Second \nogloss doesn't seem to respect the language/font choice, so that may need to be adjusted too in the code. – Alan Munn Jul 31 '17 at 14:39
  • @UlrikeFischer would you kindly post images of your output before and after the \nogloss so that I can tell you if the Hebrew looks good? I'm having problems getting this to work on my end. – AML Jul 31 '17 at 15:17
  • @AML no, the Hebrew is not correct here (rendered LTR). – Alan Munn Jul 31 '17 at 15:44