Prevent xparse from stripping braces?











up vote
2
down vote

favorite












So I'm trying to implement a COOL-style Sum macro which is supposed to support the following syntax:



Sum{ldots}  % -> sum ldots
Sum[i]{ldots} % -> sum_{i} ldots
Sum[i in I]{ldots} % -> sum_{i in I} ldots
Sum[i, 0, N]{ldots} % -> sum_{i=0}^{N} ldots
Sum[{i,j}, 0, N]{ldots} % -> sum_{i,j=0}^{N} ldots
Sum[{i,j,k}]{ldots} % -> sum_{i,j,k} ldots


The important bit is that I would like braces to protect commas in the first argument. The actual implementation is in expl3 with the user interface using xparse. Unfortunately, xparse appears to always strip braces inside arguments if they surround the whole argument such that this protection will not work in all cases, no matter what my internal code does. Looking at the docs, I couldn't find a way to prevent this.



I tried macros signatures of the forms



DeclareDocumentCommand Sum { s >{ SplitArgument{2}{,} } o m }
{ ... }
DeclareDocumentCommand Sum { s o m }
{ ... }


Am I missing something here, is there a (undocumented) way to make xparse not strip such braces short of circumventing xparse and implementing the interface manually (maybe using argument processors?)? If not, would this warrant a bug report/feature request at the latex github?










share|improve this question






















  • Not a solution: You could input Sum[{{i,j,k}}]{ldots}.
    – Skillmon
    2 hours ago






  • 2




    Why not simply using ; as delimiter? You would need no braces.
    – egreg
    2 hours ago

















up vote
2
down vote

favorite












So I'm trying to implement a COOL-style Sum macro which is supposed to support the following syntax:



Sum{ldots}  % -> sum ldots
Sum[i]{ldots} % -> sum_{i} ldots
Sum[i in I]{ldots} % -> sum_{i in I} ldots
Sum[i, 0, N]{ldots} % -> sum_{i=0}^{N} ldots
Sum[{i,j}, 0, N]{ldots} % -> sum_{i,j=0}^{N} ldots
Sum[{i,j,k}]{ldots} % -> sum_{i,j,k} ldots


The important bit is that I would like braces to protect commas in the first argument. The actual implementation is in expl3 with the user interface using xparse. Unfortunately, xparse appears to always strip braces inside arguments if they surround the whole argument such that this protection will not work in all cases, no matter what my internal code does. Looking at the docs, I couldn't find a way to prevent this.



I tried macros signatures of the forms



DeclareDocumentCommand Sum { s >{ SplitArgument{2}{,} } o m }
{ ... }
DeclareDocumentCommand Sum { s o m }
{ ... }


Am I missing something here, is there a (undocumented) way to make xparse not strip such braces short of circumventing xparse and implementing the interface manually (maybe using argument processors?)? If not, would this warrant a bug report/feature request at the latex github?










share|improve this question






















  • Not a solution: You could input Sum[{{i,j,k}}]{ldots}.
    – Skillmon
    2 hours ago






  • 2




    Why not simply using ; as delimiter? You would need no braces.
    – egreg
    2 hours ago















up vote
2
down vote

favorite









up vote
2
down vote

favorite











So I'm trying to implement a COOL-style Sum macro which is supposed to support the following syntax:



Sum{ldots}  % -> sum ldots
Sum[i]{ldots} % -> sum_{i} ldots
Sum[i in I]{ldots} % -> sum_{i in I} ldots
Sum[i, 0, N]{ldots} % -> sum_{i=0}^{N} ldots
Sum[{i,j}, 0, N]{ldots} % -> sum_{i,j=0}^{N} ldots
Sum[{i,j,k}]{ldots} % -> sum_{i,j,k} ldots


The important bit is that I would like braces to protect commas in the first argument. The actual implementation is in expl3 with the user interface using xparse. Unfortunately, xparse appears to always strip braces inside arguments if they surround the whole argument such that this protection will not work in all cases, no matter what my internal code does. Looking at the docs, I couldn't find a way to prevent this.



