为什么 scalerel 在多行编程环境中会产生错误输出

为什么 scalerel 在多行编程环境中会产生错误输出

我有一个命令可以在数学模式下生成长行,并且希望它在多行环境中使用可选星号调用该命令时生成分割线。分割线的代码可以正确呈现左侧和右侧,但中间的文本会显示为空白。如果我删除双反斜杠,则丢失的文本会重新出现,但会有大量嵌入的空白。

\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
        \\  % Remove the \\ and TeX renders the condition, but with massive white space
        right
%        \msg_term:n  {scalerel returns \scalerel{\g_style_set_sep_tl}{\g_tmpa_tl}}
        \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

问题原来是 \\ 和 \scalerel 改变了 \l_tmpa_tl 的值;如果我在每次使用 \\ 和 \scalerel 后重新计算它,那么我就会得到我想要的输出。

相关内容