0

I have a table which I will be generating repeatedly with few variable entries (the number of rows and columns are fixed in the table):

कारक एकवचन बहुवचन
कर्ता театр театры
कर्म театр театры
संबंध театра театров
संप्रदान театре театрых
अधिकरण театре театрых
अपादान театре театрых

The part in Devanagari script will remain fixed and in Cyrillic script will vary. For that, I created a function \gencasetable taking parameters. I am getting error Latex3 error: Too many arguments in argument specification. I also tried using semicolon separated list with \SplitArgument, and I can't seem to get that working either. In the latter case, I am having trouble accessing the "split" arguments.

Here is an example:

\documentclass{book}

\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage[backend=biber,
    style=numeric]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english,russian,hindi]{babel} % last language in the entry is treated as the main language
\usepackage{imakeidx}
\usepackage[log-declarations=true]{xparse}
\usepackage{xcolor}   % Compiler recommended to load package
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{csquotes} % Compiler recommended to load package

\babelfont[hindi]{rm}{Aparajita}
\babelfont[russian]{rm}{Arial}

\NewDocumentCommand{\gencasetable}{m m m m m m m m m m m m m m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of ; separated table entries


    \begin{tabularx} {\linewidth} { c | X | X | }
        \caption{#13}\label{#14}\tabularnewline
        \toprule

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
        \midrule
        \endfirsthead

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
        \midrule
        \endhead

        \multicolumn{3}{r}{\footnotesize{अगले पृष्ट पर जारी}}
        \endfoot

        \bottomrule
        \multicolumn{3}{r}{\footnotesize{इति तालिका~\ref{#14} }} \tabularnewline
        \endlastfoot

        कर्ता & \foreignlanguage{russian}{#1} & \foreignlanguage{russian}{#2}
        \tabularnewline
        \hline
        कर्म  & \foreignlanguage{russian}{#3} & \foreignlanguage{russian}{#4}
        \tabularnewline
        \hline
        संबंध & \foreignlanguage{russian}{#5} & \foreignlanguage{russian}{#6}
        \tabularnewline
        \hline
        संप्रदान        & \foreignlanguage{russian}{#7} & \foreignlanguage{russian}{#8}
        \tabularnewline
        \hline
        अधिकरण           & \foreignlanguage{russian}{#9} & \foreignlanguage{russian}{#10}
        \tabularnewline
        \hline
        करण           & \foreignlanguage{russian}{#11} & \foreignlanguage{russian}{#12}


    \end{tabularx}
}

% Used for tabularx package to put some gap between text and row heights 
\renewcommand{\arraystretch}{1.5}

\title{हिन्दी भाषियों के लिए रूसी अध्यन}

\begin{document}
\gencasetable{театр}{театры}{театр}{театры}{театра}{театров}{театре}{театрых}{театру}{театрам}{театром}{театрами}{\ru{р}-कारांत संज्ञा}{tab:noun-endings-g}

\end{document}

13
  • 4
    unrelated to tables but never use \usepackage[utf8]{inputenc}\usepackage[T1]{fontenc} with xetex. The first detects xetex and issues a warning that it is being ignored, and the second completely breaks xelatex. Commented Jun 9, 2021 at 7:59
  • 3
    tex commands can have at most 9 arguments #1 to #9 so your input can not work Commented Jun 9, 2021 at 8:00
  • So, all your tables will contain a header row and 4 additional table rows with varying contents? If all of your tables are that short, why do you use ltablex and commands like \endfirsthead and \endhead in your table code? I would expect that such a table always fits onto a single page.
    – leandriis
    Commented Jun 9, 2021 at 8:21
  • 1
    Please also keep in mind that horizontal lines from the booktabs pacakge were desigend to be used in tables without vertical lines.
    – leandriis
    Commented Jun 9, 2021 at 8:24
  • 1
    Althoug a bit lenghtier than the input syntax of your non working command, but would you also be satisfied with an input such as the following \begin{table} \caption{caption text}\label{label} \begin{gencasetable} \mytablerow{\first}{1}{2} \mytablerow{\second}{3}{4} \end{gencasetable} \end{table} ? With a custom environment that takes care of the column definitions as well as the header rows and individual commands for each table row with predefined terms for the first cell in each row?
    – leandriis
    Commented Jun 9, 2021 at 9:09

5 Answers 5

1

I do not have the fonts to render the result, but I suggest using something like listofitems to parse the input as a single argument. Here I set the list separator as a space, but you can change that, since it otherwise makes it challenging to put spaces in the input list.

The fact that you say the Devanagari part remains fixed implies a fixed number of rows (which is what I use here). If that is not so, you will somehow have to better explain how that is supposed to work.

p.s. \ru was undefined, so I set \newcommand\ru[1]{#1}.

p.p.s. Other parts of the table (headers and footers) I have no experience with and cannot offer fixes/explanations for those parts.

\documentclass{book}

\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage[backend=biber,
    style=numeric]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english,russian,hindi]{babel} % last language in the entry is treated as the main language
\usepackage{imakeidx}
\usepackage[log-declarations=true]{xparse}
\usepackage{xcolor}   % Compiler recommended to load package
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{csquotes} % Compiler recommended to load package
\usepackage{listofitems}
\babelfont[hindi]{rm}{Aparajita}
\babelfont[russian]{rm}{Arial}

\newcommand\ru[1]{#1}

\NewDocumentCommand{\gencasetable}{m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of ; separated table entries

  \setsepchar{ }%
  \readlist\z{#1}%
    \begin{tabularx} {\linewidth} { c | X | X | }
        \caption{\z[13]}\label{\z[14]}\tabularnewline
        \toprule

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
        \midrule
        \endfirsthead

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
        \midrule
        \endhead

        \multicolumn{3}{r}{\footnotesize{अगले पृष्ट पर जारी}}
        \endfoot

        \bottomrule
        \multicolumn{3}{r}{\footnotesize{इति तालिका~\ref{\z[14]} }} \tabularnewline
        \endlastfoot

        कर्ता & \foreignlanguage{russian}{\z[1]} & \foreignlanguage{russian}{\z[2]}
        \tabularnewline
        \hline
        कर्म  & \foreignlanguage{russian}{\z[3]} & \foreignlanguage{russian}{\z[4]}
        \tabularnewline
        \hline
        संबंध & \foreignlanguage{russian}{\z[5]} & \foreignlanguage{russian}{\z[6]}
        \tabularnewline
        \hline
      संप्रदान  & \foreignlanguage{russian}{\z[7]} & \foreignlanguage{russian}{\z[8]}
        \tabularnewline
        \hline
  अधिकरण   & \foreignlanguage{russian}{\z[9]} & \foreignlanguage{russian}{\z[10]}
        \tabularnewline
        \hline
        करण   & \foreignlanguage{russian}{\z[11]} & \foreignlanguage{russian}{\z[12]}


    \end{tabularx}
}

% Used for tabularx package to put some gap between text and row heights 
\renewcommand{\arraystretch}{1.5}

\title{हिन्दी भाषियों के लिए रूसी अध्यन}

\begin{document}
\gencasetable{%
  театр театры театр театры 
  театра театров театре театрых 
  театру театрам театром театрами 
  \ru{р}-कारांत संज्ञा   tab:noun-endings-g}

\end{document}

enter image description here

For others with the same compilation problem...If I substitute Latin text for the Devanagari and make english the default language, it compiles without a problem:

\documentclass{book}

\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage[backend=biber,
    style=numeric]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[russian,english]{babel} % last language in the entry is treated as the main language
\usepackage{imakeidx}
\usepackage[log-declarations=true]{xparse}
\usepackage{xcolor}   % Compiler recommended to load package
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{csquotes} % Compiler recommended to load package
\usepackage{listofitems}
\babelfont[russian]{rm}{Arial}

\newcommand\ru[1]{#1}

\NewDocumentCommand{\gencasetable}{m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of ; separated table entries

  \setsepchar{ }%
  \readlist\z{#1}%
    \begin{tabularx} {\linewidth} { c | X | X | }
        \caption{\z[13]}\label{\z[14]}\tabularnewline
        \toprule

        \midrule
        \textbf{A} & \textbf{B} & \textbf{C} \tabularnewline
        \midrule
        \endfirsthead

        \midrule
        \textbf{D} & \textbf{E} & \textbf{F} \tabularnewline
        \midrule
        \endhead

        \multicolumn{3}{r}{\footnotesize{G}}
        \endfoot

        \bottomrule
        \multicolumn{3}{r}{\footnotesize{H~\ref{\z[14]} }} \tabularnewline
        \endlastfoot

        I & \foreignlanguage{russian}{\z[1]} & \foreignlanguage{russian}{\z[2]}
        \tabularnewline
        \hline
       J  & \foreignlanguage{russian}{\z[3]} & \foreignlanguage{russian}{\z[4]}
        \tabularnewline
        \hline
       K & \foreignlanguage{russian}{\z[5]} & \foreignlanguage{russian}{\z[6]}
        \tabularnewline
        \hline
      L  & \foreignlanguage{russian}{\z[7]} & \foreignlanguage{russian}{\z[8]}
        \tabularnewline
        \hline
  M  & \foreignlanguage{russian}{\z[9]} & \foreignlanguage{russian}{\z[10]}
        \tabularnewline
        \hline
        N   & \foreignlanguage{russian}{\z[11]} & \foreignlanguage{russian}{\z[12]}


    \end{tabularx}
}

% Used for tabularx package to put some gap between text and row heights 
\renewcommand{\arraystretch}{1.5}

\title{Title}

\begin{document}
\gencasetable{%
  театр театры театр театры 
  театра театров театре театрых 
  театру театрам театром театрами 
  \ru{J}-J   tab:noun-endings-g}

\end{document}

enter image description here

3

The number of parameters in TeX macros are limited to 9, see TeX in a Nutshell, for example.

Your case can be solved as follows:

\def\gencasetable #1#2#3#4#5#6#7#8{%
   \def\gencasetableA{%
        कर्ता & \foreignlanguage{russian}{#1} & \foreignlanguage{russian}{#2}
        \tabularnewline
        \hline
        कर्म  & \foreignlanguage{russian}{#3} & \foreignlanguage{russian}{#4}
        \tabularnewline
        \hline
        संबंध & \foreignlanguage{russian}{#5} & \foreignlanguage{russian}{#6}
        \tabularnewline
        \hline
        संप्रदान        & \foreignlanguage{russian}{#7} & \foreignlanguage{russian}{#8}
        \tabularnewline
        \hline
   }\gencasetableB
}
\def\gencasetableB #1#2#3#4#5#6{%
    \begin{tabularx} {\linewidth} { c | X | X | }
        \caption{#5}\label{#6}\tabularnewline
        \toprule

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
        \midrule
        \endfirsthead

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} \tabularnewline
        \midrule
        \endhead

        \multicolumn{3}{r}{\footnotesize{अगले पृष्ट पर जारी}}
        \endfoot

        \bottomrule
        \multicolumn{3}{r}{\footnotesize{इति तालिका~\ref{#14} }} \tabularnewline
        \endlastfoot

        \gencasetableA
        अधिकरण           & \foreignlanguage{russian}{#1} & \foreignlanguage{russian}{#2}
        \tabularnewline
        \hline
        करण           & \foreignlanguage{russian}{#3} & \foreignlanguage{russian}{#4}


    \end{tabularx}
}
2

TeX only supports 9 arguments #1 to #9 while it is possible to arrange to grab a list of 14 brace groups using some internal helper commands, a command with that many arguments is not a very friendly user interface.

If you group some of them together you need fewer arguments, here I ended up with 8 which is still more than you would want really.

enter image description here

\documentclass{article}

\newcommand\zz[8]{%
\begin{table}[htp]
\centering
\caption{#1\label{#2}}
\begin{tabular}{ccc}
AAA&BBB&CCC\\
\hline
Z1&#3\\
Z2&#4\\
Z3&#5\\
Z4&#6\\
Z5&#7\\
Z6&#8
\end{tabular}
\end{table}}

\begin{document}

\zz{A caption}{tab:zzz}
 {111 & 222}
 {333 & 444}
 {555 & 666}
 {777 & 888}
 {999 & AAA}
 {BBB & CCC}


\end{document}
1

\pgffor package's \foreach command can do loop processing.

If it is done outside the table, creating macros to "drop into" the table, instead of doing its looping inside the table, the table's cells' grouping integrity is maintained.

taalika

Just for illustrative purposes only, to show only one of the possible layout methods for tables, as alluded to in the comments. Less is more. I don't know Hindi (or Russian), so the text part requires proofing.

Looping can also be done in expl3 syntax (using the split and map inline functions).

Unrelated: There is also a biblatex/babel interaction I wasn't able to resolve at this stage.

MWE

\documentclass{book}
\usepackage[table]{xcolor}   
\usepackage{fontspec}
\newfontfamily\fhn{Noto Sans Devanagari}[Scale=0.8,Script=Devanagari]

\usepackage{xparse}
\usepackage{pgffor}

\usepackage[english,russian,hindi]{babel}
\babelprovide[import, onchar=ids fonts]{hindi}
\babelprovide[import, onchar=ids fonts]{russian}
\babelprovide[import, onchar=ids fonts]{english}
\defaultfontfeatures{ Scale=MatchUppercase, Ligatures=TeX, Renderer=HarfBuzz }
\babelfont{rm}{Noto Serif}
\babelfont{sf}{Noto Sans}
\babelfont{tt}{Noto Sans Mono}
\babelfont[hindi]{rm}{Aparajita}

\usepackage{csquotes}

\usepackage{ltablex}
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage{imakeidx}
%\usepackage[style=numeric]{biblatex}


\newcommand\wordcbg{green!10}


\NewDocumentCommand{\gencasetable}{m m m}
{
% First parameter = table caption
% Second parameter = table label
% Third parameter = List of , separated table entries

%populate the 12 numbered variables:
\foreach \x [count=\xi] in {#3}{%
    \expandafter\xdef\csname placeholder\xi\endcsname{\noexpand\textcolor{blue}{\x}}
}

    \begin{tabularx} {\linewidth} { c  X  X  l }
        \caption{#1}\label{#2}\tabularnewline
        \toprule

%        \midrule
        \rowcolor{blue!14}
        \textbf{कारक} & 
        \textbf{एकवचन} & 
        \textbf{बहुवचन} & 
        \ldots \textbf{падеж} 
        \tabularnewline
%        \midrule
         &
        \tiny\ttfamily \parbox{0.5in}{\centering единственное число} &
        \tiny\ttfamily \parbox{0.5in}{\centering множественное число} &
        \tabularnewline
        \toprule
        \endfirsthead

        \midrule
        \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन} & \ldots \textbf{падеж} 
        \tabularnewline
        \midrule
        \endhead

%        \multicolumn{4}{r}{\footnotesize{अगले पृष्ट पर जारी}}
%        \endfoot

        \bottomrule
        \multicolumn{4}{r}{\footnotesize{ \fhn इति तालिका ~\ref{xxx} }}
         \tabularnewline
        \endlastfoot

        कर्ता & %(nom) 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder1\endcsname} & 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder2\endcsname} &
        \texttt{именительный}
        \tabularnewline
        \hline
        
        कर्म  & %(acc): अभियोगात्मक मामला
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder3\endcsname} & 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder4\endcsname} &
        \texttt{винительный}
        \tabularnewline
        \hline
        
        संबंध & %(gen) सम्बन्ध कारक स्थिति
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder5\endcsname} & 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder6\endcsname} &
        \texttt{родительный}
        \tabularnewline
        \hline
        
        संप्रदान        & % (dat) मूल मामला
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder7\endcsname} & 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder8\endcsname} &
        \texttt{дательный}
        \tabularnewline
        \hline
        
        करण           & %  (instr) वाद्य मामला 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder9\endcsname} & 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder10\endcsname} & \texttt{творительный}
        \tabularnewline
        \hline
        
         अधिकरण     & % (loc?) (prep) पूर्वसर्गीय मामला
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder11\endcsname} & 
        \cellcolor{\wordcbg}
        \foreignlanguage{russian}{\csname placeholder12\endcsname} & \texttt{предложный }
        
    \end{tabularx}
    

}

\renewcommand{\arraystretch}{1.5}

\title{हिन्दी भाषियों के लिए रूसी अध्यन}

\begin{document}

\gencasetable{театр}{tab:noun-endings-g}{%
театр, %nom
театры, 
театр, %acc
театры, 
театра, %gen
театров, 
театру, %dat
театрам, 
театром, %instr
театрами,
театре, %prep
театрах}


\end{document}
1

You can have your semicolon separated list. There's no need of ltablex, because such tables should not split across pages.

\documentclass{book}

\usepackage[english,russian,hindi]{babel} % last language in the entry is treated as the main language
\usepackage{fontspec} % Compiler recommended to load package
\usepackage{booktabs} % for \toprule \midrule \bottomrule in tables
\usepackage{capt-of,array}

\babelfont[hindi]{rm}{ITF Devanagari}
\babelfont[russian]{rm}{Old Standard}

\newcommand{\ru}[1]{\foreignlanguage{russian}{#1}} % ???

\ExplSyntaxOn
\NewDocumentCommand{\gencasetable}{m m m}
 {
  % #1 = List of ; separated table entries
  % #2 = table caption
  % #3 = table label
  \group_begin:
  \setlength{\tabcolsep}{0pt}
  \vinay_gencasetable:nnn { #1 } { #2 } { #3 }
  \group_end:
 }

\seq_new:N \l__vinay_gencasetable_items_seq

\cs_new_protected:Nn \__vinay_gencasetable_case:n
 {
  \foreignlanguage{russian}{ \seq_item:Nn \l__vinay_gencasetable_items_seq { #1 } }
 }

\cs_new_protected:Nn \vinay_gencasetable:nnn
 {
  \seq_set_split:Nnn \l__vinay_gencasetable_items_seq { ; } { #1 }
  \begin{tabular}
   {
    w{c}{\dim_eval:n { \linewidth/3 }}
    w{c}{\dim_eval:n { \linewidth/3 }}
    w{c}{\dim_eval:n { \linewidth/3 }}
   }
  \multicolumn{3}{c}{\parbox{\linewidth}{\captionof{table}{#2}\label{#3}}}
  \tabularnewline
  \midrule[\heavyrulewidth]
  \textbf{कारक} & \textbf{एकवचन} & \textbf{बहुवचन}\tabularnewline
  \midrule

  कर्ता     & \__vinay_gencasetable_case:n {1}  & \__vinay_gencasetable_case:n {2}
  \tabularnewline
  कर्म     & \__vinay_gencasetable_case:n {3}  & \__vinay_gencasetable_case:n {4}
  \tabularnewline
  संबं ध   & \__vinay_gencasetable_case:n {5}  & \__vinay_gencasetable_case:n {6}
  \tabularnewline
  संप्रदान   & \__vinay_gencasetable_case:n {7}  & \__vinay_gencasetable_case:n {8}
  \tabularnewline
  अधिकरण & \__vinay_gencasetable_case:n {9}  & \__vinay_gencasetable_case:n {10}
  \tabularnewline
  करण    & \__vinay_gencasetable_case:n {11} & \__vinay_gencasetable_case:n {12}
  \tabularnewline
  \midrule[\heavyrulewidth]
  \multicolumn{3}{r}{\footnotesize इति तालिका~\ref{#3}}
  \end{tabular}
}

\ExplSyntaxOff

% Used for tabularx package to put some gap between text and row heights 
\renewcommand{\arraystretch}{1.5}

\title{हिन्दी भाषियों के लिए रूसी अध्यन}

\begin{document}
\gencasetable{
  театр;театры;
  театр;театры;
  театра;театров;
  театре;театрых;
  театру;театрам;
  театром;театрами
}{\ru{р}-कारांत संज्ञा}{tab:noun-endings-g}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .