用奇數個大括號定義指令

用奇數個大括號定義指令

在我的程式碼中,我更改為“2 列”模式,輸入:

\twocolumn[{

我試圖透過建立一個新命令來簡化此程式碼:

\renewcommand{\twocolumn}{\twocolumn[{}

是否可以在這個新指令中插入括號和大括號?我這樣做時遇到很多錯誤。

答案1

序列

\renewcommand{\twocolumn}{\twocolumn[{}

將定義一個命令\twocolumn,除其他外,該命令將調用自身。當遞歸期間累積了太多左括號和左大括號時,您將得到某種遞歸循環,其中編譯可能會終止並出現錯誤訊息TeX capacity exceeded等。

除此之外,這\twocolumn是一個可以在巨集包等中使用的巨集。重新定義它可能會導致(包)代碼出現問題,因為它依賴於\twocolumn.

也許定義您自己的巨集來呼叫\twocolumn 可能是一個選項:

\makeatletter
\newcommand\calltwocolumn{%
  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \romannumeral0\expandafter\@gobble\string} %
}%
\makeatother

該命令\calltwocolumn將產生以下標記:

  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \romannumeral0\expandafter\@gobble\string} %

鏈將在執行 之前\expandafter打開\romannumeral擴展。 - 擴展反過來會導致在終止之前字串化併吞噬右大括號而不傳遞任何令牌。\twocolumn\romannumeral

有些人在使用時不願意\makeatletter。您可以使用以下方法避免這種情況\csname

\newcommand\calltwocolumn{%
  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \romannumeral0\csname @gobble\expandafter\endcsname\string} %
}%

\iffalse您也可以按照 Gustavo Mezzetti 的建議避免使用:

\newcommand\calltwocolumn{%
  \expandafter\twocolumn
  \expandafter[%
  \expandafter{%
  \iffalse}\fi
}%

相關內容