3

This is a follow-up to this answer and comment. Does anyone have an idea how to automate the \nogloss macro so that I don't have to label every punctuation mark (or at least ! ? " , .) with it?

EDIT: Thanks to @Alan Munn, I now realize that I'm looking for a XeTeX-compatible solution.

MWE:

\documentclass{book}        
\usepackage{expex}    
\lingset{glwordalign=center}

\begin{document}    
\exdisplay
\begingl
  \gla \nogloss{``} @ aaaaa aaaaaaa @ \nogloss{!''} aaaa aaaa aaaa @ \nogloss{\ldots} //      
  \glb bbbbb bbbbbbb bbbb bbbb bbbb //      
  \glc ccccc ccccccc cccc cccc cccc //      
\endgl
\xe    
\end{document}

EDIT: To clarify, I want my input to be like the MWE below but for the automation to yield the MWE above, or at least the output of what the above code would yield.

\documentclass{book}        
\usepackage{expex}    
\lingset{glwordalign=center}

\begin{document}    
\exdisplay
\begingl
  \gla "aaaaa aaaaaaa!" aaaa aaaa aaaa... //      
  \glb bbbbb bbbbbbb bbbb bbbb bbbb //      
  \glc ccccc ccccccc cccc cccc cccc //      
\endgl
\xe    
\end{document}
AML
  • 2,265

1 Answers1

4

Using the technique explained in Mico's answer here:

We can do the same thing for your cases. This requires compilation with LuaLaTeX.

Note: This answer was added before we discovered that a XeLaTeX solution was required, but I will leave it here since many (but not all) XeLaTeX documents can be compiled with LuaLaTeX as well.

This is lightly tested. The function checks for opening quotes and trailing punctuation followed by a space, so it should work as intended if your input looks like that. For example, it won't include word internal punctuation marks like a colon marking vowel length.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{expex}
\lingset{glwordalign=center}

\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*}


\begin{document}    
\exdisplay
\begingl
  \gla ``aaaaa aaaaaaa!?:!'' aaaa aaaa aaaa. //      
  \glb a bbbbbbb bbbb bbbb bbbb //      
  \glc ccccc ccccccc cccc cccc cccc //      
\endgl
\xe    

\end{document}

output of code

Alan Munn
  • 218,180
  • This does indeed work (in LuaLaTex). The only problem is that I use a XeLaTex environment. Is there a fix for that? I didn't realize that would be an issue when I first posed the question. – AML Jul 29 '17 at 00:04
  • This is a LuaTeX only solution, I'm afraid. But for most things, any document that compiles with XeLaTeX will also compile with LuaLaTeX without any changes, unless your're using XeTeX specific stuff (e.g. xeCJK for Chinese). – Alan Munn Jul 29 '17 at 00:10
  • I do seem to be using XeTeX specific stuff. Should I post this same question again but make it XeTeX specific, or can you edit your answer to give a XeTex solution as well? – AML Jul 29 '17 at 00:24
  • No, there's no way to do what I did with any other TeX engine. This is using Lua to preprocess the document before TeX even sees it, which only LuaTeX can do. Are you sure that you are using XeTeX specific code in your documents? Most normal XeLaTeX documents won't use it. If you take one of your existing documents and compile it with LuaLaTeX, what happens? As for asking another question, I don't think there's much sense in that. You're welcome to "unaccept" this answer for a while to see if another kind of solution is possible, although I'm skeptical of that. – Alan Munn Jul 29 '17 at 00:32
  • When I compile my document with LuaLaTex, it fails. The packages I'm using are microtype, geometry, expex, polyglossia with Hebrew script, fontenc, ifoddpage. I'm unclear which of those are XeLaTeX-only. I think maybe the fontenc. – AML Jul 29 '17 at 00:46
  • Ok, the problem is bidi which is loaded by polyglossia for RTL language support. This is XeTeX only. There is a luabidi on CTAN, but I don't know much about that; I think it's pretty rudimentary. RTL language support in LuaTeX lags behind XeTeX in this respect, unfortunately. One thing you could do would be to preprocess your TeX files with a script (which is basically what the Lua code is doing). Not as convenient, but doable. You might even be able to automate the process with arara (an automation tool for compiling). – Alan Munn Jul 29 '17 at 00:59
  • I have changed the title and noted in the body that I'd like a XeTeX-compatible solution. Hopefully that will generate other responses. Perhaps there is a solution with xesearch. – AML Jul 29 '17 at 02:09