TeX/ignorespaces
外觀
< TeX
< TeX
\ignorespaces
使 TeX 忽略緊隨其後的輸入中的空格。這通常用於在宏中抑制緊隨其後的空格,就像它是一個沒有引數的宏一樣。但是,由於宏和佔位符呼叫會將輸入視為直接包含這些文字,因此它們也會受到影響。請參閱下面的示例。
隨機地忽略包含一段執行文字的宏中的空格通常不是使用者的預期。另一方面,在宏用於特殊位置的情況下,例如定義圖形或建立 LaTeX 列表或其專案,使用 \ignorespaces 有時很有用,以允許更多空格,以便輸入更具可讀性。
% in macro definition
\def\test#1{(#1)}
\test{a} b % Generate "(a) b" with space
\def\test#1{(#1)\ignorespaces}
\test{a} b % Generate "(a)b" without space (space ignored after a command)
% in macro invocation
\def\test{ a}
(\test)b % Generate "( a)b" with space
(\ignorespaces \test)b % Generate "(a)b" without space
% Placeholder invocations
\def\test#1{(#1)}
\test{ a}b % Generate "( a)b" with space
\def\test#1{(\ignorespaces #1)}
\test{ a}b % Generate "(a)b" without space