如何以编程方式在方程环境中插入新行?

如何以编程方式在方程环境中插入新行?

我有一个宏,它以几种不同的样式生成集合前体 {x|P(x)}。我的一些方程太长了,我想将它们拆分。我添加了代码,\\当宏被调用为 时,在这样的字符之后发出,但它在环境中因“ ”\set{x}[P(x)]*而失败。我有,,! Missing } inserted.multline\equant\intersection\union宏,\uquant它们成功发出了\\

为什么该代码对其他命令有效,但对 set 无效,并且是否有可行的解决方法可以在编号方程式环境中插入新行?

根据建议从星号中删除 和\left\right以及额外的一对。现在它呈现为 {elements|whitespace}。如果我删除{}\set{elements}[conditions]*\\,它会在条件中插入大量空格,但其他方面是正确的。

为了阐明我想做的事情,我想要一个命令,它可以将一组前者渲染成几种不同的房屋风格,放大{|}{:}根据操作数的渲染大小

第一版的跟踪输出和错误消息遵循原始示例文档。更正后的版本在最后

\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}

收到消息

.................................................
. 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}

已更正但仍然失败的版本:

\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}

答案1

您不能在\left\right成对或成{}组内中断,而您的代码似乎同时存在这两种情况。如果我修复了这个问题,它就可以正常运行,尽管中断位置似乎不是最佳的,但我并没有尝试在这里破译您的中断逻辑

在此处输入图片描述

\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} 

相关内容