我正在制作一份多语言文档。在 Steven B. Segletes 先生的大力帮助下,我能够处理多语言混合文档,该文档只能输出所需的一种或多种语言。请参阅主题解析以逗号分隔的命令参数
我还将\mulan
新命令别名为\mulanp
和 ,\mulanr
以便\mulan
当文本由\par
或分隔时可以简化命令/
。
现在我正在定义一个别名命令,使之\mulan
在表中也能工作。(我不知道如何定义可变数字参数命令,所以我只是将参数数量固定为三个)当我编译以下最小示例时,它按预期工作。但是当我在表前注释一个毫无意义的语句时,它会给出一条错误消息,
!Missing \endcsname inserted.
你能帮忙吗?提前谢谢。
%
% Command \mulan usage example
% Compiled by XeLatex
\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Table packages
\usepackage{longtable} %long table across multi pages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \mulan comand defintion to deal with multiple language
\newif\ifen %English
\newif\iffr %French
\newif\ifru %Russian
\newif\ifjp %Japanese
\newif\ifcn %Chinese
\newif\ifkr %Korean
%
\def\en#1{\ifen\callsep #1\fi\langcmd}
\def\fr#1{\iffr\callsep #1\fi\langcmd}
\def\ru#1{\ifru\callsep #1\fi\langcmd}
\def\jp#1{\ifjp\callsep #1\fi\langcmd}
\def\cn#1{\ifcn\callsep #1\fi\langcmd}
\def\kr#1{\ifkr\callsep #1\fi\langcmd}
%specify the multi languge sequence variable globaly
\def\mulanseq#1{\gdef\my@mulanseq{#1}}
%\gdef\my@mulanseq{en,jp,cn}
\newcounter{mulan@args}
%\newcommand\mulan[2][en,jp,cn]{%
\newcommand\mulan[2][en,jp,cn]{%
\gdef\thesep{#2}%
\setcounter{mulan@args}{0}%
\commaparse#1,\relax%
\stepcounter{mulan@args}%
\expandafter\def\csname arg\romannumeral\value{mulan@args}\endcsname{relax}%
\setcounter{mulan@args}{0}%
\langcmd%
}
\def\commaparse#1,#2\relax{%
\stepcounter{mulan@args}%
\expandafter\def\csname arg\romannumeral\value{mulan@args}\endcsname{#1}%
\if\relax#2\else\commaparse#2\relax\fi%
}
\newcommand\langcmd{%
\stepcounter{mulan@args}%
\csname\csname arg\romannumeral\value{mulan@args}\endcsname\endcsname%
}
\newcommand\callsep{\ifnum\value{mulan@args}>1\thesep\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Convient alias command for \mulan
\def\mulanp{\expandafter\mulan{\par}}
\def\mulanr{\expandafter\mulan{ \space {\textbf{/}}\space}}
% multiline in tab cell !!! problem yet !!!
\newcommand\mulanT[4][l]{
\begin{tabular}{#1}
\mulan{\\}{#2}{#3}{#4} %
\end{tabular}
}
%
\newcommand\mulanTL{\mulanT[l]}
\newcommand\mulanTC{\mulanT[c]}
\newcommand\mulanTR{\mulanT[r]}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%---------------------
\entrue \jptrue \cntrue
%%%---------This command has not been finished yet------
%\mulanseq{en,jp,cn}
\title{\mulanp{English Document}{Japanese Document}{Chinese Document}}
\author{\mulanr{English name}{Japanese name}{Chinese name}}
\maketitle
\tableofcontents
\abstract
\section{\mulanr{English title}{Japanese title}{Chinese title}}
%%% !!! if the following statement is commented, there will be an error occured.
%\mulan{}{}{}{} % I just make it do nothing
\begin{longtable}{ccc}
\hline
\mulanT{English item}{Japanese item}{Chinese item} & Price(USD) & \mulanT{Englishi-Repark}{Japanese-Repark}{Chinese-Remark}\\
\hline
\mulanT{IamEnglish}{IamJapanese}{IamChinese} & 15.0 & \mulanT{This is remark in English and is very long.}{This is remark in Japanese and is very long.}{This is remark in Chinese and is very long.} \\
\hline
\end{longtable}
\end{document}
答案1
你的命令的编码\mulan
有点奇怪,我不确定它的目的是什么,所以我不会建议改变,但评论具有误导性:
\mulan{}{}{}{} % I just make it do nothing
它不做任何事情。该命令定义了几个命令,特别是\argiii
,您收到的错误是由于该命令未定义(或更准确地说,它被定义为\relax
)
! Missing \endcsname inserted.
<to be read again>
\argiii
^^^^^^^
l.96 ...English item}{Japanese item}{Chinese item}