科溫頓,以行作為封閉宏的參數

科溫頓,以行作為封閉宏的參數

我需要一些光澤並使用卡溫頓麥地那為此(如果你能解決我的問題另一個包裹我不介意,無論如何,我需要重構解決方案的所有內容)。\gll需要兩行:要註解的文字(Hallo Welt在範例中)和文字的註解(Hello World在範例中)。現在我想要一個自動\autogloss為我寫入第二行的命令。也就是說,\hello{} \world{}兩行通用的指令\gll成為 的第一個參數\autogloss。但是,這無法使用Something's wrong--perhaps a missing \item..

我猜這可能是因為論證沒有擴展,儘管它仍然應該掩蓋它(只是不正確)——而且\expandafter似乎沒有任何作用。

%當我在工作範例的行末尾放置 a 時,我得到了相同的訊息,所以我認為解決方案來自這個問題可能有用,但似乎不起作用(但也許我在那裡做錯了什麼)。

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

輸出

在此輸入影像描述

相關內容