自动换行显示的长公式(例如,使用与内联公式相同的算法)

自动换行显示的长公式(例如,使用与内联公式相同的算法)

印刷工警告不要自动换行较长的公式;然而,在某些情况下这样做是有意义的。下面就是其中一种: 在此处输入图片描述

\documentclass[twocolumn]{article} 
\usepackage{lipsum,framed,amsmath}
\newcommand{\wrapMe}{1A+2B+3C+4D+5E+6F+7G+8H+9I+10J+11K+12L+13M+14N+15O+16P+17Q+18R+19S+20T+21U+22V+24W+25X+25Y+26Z}
\begin{document}
  \thispagestyle{empty}
  See how~$\zeta=\wrapMe$ wraps nicely within the text.
  I can also manually produce an even nicer displayed version
  \begin{equation}
    \begin{split}
      \zeta  = & 1A+2B+3C+4D+5E+6F+7G+8H\\
      & + 9I+ 10J+11K+12L+13M+14N+15O\\
      & +16P+ 17Q+18R+19S+20T+21U+22V\\
      & +24W+25X+25Y+26Z
    \end{split}
  \end{equation}
  Can this be done automatically? Let's try!
  \begin{equation}
    \zeta =\wrapMe
  \end{equation}
  \par
  \lipsum[\inputlineno]
  \par
  \begin{minipage}{0.9\columnwidth}
    \begin{framed}
      \begin{equation}
        \zeta =\wrapMe
      \end{equation}
    \end{framed}
  \end{minipage}
  \par
  \lipsum[\inputlineno]
  \par
  \begin{minipage}{0.7\columnwidth}
    \begin{framed}
      \begin{equation}
        \zeta = \wrapMe
      \end{equation}
    \end{framed}
  \end{minipage}
  \par
  \lipsum[\inputlineno]
  \par

  \begin{minipage}{0.5\columnwidth}
    \begin{framed}
      \begin{equation}
        \zeta =\wrapMe
      \end{equation}
    \end{framed}
  \end{minipage}
  \par
  \lipsum[\inputlineno]
  \begin{minipage}{0.3\columnwidth}
    \begin{framed}
      \begin{equation}
        \zeta =\wrapMe
      \end{equation}
    \end{framed}
  \end{minipage}
\end{document}

澄清 理想情况下,将使用名为 的宏(例如 )\wrap来包装\wrapMe

  \begin{equation}
    \zeta = \wrap[\lineLength - 5ex]{\wrapMe}
  \end{equation}

但是,可能存在其他巧妙的方案来自动确定“正确”的包装宽度。

答案1

这将在加号和减号之前中断,其他二元运算符可以以类似的方式添加。

可选参数wrapeqn是总宽度,默认为分配宽度的 90%。

\documentclass[twocolumn]{article} 
\usepackage{lipsum,amsmath}

\newcommand{\wrapMe}{%
  1A+2B+3C+4D+5E+6F+7G+8H+9I+10J+11K+12L+13M+14N+
  15O+16P+17Q+18R+19S+20T+21U+22V+24W+25X+25Y+26Z%
}

