# breqn does not automatically break lines

I am writing a two column journal in which I am listing the components of a vector. The vector is too long to fit in one column, and I am using the \left and \right around the brackets that enclose the vector. However the dmath environment does not automatically break the vector into two lines. The code is listed below

 \begin{dmath}
\left(\frac{-(n-1)}{2}h_{12}l,\ldots,\frac{-3}{2}h_{12}l,\frac{-1}{2}h_{12}l, \frac{1}{2}h_{12}l,\frac{3}{2}h_{12}l,
\ldots,\frac{n-1}{2}h_{12}l\right). \label{eq:x2}
\end{dmath}


The output looks like this

Any one has an idea how to correct this?

EDIT: The preamble of my document is listed below

\documentclass[journal]{IEEEtran}

\usepackage{cite}
\ifCLASSINFOpdf
\usepackage[pdftex]{graphicx}
% declare the path(s) where your graphic files are
\graphicspath{{../figs/}}
\else
\usepackage[dvips]{graphicx}
% declare the path(s) where your graphic files are
\graphicspath{{../figs/}}
\fi
% *** MATH PACKAGES ***
\usepackage[cmex10]{amsmath}
\interdisplaylinepenalty=2500
\usepackage[caption=false,font=footnotesize]{subfig}
\usepackage{url}
\usepackage{breqn}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\section{Some Random Section}
\begin{dmath}
\left(\frac{-(n-1)}{2}h_{12}l,\ldots,\frac{-3}{2}h_{12}l,\frac{-1}{2}h_{12}l, \frac{1}{2}h_{12}l,\frac{3}{2}h_{12}l,
\ldots,\frac{n-1}{2}h_{12}l\right). \label{eq:x2}
\end{dmath}
\end{document}


Hopefully this helps!

-
All the code from \ifCLASSINFOpdf to \fi (included) can safely be replaced simply by \usepackage{graphicx}\graphicspath{{../figs/}}. If the manual says differently, don't trust it. :) –  egreg Jun 21 '12 at 22:26
These are the template codes that are provided by IEEEtran.sty author. This template is written in 2007. So I guess the codes are a bit outdated. –  Rich Jun 22 '12 at 20:03

breqn won't break after commas and ordinary atoms, so your formula has no feasible break point. You have to help breqn telling it that, in this case, breaking at commas is allowed.

\documentclass{article}
\textwidth=.7\textwidth % just to show the result

\newcommand{\breakingcomma}{%
\begingroup\lccode~=,
\lowercase{\endgroup\expandafter\def\expandafter~\expandafter{~\penalty0 }}}

\usepackage{breqn}
\begin{document}

\begin{dmath}\breakingcomma
\left(\frac{-(n-1)}{2}h_{12}l,\ldots,\frac{-3}{2}h_{12}l,
\frac{-1}{2}h_{12}l, \frac{1}{2}h_{12}l,\frac{3}{2}h_{12}l,
\ldots,\frac{n-1}{2}h_{12}l\right). \label{eq:x2}
\end{dmath}

\end{document}


I wouldn't make the change permanent: this would break the other formulas in unsuitable places.

-

It works if you use + rather than , so this just makes comma work like plus. Note This also makes , have the spacing of a binary operator like +.

I suspect it isn't quite the official breqn interface, but....

\documentclass{article}

\usepackage{breqn}

\textwidth.5\textwidth

\begin{document}

{\catcode+\active
\def\foo#1#2#3#4#5{%
\def\tmp{#1,#3#4{2C}}}
\expandafter\foo+
\catcode,\active
\global\let,\tmp
}

\noindent X\dotfill X

\begin{dmath}
\left(\frac{-(n-1)}{2}h_{12}l,\ldots,\frac{-3}{2}h_{12}l,\frac{-1}{2}h_{12}l, \frac{1}{2}h_{12}l,\frac{3}{2}h_{12}l,
\ldots,\frac{n-1}{2}h_{12}l\right) \label{eq:x2}
\end{dmath}

\noindent X\dotfill X

\end{document}


As pointed out by @egreg in chat, the fancy redefinition isn't needed and a better solution that doesn't globally redefine comma to be a binary operator is just to explictly allow a break after some (or all) of the commas:

\begin{dmath}
\left(\frac{-(n-1)}{2}h_{12}l,\penalty0 \ldots,\penalty0 \frac{-3}{2}h_{12}l,\penalty0 \frac{-1}{2}h_{12}l,\penalty0  \frac{1}{2}h_{12}l,\penalty0 \frac{3}{2}h_{12}l,\penalty0
\ldots,\penalty0 \frac{n-1}{2}h_{12}l\right) \label{eq:x2}
\end{dmath}

-
I don't quite understand the part starting with {\catcode+\active.... are those pure TeX code instead of LaTeX code? Can you briefly explain what they do? –  Rich Jun 21 '12 at 21:32
It's probably best not to ask:-) But it expands the definition of + (after breqn has redefined it to allow breaking) which it turns out is 5 tokens one of which is + and one is {2B}` which is the hex code for plus. The code then defines , to be the same definition but with , replacing + and 2C (the hex code for comma) replacing 2B, –  David Carlisle Jun 21 '12 at 21:46