我正在尝试让 lingmacros gloss 自动知道它需要生成的列数。基本上,对于 \shortex 命令,输入之一是要生成的列数。这相当于实际注释文本中“&”出现的次数加一。我见过一种从中获取字符串出现次数的方法这个帖子,但是当我尝试为其创建宏时,它给出了“未检测到数字”错误。这是基本代码:
\documentclass{article}
\usepackage{xparse}
\usepackage{expl3}
\usepackage{lingmacros}
\ExplSyntaxOn
\NewDocumentCommand{\CountSubStr}{ m m }{%
\seq_set_split:Nnn \l_tmpa_seq { #1 } { #2 }%
\int_eval:n {(\seq_count:N \l_tmpa_seq)}%
}
\ExplSyntaxOff
% \CountSubStr{<substring>}{<string>}
\newcommand{\glossthis}[3]{%
\shortex{\CountSubStr{&}{#1}}
{#1}{#2}{#3}}
\begin{document}
\enumsentence{\glossthis%
{?& \.{I}ki & karde\c{s}-im & var. & Hi\c{c}-biri & kitap & oku-mu-yor-0.}
{& two & sibling-\textsc{1.sg} & have. & no-one & book & read-\textsc{neg}-\textsc{imperf}-\textsc{agr}.}
{`I have two siblings. None of them have read the book.'}}
\end{document}
我认为改变这种情况的最简单方法是修改 \CountSubStr 命令,使其输出实际数字而不是字符串。这是真的吗?我该如何解决这个问题?
答案1
您可以重新实现计数\glossthis
:
\documentclass{article}
\usepackage{xparse}
\usepackage{expl3}
\usepackage{lingmacros}
\ExplSyntaxOn
\newcommand{\glossthis}[3]{%
\seq_set_split:Nnn \l_tmpa_seq {&} {#1}
\shortex{\seq_count:N \l_tmpa_seq}{#1}{#2}{#3}
}
\ExplSyntaxOff
\begin{document}
\enumsentence{\glossthis%
{?& \.{I}ki & karde\c{s}-im & var. & Hi\c{c}-biri & kitap & oku-mu-yor-0.}
{& two & sibling-\textsc{1.sg} & have. & no-one & book & read-\textsc{neg}-\textsc{imperf}-\textsc{agr}.}
{`I have two siblings. None of them have read the book.'}}
\end{document}
\shortex
扩展为\begin{tabular}[t]{@{}*{#1}{l@{\ }}} ... \end{tabular}
。由于\CountSubSeq
除了扩展为数字之外还做了其他事情,因此它在那里不起作用。