我喜欢缩进代码以提高可读性(谁不喜欢呢?)。但这似乎会干扰 LaTeX(LaTeX 认为缩进就是空格):
如何缩进代码而不添加不需要的空格?
\documentclass{article}
\usepackage{lipsum}
\usepackage{xparse}
\makeatletter
\NewDocumentCommand{\ImUnreadible}{ss+m+m}{\IfBooleanTF{#1}{\IfBooleanTF{#2}{#4}{#3}}{Let me check...}}
\NewDocumentCommand{\ImReadable}{ss+m+m}{
\IfBooleanTF{#1}{%
\IfBooleanTF{#2}{%
%% We force the display of the big text
#4
}{% We force the display of the small text
#3
}
}{%
Let me check...
}
}
\makeatother
\begin{document}
\noindent A\ImUnreadible*{Short}{Long}B.\\
A\ImReadable*{Short}{Long}B.\\
\end{document}
答案1
不是缩进导致额外的空格,而是行尾的尾随空格导致的。为了避免这种情况,请用 结束宏定义行%
(例外:如果一行代码以控制序列结尾,则%
不需要尾随)。
\documentclass{article}
\usepackage{lipsum}
\usepackage{xparse}
\makeatletter
\NewDocumentCommand{\ImUnreadible}{ss+m+m}{\IfBooleanTF{#1}{\IfBooleanTF{#2}{#4}{#3}}{Let me check...}}
\NewDocumentCommand{\ImReadable}{ss+m+m}{%
\IfBooleanTF{#1}{%
\IfBooleanTF{#2}{%
%% We force the display of the big text
#4%
}{% We force the display of the small text
#3%
}%
}{%
Let me check...%
}%
}
\makeatother
\begin{document}
\noindent A\ImUnreadible*{Short}{Long}B.\\
A\ImReadable*{Short}{Long}B.\\
\end{document}