我的新命令前出现大空格

我的新命令前出现大空格

我创建了这个代码,希望它能让注释变得容易得多,第一个输入决定了音标、音素阅读、语音阅读和注释的顺序,并使用输入以我想要的顺序和格式生成文本注释。编译时,生成的 pdf 在注释前的文本和命令生成的注释之间插入了一个很大的空格。我根据一个执行批量替换的代码编写了这段代码,就像 egreg 的漂亮代码回答一样:如何进行多个字符串替换?。我遗漏了什么会导致这么大的差距吗?

\documentclass[a4paper]{article}
\usepackage{xstring}
\usepackage{tipa}

\newcommand{\glossstep}[2]{
\expandafter\StrSubstitute\expandafter{\x}{#1}{#2}[\x]}

\newcommand{\totalgloss}[5][T P A Q]{
\noexpandarg
\StrSubstitute{#1}{T}{\textit{#2}}[\x]
\glossstep{P}{/\textipa{#3}/}
\glossstep{A}{[\textipa{#4}]}
\glossstep{G}{#5}
\glossstep{Q}{`#5'}
\glossstep{S}{\textsc{#5}}
\x}

\begin{document}

. . . the plural form is \totalgloss[T A Q]{sargata}{sar\;Gan+ta}{sar\;Gata}{wives} which as you can see is . . . 

\end{document}

答案1

查找here! 定义主体中的每个结束行都贡献一个空格。 之后没有空格\noexpandarg

\newcommand{\glossstep}[2]{% <--- here
\expandafter\StrSubstitute\expandafter{\x}{#1}{#2}[\x]}

\newcommand{\totalgloss}[5][T P A Q]{% <--- here
\noexpandarg
\StrSubstitute{#1}{T}{\textit{#2}}[\x]% <--- here
\glossstep{P}{/\textipa{#3}/}% <--- here
\glossstep{A}{[\textipa{#4}]}% <--- here
\glossstep{G}{#5}% <--- here
\glossstep{Q}{`#5'}% <--- here
\glossstep{S}{\textsc{#5}}% <--- here
\x}

相关内容