有没有办法用宏来检查方程式是否太长而无法在一行中容纳?

有没有办法用宏来检查方程式是否太长而无法在一行中容纳?

我有一些很长的方程式,跨越几行。我想

  1. 自动断线。
  2. 分页符。
  3. 第一行末尾和第二行开头都有等号。
  4. 整个事物只有一个数字。

我尝试过的环境:

  1. 在方程式内分割(手动换行,无分页符)
  2. dmath(第一行末尾没有等号,所有解决方法都会导致手动换行,没有分页符)(在行尾和行首都放置等号 (dmath)
  3. 对齐(手动换行,无分页)
  4. 对齐(手动换行,必须手动删除过多的数字,缺乏居中效果可怕对我来说(刚看了我的微积分教科书,似乎我不是唯一一个认为多线方程应该居中的人在)
  5. 聚集(手动换行,必须手动删除多余的数字)
  6. 多行(手动换行)

其中 1-3 不可用,因为我剩下半页空白。其中 4-6 多行似乎是最好的,对齐看起来正常,并且不会在每一行添加数字。

我想编写一个接受一个参数的宏。此参数将是一个等式(不插入任何 \\ 和 \nonumber)。它将查找所有等号,并在每个符号处确定是否应将等号替换为 =\\=。然后它将所有内容放入多行环境中。

所以我的问题是:是否有任何函数,给定一个方程作为参数,可以告诉我它是否适合一行?

答案1

按照您的要求修改multline即可(我认为)。结果对我来说看起来相当难以阅读,但也许我只是不习惯阅读俄语文章。

multline像所有 AMS 对齐一样,抓住环境体并设置两次来测量它,这只是对其进行修改,以便如果第一次通过时它太宽,则=重新定义并重复测量。

在此处输入图片描述

您可能可以对任何 amsmath 对齐做类似的事情。

\documentclass{article}

\usepackage{amsmath}

\DeclareMathSymbol{\realequals}{\mathrel}{operators}{"3D}
\makeatletter
{\catcode`=\active \gdef={\realequals{}\\{}\realequals} }
\def\multline@#1{%
    \Let@
    \@display@init{\global\advance\row@\@ne \global\dspbrk@lvl\m@ne}%
    \chardef\dspbrk@context\z@
    \restore@math@cr
    \let\tag\tag@in@align
    \global\tag@false \global\let\raise@tag\@empty
    \mmeasure@{#1}%
\ifdim\totwidth@>.7\displaywidth
\mathcode`=\mathcode`' %
    \mmeasure@{#1}%
\toks@{#1}%
\else
\toks@{\hfill#1\hfill}%
\fi
    \let\tag\gobble@tag \let\label\@gobble
    \tabskip \if@fleqn \@mathmargin \else \z@skip \fi
    \totwidth@\displaywidth
    \if@fleqn
        \advance\totwidth@-\@mathmargin
    \fi
    \halign\bgroup
        \hbox to\totwidth@{%
            \if@fleqn
                \hskip \@centering \relax
            \else
                \hfil
            \fi
            \strut@
            $\m@th\displaystyle{}##\endmultline@math
            \hfil
        }%
        \crcr
        \if@fleqn
            \hskip-\@mathmargin
            \def\multline@indent{\hskip\@mathmargin}% put it back
        \else
            \hfilneg
            \def\multline@indent{\hskip\multlinegap}%
        \fi
        \iftagsleft@
            \iftag@
                \begingroup
                    \ifshifttag@
                        \rlap{\vbox{%
                                \normalbaselines
                                \hbox{%
                                    \strut@
                                    \make@display@tag
                                }%
                                \vbox to\lineht@{}%
                                \raise@tag
                        }}%
                        \multline@indent
                    \else
                        \setbox\z@\hbox{\make@display@tag}%
                        \dimen@\@mathmargin \advance\dimen@-\wd\z@
                        \ifdim\dimen@<\multlinetaggap
                          \dimen@\multlinetaggap
                        \fi
                        \box\z@ \hskip\dimen@\relax
                    \fi
                \endgroup
            \else
                \multline@indent
            \fi
        \else
            \multline@indent
        \fi
    \the\toks@%
}

\begin{document}

\begin{multline}
ax^2 +bx^3 +dx^4 =
(1+x)^9 -(a+x)(x+a)^3 =
a+b
=5
\end{multline}


\begin{multline}
a=5
\end{multline}

\begin{multline}
ax^2 +bx^3 +dx^4 +ex^5 =
ax^2 +bx^3 +dx^4 =
(1+x)^9 -(a+x)(x+a)^3 =
a+b
=5
\end{multline}

\end{document}

或者将第一行和最后一行居中(这仍然很难阅读)

在此处输入图片描述

\documentclass{article}

\usepackage{amsmath}

\DeclareMathSymbol{\realequals}{\mathrel}{operators}{"3D}
\makeatletter
{\catcode`=\active \gdef={\realequals{}\\{}\realequals} }
\def\multline@#1{%
    \Let@
    \@display@init{\global\advance\row@\@ne \global\dspbrk@lvl\m@ne}%
    \chardef\dspbrk@context\z@
    \restore@math@cr
    \let\tag\tag@in@align
    \global\tag@false \global\let\raise@tag\@empty
    \mmeasure@{#1}%
\ifdim\totwidth@>.7\displaywidth
\mathcode`=\mathcode`' %
    \mmeasure@{#1}%
\toks@{\hfil#1\hfil}%
\else
\toks@{\hfill#1\hfill}%
\fi
    \let\tag\gobble@tag \let\label\@gobble
    \tabskip \if@fleqn \@mathmargin \else \z@skip \fi
    \totwidth@\displaywidth
    \if@fleqn
        \advance\totwidth@-\@mathmargin
    \fi
    \halign\bgroup
        \hbox to\totwidth@{%
            \if@fleqn
                \hskip \@centering \relax
            \else
                \hfil
            \fi
            \strut@
            $\m@th\displaystyle{}##\endmultline@math
            \hfil
        }%
        \crcr
        \if@fleqn
            \hskip-\@mathmargin
            \def\multline@indent{\hskip\@mathmargin}% put it back
        \else
            \hfilneg
            \def\multline@indent{\hskip\multlinegap}%
        \fi
        \iftagsleft@
            \iftag@
                \begingroup
                    \ifshifttag@
                        \rlap{\vbox{%
                                \normalbaselines
                                \hbox{%
                                    \strut@
                                    \make@display@tag
                                }%
                                \vbox to\lineht@{}%
                                \raise@tag
                        }}%
                        \multline@indent
                    \else
                        \setbox\z@\hbox{\make@display@tag}%
                        \dimen@\@mathmargin \advance\dimen@-\wd\z@
                        \ifdim\dimen@<\multlinetaggap
                          \dimen@\multlinetaggap
                        \fi
                        \box\z@ \hskip\dimen@\relax
                    \fi
                \endgroup
            \else
                \multline@indent
            \fi
        \else
            \multline@indent
        \fi
    \the\toks@%
}

\begin{document}

\begin{multline}
ax^2 +bx^3 +dx^4 =
(1+x)^9 -(a+x)(x+a)^3 =
a+b
=5
\end{multline}


\begin{multline}
a=5
\end{multline}

\begin{multline}
ax^2 +bx^3 +dx^4 +ex^5 =
ax^2 +bx^3 +dx^4 =
(1+x)^9 -(a+x)(x+a)^3 =
a+b
=5
\end{multline}

\end{document}

答案2

我做到了!它可以用点来测量公式的宽度,将其与页面宽度进行比较,并根据比较结果输出不同的字符串。

\documentclass{article}
\usepackage{amsmath}
\usepackage{ifthen}
\makeatletter
    \def\measure#1{
        \settowidth{\length}{$#1$}
        \ifthenelse{\length>\textwidth}{output1}{output2}}
    \newlength{\length}
\makeatother
\begin{document}
\end{document}

由于某些原因,我尝试的所有不错的递归宏都失败了。所以这是一个丑陋但完全有效的解决方案。九个公式的宏不符合字符限制,所以我不得不把它去掉,但它可以很容易地基于八个公式的宏构建。可以通过给出一个参数来构建九个以上公式的宏,然后使用包xstring将其分成十个或更多等号所在的部分,然后对这些部分使用类似的算法。

\documentclass{article}
\usepackage{amsmath}
\usepackage{ifthen}
\makeatletter
    \def\gathereight#1#2#3#4#5#6#7#8{
        \settowidth{\fiveeight}{$=#5=#6=#7=#8$}
        \settowidth{\fiveseven}{$=#5=#6=#7=$}
        \settowidth{\fivesix}{$=#5=#6=$}
        \settowidth{\foureight}{$=#4=#5=#6=#7=#8$}
        \settowidth{\fourfive}{$=#4=#5=$}
        \settowidth{\fourseven}{$=#4=#5=#6=#7=$}
        \settowidth{\foursix}{$=#4=#5=#6=$}
        \settowidth{\oneeight}{$#1=#2=#3=#4=#5=#6=#7=#8$}
        \settowidth{\onefive}{$#1=#2=#3=#4=#5=$}
        \settowidth{\onefour}{$#1=#2=#3=#4=$}
        \settowidth{\oneseven}{$#1=#2=#3=#4=#5=#6=#7=$}
        \settowidth{\onesix}{$#1=#2=#3=#4=#5=#6=$}
        \settowidth{\onethree}{$#1=#2=#3=$}
        \settowidth{\onetwo}{$#1=#2=$}
        \settowidth{\seveneight}{$=#7=#8$}
        \settowidth{\sixeight}{$=#6=#7=#8$}
        \settowidth{\sixseven}{$=#6=#7=$}
        \settowidth{\threeeight}{$=#3=#4=#5=#6=#7=#8$}
        \settowidth{\threefive}{$=#3=#4=#5=$}
        \settowidth{\threefour}{$=#3=#4=$}
        \settowidth{\threeseven}{$=#3=#4=#5=#6=#7=$}
        \settowidth{\threesix}{$=#3=#4=#5=#6=$}
        \settowidth{\twoeight}{$=#2=#3=#4=#5=#6=#7=#8$}
        \settowidth{\twofive}{$=#2=#3=#4=#5=$}
        \settowidth{\twofour}{$=#2=#3=#4=$}
        \settowidth{\twoseven}{$=#2=#3=#4=#5=#6=#7=$}
        \settowidth{\twosix}{$=#2=#3=#4=#5=#6=$}
        \settowidth{\twothree}{$=#2=#3=$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2=\ifthenelse{\twothree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\foureight>\textwidth}{\\\nonumber=#8}{#8}}}}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\threesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\threeseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\threeeight>\textwidth}{\\\nonumber=#8}{#8}}}}}}{#3=\ifthenelse{\twofour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\foureight>\textwidth}{\\\nonumber=#8}{#8}}}}}{#4=\ifthenelse{\twofive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\twosix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\twoseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\twoeight>\textwidth}{\\\nonumber=#8}{#8}}}}}}}{#2=\ifthenelse{\onethree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\foureight>\textwidth}{\\\nonumber=#8}{#8}}}}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\threesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\threeseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\threeeight>\textwidth}{\\\nonumber=#8}{#8}}}}}}{#3=\ifthenelse{\onefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\foureight>\textwidth}{\\\nonumber=#8}{#8}}}}}{#4=\ifthenelse{\onefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\fiveeight>\textwidth}{\\\nonumber=#8}{#8}}}}{#5=\ifthenelse{\onesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\sixeight>\textwidth}{\\\nonumber=#8}{#8}}}{#6=\ifthenelse{\oneseven>\textwidth}{\\\nonumber=#7=\ifthenelse{\seveneight>\textwidth}{\\\nonumber=#8}{#8}}{#7=\ifthenelse{\oneeight>\textwidth}{\\\nonumber=#8}{#8}}}}}}}
        \end{gather}}
    \def\gatherfive#1#2#3#4#5{
        \settowidth{\fourfive}{$=#4=#5$}
        \settowidth{\onefive}{$#1=#2=#3=#4=#5$}
        \settowidth{\onefour}{$#1=#2=#3=#4=$}
        \settowidth{\onethree}{$#1=#2=#3=$}
        \settowidth{\onetwo}{$#1=#2=$}
        \settowidth{\threefive}{$=#3=#4=#5$}
        \settowidth{\threefour}{$=#3=#4=$}
        \settowidth{\twofive}{$=#2=#3=#4=#5$}
        \settowidth{\twofour}{$=#2=#3=#4=$}
        \settowidth{\twothree}{$=#2=#3=$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2=\ifthenelse{\twothree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5}{#5}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5}{#5}}}{#3=\ifthenelse{\twofour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5}{#5}}{#4=\ifthenelse{\twofive>\textwidth}{\\\nonumber=#5}{#5}}}}{#2=\ifthenelse{\onethree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5}{#5}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5}{#5}}}{#3=\ifthenelse{\onefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5}{#5}}{#4=\ifthenelse{\onefive>\textwidth}{\\\nonumber=#5}{#5}}}}
        \end{gather}}
    \def\gatherfour#1#2#3#4{
        \settowidth{\onefour}{$#1=#2=#3=#4$}
        \settowidth{\onethree}{$#1=#2=#3=$}
        \settowidth{\onetwo}{$#1=#2=$}
        \settowidth{\threefour}{$=#3=#4$}
        \settowidth{\twofour}{$=#2=#3=#4$}
        \settowidth{\twothree}{$=#2=#3=$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2=\ifthenelse{\twothree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4}{#4}}{#3=\ifthenelse{\twofour>\textwidth}{\\\nonumber=#4}{#4}}}{#2=\ifthenelse{\onethree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4}{#4}}{#3=\ifthenelse{\onefour>\textwidth}{\\\nonumber=#4}{#4}}}
        \end{gather}}
    \def\gatherone#1{
        \begin{gather}
            #1
        \end{gather}}
    \def\gatherseven#1#2#3#4#5#6#7{
        \settowidth{\fiveseven}{$=#5=#6=#7$}
        \settowidth{\fivesix}{$=#5=#6=$}
        \settowidth{\fourfive}{$=#4=#5=$}
        \settowidth{\fourseven}{$=#4=#5=#6=#7$}
        \settowidth{\foursix}{$=#4=#5=#6=$}
        \settowidth{\onefive}{$#1=#2=#3=#4=#5=$}
        \settowidth{\onefour}{$#1=#2=#3=#4=$}
        \settowidth{\oneseven}{$#1=#2=#3=#4=#5=#6=#7$}
        \settowidth{\onesix}{$#1=#2=#3=#4=#5=#6=$}
        \settowidth{\onethree}{$#1=#2=#3=$}
        \settowidth{\onetwo}{$#1=#2=$}
        \settowidth{\sixseven}{$=#6=#7$}
        \settowidth{\threefive}{$=#3=#4=#5=$}
        \settowidth{\threefour}{$=#3=#4=$}
        \settowidth{\threeseven}{$=#3=#4=#5=#6=#7$}
        \settowidth{\threesix}{$=#3=#4=#5=#6=$}
        \settowidth{\twofive}{$=#2=#3=#4=#5=$}
        \settowidth{\twofour}{$=#2=#3=#4=$}
        \settowidth{\twoseven}{$=#2=#3=#4=#5=#6=#7$}
        \settowidth{\twosix}{$=#2=#3=#4=#5=#6=$}
        \settowidth{\twothree}{$=#2=#3=$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2=\ifthenelse{\twothree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7}{#7}}}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\threesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\threeseven>\textwidth}{\\\nonumber=#7}{#7}}}}}{#3=\ifthenelse{\twofour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7}{#7}}}}{#4=\ifthenelse{\twofive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\twosix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\twoseven>\textwidth}{\\\nonumber=#7}{#7}}}}}}{#2=\ifthenelse{\onethree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7}{#7}}}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\threesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\threeseven>\textwidth}{\\\nonumber=#7}{#7}}}}}{#3=\ifthenelse{\onefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fourseven>\textwidth}{\\\nonumber=#7}{#7}}}}{#4=\ifthenelse{\onefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\fiveseven>\textwidth}{\\\nonumber=#7}{#7}}}{#5=\ifthenelse{\onesix>\textwidth}{\\\nonumber=#6=\ifthenelse{\sixseven>\textwidth}{\\\nonumber=#7}{#7}}{#6=\ifthenelse{\oneseven>\textwidth}{\\\nonumber=#7}{#7}}}}}}
        \end{gather}}
    \def\gathersix#1#2#3#4#5#6{
        \settowidth{\fivesix}{$=#5=#6$}
        \settowidth{\fourfive}{$=#4=#5=$}
        \settowidth{\foursix}{$=#4=#5=#6$}
        \settowidth{\onefive}{$#1=#2=#3=#4=#5=$}
        \settowidth{\onefour}{$#1=#2=#3=#4=$}
        \settowidth{\onesix}{$#1=#2=#3=#4=#5=#6$}
        \settowidth{\onethree}{$#1=#2=#3=$}
        \settowidth{\onetwo}{$#1=#2=$}
        \settowidth{\threefive}{$=#3=#4=#5=$}
        \settowidth{\threefour}{$=#3=#4=$}
        \settowidth{\threesix}{$=#3=#4=#5=#6$}
        \settowidth{\twofive}{$=#2=#3=#4=#5=$}
        \settowidth{\twofour}{$=#2=#3=#4=$}
        \settowidth{\twosix}{$=#2=#3=#4=#5=#6$}
        \settowidth{\twothree}{$=#2=#3=$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2=\ifthenelse{\twothree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6}{#6}}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\threesix>\textwidth}{\\\nonumber=#6}{#6}}}}{#3=\ifthenelse{\twofour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6}{#6}}}{#4=\ifthenelse{\twofive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\twosix>\textwidth}{\\\nonumber=#6}{#6}}}}}{#2=\ifthenelse{\onethree>\textwidth}{\\\nonumber=#3=\ifthenelse{\threefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6}{#6}}}{#4=\ifthenelse{\threefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\threesix>\textwidth}{\\\nonumber=#6}{#6}}}}{#3=\ifthenelse{\onefour>\textwidth}{\\\nonumber=#4=\ifthenelse{\fourfive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\foursix>\textwidth}{\\\nonumber=#6}{#6}}}{#4=\ifthenelse{\onefive>\textwidth}{\\\nonumber=#5=\ifthenelse{\fivesix>\textwidth}{\\\nonumber=#6}{#6}}{#5=\ifthenelse{\onesix>\textwidth}{\\\nonumber=#6}{#6}}}}}
        \end{gather}}
    \def\gatherthree#1#2#3{
        \settowidth{\onethree}{$#1=#2=#3$}
        \settowidth{\onetwo}{$#1=#2=$}
        \settowidth{\twothree}{$=#2=#3$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2=\ifthenelse{\twothree>\textwidth}{\\\nonumber=#3}{#3}}{#2=\ifthenelse{\onethree>\textwidth}{\\\nonumber=#3}{#3}}
        \end{gather}}
    \def\gathertwo#1#2{
        \settowidth{\onetwo}{$#1=#2$}
        \begin{gather}
            #1=\ifthenelse{\onetwo>\textwidth}{\\\nonumber=#2}{#2}
        \end{gather}}
    \def\rbr#1{\left(#1\right)}
    \newlength{\fiveeight}
    \newlength{\fiveseven}
    \newlength{\fivesix}
    \newlength{\foureight}
    \newlength{\fourfive}
    \newlength{\fourseven}
    \newlength{\foursix}
    \newlength{\oneeight}
    \newlength{\onefive}
    \newlength{\onefour}
    \newlength{\oneseven}
    \newlength{\onesix}
    \newlength{\onethree}
    \newlength{\onetwo}
    \newlength{\seveneight}
    \newlength{\sixeight}
    \newlength{\sixseven}
    \newlength{\threeeight}
    \newlength{\threefive}
    \newlength{\threefour}
    \newlength{\threeseven}
    \newlength{\threesix}
    \newlength{\twoeight}
    \newlength{\twofive}
    \newlength{\twofour}
    \newlength{\twoseven}
    \newlength{\twosix}
    \newlength{\twothree}
\makeatother
\begin{document}
    \gatherfour{ax_2+bx^3+dx^4}{\rbr{1+x}s^9-\rbr{a+x}\rbr{x+a}^3}{a+b}{5}
    \gathertwo{a}{5}
    \gatherfive{ax^2+bx^3+dx^4+ex^5}{ax^2+bx^3+dx^4}{\rbr{1+x}^9-\rbr{a+x}\rbr{x+a}^3}{a+b}{5}
\end{document}

可以轻松修改方程编号的位置(通过改变其位置\nonumber)以及允许填充多少页面宽度(通过调整条件)。

相关内容