嵌套兩個環境時出錯;嘗試重新定義 \begin{equation*} 和 \begin{spit};命令已經定義了嗎?

嵌套兩個環境時出錯;嘗試重新定義 \begin{equation*} 和 \begin{spit};命令已經定義了嗎?

我試著將 \begin{equation*} 和 \begin{split} 組合成一個縮寫的東西。而不是這樣做:

\begin{equation*}
\begin{split}
      a = b & = b \\ & = b
\end{split}
\end{equation*}

我想創建一些如下:

    \fff a = b & = b \\ & = b 
    \endfff

我正在嘗試使用 \newenvironment 和 \newcommand 但它工作得不好。

\newenvironment{placeholdername}
{\begin{equation*}
\begin{split}
}
{ 
\end{split} 
\end{equation*}
}

\newcommand{\fff}{\begin{placeholdername}}
\newcommand{\endfff}{\end{placeholdername}}

請原諒我糟糕的命名方案。我還收到一個錯誤“命令 \endfff 已定義”,這對我來說毫無意義。順便說一句,我是 LaTeX 新手。請幫忙!

答案1

你可以做到,但我不認為它真的有用。這裡的想法是獲取全部內容,然後做你需要做的事情。

\documentclass{article}
\usepackage{amsmath}

\NewDocumentEnvironment{eqsplit*}{b}
 {\begin{equation*}\begin{split}#1\end{split}\end{equation*}}
 {}

\begin{document}

\begin{eqsplit*}
  a & = b \\ & = c
\end{eqsplit*}

\end{document}

在此輸入影像描述

答案2

您無法\end在 LaTeX 中定義以 開頭的命令,否則會阻止定義環境fff

此外,由於其他原因,您無法在巨集中隱藏 AMS 對齊環境,split需要取得其環境主體,因此需要向前掃描以查找所有 AMS 顯示結構(例如等)\end{split}也是如此。aligngather

請注意,任何合理的編輯器都將允許您輸入\begin{equation}..\end{equation}兩到三個擊鍵或選單選項,因此定義縮寫語法不會節省鍵入,並且很難或不可能在編輯器中獲得上下文相關的語法著色或完成。

相關內容