0

I have a command that generates a long line in math mode, and want it to generate split lines in a multline environment when the command is called with an optional asterisk. The code for the split line renders the left and right hand sides properly, but the text in the middle comes out blank. If I remove the double backslash, then the missing text reappears but has a massive amount of embedded white space.

\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

The problem turns out to be that \\ and \scalerel alter the value of \l_tmpa_tl; if I recalculate it after each use of \\ and \scalerel then I get the output that I want.

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.