如何在 LaTeX 中進行條件格式化?

如何在 LaTeX 中進行條件格式化?

我有興趣格式化以下程式碼,以便如果滿足條件(Add = 0 和 Del = 0),那麼我的文件會列印「沒有新增或刪除」。否則,文件將列印出包含 Add 和 Del 值的項目符號清單。

AddName = 0
DelName = 0
cat("\\newcommand{\\Add}{",AddName,"}",sep="")
cat("\\newcommand{\\Delete}{",DelName,"}",sep="")

\if <\Add = 0 AND \Del = 0> 
  <\normal{There are no additions or deletions.}>
\fi

\begin{compactitem}
    \item[$\bullet$ \Add { } {\color{OliveGreen}\bf{+}}:]
    \item[$\bullet$ \Del { } {\color{red}\bf{-}}:]
\end{compactitem}

我在網上找不到太多文檔,以下是我收到的錯誤訊息:

> \if <\Add = 0 AND \Del = 0> 
Error: unexpected input in "\"
>   <\normal{There are no additions or deletions.}>
Error: unexpected '<' in "  <"
> \fi
Error: unexpected input in "\"

> \begin{compactitem}
Error: unexpected input in "\"
> \item[$\bullet$ \Add { } {\color{OliveGreen}\bf{+}}:]
Error: unexpected input in "\"
> \item[$\bullet$ \Del { } {\color{red}\bf{-}}:]
Error: unexpected input in "\"
> \end{compactitem}
Error: unexpected input in "\"

有人可以幫我調試這些錯誤嗎?

相關內容