I tried macros signatures of the forms



DeclareDocumentCommand Sum { s >{ SplitArgument{2}{,} } o m }
{ ... }
DeclareDocumentCommand Sum { s o m }
{ ... }


Am I missing something here, is there a (undocumented) way to make xparse not strip such braces short of circumventing xparse and implementing the interface manually (maybe using argument processors?)? If not, would this warrant a bug report/feature request at the latex github?










share|improve this question













So I'm trying to implement a COOL-style Sum macro which is supposed to support the following syntax:



Sum{ldots}  % -> sum ldots
Sum[i]{ldots} % -> sum_{i} ldots
Sum[i in I]{ldots} % -> sum_{i in I} ldots
Sum[i, 0, N]{ldots} % -> sum_{i=0}^{N} ldots
Sum[{i,j}, 0, N]{ldots} % -> sum_{i,j=0}^{N} ldots
Sum[{i,j,k}]{ldots} % -> sum_{i,j,k} ldots


The important bit is that I would like braces to protect commas in the first argument. The actual implementation is in expl3 with the user interface using xparse. Unfortunately, xparse appears to always strip braces inside arguments if they surround the whole argument such that this protection will not work in all cases, no matter what my internal code does. Looking at the docs, I couldn't find a way to prevent this.



I tried macros signatures of the forms



DeclareDocumentCommand Sum { s >{ SplitArgument{2}{,} } o m }
{ ... }
DeclareDocumentCommand Sum { s o m }
{ ... }


Am I missing something here, is there a (undocumented) way to make xparse not strip such braces short of circumventing xparse and implementing the interface manually (maybe using argument processors?)? If not, would this warrant a bug report/feature request at the latex github?







xparse






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









Wisperwind

1455




1455












  • Not a solution: You could input Sum[{{i,j,k}}]{ldots}.
    – Skillmon
    2 hours ago






  • 2




    Why not simply using ; as delimiter? You would need no braces.
    – egreg
    2 hours ago




















  • Not a solution: You could input Sum[{{i,j,k}}]{ldots}.
    – Skillmon
    2 hours ago






  • 2




    Why not simply using ; as delimiter? You would need no braces.
    – egreg
    2 hours ago


















Not a solution: You could input Sum[{{i,j,k}}]{ldots}.
– Skillmon
2 hours ago




Not a solution: You could input Sum[{{i,j,k}}]{ldots}.
– Skillmon
2 hours ago




2




2




Why not simply using ; as delimiter? You would need no braces.
– egreg
2 hours ago






Why not simply using ; as delimiter? You would need no braces.
– egreg
2 hours ago












3 Answers
3






active

oldest

votes

















up vote
2
down vote













You can trick this by inserting another token after the opening bracket if there is one (proof of concept like answer). Replace Wisperwind_Sum_original_code:nnn with your original code to typeset the sum (including the handling of the optional star with IfBooleanTF).



documentclass{article}

