多重分割方程

多重分割方程

我发现自己一次又一次地使用gatheraligned环境的组合。所以不用写那么多就好了。特别是,通常只有在写完公式后才清楚是否需要拆分。所以新的环境应该像gather,只是当行被特殊符号/宏分隔时(\n例如)它们应该放在一起进入aligned-环境。我尝试了以下

\documentclass{article}
\usepackage[fleqn]{amsmath}

\newenvironment{multeq}{%
    \let\n{\\}
    \let\\{\end{aligned}\\\begin{aligned}}
    \begin{aligned}
}{%
    \end{aligned}
    \let\\{\n}
}

\begin{document}

    \begin{gather}
        \begin{aligned}
            S(A) &= (I_{n-k, k}AI_{n-k,k})_{i,j} = (I_{n-k,k})_{i,i}A_{i,j}(I_{n-k,k})_{j,j}\\
            &= \begin{cases}A_{i,j}&\begin{aligned}&(i\leq n-k\wedge j\leq n-k)\\\vee&(i>n-k\wedge j>n-k)\end{aligned}\\-A_{i,j}&\text{otherwise}\end{cases}
        \end{aligned}\\
        \Rightarrow H = S(U(n-k)\times U(k))
    \end{gather}

    \begin{multeq}
        S(A) &= (I_{n-k, k}AI_{n-k,k})_{i,j} = (I_{n-k,k})_{i,i}A_{i,j}(I_{n-k,k})_{j,j}\n
        &= \begin{cases}A_{i,j}&\begin{aligned}&(i\leq n-k\wedge j\leq n-k)\n\vee&(i>n-k\wedge j>n-k)\end{aligned}\n-A_{i,j}&\text{otherwise}\end{cases}\\
    \Rightarrow H = S(U(n-k)\times U(k))
    \end{multeq}

\end{document}

输出应为 2× 示例输出

但它给出了错误:

! LaTeX Error: There's no line here to end.
l.24    \begin{multeq}

这个错误是如何发生的,有什么好的办法可以创建这样的环境?


因此使用 David 的修正并添加gather

\newenvironment{multeq}{\begin{gather}%
    \def\n{\\}%
    \def\\{\end{aligned}\\\begin{aligned}}%
    \begin{aligned}%
}{%
    \end{aligned}%
    \end{gather}}

我有

! Paragraph ended before \gather was complete.

所以我尝试\Collect@Body使用environ

\def\savebody#1{\def\BODY{#1}}
\usepackage{environ}
\makeatletter

\newenvironment{multeq}{
    \def\n{\\}%
    \def\\{\end{aligned}\\\begin{aligned}}%
    \Collect@Body\savebody
}{\begin{gather}%
    \begin{aligned}%
            \BODY%
    \end{aligned}%
    \end{gather}}

\makeatother

但现在的重新定义\\被忽略了。我还能做什么?

答案1

\def不需要\let\nd 你需要进入数学模式:

\documentclass{article}
\usepackage[fleqn]{amsmath}

\newenvironment{multeq}{\[%
    \def\n{\\}%
    \def\\{\end{aligned}\\\begin{aligned}}%
    \begin{aligned}%
}{%
    \end{aligned}%
    \]}

\begin{document}

    \begin{gather}
        \begin{aligned}
            S(A) &= (I_{n-k, k}AI_{n-k,k})_{i,j} = (I_{n-k,k})_{i,i}A_{i,j}(I_{n-k,k})_{j,j}\\
            &= \begin{cases}A_{i,j}&\begin{aligned}&(i\leq n-k\wedge j\leq n-k)\\\vee&(i>n-k\wedge j>n-k)\end{aligned}\\-A_{i,j}&\text{otherwise}\end{cases}
        \end{aligned}\\
        \Rightarrow H = S(U(n-k)\times U(k))
    \end{gather}

    \begin{multeq}
        S(A) &= (I_{n-k, k}AI_{n-k,k})_{i,j} = (I_{n-k,k})_{i,i}A_{i,j}(I_{n-k,k})_{j,j}\n
        &= \begin{cases}A_{i,j}&\begin{aligned}&(i\leq n-k\wedge j\leq n-k)\n\vee&(i>n-k\wedge j>n-k)\end{aligned}\n-A_{i,j}&\text{otherwise}\end{cases}\\
    \Rightarrow H = S(U(n-k)\times U(k))
    \end{multeq}

\end{document}

您可能需要进行一些其他更改,具体取决于您想要的输入标记,上面产生

在此处输入图片描述

答案2

在查看了一些宏扩展之后,我发现了实际问题。在扩展时amsmath定义。因此,无论我事先对做什么,都无关紧要。因此我进行了更改,它起作用了。至少如果我用收集主体。\let\\\math@crgather\\\math@crNewEnviron

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{environ}

\makeatletter
\NewEnviron{multeq}{%
    \begingroup
        \let\n\math@cr
        \begin{gather}
            \def\math@cr{\end{aligned}\n\begin{aligned}}
            \begin{aligned}
                \BODY
            \end{aligned}
        \end{gather}
    \endgroup
}
\makeatother

是所需的定义。它还可以与align代替gathersplit代替 一起使用aligned。下面是一个更简单的用法示例:

\begin{document}
\begin{multeq}
    0 + 0 = 0\n
    0 * 0 = 0\\
    1 + 1 = 2\n
    1 * 1 = 1
\end{multeq}
\end{document}

将打印为

示例输出

相关内容