別名 ( 到 \begin{pmatrix}?

別名 ( 到 \begin{pmatrix}?

我想知道是否有任何方法可以將()按鈕別名為\begin{pmatrix}\end{pmatrix},這樣當我在數學模式下鍵入這些字元時,LaTeX 就會神奇地用正確的命令替換它們。

據我所知,沒有理由使用“啞”版本,這會節省我很多時間。這可能嗎?

我其實並不是問如何重新定義(.我要求 LaTeX 將(數學模式中的所有 s 替換為\begin{pmatrix}.

答案1

編輯

我看到的原始問題要求\( ... \)擴展到,\begin{pmatrix} ... \end{pmatrix}但事實上,OP 希望( ... )自動擴展到\begin{pmatrix} ... \end{pmatrix}.我投票關閉這個,因為它是重複的自動向左和向右命令(請參閱LSpice的回答),然後問題被關閉並重新開啟。所以,我重新回答。

做OP想要的事情的訣竅是創造()活躍角色。完成此操作後,可以隨意重新定義它們:

\documentclass{amsart}

\let\lparen=(\let\rparen=)           % save parentheses
\catcode`(=\active\catcode`)=\active % make them active
\def({\begin{pmatrix}}               % redefine them
\def){\end{pmatrix}}

\begin{document}

  \[    ( 1 & 0  & 1 \\ 0 & 1 & 0\\ 0 & 0 & 1 ) \]

\end{document}

使用此代碼,如果您想輸入(or ,)則需要使用\lparenand \rparen。這很可能會產生奇怪且不那麼美妙的副作用。

稍微好一點的方法是定義一個環境,(​​並)擴展以給出pmatrix它們在該環境之外的正常行為。在環境中重新定義catcodes需要更多的體操(參見如何更改環境定義中的目錄程式碼?):

\documentclass{amsart}

\let\lparen=(\let\rparen=)% save parentheses

\catcode`(=\active\catcode`)=\active% change catcode for newenvironment
\newenvironment{pequation}{%
  \catcode`(=\active\catcode`)=\active% make them active in environment
  \def({\begin{pmatrix}}% redefine them
  \def){\end{pmatrix}}%
  \equation%
}{\endequation}
\catcode`(=12\catcode`)=12% restore to original catcodes

\begin{document}

  \begin{pequation}
   ( 1 & 0  & 1 \\ 0 & 1 & 0\\ 0 & 0 & 1 )
  \end{pequation}

  $\sin(x)$
\end{document}

原答案

你可以這樣做,如果你真的想要,但正如評論所示,大多數人建議不要這樣做。主要問題是,預設情況下,LaTeX 用於\( ... \)排版數學,因此它(幾乎)相當於$ ... $--- 事實上,透過對於數學模式來說,\( 和 \) 比美元符號好嗎?\(...\)提供更好的錯誤訊息。這個\(...\)指令與 LaTeX 鼓勵我們使用 排版顯示方程式的方式相反\[ ... \]。注意\[ ... \]不是相當於$$ ... $$!看為什麼 \[ ... \] 優於 $$ ... $$?

\renewcommand也就是說,您可以使用(或)覆寫任何指令的定義\def。覆蓋命令的定義應該小心,因為這樣做可能會破壞其他東西。

除了這些注意事項之外,以下內容可以滿足您的要求:

\documentclass{amsart}

\renewcommand\({\begin{pmatrix}}
\renewcommand\){\end{pmatrix}}

\begin{document}

Here is a wonderful matrix
\[    \( 1 & 0 & 1 \\ 0 & 1 & 0\\ 0 & 0 & 1\) \]

\end{document}

可能會產生意想不到的後果,但我認為這應該沒問題,儘管它很可能會讓你的合著者感到困惑!在我看來,更好的方法是正確配置你的編輯器:)

[我必須承認,我曾經重新定義\(\bigl(\)\bigr),所以我對上面的道德陳述有可疑的理由,認為你不應該這樣做! ] ]

相關內容