
當我定義\newcommand
多行時,我的輸出中出現了不必要的空白。
我如何才能編寫一個長命令,但仍然使其可讀,而不會出現額外的空格?
我目前的解決方案只是在不換行的情況下編寫所有內容,但這不太可持續。
這是這種行為的 MWE:
\documentclass{memoir}
\begin{document}
\newcommand{\lraA}{B}
\newcommand{\lraB}{
%lots of latex logic
%so this command is on multiple lines
B
}
\ \\
A\lraA{}C\\
A\lraB{}C
\end{document}
這會產生:
ABC
ABC
答案1
新行被視為空格。所以在你的程式碼中
\newcommand{\lraB}{ % <-- you are putting a space here!
%lots of latex logic
%so this command is on multiple lines
B % <-- you are putting a space here!
}
如果您想避免虛假空格,您應該以註解字元結束行%
:
\newcommand{\lraB}{% <-- HERE
%lots of latex logic
%so this command is on multiple lines
B% <-- HERE
}