# Automatically break a very large formula through multiple pages, using package breqn

I have a document which contains very large sets, consisting of hundreds of large numbers, which have to be represented as products of their prime factors. So I need to use dseries* environment of the breqn package, in order to prevent automatic line breaking in the middle of a product-expression. Here is my tex code of such a set:

\begin{dseries*}
$A_{1} = \{$
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math}
% and a few hundreds of more numbers
$\}$
\end{dseries*}


I have two problems with this code: The first and most important one is that the result pdf does not break through pages, and it seems to be an unbreakable box that must fit only into one page.

The second and less important problem is that I prefer Latex to add a little bit of indentation to the second line of the set and its following lines.

Please keep in mind that I need Latex to automatically break the set through pages, not to break it manually by a command like \newpage. I also need each number to not span more than one line, So I do have to use dseries* environment. Please help me solve this problem. Thanks in advance.

I can offer you a solution without breqn. The difference is that the multiplication sign will be, in case of a line break, at the end of the line. I don't think it's a big nuisance.

The idea is to define , to issue a “good break point” filling the line if a break is taken. Also \times is redefined so that, in case of a break after it, the following line is indented.

\documentclass{article}
\usepackage{showframe}

\newenvironment{longlist}
{
\par\nobreak\vspace{\abovedisplayskip}%
\begingroup\lccode~=, \lowercase{\endgroup\def~}{,\hfil\penalty0\hfilneg}%
\catcode,=\active
\let\originaltimes\times
\renewcommand{\times}{\originaltimes{}\discretionary{}{\kern1em}{}}%
\setlength{\parindent}{0pt}%
\hangindent=1em \hangafter=1
}
{\par\vspace{\belowdisplayskip}}

\begin{document}

\begin{longlist}
$A_{1} = \{$
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
\begin{math} 2 \times 3 \end{math},
\begin{math} 3^2 \times 5^2 \times 7^2 \end{math},
\begin{math} 2^6 \times 3^3 \times 19 \times 23 \times 29 \times 37 \times 43 \end{math},
\begin{math} 3^2 \times 5^2 \times 7 \times 17 \times 19 \times 23 \times 29 \times 37 \times 41 \times 47 \times 53 \end{math},
\begin{math} 2^5 \times 3 \times 5 \times 7^2 \times 11 \times 13 \times 19 \times 23 \times 29 \times 31 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \end{math},
\begin{math} 2^7 \times 3^4 \times 5^2 \times 7^2 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 \times 37 \times 41 \times 43 \times 47 \times 53 \times 97 \times 103 \times 257 \times 65537\end{math},
% and a few hundreds of more numbers
$\}$
\end{longlist}

\end{document}


If all the products fit on one line, the code can be modified so that no break is taken at \times, but only at commas.

• This is exactly what I needed. For future article modifications, I will need to insert even larger numbers that will span multiple lines, so they have to be broken down through several lines. Thank you very much dear @egreg. It was a great help. Apr 16 '20 at 22:32
• Dear @egreg, I changed \hangindent value to 3.4em`s so that all line beginnings of a set are vertically aligned. I also need two more things: first, the ending brace of all sets go to new lines, and second, the opening and closing braces of each set are vertically aligned. Is it possible to do so? Apr 17 '20 at 0:44