# Splitting a set over two lines

I am trying to include the following in my document:

$$\mathcal{C} = \{84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492, 555, 696, 708, 732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920, 936, 948, 952, 984, 996\}$$.


However, it continues on one line. How do I fix this so it splits into multiple lines? If possible, I would like the parenthesis to surround all lines.

• Possible duplicate of How can I split an equation over two lines – Werner Apr 2 '17 at 16:20
• Comment aside: don't use $$…$$ for displayed equations. This is plain TeX syntax, and it cant lead to bad spacings. – Bernard Apr 2 '17 at 16:32
• @Bernard "can" not "cant" and in fact does depending on circumstances (and doesn't obey "fleqn" etc) – Frank Mittelbach Apr 2 '17 at 21:31
• @Frank Mittelbach: One of my (too) many typos. It 's precisely because it depends on the context that I didn't write ‘it leads’? I agree ‘it can't’ is especially unfortunate in my comment. – Bernard Apr 2 '17 at 21:44

You can let TeX compute the line breaks.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\usepackage{lipsum} % just for the example

\ExplSyntaxOn
\NewDocumentCommand{\longset}{mm}
{
\begin{gathered}
\egreg_longset:nn { #1 } { #2 }
\end{gathered}
}

\box_new:N \l_egreg_longset_set_box
\seq_new:N \l_egreg_longset_elements_seq

\cs_new_protected:Nn \egreg_longset:nn
{
% measure the left hand side (with the open brace)
\hbox_set:Nn \l_egreg_longset_set_box { $#1=\lbrace\,$ }
% typeset the left hand side and the open brace
#1 = \lbrace\,
% add a minipage, the width is \displaywidth, minus the left hand side
% minus 4em to have space for the equation number
\begin{minipage}[t]
{
\dim_eval:n { \displaywidth - \box_wd:N \l_egreg_longset_set_box - 4em }
}
% add some stretching to \thinmuskip
\muskip_set:Nn \thinmuskip { 1\thinmuskip plus 5mu }
% split the input at commas
\seq_set_from_clist:Nn \l_egreg_longset_elements_seq { #2 }
% use the items, adding back the comma, followed by a penalty
% so a line break can be taken
$\seq_use:Nn \l_egreg_longset_elements_seq { , \penalty0~ }\,\rbrace$
% the end
\end{minipage}
}
\ExplSyntaxOff

\begin{document}

\lipsum*[2]
\begin{equation*}$$\longset{\mathcal{C}}{ 84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492, 555, 696, 708,732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920, 936, 948, 952, 984, 996 }$$\end{equation*}
\lipsum*[3]
$$\longset{\mathcal{C}}{ 84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492, 555, 696, 708,732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920, 936, 948, 952, 984, 996 }$$
\lipsum[4]

\end{document}


\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\mathcal{C} = \{\,
& 84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492, \\
& 555, 696, 708,732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920, \\
& 936, 948, 952, 984, 996\,\}\enspace.
\end{align*}
\end{document}