2

I have a macro that generates the set former {x|P(x)} in several different styles. Some of my equations are too long, and I would like to split them. I added code to emit \\ after the such that character when the macro is called as \set{x}[P(x)]*, but it fails with "! Missing } inserted." in the multline environment. I have \equant, \intersection, \union and \uquant macros that successfully emit the \\.

Why does the code work for the other commands but not for set, and is there a viable workaround to insert the new line in a numbered equation environment?

Remove \left, \right and extra {} pair from star case per suggestions. Now it renders \set{elements}[conditions]* as {elements|whitespace}. If I remove the \\ from the star case in the code, it inserts massive amounts of white space within the conditions but is other wise correct.

To clarify what I am trying to do, I want a command that will render a set former in several different house styles, enlarging the {|} or {:} characters based on the rendered sizes of the operands. I'd prefer using expl3 rather than native TeX.

Trace output and error messages from the first version follow the original sample document. The corrected version is at the end

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{scalerel}
\usepackage{xparse} % loads expl3
%See interface3.pdf

% --------------------------------------------------------------------
% | From here to closing --- belongs in package                      |
% |                                                                  |

\ExplSyntaxOn

\int_gzero_new:N \g_style_quant_parens_int
\int_gzero_new:N \g_style_quant_subscr_int
\int_gzero_new:N \g_style_set_subscr_int

