我\newcommand
使用包为我的注释示例制作了一个ExPex
,如下所示:
\newcommand{\exgl}[6]{\ex\label{#1}\begingl\glpreamble \tt #2// \gla #3// \glb #4// \glft #5 // \endgl \begin{flushright}(#6)\end{flushright}\xe}
参数#5
是翻译,有一些例子我不需要翻译。如果我将参数留空,LaTeX 仍会为其留出空间。如果参数为空,我该如何制定删除此空间的命令\newcommand
??
非常高兴 :)
答案1
由于使用包的一些命令expex
我不理解,所以我提供了一些虚拟命令。
相关问题是参数#5
,它可以为空。一种解决方案是使用\ifblank{}
frometoolbox
或可选参数,最好用 定义命令\NewDocumentCommand
。
\documentclass{article}
% A lot of dummy commands
\providecommand{\ex}{}
\providecommand{\xe}{}
\newenvironment{gl}{}{}
\providecommand{\glpreamble}{}%
\providecommand{\gla}[1]{#1}%
\providecommand{\glb}[1]{#1}%
\providecommand{\glft}[1]{\Large\textbf{#1}}%
\usepackage{ragged2e} % For \RaggedRight
\usepackage{etoolbox} % For \ifblank{#5}{true}{false}
\usepackage{xparse}
\newcommand{\exgl}[6]{\ex\label{#1}\begin{gl}\glpreamble \texttt{#2}// \gla{#3}// \glb{#4}//\ifblank{#5}{}{\glft{#5}//} \end{gl}\RaggedRight(#6)\xe}%
\NewDocumentCommand{\exglenhanced}{mmmmom}{\ex\label{#1}\begin{gl}\glpreamble \texttt{#2}// \gla{#3}// \glb{#4}//\IfValueT{#5}{\glft{#5}//} \end{gl}\RaggedRight(#6)\xe}
\begin{document}
\noindent\exgl{foo}{This Is}{Some}{Command}{}{I don't understand}
\exgl{foocmd}{This Is}{Some}{Command}{which}{I don't understand}
Now with \verb+\exglenhanced+ and optional argument:
\exglenhanced{fooother}{This Is}{Some}{Command}{I don't understand}
\exglenhanced{fooothercmd}{This Is}{Some}{Command}[which]{I don't understand}
\end{document}