3

I need some glosses and use covington.sty for that (if you can solve my problem with another package I don't mind, I'd need to refactor everything for the solution, anyway). \gll expects two lines: the text to be glossed (Hallo Welt in the example) and the gloss of the text (Hello World in the example). Now I want a command \autogloss that automatically writes the second line for me. That is, the commands \hello{} \world{} that are common to both lines of \gll become the first argument of \autogloss. However, this fails to compile with Something's wrong--perhaps a missing \item..

I guessed it might be because the argument is not expanded, though then it should still have glossed it (just not properly) - and no amount of \expandafter seems to work.

I get the same message when I put a % at the ends of the lines of the working example so I thought the solution from this problem might work, but it doesn't seem to (but maybe I did something wrong there).

\documentclass{article}
\usepackage{etoolbox}
\usepackage{covington}

\newcounter{@language}
\setcounter{@language}{0}
\def\english{\setcounter{@language}{0}}
\def\german{\setcounter{@language}{1}}

\newcommand\hello{\ifnumcomp{\value{@language}}{=}{0}{Hello}{Hallo}}
\newcommand\world{\ifnumcomp{\value{@language}}{=}{0}{World}{Welt}}

\newcommand\autogloss[2]{%
    \gll \german{}#1
    \english{}#1
    \glt `#2'
    \glend
}

\begin{document}
\begin{examples}
\item this one works:
    \gll \german{}\hello{} \world{}
    \english{}\hello{} \world{}
    \glt `Hello World.'
    \glend
\item this one doesn't: % comment next line to compile.
    \autogloss{\hello{} \world{}}{`Hello World.'}
\end{examples}
\end{document}
user66554
  • 327

1 Answers1

5

With gb4e?

\documentclass{article}
\usepackage{etoolbox}
\usepackage{gb4e}

\newcounter{@language}
\setcounter{@language}{0}
\def\english{\setcounter{@language}{0}}
\def\german{\setcounter{@language}{1}}

\newcommand\hello{\ifnumcomp{\value{@language}}{=}{0}{Hello}{Hallo}}
\newcommand\world{\ifnumcomp{\value{@language}}{=}{0}{World}{Welt}}

\newcommand\autogloss[2]{%
    \gll \german{}#1\\
    \english{}#1\\
    \glt `#2'
}

\let\eachwordone=\it

\begin{document}
\begin{exe}
\ex this one works:
    \gll \german{}\hello{} \world{}\\
    \english{}\hello{} \world{}\\
    \glt `Hello World.'
\ex this one does, as well:
    \autogloss{\hello{} \world{}}{Hello World.}
\end{exe}
\end{document} 

Output

enter image description here

karlkoeller
  • 124,410