长数学公式的更美观的排版:数学环境中的换行符(标准模型拉格朗日示例)

长数学公式的更美观的排版:数学环境中的换行符(标准模型拉格朗日示例)

我几乎从不使用math环境,因为它align更适合我的需求。但面对公式的复杂性,我不想手动输入 \\& 因为它会花很长时间。

是否有其他方法可以改善环境外观math,以便

  • 它会在一定长度时断行表达式吗?
  • 它不是将符号 + 和 - 放在换行符之前,而是放在开头?
  • 是否更“可读”?

当然,我更乐意这么做align,但我不知道如何实现其自动化。

作为示例(以对更多人有用为目标),考虑由 Gutierrez 输入的标准模型拉格朗日量:(完整 .tex 点击此处

% Extracted and typed by T.D. Gutierrez from Diagrammatica by Martinus Veltman sometime in 1999.
% Yes, there is probably a sign error.
% http://nuclear.ucdavis.edu/~tgutierr
% http://www.scuma.org

\documentclass[14pt]{article}
\pagestyle{empty}
\setlength{\textheight}{10in}

\begin{document}
\Large Only Fragment!  
\large
\begin{center}
\begin{math}
-\frac{1}{2}\partial_{\nu}g^{a}_{\mu}\partial_{\nu}g^{a}_{\mu}
-g_{s}f^{abc}\partial_{\mu}g^{a}_{\nu}g^{b}_{\mu}g^{c}_{\nu}
-\frac{1}{4}g^{2}_{s}f^{abc}f^{ade}g^{b}_{\mu}g^{c}_{\nu}g^{d}_{\mu}g^{e}_{\nu}
+\frac{1}{2}ig^{2}_{s}(\bar{q}^{\sigma}_{i}\gamma^{\mu}q^{\sigma}_{j})g^{a}_{\mu}
+\bar{G}^{a}\partial^{2}G^{a}+g_{s}f^{abc}\partial_{\mu}\bar{G}^{a}G^{b}g^{c}_{\mu}
-\partial_{\nu}W^{+}_{\mu}\partial_{\nu}W^{-}_{\mu}-M^{2}W^{+}_{\mu}W^{-}_{\mu}
-\frac{1}{2}\partial_{\nu}Z^{0}_{\mu}\partial_{\nu}Z^{0}_{\mu}-\frac{1}{2c^{2}_{w}}
M^{2}Z^{0}_{\mu}Z^{0}_{\mu}
-\frac{1}{2}\partial_{\mu}A_{\nu}\partial_{\mu}A_{\nu}
-\frac{1}{2}\partial_{\mu}H\partial_{\mu}H-\frac{1}{2}m^{2}_{h}H^{2}
-\partial_{\mu}\phi^{+}\partial_{\mu}\phi^{-}-M^{2}\phi^{+}\phi^{-}
-\frac{1}{2}\partial_{\mu}\phi^{0}\partial_{\mu}\phi^{0}-\frac{1}{2c^{2}_{w}}M\phi^{0}\phi^{0}
-\beta_{h}[\frac{2M^{2}}{g^{2}}+\frac{2M}{g}H+\frac{1}{2}(H^{2}+\phi^{0}\phi^{0}+2\phi^{+}\phi^{-%%@
})]+\frac{2M^{4}}{g^{2}}\alpha_{h}
-igc_{w}[\partial_{\nu}Z^{0}_{\mu}(W^{+}_{\mu}W^{-}_{\nu}-W^{+}_{\nu}W^{-}_{\mu})
-Z^{0}_{\nu}(W^{+}_{\mu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\mu}\partial_{\nu}W^{+}_{\mu})
+Z^{0}_{\mu}(W^{+}_{\nu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\nu}\partial_{\nu}W^{+}_{\mu})]
-igs_{w}[\partial_{\nu}A_{\mu}(W^{+}_{\mu}W^{-}_{\nu}-W^{+}_{\nu}W^{-}_{\mu})
-A_{\nu}(W^{+}_{\mu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\mu}\partial_{\nu}W^{+}_{\mu})
+A_{\mu}(W^{+}_{\nu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\nu}\partial_{\nu}W^{+}_{\mu})]
-\frac{1}{2}g^{2}W^{+}_{\mu}W^{-}_{\mu}W^{+}_{\nu}W^{-}_{\nu}+\frac{1}{2}g^{2}
W^{+}_{\mu}W^{-}_{\nu}W^{+}_{\mu}W^{-}_{\nu}
+g^2c^{2}_{w}(Z^{0}_{\mu}W^{+}_{\mu}Z^{0}_{\nu}W^{-}_{\nu}-Z^{0}_{\mu}Z^{0}_{\mu}W^{+}_{\nu}
W^{-}_{\nu})
+g^2s^{2}_{w}(A_{\mu}W^{+}_{\mu}A_{\nu}W^{-}_{\nu}-A_{\mu}A_{\mu}W^{+}_{\nu}
W^{-}_{\nu})... 
\end{math}
\end{center}

\end{document}

在此处输入图片描述

答案1

这种模拟multline环境,第一行左对齐,最后一行右对齐,中间几行居中,显示样式间距增加,并且 + 和 - 位于行首而不是行尾,

在此处输入图片描述

\documentclass[12pt]{article}
\pagestyle{empty}
\setlength{\textheight}{10in}

\DeclareMathSymbol{\zplus}{\mathbin}{operators}{"2B}
\DeclareMathSymbol{\zminus}{\mathbin}{symbols}{"00}

\begin{document}
\Large Only Fragment!  
\large
\begin{center}\makeatletter
% could make these local and use mathcode "8000 but no need really
\catcode`\+\active
\def+{\penalty0\zplus}
\catcode`\-\active
\def-{\penalty0\zminus}
\renewcommand\baselinestretch{2}\selectfont

\hspace*{\string-\@flushglue}%
\begin{math}\displaystyle
-\frac{1}{2}\partial_{\nu}g^{a}_{\mu}\partial_{\nu}g^{a}_{\mu}
-g_{s}f^{abc}\partial_{\mu}g^{a}_{\nu}g^{b}_{\mu}g^{c}_{\nu}
-\frac{1}{4}g^{2}_{s}f^{abc}f^{ade}g^{b}_{\mu}g^{c}_{\nu}g^{d}_{\mu}g^{e}_{\nu}
+\frac{1}{2}ig^{2}_{s}(\bar{q}^{\sigma}_{i}\gamma^{\mu}q^{\sigma}_{j})g^{a}_{\mu}
+\bar{G}^{a}\partial^{2}G^{a}+g_{s}f^{abc}\partial_{\mu}\bar{G}^{a}G^{b}g^{c}_{\mu}
-\partial_{\nu}W^{+}_{\mu}\partial_{\nu}W^{-}_{\mu}-M^{2}W^{+}_{\mu}W^{-}_{\mu}
-\frac{1}{2}\partial_{\nu}Z^{0}_{\mu}\partial_{\nu}Z^{0}_{\mu}-\frac{1}{2c^{2}_{w}}
M^{2}Z^{0}_{\mu}Z^{0}_{\mu}
-\frac{1}{2}\partial_{\mu}A_{\nu}\partial_{\mu}A_{\nu}
-\frac{1}{2}\partial_{\mu}H\partial_{\mu}H-\frac{1}{2}m^{2}_{h}H^{2}
-\partial_{\mu}\phi^{+}\partial_{\mu}\phi^{-}-M^{2}\phi^{+}\phi^{-}
-\frac{1}{2}\partial_{\mu}\phi^{0}\partial_{\mu}\phi^{0}-\frac{1}{2c^{2}_{w}}M\phi^{0}\phi^{0}
-\beta_{h}[\frac{2M^{2}}{g^{2}}+\frac{2M}{g}H+\frac{1}{2}(H^{2}+\phi^{0}\phi^{0}+2\phi^{+}\phi^{-%%@
})]+\frac{2M^{4}}{g^{2}}\alpha_{h}
-igc_{w}[\partial_{\nu}Z^{0}_{\mu}(W^{+}_{\mu}W^{-}_{\nu}-W^{+}_{\nu}W^{-}_{\mu})
-Z^{0}_{\nu}(W^{+}_{\mu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\mu}\partial_{\nu}W^{+}_{\mu})
+Z^{0}_{\mu}(W^{+}_{\nu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\nu}\partial_{\nu}W^{+}_{\mu})]
-igs_{w}[\partial_{\nu}A_{\mu}(W^{+}_{\mu}W^{-}_{\nu}-W^{+}_{\nu}W^{-}_{\mu})
-A_{\nu}(W^{+}_{\mu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\mu}\partial_{\nu}W^{+}_{\mu})
+A_{\mu}(W^{+}_{\nu}\partial_{\nu}W^{-}_{\mu}-W^{-}_{\nu}\partial_{\nu}W^{+}_{\mu})]
-\frac{1}{2}g^{2}W^{+}_{\mu}W^{-}_{\mu}W^{+}_{\nu}W^{-}_{\nu}+\frac{1}{2}g^{2}
W^{+}_{\mu}W^{-}_{\nu}W^{+}_{\mu}W^{-}_{\nu}
+g^2c^{2}_{w}(Z^{0}_{\mu}W^{+}_{\mu}Z^{0}_{\nu}W^{-}_{\nu}-Z^{0}_{\mu}Z^{0}_{\mu}W^{+}_{\nu}
W^{-}_{\nu})
+g^2s^{2}_{w}(A_{\mu}W^{+}_{\mu}A_{\nu}W^{-}_{\nu}-A_{\mu}A_{\mu}W^{+}_{\nu}
W^{-}_{\nu})... 
\end{math}%
\hspace*{\string-\@flushglue}\mbox{}%
\end{center}

\end{document}

答案2

TeX 能够读取更多人性化、可读性更强的源代码,因为其中不相关的括号 {} 较少。这可能适用于以下复杂的方程式:

\mathchardef\plus=\mathcode`+ 
\catcode`+=13 \def+{\penalty0\plus} \catcode`+=12
\mathcode`+="8000
\mathchardef\minus=\mathcode`- 
\catcode`-=13 \def-{\penalty0\minus} \catcode`-=12
\mathcode`-="8000
\def\sppp#1{\spp{#1}}
\catcode`^=7 \let\spp=^ \catcode`^=13 \let^=\sppp \catcode`^=12
\mathcode`^="8000

\def\begininv{\par\noindent\hskip0pt plus-1fil $\displaystyle}
\def\endinv{${\advance\baselineskip by1em \leftskip=0pt plus1fil \rightskip=\leftskip
           \parfillskip=0pt plus-1fil \par}}

\begininv
- {1\over2} \partial_\nu g^a_\mu \partial_\nu g^a_\mu
- g_s f^{abc} \partial_\mu g^a_\nu g^b_\mu g^c_\nu 
- {1\over4} g^2_s f^{abc} f^{ade} g^b_\mu g^c_\nu g^d_\mu g^e_\nu 
+ {1\over2} ig^2_s (\bar q^\sigma_i \gamma^\mu q^\sigma_j) g^a_\mu 
+ \bar G^a \partial^2 G^a + g_s f^{abc} \partial_\mu \bar G^a G^b g^c_\mu 
- \partial_\nu W^+_\mu \partial_\nu W^-_\mu - M^2 W^+_\mu W^-_\mu 
- {1\over2} \partial_\nu Z^0_\mu \partial_\nu Z^0_\mu 
- {1\over 2c^2_w} M^2 Z^0_\mu Z^0_\mu 
- {1\over2} \partial_\mu A_\nu \partial_\mu A_\nu 
- {1\over2} \partial_\mu H\partial_\mu H - {1\over2} m^2_h H^2
- \partial_\mu \phi^+ \partial_\mu \phi^- - M^2 \phi^+ \phi^-
- {1\over2} \partial_\mu \phi^0 \partial_\mu \phi^0 - {1\over 2c^2_w} M \phi^0 \phi^0
- \beta_h [{2M^2\over g^2} + {2M\over g} H + {1\over2} (H^2 + \phi^0 \phi^0 + 2\phi^+ \phi^-)]
+ {2M^4\over g^2}\alpha_h
- igc_w [\partial_\nu Z^0_\mu (W^+_\mu W^-_\nu - W^+_\nu W^-_\mu)
- Z^0_\nu (W^+_\mu \partial_\nu W^-_\mu - W^-_\mu \partial_\nu W^+_\mu)
+ Z^0_\mu (W^+_\nu \partial_\nu W^-_\mu -W^-_\nu \partial_\nu W^+_\mu )]
- igs_w [\partial_\nu A_\mu (W^+_\mu W^-_\nu - W^+_\nu W^-_\mu)
- A_\nu (W^+_\mu \partial_\nu W^-_\mu - W^-_\mu \partial_\nu W^+_\mu)
+ A_\mu (W^+_\nu \partial_\nu W^-_\mu - W^-_\nu \partial_\nu W^+_\mu)]
- {1\over2} g^2 W^+_\mu W^-_\mu W^+_\nu W^-_\nu 
+ {1\over2} g^2 W^+_\mu W^-_\nu W^+_\mu W^-_\nu 
+ g^2c^2_w (Z^0_\mu W^+_\mu Z^0_\nu W^-_\nu - Z^0_\mu Z^0_\mu W^+_\nu W^-_\nu)
+ g^2s^2_w (A_\mu W^+_\mu A_\nu W^-_\nu - A_\mu A_\mu W^+_\nu W^-_\nu)... 
\endinv

此外,如果您使用 Unicode-math,那么您的源代码将更具可读性:

\begininv
- {1\over2} ∂_ν g_µ^a ∂_ν g_µ^a - g_s f^{abc} ∂_µ g_ν^a g_µ^b g_ν^c -  ...
\endinv

请注意,您必须替换\mathchardef\plus=\mathcode +

\Umathcharnumdef\plus=\Umathcodenum`+

在这种情况下(对于 也类似\minus)。

相关内容