2

I was delighted to see that expex does interlinear text in right-to-left languages nearly perfectly. One issue, however, is that the example number is placed in the right margin instead of aligned to the text in the page. I am currently working around this by placing the entire gloss line in a minipage (the commented lines below), but I would like to avoid this if I can so that lines of the gloss can break across pages.

\documentclass{book}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{expex,polyglossia,lipsum}
\setdefaultlanguage[variant=american]{english}
\setotherlanguage[numerals=eastern]{farsi}
\newfontfamily\englishfont[Mapping=tex-text]{Times New Roman}
\newfontfamily\farsifont[Script=arab,Scale=MatchLowercase]{Scheherazade}
\begin{document}
\lipsum[1]
%\begin{minipage}{155mm}
\begin{farsi}
\ex[everyglb=\englishfont] \begingl
\gla این مثال من است// 
\glb in masale man ast //
\glb this example me is //
\endgl\xe
\end{farsi}
%\end{minipage}
\end{document}
2

I was able to get the proper behavior by editing \ex@c and \glw@begingl@a. In both cases I was able to figure out some alternate code appropriate to the RTL context.

My modifications to \ex@c:

   % \llap{\hbox to\leftskip{\unhbox\numbox \hss}}%
   \if@RTL
     \hbox to\leftskip{\unhbox\numbox \hss}%
   \else
     \llap{\hbox to\leftskip{\unhbox\numbox \hss}}%
   \fi

My modifications to \glw@begingl@a:

           % \advance\hsize by -\leftskip
           \if@RTL
              \advance\hsize by -2\leftskip
           \else
              \advance\hsize by -\leftskip
           \fi

The following MWE is unfortunately not very minimal. I illustrate the proper margin alignment for LTR normal examples and glosses (both unchanged), RTL normal examples, RTL glosses, and RTL multi-line glosses.

\documentclass[a4paper]{article}
\usepackage{fullpage,polyglossia,expex,lipsum}
\setdefaultlanguage{english}
\setotherlanguage{farsi}
\setmainfont[Mapping=tex-text]{Charis SIL}
\newfontfamily\englishfont[Mapping=tex-text]{Charis SIL}
\newfontfamily\farsifont[Script=arab,Scale=1.25]{Adobe Arabic}
\begin{document}

\makeatletter
\def\ex@c{%
   \ex@setup
   \leavevmode
   \setbox\numbox=\hbox{\hskip\lingnumoffset\ep@actualexnoprint}%
   \epd@numright=\wd\numbox
   \ifcase\ep@textanchor                          % numleft
         \ep@settosum\leftskip\lingnumoffset\lingtextoffset
      \or                                         % normal
         \ep@settosum\leftskip\epd@numright\lingtextoffset
      \fi
   % begin changes
   % \llap{\hbox to\leftskip{\unhbox\numbox \hss}}%
   \if@RTL
     \hbox to\leftskip{\unhbox\numbox \hss}%
   \else
     \llap{\hbox to\leftskip{\unhbox\numbox \hss}}%
   \fi
   % end changes
   \lingeveryex
   \latex@tagex
   \ignorespaces
}

\def\glw@begingl@a{%
   \bgroup
   \parindent0pt
   \ep@setglstrut
   \ifdim\ling@glwidth=0pt
      \ifling@glossbreaking
         \bgroup
       \else
         \vtop\bgroup
           % begin changes
           % \advance\hsize by -\leftskip
           \if@RTL
              \advance\hsize by -2\leftskip
           \else
              \advance\hsize by -\leftskip
           \fi
           % end changes
            \advance\hsize by -\rightskip
            \leftskip=0pt
       \fi
   \else
      \vtop\bgroup
         \hsize=\ling@glwidth
         \leftskip=0pt
   \fi
   \bgroup
   \parindent=0pt
   \@glpreamblefalse
   \@glftfalse
   \let\mainlist=\empty
   \let\itemtypelist=\empty
   \let\aboveskiplist=\empty
   \let\strutlist=\empty
   \let\everylist=\empty
}
\makeatother

% for seeing the margins:
\hrule

% LTR expex environments are not affected:
\ex Ahmad is asking me for forgiveness. \xe

\ex
\begingl
\gla ahmad az ma ʊzr-xʌ-ji me-kʊn-a //
\glc Ahmad from \textsc{1s} pardon-want-\textsc{nom} \textsc{cont}-do-\textsc{3s} //
\endgl
\xe

\hrule

% proper right margin for RTL languages with simple \ex\xe
\begin{farsi}
\ex
احمد از من عذرخواهی می‌کند.
\xe
\end{farsi}

\hrule

% proper right margin for RTL languages with glosses
\begin{farsi}
\ex 
\begingl
\gla احمد از من عذرخواهی می‌کند. //

\glb \textenglish{ahmad} \textenglish{az} \textenglish{man} \textenglish{ʊzr-xwʌh -i} \textenglish{me-kʊn-ad} //