\makeatletter
\newenvironment{wrapeqn}[2][.9\displaywidth]
 {\begin{minipage}{#1}\openup\jot\change@operations
  \@hangfrom{$\displaystyle#2{}$}$\displaystyle}
 {$\end{minipage}}
\newcommand{\change@operations}{%
  \begingroup\lccode`~=`+\lowercase{\endgroup\let~}\prebin@plus
  \begingroup\lccode`~=`-\lowercase{\endgroup\let~}\prebin@minus
  \mathcode`+="8000 \mathcode`-="8000
}
\edef\prebin@plus{\penalty\binoppenalty\mathchar\the\mathcode`+\noexpand\nobreak}
\edef\prebin@minus{\penalty\binoppenalty\mathchar\the\mathcode`-\noexpand\nobreak}
\makeatother


\begin{document}

See how~$\zeta=\wrapMe$ wraps nicely within the text.
I can also manually produce an even nicer displayed version
\begin{equation}
\begin{split}
\zeta={} & 1A+2B+3C+4D+5E+6F+7G+8H\\
         & + 9I+ 10J+11K+12L+13M+14N+15O\\
         & +16P+ 17Q+18R+19S+20T+21U+22V\\
         & +24W+25X+25Y+26Z
\end{split}
\end{equation}
Can this be done automatically? Let's try!
\begin{equation*}
\begin{wrapeqn}{\zeta =}
\wrapMe
\end{wrapeqn}
\end{equation*}
\lipsum*[2]
\begin{equation}
\begin{wrapeqn}[.8\columnwidth]{\zeta =}
\wrapMe
\end{wrapeqn}
\end{equation}

\end{document}

在此处输入图片描述

答案2

结合\hangindent\hangafter,您可以按照在中所做的那样对齐公式split

\documentclass{article} 
\usepackage{lipsum}
\begin{document}

\lipsum[1]

\newdimen\tempindent
\settowidth\tempindent{$0<\mathopen{}$}
\hangafter1\hangindent\tempindent
\medskip\noindent
$\displaystyle0<(k+2)(1-[wz+h+j-q]^2-[(gk+2g+k+1)(h+j)+h-z]^2-[16(k+1)^3(k+2)(n+1)^2+1-f^2]^2-[2n+p+q+z-e]^2-[e^3(e+2)(a+1)^2+1-o^2]^2-[(a^2-1)y^2+1-x^2]^2-[16r^2y^4(a^2-1)+1-u^2]^2-[n+l+v-y]^2-[(a^2-1)l^2+1-m^2]^2-[ai+k+1-l-i]^2-[((a+u^2(u^2-a))^2-1)(n+4dy)^2+1-(x+cu)^2]^2-[p+l(a-n-1)+b(2an+2a-n^2-2n-2)-m]^2-[q+y(a-p-1)+s(2ap+2a-p^2-2p-2)-x]^2-[z+pl(a-p)+t(2ap-p^2-1)-pm]^2)$
\par\medskip

\lipsum[2]

也可以从中导入示例TeXBook

\newdimen\varunit
\varunit=3.2pt
\hfill\vtop{\null
\baselineskip6\varunit
\parfillskip0pt
\parshape 19
-18.25\varunit 36.50\varunit
-30.74\varunit 61.48\varunit
-38.54\varunit 77.07\varunit
-44.19\varunit 88.39\varunit
-48.47\varunit 96.93\varunit
-51.70\varunit 103.40\varunit
-54.08\varunit 108.17\varunit
-55.72\varunit 111.45\varunit
-56.68\varunit 113.37\varunit
-57.00\varunit 114.00\varunit
-56.68\varunit 113.37\varunit
-55.72\varunit 111.45\varunit
-54.08\varunit 108.17\varunit
-51.70\varunit 103.40\varunit
-48.47\varunit 96.93\varunit
-44.19\varunit 88.39\varunit
-38.54\varunit 77.07\varunit
-30.74\varunit 61.48\varunit
-18.25\varunit 36.50\varunit
\frenchspacing
\noindent
\hbadness 6000
\tolerance 9999
\pretolerance 0
$\displaystyle0<(k+2)(1-[wz+h+j-q]^2-[(gk+2g+k+1)(h+j)+h-z]^2-[16(k+1)^3(k+2)(n+1)^2+1-f^2]^2-[2n+p+q+z-e]^2-[e^3(e+2)(a+1)^2+1-o^2]^2-[(a^2-1)y^2+1-x^2]^2-[16r^2y^4(a^2-1)+1-u^2]^2-[n+l+v-y]^2-[(a^2-1)l^2+1-m^2]^2-[ai+k+1-l-i]^2-[((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