6

Is there a way to allow long math expressions to break automatically, whenever (and only) in situations where they extend beyond the body text of a document?

For example, I would like something like the following to break over two lines if (and only if) it finds itself in a narrow column of text (say, if <class> is IEEEtran), but otherwise remain on a single line (if, for example <class> is article), as long as it fits within a single (wider) column.

\documentclass{article}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\[ 
\hat{S}=\sum_{l\in\left\{ 1,\ldots L\right\} }\left[\bigl[1\!-\! f_{p}(l\!+\!1)\bigr]\;\overline{w}(l-1)\;\biggl[\,\prod_{i=0}^{l-1}\; f_{p}(i)\;\,\overline{\! N}(i)\biggr]\;\hat{H}_{S}(l-1)\right]
\]   
\lipsum[2]

\end{document}
  • 3
    I think the breqn package aims to do this... – cmhughes Mar 17 '12 at 19:14
  • @cmhughes: Is there an approach that avoids using an additional package (breqn sounds a bit disruptive)? – orome Mar 17 '12 at 19:26
  • @cmhughes: It looks like I need to redefine \[ to be \begin{dmath}` to use breqn. Is there a way to do that? – orome Mar 17 '12 at 23:42
  • 2
    @raxacoricofallapatorius: Automatic line breaking for math expressions is extremely difficult (algorithmically). It is much easier to use breqn rather than trying to implement that algorithm on your own. – Aditya Mar 18 '12 at 1:02
  • 1
    @raxacoricofallapatorius: (Untested), but that is something as simple as \let\[\dmath \let\]\enddmath. – Aditya Mar 18 '12 at 3:36
2

To combine some of the comments to the question, this answer uses the breqn package and redefines the \[ and \] commands as \begin{dmath} and \end{dmath}, respectively.

Code:

\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage[]{breqn}

\renewcommand\[{\begin{dmath}}
\renewcommand\]{\end{dmath}}

\begin{document}

\lipsum[1]
\[
\hat{S}=\sum_{l\in\left\{ 1,\ldots L\right\} }\left[\bigl[1\!-\! f_{p}(l\!+\!1)\bigr]\;\overline{w}(l-1)\;\biggl[\,\prod_{i=0}^{l-1}\; f_{p}(i)\;\,\overline{\! N}(i)\biggr]\;\hat{H}_{S}(l-1)\right]
\]
\lipsum[2]

\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.