Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
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)? –  raxacoricofallapatorius 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? –  raxacoricofallapatorius 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

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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