1

I am trying to make lingmacros gloss automatically be aware of the number of columns it will need to produce. Basically, for the \shortex command, one of the inputs is the number of columns you want to produce. This is equivalent to the number of times that "&" appears in the actual gloss text plus one. I've seen a way to get the number of occurrences of a string from this post, but when I try to make a macro for it, it gives me a "no number detected" error. Here is the basic code:

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

I imagine the easiest way to change this is to modify the \CountSubStr command so that it outputs an actual number, rather than a string. Is this true? And how do I fix this issue?

Jackirab
  • 145
  • Why are you subtracting 1 from the count and then stepping another counter? Why not just use the count without decreasing it, passing it to something else and then increasing it back to its original value? You've forgotten \documentclass by the way. – cfr Oct 13 '19 at 01:03
  • Fixed those two issues! Any suggestions as to how to fix the "no number detected" error? – Jackirab Oct 13 '19 at 14:40

1 Answers1

2

You can reimplement the counting in \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 expands to \begin{tabular}[t]{@{}*{#1}{l@{\ }}} ... \end{tabular}. Since \CountSubSeq did other things besides just expanding to a number, it would not work there.