\glc \textenglish{Ahmad} \textenglish{from} \textenglish{\textsc{1s}} \textenglish{pardon-want-\textsc{nom}} \textenglish{\textsc{cont}-do-\textsc{3s}} //
\endgl
\xe
\end{farsi}

\hrule

% also works for multiline RTL glosses
\begin{farsi}
\ex
\begingl
\gla {محمد} {اشرف} {غنی} {احمدزی،} {رئیس} {جمهور} {افغانستان} {با} {صدور} {فرمانی} {اعلام} {کرد} {که} {تمام} {والیان} {۳۴} {ولایت} {این} {کشور} {بعد} {از} {این} {به} {عنوان} {سرپرست} {به} {کار} {خود} {ادامه} {دهند.} //

\glb \textenglish{mʊhamad} \textenglish{aʃraf} \textenglish{ɣani} \textenglish{ahmadzaj} \textenglish{rajis-ɛ} \textenglish{dʒamhur-ɛ} \textenglish{afɣʌnɛstʌn} \textenglish{bʌ} \textenglish{sʊdur-ɛ} \textenglish{farmʌn-e} \textenglish{ɛlʌm} \textenglish{kard} \textenglish{ke} \textenglish{tamʌm-ɛ} \textenglish{wʌli-jʌn-ɛ} \textenglish{si-o-tʃʌr} \textenglish{wʊlʌjat-ɛ} \textenglish{in} \textenglish{kɛʃwar} \textenglish{bad} \textenglish{az} \textenglish{in} \textenglish{ba} \textenglish{ɛnwʌn-ɛ} \textenglish{sarparast} \textenglish{ba} \textenglish{kʌr-ɛ} \textenglish{xʊd} \textenglish{ɛdʌma} \textenglish{dɛh-and} //

\glc \textenglish{Muhammad} \textenglish{Ashraf} \textenglish{Ghani} \textenglish{Ahmadzai} \textenglish{boss-\textsc{ez}} \textenglish{republic-\textsc{ez}} \textenglish{Afghanistan} \textenglish{with} \textenglish{issuance-\textsc{ez}} \textenglish{command-\textsc{indef}} \textenglish{announcement} \textenglish{do\textsc{.pst}} \textenglish{that} \textenglish{all-\textsc{ez}} \textenglish{governor-\textsc{pl}-\textsc{ez}} \textenglish{thirty-and-four} \textenglish{province-\textsc{ez}} \textenglish{this} \textenglish{country} \textenglish{later} \textenglish{from} \textenglish{this} \textenglish{to} \textenglish{title-\textsc{ez}} \textenglish{supervisor} \textenglish{to} \textenglish{work-\textsc{ez}} \textenglish{own} \textenglish{continue} \textenglish{give-\textsc{3p}} //
\endgl
\xe
\end{farsi}

\hrule

\end{document}
1

It seems like numoffset is the parameter we would want to manipulate in order to keep the number at (but not in) the right margin, but neither positive nor negative values for that make any difference in your MWE.

If you set textoffset to -\textwidth, the number will be aligned with the left margin. Wider labels are handled correctly. However, this breaks expex's line-breaking algorithm, so it's probably not a workable solution, and depending on the language of the main text, you might not want the numbers on the left anyway.

enter image description here

\documentclass{book}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{expex,polyglossia,lipsum}
\lingset{textoffset=-\textwidth}
\usepackage{showframe} % used to show lines at margins
\setdefaultlanguage[variant=american]{english}
\setotherlanguage[numerals=eastern]{farsi}
\newfontfamily\englishfont[Mapping=tex-text]{Times New Roman}
\newfontfamily\farsifont[Script=arab,Scale=MatchLowercase]{Scheherazade}

\begin{document}
\lipsum[1]
\begin{farsi}
    \ex[everyglb=\englishfont] \begingl
    \gla این مثال من است// 
    \glb in masale man ast //
    \glb this example me is //
    \endgl\xe
\end{farsi}

\excnt 99999\relax % to create a wider label
\begin{farsi}
    \ex[everyglb=\englishfont] \begingl
    \gla این مثال من است// 
    \glb in masale man ast //
    \glb this example me is //
    \endgl\xe
\end{farsi}

% long example doesn't break across lines   
\excnt 2\relax
\begin{farsi}
    \ex[everyglb=\englishfont] \begingl
    \gla این مثال من است این مثال من است این مثال من است این مثال من است این مثال من است این مثال من است این مثال من است این مثال من است// 
    \glb in masale man ast in masale man ast in masale man ast in masale man ast in masale man ast in masale man ast in masale man ast //
    \glb this example me is this example me is this example me is this example me is this example me is this example me this example me this example me //
    \endgl\xe
\end{farsi}
\end{document}

I would recommend sending an email to the Ling-TeX list. John Frampton, the package author, responds to expex questions there, but he isn't on this site much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.