囲むマクロの引数として行を持つコビントン

囲むマクロの引数として行を持つコビントン

グロスが必要なのでコビントンそのために(私の問題を解決できるなら別のパッケージ気にしません。いずれにせよ、ソリューションのためにすべてをリファクタリングする必要があるからです)。 は\gll、注釈を付けるテキスト (Hallo Welt例では ) とテキストの注釈 (Hello World例では ) の 2 行を想定しています。ここで、2 行目を自動的に書き込むコマンドが必要です。つまり、の両方の行に共通する\autoglossコマンドがの最初の引数になります。ただし、 ではコンパイルできません。\hello{} \world{}\gll\autoglossSomething's wrong--perhaps a missing \item.

議論が展開されていないからかもしれないと私は推測しましたが、それでも(適切ではないだけで)解説されているはずですが、いくら説明しても\expandafter効果がないようです。

%動作例の行末にを付けると同じメッセージが表示されるので、解決策はこの問題動作するかもしれないが、動作しないようだ(ただし、何か間違ったことをしたかもしれない)。

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

答え1

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} 

出力

ここに画像の説明を入力してください

関連情報