\NewDocumentCommand{\equant}{mm}
  {
    \quant:nnn {\exists} {#1} {#2}
  }

\NewDocumentCommand{\uquant}{mm}
  {
    \quant:nnn {\forall} {#1} {#2}
  }

\NewDocumentCommand \setupquant {m}
  {
    \keys_set:nn {shmuel / quant} {#1}
  }

\keys_define:nn {shmuel / quant}
 {
  subscript            .choices:nn =
    {
      {
        none,
        stacked,
        multiple
      }
      {
        \int_gset:Nn \g_style_quant_subscr_int {\l_keys_choice_int-1}
      }
    },
  subscript            .default:n = multiple,
  subscript            .initial:n = none,
  parentheses          .choices:nn =
    {
      {
        none,
        single,
        multiple
      }
      {
        \int_gset:Nn \g_style_quant_parens_int {\l_keys_choice_int - 1}
      }
    },
  parentheses          .default:n = multiple,
  parentheses          .initial:n = none,
  separater            .tl_set:N = \g_style_quant_sep_tl,
  separater            .default:n = {.},
  separater            .initial:n = {}
 }

\cs_new:Npn \quant:nnn #1 #2 #3
  {
    %\int_show:N \g_style_quant_parens_int
    %\int_show:N \g_style_quant_subscr_int
    % g_style_quant_parens_int \ \int_use:N \g_style_quant_parens_int \
    % g_style_quant_subscr_int \ \int_use:N \g_style_quant_subscr_int \
    \clist_set:Nn \l_tmpa_clist {#2}
    \int_case:nn
      {\g_style_quant_subscr_int}
      {
        {0}
        {
          % No subscript
          % Set separater to ) ( quantifier or just quantifier
          \int_compare:nTF {\g_style_quant_parens_int = 2}
            {\tl_set:Nn \l_tmpa_tl {\right ) \left ( #1}}
            {\tl_set:Nn \l_tmpa_tl {#1}}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
          #1
          \clist_use:Nn \l_tmpa_clist {\l_tmpa_tl}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
          \g_style_quant_sep_tl #3
        }
        {1}
        {
          % Stacked subscript on single quantifier
          \fp_set:Nn \l_tmpa_fp {ceil{\clist_count:N{\l_tmpa_clist} - 1} * .2 + 1}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
          \scaleobj{\fp_to_decimal:N \l_tmpa_fp}{#1} \sb
             { \substack { \clist_use:Nn \l_tmpa_clist { \\ } } }
          \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
          #3
        }
        {2}
        {
          % Subscripts on separate quantifiers
          \clist_map_inline:Nn
            \l_tmpa_clist
            {
              % (quantifier \sb predicate) or quantifier \sb predicate
              {
                \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
                \scaleobj{1.2}{#1} \sb
                {##1}
                \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
              }
            }
          #3
        }
      }
  }

\NewDocumentCommand{\set}{mos}
  {
    \IfBooleanTF {#3}
    {
%      \msg_term:n {set with star}
%      \msg_term:n{{P1 #1}}
%      \msg_term:n{{P2 #2}}
      \bool_set_true:N \l_tmpa_bool
%      \bool_show:N \l_tmpa_bool
    }
    {
      \bool_set_false:N \l_tmpa_bool
    }
    \set_of:nnn {#1} {#2} {\l_tmpa_bool}
  }

%\tl_new:N \g_style_set_sep_tl
%\tl_gset:Nn \g_style_set_sep_tl {\mid}

\NewDocumentCommand \setupset {m}
  {
    \keys_set:nn {shmuel / set} {#1}
  }

\keys_define:nn {shmuel / set}
  {
    separater .tl_set:N = \g_style_set_sep_tl,
    subscript            .choices:nn =
      {
        {
          stacked,
          multiple
        }
        {
          \int_gset:Nn \g_style_set_subscr_int {\l_keys_choice_int-1}
        }
      },
    separater .initial:n = {\mid},
    subscript .initial:n = stacked
  }

\cs_new:Npn \set_of:nnn #1 #2 #3
  {
    \IfValueTF {#2}
    {
      \msg_log:n {set_of:nn \ has \ predicates \ #2}
    }
    {
      \msg_log:n {set_of:nn \ has \ no \ predicates}
    }
    \clist_set:Nn \l_tmpa_clist {#2}
    \msg_log:n {l_tmpa_clist \ set}
    \tl_set:Nn \l_tmpa_tl {\clist_use:Nn \l_tmpa_clist {\land}}
    \msg_log:n {l_tmpa_tl \ set \ to \ \l_tmpa_tl}
    \IfValueTF {#2}
    {
      {
        \left \{
        #1
        \scalerel{\g_style_set_sep_tl}{\mathbin{\l_tmpa_tl}}
        \bool_if:nT {#3}
        {{
          \\
        }}
        \right \}
      }
    }
    {
      {\left \{ #1 \right \}}
    }
  }

\NewDocumentCommand{\seqname}{m}
  {
    \seqname:n {#1}
  }

\cs_new:Npn \seqname:n #1
  {
    %code here \tl_count:n
    \int_compare:nTF {\tl_count:n{#1} > 1}
      {
        {\mathbf{#1}}
      }
      {
        {\bm {#1}}
      }
  }

\NewDocumentCommand{\intersection}{om}
  {
    \unint_of:nnn \bigcap {#1} {#2}
  }

\NewDocumentCommand{\union}{om}
  {
    \unint_of:nnn \bigcup {#1} {#2}
  }

\cs_new:Npn \unint_of:nnn #1 #2 #3
  {
    \IfValueTF {#3}
    {
%      \int_show:N \g_style_set_subscr_int
      \clist_set:Nn \l_tmpa_clist {#2}
      \int_case:nn
        {\g_style_set_subscr_int}
        {
          {0}
          {
            % Stacked subscript
%            \msg_term:n {\clist_count:N{\l_tmpa_clist} \ tokens \ stacked}
%            \clist_show:N \l_tmpa_clist
            \fp_set:Nn \l_tmpa_fp {ceil{\clist_count:N{\l_tmpa_clist} - 1} * .2 + 1}
            \scaleobj{\fp_to_decimal:N \l_tmpa_fp}{#1} \sb
            {\substack { \clist_use:Nn \l_tmpa_clist { \\ } }}
            #3
          }
          {1}
          {
            % Subscripts comma separated
%            \msg_term:n {\clist_count:N{\l_tmpa_clist} \ tokens \ comma \ separated}
%            \clist_show:N \l_tmpa_clist
            #1 \sb
            \clist_use:Nn \l_tmpa_clist {,}
          }
        }
    }
    {
      % No subscript
      \msg_term:n {No subscript}
      \clist_show:N \l_tmpa_clist
      #1 #3
    }
  }

\ExplSyntaxOff

% |                                                                  |
% | From opening to here --- belongs in package                      |

\begin{document}

\[ \set{x,y,z} \]

\[ \set{x}[P(x)] \]

\[ \set{x}[{{P(x)},{Q(x)}}] \]

\begin{multline}
\set{\phi \circ \phi'^{-1}}[\equant{{(U,V,\phi) \in A},{(U',V',\phi') \in A}}{V \cap V' \ne \emptyset}]*
\end{multline}

\end{document}

Got messages

.................................................
. set_of:nn has no predicates
.................................................
.................................................
. l_tmpa_clist set
.................................................
.................................................
. l_tmpa_tl set to -NoValue-
.................................................
.................................................
. set_of:nn has predicates P(x)
.................................................
.................................................
. l_tmpa_clist set
.................................................
.................................................
. l_tmpa_tl set to P(x)
.................................................
.................................................
. set_of:nn has predicates {P(x)},{Q(x)}
.................................................
.................................................
. l_tmpa_clist set
.................................................
.................................................
. l_tmpa_tl set to P(x)\land Q(x)
.................................................
.................................................
. set_of:nn has predicates \equant {{(U,V,\phi ) \in A},{(U',V',\phi ') \in
. A}}{V \cap V' \not =\emptyset }
.................................................
.................................................
. l_tmpa_clist set
.................................................
.................................................
. l_tmpa_tl set to \equant {{(U,V,\phi ) \in A},{(U',V',\phi ') \in A}}{V \cap
. V' \ne \emptyset }
.................................................

! Missing } inserted.
<inserted text>
                }
l.271 \end{multline}

Corrected, but still failing, version:

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{scalerel}
\usepackage{xparse} % loads expl3
%See interface3.pdf

% --------------------------------------------------------------------
% | From here to closing --- belongs in package                      |
% |                                                                  |

\ExplSyntaxOn

\int_gzero_new:N \g_style_quant_parens_int
\int_gzero_new:N \g_style_quant_subscr_int
\int_gzero_new:N \g_style_set_subscr_int

\NewDocumentCommand{\equant}{mm}
  {
    \quant:nnn {\exists} {#1} {#2}
  }

\NewDocumentCommand{\uquant}{mm}
  {
    \quant:nnn {\forall} {#1} {#2}
  }

\NewDocumentCommand \setupquant {m}
  {
    \keys_set:nn {shmuel / quant} {#1}
  }

\keys_define:nn {shmuel / quant}
 {
  subscript            .choices:nn =
    {
      {
        none,
        stacked,
        multiple
      }
      {
        \int_gset:Nn \g_style_quant_subscr_int {\l_keys_choice_int-1}
      }
    },
  subscript            .default:n = multiple,
  subscript            .initial:n = none,
  parentheses          .choices:nn =
    {
      {
        none,
        single,
        multiple
      }
      {
        \int_gset:Nn \g_style_quant_parens_int {\l_keys_choice_int - 1}
      }
    },
  parentheses          .default:n = multiple,
  parentheses          .initial:n = none,
  separater            .tl_set:N = \g_style_quant_sep_tl,
  separater            .default:n = {.},
  separater            .initial:n = {}
 }

\cs_new:Npn \quant:nnn #1 #2 #3
  {
    %\int_show:N \g_style_quant_parens_int
    %\int_show:N \g_style_quant_subscr_int
    % g_style_quant_parens_int \ \int_use:N \g_style_quant_parens_int \
    % g_style_quant_subscr_int \ \int_use:N \g_style_quant_subscr_int \
    \clist_set:Nn \l_tmpa_clist {#2}
    \int_case:nn
      {\g_style_quant_subscr_int}
      {
        {0}
        {
          % No subscript
          % Set separater to ) ( quantifier or just quantifier
          \int_compare:nTF {\g_style_quant_parens_int = 2}
            {\tl_set:Nn \l_tmpa_tl {\right ) \left ( #1}}
            {\tl_set:Nn \l_tmpa_tl {#1}}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
          #1
          \clist_use:Nn \l_tmpa_clist {\l_tmpa_tl}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
          \g_style_quant_sep_tl #3
        }
        {1}
        {
          % Stacked subscript on single quantifier
          \fp_set:Nn \l_tmpa_fp {ceil{\clist_count:N{\l_tmpa_clist} - 1} * .2 + 1}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
          \scaleobj{\fp_to_decimal:N \l_tmpa_fp}{#1} \sb
             { \substack { \clist_use:Nn \l_tmpa_clist { \\ } } }
          \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
          #3
        }
        {2}
        {
          % Subscripts on separate quantifiers
          \clist_map_inline:Nn
            \l_tmpa_clist
            {
              % (quantifier \sb predicate) or quantifier \sb predicate
              {
                \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
                \scaleobj{1.2}{#1} \sb
                {##1}
                \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
              }
            }
          #3
        }
      }
  }

\NewDocumentCommand{\set}{mos}
  {
    \IfBooleanTF {#3}
    {
%      \msg_term:n {set with star}
%      \msg_term:n{{P1 #1}}
%      \msg_term:n{{P2 #2}}
      \bool_set_true:N \l_tmpa_bool
%      \bool_show:N \l_tmpa_bool
    }
    {
      \bool_set_false:N \l_tmpa_bool
    }
    \set_of:nnn {#1} {#2} {\l_tmpa_bool}
  }

%\tl_new:N \g_style_set_sep_tl
%\tl_gset:Nn \g_style_set_sep_tl {\mid}

\NewDocumentCommand \setupset {m}
  {
    \keys_set:nn {shmuel / set} {#1}
  }

\keys_define:nn {shmuel / set}
  {
    separater .tl_set:N = \g_style_set_sep_tl,
    subscript            .choices:nn =
      {
        {
          stacked,
          multiple
        }
        {
          \int_gset:Nn \g_style_set_subscr_int {\l_keys_choice_int-1}
        }
      },
    separater .initial:n = {\mid},
    subscript .initial:n = stacked
  }

\cs_new:Npn \set_of:nnn #1 #2 #3
  {
    \IfValueTF {#2}
    {
      \msg_term:n {set_of:nn \ has \ predicates \ #2}
    }
    {
      \msg_term:n {set_of:nn \ has \ no \ predicates}
    }
    \clist_set:Nn \l_tmpa_clist {#2}
    \msg_term:n {l_tmpa_clist \ set}
    \tl_gset:Nn \g_tmpa_tl {\clist_use:Nn \l_tmpa_clist {\land}}
    \msg_term:n {g_tmpa_tl \ set \ to \ \g_tmpa_tl}
    \IfValueTF {#2}
    {
      \bool_if:nTF {#3}
      {
        \{
        #1
        \\
        \scalerel{\g_style_set_sep_tl}{\g_tmpa_tl}
%         \tl_show:N \g_tmpa_tl
        \}
      }
      {
        \left \{
        #1
        \scalerel{\g_style_set_sep_tl}{\g_tmpa_tl}
        \right \}
      }
    }
    {
      \left \{ #1 \right \}
    }
  }

\NewDocumentCommand{\seqname}{m}
  {
    \seqname:n {#1}
  }

\cs_new:Npn \seqname:n #1
  {
    %code here \tl_count:n
    \int_compare:nTF {\tl_count:n{#1} > 1}
      {
        {\mathbf{#1}}
      }
      {
        {\bm {#1}}
      }
  }

\NewDocumentCommand{\intersection}{om}
  {
    \unint_of:nnn \bigcap {#1} {#2}
  }

\NewDocumentCommand{\union}{om}
  {
    \unint_of:nnn \bigcup {#1} {#2}
  }

\cs_new:Npn \unint_of:nnn #1 #2 #3
  {
    \IfValueTF {#3}
    {
%      \int_show:N \g_style_set_subscr_int
      \clist_set:Nn \l_tmpa_clist {#2}
      \int_case:nn
        {\g_style_set_subscr_int}
        {
          {0}
          {
            % Stacked subscript
%            \msg_term:n {\clist_count:N{\l_tmpa_clist} \ tokens \ stacked}
%            \clist_show:N \l_tmpa_clist
            \fp_set:Nn \l_tmpa_fp {ceil{\clist_count:N{\l_tmpa_clist} - 1} * .2 + 1}
            \scaleobj{\fp_to_decimal:N \l_tmpa_fp}{#1} \sb
            {\substack { \clist_use:Nn \l_tmpa_clist { \\ } }}
            #3
          }
          {1}
          {
            % Subscripts comma separated
%            \msg_term:n {\clist_count:N{\l_tmpa_clist} \ tokens \ comma \ separated}
%            \clist_show:N \l_tmpa_clist
            #1 \sb
            \clist_use:Nn \l_tmpa_clist {,}
          }
        }
    }
    {
      % No subscript
      \msg_term:n {No subscript}
      \clist_show:N \l_tmpa_clist
      #1 #3
    }
  }

\ExplSyntaxOff

% |                                                                  |
% | From opening to here --- belongs in package                      |

\begin{document}
\setupquant{subscript=stacked}

\[ \set{x,y,z} \]

\[ \set{x}[P(x)] \]

\[ \set{x}[{{P(x)},{Q(x)}}] \]

\begin{multline}
\set
{
  {
  \phi \circ \phi'^{-1}
  }
}%
[
  {
  \equant
  {
    {(U,V,\phi) \in A},
    {(U',V',\phi') \in A}
  }
    {V \cap V' \ne \emptyset}
  }
]
\end{multline}

\begin{multline}
\set
{
  {
  \phi \circ \phi'^{-1}
  }
}%
[
  {
  \equant
  {
    {(U,V,\phi) \in A},
    {(U',V',\phi') \in A}
  }
    {V \cap V' \ne \emptyset}
  }
]*
\end{multline}

\end{document}
  • you can not break between \left and \right – David Carlisle Oct 31 '16 at 21:57
  • I originally had a single pair of braces around the \\; I added the second pair in an attempt to resolve the problem.I'll try removing the \left and \right, but that will create other problems, since the parameters may include big operators and it won't look right if the bracs are not enlarged. I'll update this after I try a few hacks. – shmuel Oct 31 '16 at 23:21
3

You can not break inside a \left\right pair or inside a {} group, and your code appears to have both. If I fix that it runs without error, although the break position seems suboptimal, but I didn't try to decipher your breaking logic here

enter image description here

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{scalerel}
\usepackage{xparse} % loads expl3
%See interface3.pdf

% --------------------------------------------------------------------
% | From here to closing --- belongs in package                      |
% |                                                                  |

\ExplSyntaxOn

\int_gzero_new:N \g_style_quant_parens_int
\int_gzero_new:N \g_style_quant_subscr_int
\int_gzero_new:N \g_style_set_subscr_int

\NewDocumentCommand{\equant}{mm}
  {
    \quant:nnn {\exists} {#1} {#2}
  }

\NewDocumentCommand{\uquant}{mm}
  {
    \quant:nnn {\forall} {#1} {#2}
  }

\NewDocumentCommand \setupquant {m}
  {
    \keys_set:nn {shmuel / quant} {#1}
  }

\keys_define:nn {shmuel / quant}
 {
  subscript            .choices:nn =
    {
      {
        none,
        stacked,
        multiple
      }
      {
        \int_gset:Nn \g_style_quant_subscr_int {\l_keys_choice_int-1}
      }
    },
  subscript            .default:n = multiple,
  subscript            .initial:n = none,
  parentheses          .choices:nn =
    {
      {
        none,
        single,
        multiple
      }
      {
        \int_gset:Nn \g_style_quant_parens_int {\l_keys_choice_int - 1}
      }
    },
  parentheses          .default:n = multiple,
  parentheses          .initial:n = none,
  separater            .tl_set:N = \g_style_quant_sep_tl,
  separater            .default:n = {.},
  separater            .initial:n = {}
 }

\cs_new:Npn \quant:nnn #1 #2 #3
  {
    %\int_show:N \g_style_quant_parens_int
    %\int_show:N \g_style_quant_subscr_int
    % g_style_quant_parens_int \ \int_use:N \g_style_quant_parens_int \
    % g_style_quant_subscr_int \ \int_use:N \g_style_quant_subscr_int \
    \clist_set:Nn \l_tmpa_clist {#2}
    \int_case:nn
      {\g_style_quant_subscr_int}
      {
        {0}
        {
          % No subscript
          % Set separater to ) ( quantifier or just quantifier
          \int_compare:nTF {\g_style_quant_parens_int = 2}
            {\tl_set:Nn \l_tmpa_tl {\right ) \left ( #1}}
            {\tl_set:Nn \l_tmpa_tl {#1}}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
          #1
          \clist_use:Nn \l_tmpa_clist {\l_tmpa_tl}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
          \g_style_quant_sep_tl #3
        }
        {1}
        {
          % Stacked subscript on single quantifier
          \fp_set:Nn \l_tmpa_fp {ceil{\clist_count:N{\l_tmpa_clist} - 1} * .2 + 1}
          \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
          \scaleobj{\fp_to_decimal:N \l_tmpa_fp}{#1} \sb
             { \substack { \clist_use:Nn \l_tmpa_clist { \\ } } }
          \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
          #3
        }
        {2}
        {
          % Subscripts on separate quantifiers
          \clist_map_inline:Nn
            \l_tmpa_clist
            {
              % (quantifier \sb predicate) or quantifier \sb predicate
              {
                \int_compare:nT {\g_style_quant_parens_int > 0} {\left (}
                \scaleobj{1.2}{#1} \sb
                {##1}
                \int_compare:nT {\g_style_quant_parens_int > 0} {\right )}
              }
            }
          #3
        }
      }
  }

\NewDocumentCommand{\set}{mos}
  {
    \IfBooleanTF {#3}
    {
%      \msg_term:n {set with star}
%      \msg_term:n{{P1 #1}}
%      \msg_term:n{{P2 #2}}
      \bool_set_true:N \l_tmpa_bool
%      \bool_show:N \l_tmpa_bool
    }
    {
      \bool_set_false:N \l_tmpa_bool
    }
    \set_of:nnn {#1} {#2} {\l_tmpa_bool}
  }

%\tl_new:N \g_style_set_sep_tl
%\tl_gset:Nn \g_style_set_sep_tl {\mid}

\NewDocumentCommand \setupset {m}
  {
    \keys_set:nn {shmuel / set} {#1}
  }

\keys_define:nn {shmuel / set}
  {
    separater .tl_set:N = \g_style_set_sep_tl,
    subscript            .choices:nn =
      {
        {
          stacked,
          multiple
        }
        {
          \int_gset:Nn \g_style_set_subscr_int {\l_keys_choice_int-1}
        }
      },
    separater .initial:n = {\mid},
    subscript .initial:n = stacked
  }

\cs_new:Npn \set_of:nnn #1 #2 #3
  {
    \IfValueTF {#2}
    {
      \msg_log:n {set_of:nn \ has \ predicates \ #2}
    }
    {
      \msg_log:n {set_of:nn \ has \ no \ predicates}
    }
    \clist_set:Nn \l_tmpa_clist {#2}
    \msg_log:n {l_tmpa_clist \ set}
    \tl_set:Nn \l_tmpa_tl {\clist_use:Nn \l_tmpa_clist {\land}}
    \msg_log:n {l_tmpa_tl \ set \ to \ \l_tmpa_tl}
    \IfValueTF {#2}
    {

        \left \{\vphantom{#1}\right.
        #1
        \scalerel{\g_style_set_sep_tl}{\mathbin{\l_tmpa_tl}}
        \bool_if:nT {#3}
        {
       \\
        }
        \left.\vphantom{#1}\right \}

    }
    {
      {\left \{ #1 \right \}}
    }
  }

\NewDocumentCommand{\seqname}{m}
  {
    \seqname:n {#1}
  }

\cs_new:Npn \seqname:n #1
  {
    %code here \tl_count:n
    \int_compare:nTF {\tl_count:n{#1} > 1}
      {
        {\mathbf{#1}}
      }
      {
        {\bm {#1}}
      }
  }

\NewDocumentCommand{\intersection}{om}
  {
    \unint_of:nnn \bigcap {#1} {#2}
  }

\NewDocumentCommand{\union}{om}
  {
    \unint_of:nnn \bigcup {#1} {#2}
  }

\cs_new:Npn \unint_of:nnn #1 #2 #3
  {
    \IfValueTF {#3}
    {
%      \int_show:N \g_style_set_subscr_int
      \clist_set:Nn \l_tmpa_clist {#2}
      \int_case:nn
        {\g_style_set_subscr_int}
        {
          {0}
          {
            % Stacked subscript
%            \msg_term:n {\clist_count:N{\l_tmpa_clist} \ tokens \ stacked}
%            \clist_show:N \l_tmpa_clist
            \fp_set:Nn \l_tmpa_fp {ceil{\clist_count:N{\l_tmpa_clist} - 1} * .2 + 1}
            \scaleobj{\fp_to_decimal:N \l_tmpa_fp}{#1} \sb
            {\substack { \clist_use:Nn \l_tmpa_clist { \\ } }}
            #3
          }
          {1}
          {
            % Subscripts comma separated
%            \msg_term:n {\clist_count:N{\l_tmpa_clist} \ tokens \ comma \ separated}
%            \clist_show:N \l_tmpa_clist
            #1 \sb
            \clist_use:Nn \l_tmpa_clist {,}
          }
        }
    }
    {
      % No subscript
      \msg_term:n {No subscript}
      \clist_show:N \l_tmpa_clist
      #1 #3
    }
  }

\ExplSyntaxOff

% |                                                                  |
% | From opening to here --- belongs in package                      |

\begin{document}

\[ \set{x,y,z} \]

\[ \set{x}[P(x)] \]

\[ \set{x}[{{P(x)},{Q(x)}}] \]

\begin{multline}
\set{\phi \circ \phi'^{-1}}[\equant{{(U,V,\phi) \in A},{(U',V',\phi') \in A}}{V \cap V' \ne \emptyset}]*
\end{multline}

\end{document} 
  • That solves the original problem. I've opened a new question to address two new problems. – shmuel Nov 14 '16 at 19:35

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.