usepackage{xparse}
ExplSyntaxOn
tl_new:N l_Wisperwind_tl
clist_new:N l_Wisperwind_clist
NewDocumentCommand Sum { s t[ }
{
IfBooleanTF { #2 }
{ Sum_two { #1 } [ ~ }
{ Sum_two { #1 } }
}
NewDocumentCommand Sum_two { m O{~} m }
{
tl_set:Nn l_Wisperwind_tl { #2 }
tl_remove_once:Nn l_Wisperwind_tl { ~ }
Wisperwind_Sum_original_code:nVn { #1 } l_Wisperwind_tl { #3 }
}
cs_new:Npn Wisperwind_Sum_original_code:nnn #1 #2 #3
{
sum
clist_set:Nn l_Wisperwind_clist { #2 }
int_case:nn { clist_count:N l_Wisperwind_clist }
{
{ 1 } { sb { clist_item:Nn l_Wisperwind_clist { c_one_int } } }
{ 2 }
{
sb { clist_item:Nn l_Wisperwind_clist { c_one_int } }
sp { clist_item:Nn l_Wisperwind_clist { 2 } }
}
{ 3 }
{
sb
{
clist_item:Nn l_Wisperwind_clist { c_one_int }
=
clist_item:Nn l_Wisperwind_clist { 2 }
}
sp { clist_item:Nn l_Wisperwind_clist { 3 } }
}
}
#3
}
cs_generate_variant:Nn Wisperwind_Sum_original_code:nnn { nVn }
ExplSyntaxOff

begin{document}
$Sum{ldots}$ % -> sum ldots
$Sum[i]{ldots}$ % -> sum_{i} ldots
$Sum[i in I]{ldots}$ % -> sum_{i in I} ldots
$Sum[i, 0, N]{ldots}$ % -> sum_{i=0}^{N} ldots
$Sum[{i,j}, 0, N]{ldots}$ % -> sum_{i,j=0}^{N} ldots
$Sum[{i,j,k}]{ldots}$ % -> sum_{i,j,k} ldots
end{document}


enter image description here






share|improve this answer




























    up vote
    2
    down vote













    Here using LaTeX2e:



    documentclass{article}
    usepackage{listofitems}
    makeatletter
    newcommandSum{@ifnextchar[{Sumaux[@gobble}{sum}}
    makeatother
    defSumaux[#1]#2{
    sum
    setsepchar{,}
    readlistsumargs{#1}
    ifnumlistlensumargs>1relax
    _{sumargs[1]=sumargs[2]}
    ifnumlistlensumargs>2relax^sumargs[3]fi
    else
    _{sumargs[1]}
    fi
    #2
    }
    begin{document}
    [Sum{ldots} ]% -> sum ldots
    [Sum[i]{ldots} ]% -> sum_{i} ldots
    [Sum[i in I]{ldots} ]% -> sum_{i in I} ldots
    [Sum[i, 0, N]{ldots} ]% -> sum_{i=0}^{N} ldots
    [Sum[{i,j}, 0, N]{ldots} ]% -> sum_{i,j=0}^{N} ldots
    [Sum[{i,j,k}]{ldots} ]% -> sum_{i,j,k} ldots
    end{document}


    enter image description here






    share|improve this answer




























      up vote
      0
      down vote













      The brace stripping is quite deliberate as newcommand-generated commands requires braces for the case



      foo[{]}]{bar}


      whereas xparse-generated ones do not. Without brace stripping,



      foo[{bar}]


      and



      foo[bar]


      could be treated differently.



      In your case, you have a comma list with one entry. The obvious solution is to provide a second, empty, entry



      Sum[{i,j},]{ldots}


      as this is a no-op.





      share





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "85"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f465970%2fprevent-xparse-from-stripping-braces%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote













        You can trick this by inserting another token after the opening bracket if there is one (proof of concept like answer). Replace Wisperwind_Sum_original_code:nnn with your original code to typeset the sum (including the handling of the optional star with IfBooleanTF).



        documentclass{article}

        usepackage{xparse}
        ExplSyntaxOn
        tl_new:N l_Wisperwind_tl
        clist_new:N l_Wisperwind_clist
        NewDocumentCommand Sum { s t[ }
        {
        IfBooleanTF { #2 }
        { Sum_two { #1 } [ ~ }
        { Sum_two { #1 } }
        }
        NewDocumentCommand Sum_two { m O{~} m }
        {
        tl_set:Nn l_Wisperwind_tl { #2 }
        tl_remove_once:Nn l_Wisperwind_tl { ~ }
        Wisperwind_Sum_original_code:nVn { #1 } l_Wisperwind_tl { #3 }
        }
        cs_new:Npn Wisperwind_Sum_original_code:nnn #1 #2 #3
        {
        sum
        clist_set:Nn l_Wisperwind_clist { #2 }
        int_case:nn { clist_count:N l_Wisperwind_clist }
        {
        { 1 } { sb { clist_item:Nn l_Wisperwind_clist { c_one_int } } }
        { 2 }
        {
        sb { clist_item:Nn l_Wisperwind_clist { c_one_int } }
        sp { clist_item:Nn l_Wisperwind_clist { 2 } }
        }
        { 3 }
        {
        sb
        {
        clist_item:Nn l_Wisperwind_clist { c_one_int }
        =
        clist_item:Nn l_Wisperwind_clist { 2 }
        }
        sp { clist_item:Nn l_Wisperwind_clist { 3 } }
        }
        }
        #3
        }
        cs_generate_variant:Nn Wisperwind_Sum_original_code:nnn { nVn }
        ExplSyntaxOff

        begin{document}
        $Sum{ldots}$ % -> sum ldots
        $Sum[i]{ldots}$ % -> sum_{i} ldots
        $Sum[i in I]{ldots}$ % -> sum_{i in I} ldots
        $Sum[i, 0, N]{ldots}$ % -> sum_{i=0}^{N} ldots
        $Sum[{i,j}, 0, N]{ldots}$ % -> sum_{i,j=0}^{N} ldots
        $Sum[{i,j,k}]{ldots}$ % -> sum_{i,j,k} ldots
        end{document}


        enter image description here






        share|improve this answer

























          up vote
          2
          down vote













          You can trick this by inserting another token after the opening bracket if there is one (proof of concept like answer). Replace Wisperwind_Sum_original_code:nnn with your original code to typeset the sum (including the handling of the optional star with IfBooleanTF).



          documentclass{article}

          usepackage{xparse}
          ExplSyntaxOn
          tl_new:N l_Wisperwind_tl
          clist_new:N l_Wisperwind_clist
          NewDocumentCommand Sum { s t[ }
          {
          IfBooleanTF { #2 }
          { Sum_two { #1 } [ ~ }
          { Sum_two { #1 } }
          }
          NewDocumentCommand Sum_two { m O{~} m }
          {
          tl_set:Nn l_Wisperwind_tl { #2 }
          tl_remove_once:Nn l_Wisperwind_tl { ~ }
          Wisperwind_Sum_original_code:nVn { #1 } l_Wisperwind_tl { #3 }
          }
          cs_new:Npn Wisperwind_Sum_original_code:nnn #1 #2 #3
          {
          sum
          clist_set:Nn l_Wisperwind_clist { #2 }
          int_case:nn { clist_count:N l_Wisperwind_clist }
          {
          { 1 } { sb { clist_item:Nn l_Wisperwind_clist { c_one_int } } }
          { 2 }
          {
          sb { clist_item:Nn l_Wisperwind_clist { c_one_int } }
          sp { clist_item:Nn l_Wisperwind_clist { 2 } }
          }
          { 3 }
          {
          sb
          {
          clist_item:Nn l_Wisperwind_clist { c_one_int }
          =
          clist_item:Nn l_Wisperwind_clist { 2 }
          }
          sp { clist_item:Nn l_Wisperwind_clist { 3 } }
          }
          }
          #3
          }
          cs_generate_variant:Nn Wisperwind_Sum_original_code:nnn { nVn }
          ExplSyntaxOff

          begin{document}
          $Sum{ldots}$ % -> sum ldots
          $Sum[i]{ldots}$ % -> sum_{i} ldots
          $Sum[i in I]{ldots}$ % -> sum_{i in I} ldots
          $Sum[i, 0, N]{ldots}$ % -> sum_{i=0}^{N} ldots
          $Sum[{i,j}, 0, N]{ldots}$ % -> sum_{i,j=0}^{N} ldots
          $Sum[{i,j,k}]{ldots}$ % -> sum_{i,j,k} ldots
          end{document}


          enter image description here






          share|improve this answer























            up vote
            2
            down vote










            up vote
            2
            down vote









            You can trick this by inserting another token after the opening bracket if there is one (proof of concept like answer). Replace Wisperwind_Sum_original_code:nnn with your original code to typeset the sum (including the handling of the optional star with IfBooleanTF).



            documentclass{article}

            usepackage{xparse}
            ExplSyntaxOn
            tl_new:N l_Wisperwind_tl
            clist_new:N l_Wisperwind_clist
            NewDocumentCommand Sum { s t[ }
            {
            IfBooleanTF { #2 }
            { Sum_two { #1 } [ ~ }
            { Sum_two { #1 } }
            }
            NewDocumentCommand Sum_two { m O{~} m }
            {
            tl_set:Nn l_Wisperwind_tl { #2 }
            tl_remove_once:Nn l_Wisperwind_tl { ~ }
            Wisperwind_Sum_original_code:nVn { #1 } l_Wisperwind_tl { #3 }
            }
            cs_new:Npn Wisperwind_Sum_original_code:nnn #1 #2 #3
            {
            sum
            clist_set:Nn l_Wisperwind_clist { #2 }
            int_case:nn { clist_count:N l_Wisperwind_clist }
            {
            { 1 } { sb { clist_item:Nn l_Wisperwind_clist { c_one_int } } }
            { 2 }
            {
            sb { clist_item:Nn l_Wisperwind_clist { c_one_int } }
            sp { clist_item:Nn l_Wisperwind_clist { 2 } }
            }
            { 3 }
            {
            sb
            {
            clist_item:Nn l_Wisperwind_clist { c_one_int }
            =
            clist_item:Nn l_Wisperwind_clist { 2 }
            }
            sp { clist_item:Nn l_Wisperwind_clist { 3 } }
            }
            }
            #3
            }
            cs_generate_variant:Nn Wisperwind_Sum_original_code:nnn { nVn }
            ExplSyntaxOff

            begin{document}
            $Sum{ldots}$ % -> sum ldots
            $Sum[i]{ldots}$ % -> sum_{i} ldots
            $Sum[i in I]{ldots}$ % -> sum_{i in I} ldots
            $Sum[i, 0, N]{ldots}$ % -> sum_{i=0}^{N} ldots
            $Sum[{i,j}, 0, N]{ldots}$ % -> sum_{i,j=0}^{N} ldots
            $Sum[{i,j,k}]{ldots}$ % -> sum_{i,j,k} ldots
            end{document}


            enter image description here






            share|improve this answer












            You can trick this by inserting another token after the opening bracket if there is one (proof of concept like answer). Replace Wisperwind_Sum_original_code:nnn with your original code to typeset the sum (including the handling of the optional star with IfBooleanTF).



            documentclass{article}

            usepackage{xparse}
            ExplSyntaxOn
            tl_new:N l_Wisperwind_tl
            clist_new:N l_Wisperwind_clist
            NewDocumentCommand Sum { s t[ }
            {
            IfBooleanTF { #2 }
            { Sum_two { #1 } [ ~ }
            { Sum_two { #1 } }
            }
            NewDocumentCommand Sum_two { m O{~} m }
            {
            tl_set:Nn l_Wisperwind_tl { #2 }
            tl_remove_once:Nn l_Wisperwind_tl { ~ }
            Wisperwind_Sum_original_code:nVn { #1 } l_Wisperwind_tl { #3 }
            }
            cs_new:Npn Wisperwind_Sum_original_code:nnn #1 #2 #3
            {
            sum
            clist_set:Nn l_Wisperwind_clist { #2 }
            int_case:nn { clist_count:N l_Wisperwind_clist }
            {
            { 1 } { sb { clist_item:Nn l_Wisperwind_clist { c_one_int } } }
            { 2 }
            {
            sb { clist_item:Nn l_Wisperwind_clist { c_one_int } }
            sp { clist_item:Nn l_Wisperwind_clist { 2 } }
            }
            { 3 }
            {
            sb
            {
            clist_item:Nn l_Wisperwind_clist { c_one_int }
            =
            clist_item:Nn l_Wisperwind_clist { 2 }
            }
            sp { clist_item:Nn l_Wisperwind_clist { 3 } }
            }
            }
            #3
            }
            cs_generate_variant:Nn Wisperwind_Sum_original_code:nnn { nVn }
            ExplSyntaxOff

            begin{document}
            $Sum{ldots}$ % -> sum ldots
            $Sum[i]{ldots}$ % -> sum_{i} ldots
            $Sum[i in I]{ldots}$ % -> sum_{i in I} ldots
            $Sum[i, 0, N]{ldots}$ % -> sum_{i=0}^{N} ldots
            $Sum[{i,j}, 0, N]{ldots}$ % -> sum_{i,j=0}^{N} ldots
            $Sum[{i,j,k}]{ldots}$ % -> sum_{i,j,k} ldots
            end{document}


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 1 hour ago









            Skillmon

            20.8k11941




            20.8k11941






















                up vote
                2
                down vote













                Here using LaTeX2e:



                documentclass{article}
                usepackage{listofitems}
                makeatletter
                newcommandSum{@ifnextchar[{Sumaux[@gobble}{sum}}
                makeatother
                defSumaux[#1]#2{
                sum
                setsepchar{,}
                readlistsumargs{#1}
                ifnumlistlensumargs>1relax
                _{sumargs[1]=sumargs[2]}
                ifnumlistlensumargs>2relax^sumargs[3]fi
                else
                _{sumargs[1]}
                fi
                #2
                }
                begin{document}
                [Sum{ldots} ]% -> sum ldots
                [Sum[i]{ldots} ]% -> sum_{i} ldots
                [Sum[i in I]{ldots} ]% -> sum_{i in I} ldots
                [Sum[i, 0, N]{ldots} ]% -> sum_{i=0}^{N} ldots
                [Sum[{i,j}, 0, N]{ldots} ]% -> sum_{i,j=0}^{N} ldots
                [Sum[{i,j,k}]{ldots} ]% -> sum_{i,j,k} ldots
                end{document}


                enter image description here






                share|improve this answer

























                  up vote
                  2
                  down vote













                  Here using LaTeX2e:



                  documentclass{article}
                  usepackage{listofitems}
                  makeatletter
                  newcommandSum{@ifnextchar[{Sumaux[@gobble}{sum}}
                  makeatother
                  defSumaux[#1]#2{
                  sum
                  setsepchar{,}
                  readlistsumargs{#1}
                  ifnumlistlensumargs>1relax
                  _{sumargs[1]=sumargs[2]}
                  ifnumlistlensumargs>2relax^sumargs[3]fi
                  else
                  _{sumargs[1]}
                  fi
                  #2
                  }
                  begin{document}
                  [Sum{ldots} ]% -> sum ldots
                  [Sum[i]{ldots} ]% -> sum_{i} ldots
                  [Sum[i in I]{ldots} ]% -> sum_{i in I} ldots
                  [Sum[i, 0, N]{ldots} ]% -> sum_{i=0}^{N} ldots
                  [Sum[{i,j}, 0, N]{ldots} ]% -> sum_{i,j=0}^{N} ldots
                  [Sum[{i,j,k}]{ldots} ]% -> sum_{i,j,k} ldots
                  end{document}


                  enter image description here






                  share|improve this answer























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    Here using LaTeX2e:



                    documentclass{article}
                    usepackage{listofitems}
                    makeatletter
                    newcommandSum{@ifnextchar[{Sumaux[@gobble}{sum}}
                    makeatother
                    defSumaux[#1]#2{
                    sum
                    setsepchar{,}
                    readlistsumargs{#1}
                    ifnumlistlensumargs>1relax
                    _{sumargs[1]=sumargs[2]}
                    ifnumlistlensumargs>2relax^sumargs[3]fi
                    else
                    _{sumargs[1]}
                    fi
                    #2
                    }
                    begin{document}
                    [Sum{ldots} ]% -> sum ldots
                    [Sum[i]{ldots} ]% -> sum_{i} ldots
                    [Sum[i in I]{ldots} ]% -> sum_{i in I} ldots
                    [Sum[i, 0, N]{ldots} ]% -> sum_{i=0}^{N} ldots
                    [Sum[{i,j}, 0, N]{ldots} ]% -> sum_{i,j=0}^{N} ldots
                    [Sum[{i,j,k}]{ldots} ]% -> sum_{i,j,k} ldots
                    end{document}


                    enter image description here






                    share|improve this answer












                    Here using LaTeX2e:



                    documentclass{article}
                    usepackage{listofitems}
                    makeatletter
                    newcommandSum{@ifnextchar[{Sumaux[@gobble}{sum}}
                    makeatother
                    defSumaux[#1]#2{
                    sum
                    setsepchar{,}
                    readlistsumargs{#1}
                    ifnumlistlensumargs>1relax
                    _{sumargs[1]=sumargs[2]}
                    ifnumlistlensumargs>2relax^sumargs[3]fi
                    else
                    _{sumargs[1]}
                    fi
                    #2
                    }
                    begin{document}
                    [Sum{ldots} ]% -> sum ldots
                    [Sum[i]{ldots} ]% -> sum_{i} ldots
                    [Sum[i in I]{ldots} ]% -> sum_{i in I} ldots
                    [Sum[i, 0, N]{ldots} ]% -> sum_{i=0}^{N} ldots
                    [Sum[{i,j}, 0, N]{ldots} ]% -> sum_{i,j=0}^{N} ldots
                    [Sum[{i,j,k}]{ldots} ]% -> sum_{i,j,k} ldots
                    end{document}


                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    Steven B. Segletes

                    152k9192399




                    152k9192399






















                        up vote
                        0
                        down vote













                        The brace stripping is quite deliberate as newcommand-generated commands requires braces for the case



                        foo[{]}]{bar}


                        whereas xparse-generated ones do not. Without brace stripping,



                        foo[{bar}]


                        and



                        foo[bar]


                        could be treated differently.



                        In your case, you have a comma list with one entry. The obvious solution is to provide a second, empty, entry



                        Sum[{i,j},]{ldots}


                        as this is a no-op.





                        share

























                          up vote
                          0
                          down vote













                          The brace stripping is quite deliberate as newcommand-generated commands requires braces for the case



                          foo[{]}]{bar}


                          whereas xparse-generated ones do not. Without brace stripping,



                          foo[{bar}]


                          and



                          foo[bar]


                          could be treated differently.



                          In your case, you have a comma list with one entry. The obvious solution is to provide a second, empty, entry



                          Sum[{i,j},]{ldots}


                          as this is a no-op.





                          share























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            The brace stripping is quite deliberate as newcommand-generated commands requires braces for the case



                            foo[{]}]{bar}


                            whereas xparse-generated ones do not. Without brace stripping,



                            foo[{bar}]


                            and



                            foo[bar]


                            could be treated differently.



                            In your case, you have a comma list with one entry. The obvious solution is to provide a second, empty, entry



                            Sum[{i,j},]{ldots}


                            as this is a no-op.





                            share












                            The brace stripping is quite deliberate as newcommand-generated commands requires braces for the case



                            foo[{]}]{bar}


                            whereas xparse-generated ones do not. Without brace stripping,



                            foo[{bar}]


                            and



                            foo[bar]


                            could be treated differently.



                            In your case, you have a comma list with one entry. The obvious solution is to provide a second, empty, entry



                            Sum[{i,j},]{ldots}


                            as this is a no-op.






                            share











                            share


                            share










                            answered 9 mins ago









                            Joseph Wright

                            201k21554879




                            201k21554879






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f465970%2fprevent-xparse-from-stripping-braces%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Mouse cursor on multiple screens with different PPI

                                Agildo Ribeiro

                                Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”