Beamer, philex and \hfill

I'm using the package philex for linguistic examples, and I try to put a textual element at the end of the line (right centered). I tried to use the \hfillcommand, but as the MWE will show you, it does not provide a coherent alignment.

\documentclass[12pt]{beamer}
\usepackage[francais]{babel}
\usepackage{philex}

\begin{document}

\begin{frame}{The syntactic ambiguity}
\lb{}{
\lba{}{Fred eats an apple. \hfill (a)}
\lbz{}{Fred eats an apple. \hfill (a)}
}
\end{frame}

\end{document}


Can someone help me fix this odd behavior?

• \lba{}{Fred eats an apple. \hfill\rlap{\hspace{3ex}(a)}} will get you going until someone can offer a less kludgey answer. – Steven B. Segletes Mar 18 '14 at 15:29
• This is not a beamer issue. I get the same spacing if I use article and delete the frame environment. – cfr Mar 18 '14 at 23:55

You should avoid philex for the reasons egreg gives in his answer. The most commonly used packages for typesetting linguistic examples are gb4e, expex, and linguex (which is loaded by philex). See Alan Munn's excellent comparison of these packages for more details. Many of the features that philex adds to linguex (cross-referencing, repeating examples, label customization, etc.) are available in expex.

All of these packages allow you to have a right-aligned comment. See the answers to Labeling linguistic examples with language information for code that illustrates how to do this in each package. expex is the only one that provide a native command for these right-aligned comments: \rightcomment.

The reason is that the philex package is written in a terrible way and doesn't protect end-of-lines in definitions. The space you see is caused mainly by these unprotected spaces.

See When is it harmful to add percent character at end of lines in a \newcommand, or similar for more information.

They are too many unprotected end-of-lines for proposing a fix; there's also the problem that the macro definitions are very big and don't use modularity.

You can “fix” the issue by using a wild hack; this may however give unexpected results if a space was really needed at some point of a definition.

\documentclass{article}
\usepackage{showframe}

\endlinechar=-1
\usepackage{philex}
\endlinechar=13

\begin{document}

\lb{y}{%
\lba{y1}{Fred eats an apple. \hfill (a)}%
\lbz{y2}{Fred eats an apple. \hfill (a)}%
}

\end{document}


Note that end of lines must be protected also in the input. The showframe package is just for demonstrate the alignment to the margin.

The real fix is not using the package and ask its maintainer to correct the bad code.

Just to show an example, here is the definition of \lb (line numbers added for convenience)

 95 \newcommand{\lb}[3][n]{
96 \ifdim\lastskip=\Extopsep\vspace\Exredux\else \fi
97 \immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2r\endcsname{#3}\expandafter\gdef\csname#2\endcsname{\ref{#2}}
98 \expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}}}
99 \expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
100 \expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
101 \ifhyperref%
102 \renewcommand{\theFnExNo}{\roman{FnExNo}}
103 \ex. \label{#2} \if#1c \setlength{\abovedisplayskip}{1ex}
104 \setlength{\belowdisplayskip}{2ex}%
105 \parbox{\centro}{\centering \hypertarget{#2}{#3}\philpunct}\else \hypertarget{#2}{#3}\philpunct\fi\par
106 \else
107 \ex. \label{#2} \if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}%
108 \parbox{\centro}{\centering #3\philpunct}\else #3\philpunct\fi\par%
109 \fi}


There are missing % at the end of lines 95, 97, 98, 99, 100, 102, and 103. The % at the end of lines 101 and 108 are redundant (the line ends with a control word). The only correctly placed % characters are at the end of lines 104 and 107.

The definition of \lba is similarly flawed.