How can this command be altered to work in more cases?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












So the command is as follows:



newcommandsumi1tonsumlimits_i=1^n


I want to be able to generalize this further. For example, if I type sumj3toQ then it would give me the summation from j=3 to Q. How do I make this happen without writing a command for every possible scenario?







share|improve this question


















  • 3




    Surely you must be getting an error message when you try to define a macro called sumi1ton via a newcommand or def instruction: One isn't allowed to have numerals (and other non-letter characters) in a TeX macro whose name contains one or more letter characters.
    – Mico
    Aug 7 at 20:10











  • Possible related here? tex.stackexchange.com/questions/224430/…
    – Sebastiano
    Aug 7 at 20:14







  • 1




    @Mico you are correct. I made a mistake in this post. The actual command was sumiton
    – Mohammed Shahid
    Aug 7 at 20:34














up vote
1
down vote

favorite












So the command is as follows:



newcommandsumi1tonsumlimits_i=1^n


I want to be able to generalize this further. For example, if I type sumj3toQ then it would give me the summation from j=3 to Q. How do I make this happen without writing a command for every possible scenario?







share|improve this question


















  • 3




    Surely you must be getting an error message when you try to define a macro called sumi1ton via a newcommand or def instruction: One isn't allowed to have numerals (and other non-letter characters) in a TeX macro whose name contains one or more letter characters.
    – Mico
    Aug 7 at 20:10











  • Possible related here? tex.stackexchange.com/questions/224430/…
    – Sebastiano
    Aug 7 at 20:14







  • 1




    @Mico you are correct. I made a mistake in this post. The actual command was sumiton
    – Mohammed Shahid
    Aug 7 at 20:34












up vote
1
down vote

favorite









up vote
1
down vote

favorite











So the command is as follows:



newcommandsumi1tonsumlimits_i=1^n


I want to be able to generalize this further. For example, if I type sumj3toQ then it would give me the summation from j=3 to Q. How do I make this happen without writing a command for every possible scenario?







share|improve this question














So the command is as follows:



newcommandsumi1tonsumlimits_i=1^n


I want to be able to generalize this further. For example, if I type sumj3toQ then it would give me the summation from j=3 to Q. How do I make this happen without writing a command for every possible scenario?









share|improve this question













share|improve this question




share|improve this question








edited Aug 7 at 20:01









TeXnician

20.2k52880




20.2k52880










asked Aug 7 at 19:59









Mohammed Shahid

216




216







  • 3




    Surely you must be getting an error message when you try to define a macro called sumi1ton via a newcommand or def instruction: One isn't allowed to have numerals (and other non-letter characters) in a TeX macro whose name contains one or more letter characters.
    – Mico
    Aug 7 at 20:10











  • Possible related here? tex.stackexchange.com/questions/224430/…
    – Sebastiano
    Aug 7 at 20:14







  • 1




    @Mico you are correct. I made a mistake in this post. The actual command was sumiton
    – Mohammed Shahid
    Aug 7 at 20:34












  • 3




    Surely you must be getting an error message when you try to define a macro called sumi1ton via a newcommand or def instruction: One isn't allowed to have numerals (and other non-letter characters) in a TeX macro whose name contains one or more letter characters.
    – Mico
    Aug 7 at 20:10











  • Possible related here? tex.stackexchange.com/questions/224430/…
    – Sebastiano
    Aug 7 at 20:14







  • 1




    @Mico you are correct. I made a mistake in this post. The actual command was sumiton
    – Mohammed Shahid
    Aug 7 at 20:34







3




3




Surely you must be getting an error message when you try to define a macro called sumi1ton via a newcommand or def instruction: One isn't allowed to have numerals (and other non-letter characters) in a TeX macro whose name contains one or more letter characters.
– Mico
Aug 7 at 20:10





Surely you must be getting an error message when you try to define a macro called sumi1ton via a newcommand or def instruction: One isn't allowed to have numerals (and other non-letter characters) in a TeX macro whose name contains one or more letter characters.
– Mico
Aug 7 at 20:10













Possible related here? tex.stackexchange.com/questions/224430/…
– Sebastiano
Aug 7 at 20:14





Possible related here? tex.stackexchange.com/questions/224430/…
– Sebastiano
Aug 7 at 20:14





1




1




@Mico you are correct. I made a mistake in this post. The actual command was sumiton
– Mohammed Shahid
Aug 7 at 20:34




@Mico you are correct. I made a mistake in this post. The actual command was sumiton
– Mohammed Shahid
Aug 7 at 20:34










2 Answers
2






active

oldest

votes

















up vote
6
down vote













With spaces as delimiters to make it clearer:



custom sums



documentclassarticle
defsumx #1 #2 to #3sumlimits_#1=#2^#3
begindocument
[sumx i 1 to n]
[sumx j 3 to Q]
enddocument





share|improve this answer




















  • Wonderful answer +1 surely.
    – Sebastiano
    Aug 7 at 20:06










  • Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
    – Mohammed Shahid
    Aug 7 at 20:12






  • 2




    @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
    – TeXnician
    Aug 7 at 20:14










  • @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
    – Mohammed Shahid
    Aug 7 at 20:21






  • 2




    @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
    – TeXnician
    Aug 7 at 20:29


















up vote
1
down vote













Are that enough weird use cases? The default behaviour for empty arguments could be changed though.



I've added the special case that you use only two arguments with a to in between. In that case it is assumed you did mean sumx#10#2, you can change the default start (0 in the above example) at the lines marked with % CHANGE DEFAULT START HERE.



EDIT: Allowing and parsing = contained in #1 as if both #1 and #2 were given.



EDIT: Also allow an optional = in between #1 and #2.



documentclassarticle

makeatletter
newcommandsumx%>>>
%
@ifnextcharbgroup
sumx@braces@a% if sumx is followed by
sumx@spaces@a%
%<<<
newcommandsumx@ifempty[1]%>>>
%
ifrelaxdetokenize#1relax
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
%<<<
newcommandsumx@if@equal@contained@a[1]%>>>
%
sumx@if@equal@contained@b#1=end
%<<<
newcommandsumx@if@equal@contained@b%>>>
defsumx@if@equal@contained@b#1=#2end
%
sumx@ifempty#2@secondoftwo@firstoftwo%
%<<<
newcommandsumx@braces@a[1]%>>>
%
sumx@after@a#1%
%<<<
newcommandsumx@spaces@a%>>>
defsumx@spaces@a #1
%
sumx@after@a#1%
%<<<
newcommandsumx@after@a[1]%>>>
%
sumx@if@equal@contained@a#1
sumx@after@b#1
%
@ifnextchart
sumx@to@a@after@a#1
%
@ifnextchar=
sumx@equal@after@a#1
sumx@after@after@a#1
%
%
%<<<
newcommandsumx@equal@after@a%>>>
defsumx@equal@after@a #1=%
%
sumx@after@after@a#1%
%<<<
newcommandsumx@after@after@a[1]%>>>
%
@ifnextcharbgroup
sumx@braces@b#1
sumx@spaces@b#1%
%<<<
newcommandsumx@to@a@after@a%>>>
defsumx@to@a@after@a #1t%
%
@ifnextcharo
sumx@to@b@after@a#1
sumx@braces@b#1t%
%<<<
newcommandsumx@to@b@after@a%>>>
defsumx@to@b@after@a #1o%
%
sumx@to@c@after@a#10% CHANGE DEFAULT START HERE
%<<<
newcommandsumx@to@c@after@a[2]%>>>
%
@ifnextcharbgroup
sumx@braces@c#1#2
sumx@spaces@c#1#2%
%<<<
newcommandsumx@braces@b[2]%>>>
%
sumx@after@b#1#2%
%<<<
newcommandsumx@spaces@b%>>>
defsumx@spaces@b #1#2
%
sumx@after@b#1#2%
%<<<
newcommandsumx@after@b[2]%>>>
%
@ifnextcharbgroup
sumx@braces@c#1#2
%
@ifnextchart
sumx@to@a#1#2
sumx@spaces@c#1#2%
%
%<<<
newcommandsumx@braces@c[3]%>>>
%
sumx@output#1#2#3%
%<<<
newcommandsumx@spaces@c%>>>
defsumx@spaces@c #1#2#3
%
sumx@output#1#2#3%
%<<<
newcommandsumx@to@a%>>>
defsumx@to@a #1#2t%
%
@ifnextcharo
sumx@to@b#1#2
sumx@output#1#2t%
%<<<
newcommandsumx@to@b%>>>
defsumx@to@b #1#2o%
%
@ifnextcharbgroup
sumx@braces@c#1#2
sumx@spaces@c#1#2%
%<<<
newcommandsumx@output[3]%>>>
%
sum
sumx@ifempty#1#2#3% if all arguments are empty
% do nothing more
%
limits
sumx@ifempty#1#2% if both 1 and 2 are empty
% do nothing here
%
_%
sumx@ifempty#1
#2
%
sumx@ifempty#2
#1
#1=#2%
%
%
%
sumx@ifempty#3^#3

%<<<
makeatother


begindocument
$
sumxij1030
sumxij10to30
sumx ij 10 to 30
sumx ij 10 30
sumx ij 10 30
sumx ij 10 to 30
sumx ij 10 30
sumx ij 10 30
sumx ij 10 30$par
$
sumx i 1 t %no o follows the t so it is the third argument
sumx i 1 t o fail %spaces between "t" and "o" are parsed as "to" :(
sumx110
sumxi
sumxi10
sumx i t a
sumx i to a
sumx i t o a
sumx i to a % if you really need t and o as two arguments group one or both
sumx i=1 to a
sumx i = 1 to a
$
enddocument


the many uses of sumx



The %>>> and %<<< are just the fold marks of my VIM, you can ignore them.






share|improve this answer






















    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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f445033%2fhow-can-this-command-be-altered-to-work-in-more-cases%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    6
    down vote













    With spaces as delimiters to make it clearer:



    custom sums



    documentclassarticle
    defsumx #1 #2 to #3sumlimits_#1=#2^#3
    begindocument
    [sumx i 1 to n]
    [sumx j 3 to Q]
    enddocument





    share|improve this answer




















    • Wonderful answer +1 surely.
      – Sebastiano
      Aug 7 at 20:06










    • Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
      – Mohammed Shahid
      Aug 7 at 20:12






    • 2




      @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
      – TeXnician
      Aug 7 at 20:14










    • @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
      – Mohammed Shahid
      Aug 7 at 20:21






    • 2




      @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
      – TeXnician
      Aug 7 at 20:29















    up vote
    6
    down vote













    With spaces as delimiters to make it clearer:



    custom sums



    documentclassarticle
    defsumx #1 #2 to #3sumlimits_#1=#2^#3
    begindocument
    [sumx i 1 to n]
    [sumx j 3 to Q]
    enddocument





    share|improve this answer




















    • Wonderful answer +1 surely.
      – Sebastiano
      Aug 7 at 20:06










    • Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
      – Mohammed Shahid
      Aug 7 at 20:12






    • 2




      @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
      – TeXnician
      Aug 7 at 20:14










    • @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
      – Mohammed Shahid
      Aug 7 at 20:21






    • 2




      @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
      – TeXnician
      Aug 7 at 20:29













    up vote
    6
    down vote










    up vote
    6
    down vote









    With spaces as delimiters to make it clearer:



    custom sums



    documentclassarticle
    defsumx #1 #2 to #3sumlimits_#1=#2^#3
    begindocument
    [sumx i 1 to n]
    [sumx j 3 to Q]
    enddocument





    share|improve this answer












    With spaces as delimiters to make it clearer:



    custom sums



    documentclassarticle
    defsumx #1 #2 to #3sumlimits_#1=#2^#3
    begindocument
    [sumx i 1 to n]
    [sumx j 3 to Q]
    enddocument






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 7 at 20:04









    TeXnician

    20.2k52880




    20.2k52880











    • Wonderful answer +1 surely.
      – Sebastiano
      Aug 7 at 20:06










    • Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
      – Mohammed Shahid
      Aug 7 at 20:12






    • 2




      @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
      – TeXnician
      Aug 7 at 20:14










    • @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
      – Mohammed Shahid
      Aug 7 at 20:21






    • 2




      @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
      – TeXnician
      Aug 7 at 20:29

















    • Wonderful answer +1 surely.
      – Sebastiano
      Aug 7 at 20:06










    • Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
      – Mohammed Shahid
      Aug 7 at 20:12






    • 2




      @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
      – TeXnician
      Aug 7 at 20:14










    • @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
      – Mohammed Shahid
      Aug 7 at 20:21






    • 2




      @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
      – TeXnician
      Aug 7 at 20:29
















    Wonderful answer +1 surely.
    – Sebastiano
    Aug 7 at 20:06




    Wonderful answer +1 surely.
    – Sebastiano
    Aug 7 at 20:06












    Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
    – Mohammed Shahid
    Aug 7 at 20:12




    Thank you. So in order to use this, I would need to include it in the preamble for every document, right? Is it possible to include this in every document without having to put it in the preamble everytime?
    – Mohammed Shahid
    Aug 7 at 20:12




    2




    2




    @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
    – TeXnician
    Aug 7 at 20:14




    @MohammedShahid You can compile an own format, but surely that would be more effort than just putting this into every document.
    – TeXnician
    Aug 7 at 20:14












    @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
    – Mohammed Shahid
    Aug 7 at 20:21




    @TeXnician So would having a document with all of the commands I need and then pasting it into the preamble for every other document be the easiest solution?
    – Mohammed Shahid
    Aug 7 at 20:21




    2




    2




    @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
    – TeXnician
    Aug 7 at 20:29





    @MohammedShahid It depends on the amount. Dependent on your technical knowledge it might be easier to write a package in the local texmf-tree and include that (if your definitions accumulate) or even create a new format, but yes, usually copy and paste is the easiest method.
    – TeXnician
    Aug 7 at 20:29











    up vote
    1
    down vote













    Are that enough weird use cases? The default behaviour for empty arguments could be changed though.



    I've added the special case that you use only two arguments with a to in between. In that case it is assumed you did mean sumx#10#2, you can change the default start (0 in the above example) at the lines marked with % CHANGE DEFAULT START HERE.



    EDIT: Allowing and parsing = contained in #1 as if both #1 and #2 were given.



    EDIT: Also allow an optional = in between #1 and #2.



    documentclassarticle

    makeatletter
    newcommandsumx%>>>
    %
    @ifnextcharbgroup
    sumx@braces@a% if sumx is followed by
    sumx@spaces@a%
    %<<<
    newcommandsumx@ifempty[1]%>>>
    %
    ifrelaxdetokenize#1relax
    expandafter@firstoftwo
    else
    expandafter@secondoftwo
    fi
    %<<<
    newcommandsumx@if@equal@contained@a[1]%>>>
    %
    sumx@if@equal@contained@b#1=end
    %<<<
    newcommandsumx@if@equal@contained@b%>>>
    defsumx@if@equal@contained@b#1=#2end
    %
    sumx@ifempty#2@secondoftwo@firstoftwo%
    %<<<
    newcommandsumx@braces@a[1]%>>>
    %
    sumx@after@a#1%
    %<<<
    newcommandsumx@spaces@a%>>>
    defsumx@spaces@a #1
    %
    sumx@after@a#1%
    %<<<
    newcommandsumx@after@a[1]%>>>
    %
    sumx@if@equal@contained@a#1
    sumx@after@b#1
    %
    @ifnextchart
    sumx@to@a@after@a#1
    %
    @ifnextchar=
    sumx@equal@after@a#1
    sumx@after@after@a#1
    %
    %
    %<<<
    newcommandsumx@equal@after@a%>>>
    defsumx@equal@after@a #1=%
    %
    sumx@after@after@a#1%
    %<<<
    newcommandsumx@after@after@a[1]%>>>
    %
    @ifnextcharbgroup
    sumx@braces@b#1
    sumx@spaces@b#1%
    %<<<
    newcommandsumx@to@a@after@a%>>>
    defsumx@to@a@after@a #1t%
    %
    @ifnextcharo
    sumx@to@b@after@a#1
    sumx@braces@b#1t%
    %<<<
    newcommandsumx@to@b@after@a%>>>
    defsumx@to@b@after@a #1o%
    %
    sumx@to@c@after@a#10% CHANGE DEFAULT START HERE
    %<<<
    newcommandsumx@to@c@after@a[2]%>>>
    %
    @ifnextcharbgroup
    sumx@braces@c#1#2
    sumx@spaces@c#1#2%
    %<<<
    newcommandsumx@braces@b[2]%>>>
    %
    sumx@after@b#1#2%
    %<<<
    newcommandsumx@spaces@b%>>>
    defsumx@spaces@b #1#2
    %
    sumx@after@b#1#2%
    %<<<
    newcommandsumx@after@b[2]%>>>
    %
    @ifnextcharbgroup
    sumx@braces@c#1#2
    %
    @ifnextchart
    sumx@to@a#1#2
    sumx@spaces@c#1#2%
    %
    %<<<
    newcommandsumx@braces@c[3]%>>>
    %
    sumx@output#1#2#3%
    %<<<
    newcommandsumx@spaces@c%>>>
    defsumx@spaces@c #1#2#3
    %
    sumx@output#1#2#3%
    %<<<
    newcommandsumx@to@a%>>>
    defsumx@to@a #1#2t%
    %
    @ifnextcharo
    sumx@to@b#1#2
    sumx@output#1#2t%
    %<<<
    newcommandsumx@to@b%>>>
    defsumx@to@b #1#2o%
    %
    @ifnextcharbgroup
    sumx@braces@c#1#2
    sumx@spaces@c#1#2%
    %<<<
    newcommandsumx@output[3]%>>>
    %
    sum
    sumx@ifempty#1#2#3% if all arguments are empty
    % do nothing more
    %
    limits
    sumx@ifempty#1#2% if both 1 and 2 are empty
    % do nothing here
    %
    _%
    sumx@ifempty#1
    #2
    %
    sumx@ifempty#2
    #1
    #1=#2%
    %
    %
    %
    sumx@ifempty#3^#3

    %<<<
    makeatother


    begindocument
    $
    sumxij1030
    sumxij10to30
    sumx ij 10 to 30
    sumx ij 10 30
    sumx ij 10 30
    sumx ij 10 to 30
    sumx ij 10 30
    sumx ij 10 30
    sumx ij 10 30$par
    $
    sumx i 1 t %no o follows the t so it is the third argument
    sumx i 1 t o fail %spaces between "t" and "o" are parsed as "to" :(
    sumx110
    sumxi
    sumxi10
    sumx i t a
    sumx i to a
    sumx i t o a
    sumx i to a % if you really need t and o as two arguments group one or both
    sumx i=1 to a
    sumx i = 1 to a
    $
    enddocument


    the many uses of sumx



    The %>>> and %<<< are just the fold marks of my VIM, you can ignore them.






    share|improve this answer


























      up vote
      1
      down vote













      Are that enough weird use cases? The default behaviour for empty arguments could be changed though.



      I've added the special case that you use only two arguments with a to in between. In that case it is assumed you did mean sumx#10#2, you can change the default start (0 in the above example) at the lines marked with % CHANGE DEFAULT START HERE.



      EDIT: Allowing and parsing = contained in #1 as if both #1 and #2 were given.



      EDIT: Also allow an optional = in between #1 and #2.



      documentclassarticle

      makeatletter
      newcommandsumx%>>>
      %
      @ifnextcharbgroup
      sumx@braces@a% if sumx is followed by
      sumx@spaces@a%
      %<<<
      newcommandsumx@ifempty[1]%>>>
      %
      ifrelaxdetokenize#1relax
      expandafter@firstoftwo
      else
      expandafter@secondoftwo
      fi
      %<<<
      newcommandsumx@if@equal@contained@a[1]%>>>
      %
      sumx@if@equal@contained@b#1=end
      %<<<
      newcommandsumx@if@equal@contained@b%>>>
      defsumx@if@equal@contained@b#1=#2end
      %
      sumx@ifempty#2@secondoftwo@firstoftwo%
      %<<<
      newcommandsumx@braces@a[1]%>>>
      %
      sumx@after@a#1%
      %<<<
      newcommandsumx@spaces@a%>>>
      defsumx@spaces@a #1
      %
      sumx@after@a#1%
      %<<<
      newcommandsumx@after@a[1]%>>>
      %
      sumx@if@equal@contained@a#1
      sumx@after@b#1
      %
      @ifnextchart
      sumx@to@a@after@a#1
      %
      @ifnextchar=
      sumx@equal@after@a#1
      sumx@after@after@a#1
      %
      %
      %<<<
      newcommandsumx@equal@after@a%>>>
      defsumx@equal@after@a #1=%
      %
      sumx@after@after@a#1%
      %<<<
      newcommandsumx@after@after@a[1]%>>>
      %
      @ifnextcharbgroup
      sumx@braces@b#1
      sumx@spaces@b#1%
      %<<<
      newcommandsumx@to@a@after@a%>>>
      defsumx@to@a@after@a #1t%
      %
      @ifnextcharo
      sumx@to@b@after@a#1
      sumx@braces@b#1t%
      %<<<
      newcommandsumx@to@b@after@a%>>>
      defsumx@to@b@after@a #1o%
      %
      sumx@to@c@after@a#10% CHANGE DEFAULT START HERE
      %<<<
      newcommandsumx@to@c@after@a[2]%>>>
      %
      @ifnextcharbgroup
      sumx@braces@c#1#2
      sumx@spaces@c#1#2%
      %<<<
      newcommandsumx@braces@b[2]%>>>
      %
      sumx@after@b#1#2%
      %<<<
      newcommandsumx@spaces@b%>>>
      defsumx@spaces@b #1#2
      %
      sumx@after@b#1#2%
      %<<<
      newcommandsumx@after@b[2]%>>>
      %
      @ifnextcharbgroup
      sumx@braces@c#1#2
      %
      @ifnextchart
      sumx@to@a#1#2
      sumx@spaces@c#1#2%
      %
      %<<<
      newcommandsumx@braces@c[3]%>>>
      %
      sumx@output#1#2#3%
      %<<<
      newcommandsumx@spaces@c%>>>
      defsumx@spaces@c #1#2#3
      %
      sumx@output#1#2#3%
      %<<<
      newcommandsumx@to@a%>>>
      defsumx@to@a #1#2t%
      %
      @ifnextcharo
      sumx@to@b#1#2
      sumx@output#1#2t%
      %<<<
      newcommandsumx@to@b%>>>
      defsumx@to@b #1#2o%
      %
      @ifnextcharbgroup
      sumx@braces@c#1#2
      sumx@spaces@c#1#2%
      %<<<
      newcommandsumx@output[3]%>>>
      %
      sum
      sumx@ifempty#1#2#3% if all arguments are empty
      % do nothing more
      %
      limits
      sumx@ifempty#1#2% if both 1 and 2 are empty
      % do nothing here
      %
      _%
      sumx@ifempty#1
      #2
      %
      sumx@ifempty#2
      #1
      #1=#2%
      %
      %
      %
      sumx@ifempty#3^#3

      %<<<
      makeatother


      begindocument
      $
      sumxij1030
      sumxij10to30
      sumx ij 10 to 30
      sumx ij 10 30
      sumx ij 10 30
      sumx ij 10 to 30
      sumx ij 10 30
      sumx ij 10 30
      sumx ij 10 30$par
      $
      sumx i 1 t %no o follows the t so it is the third argument
      sumx i 1 t o fail %spaces between "t" and "o" are parsed as "to" :(
      sumx110
      sumxi
      sumxi10
      sumx i t a
      sumx i to a
      sumx i t o a
      sumx i to a % if you really need t and o as two arguments group one or both
      sumx i=1 to a
      sumx i = 1 to a
      $
      enddocument


      the many uses of sumx



      The %>>> and %<<< are just the fold marks of my VIM, you can ignore them.






      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        Are that enough weird use cases? The default behaviour for empty arguments could be changed though.



        I've added the special case that you use only two arguments with a to in between. In that case it is assumed you did mean sumx#10#2, you can change the default start (0 in the above example) at the lines marked with % CHANGE DEFAULT START HERE.



        EDIT: Allowing and parsing = contained in #1 as if both #1 and #2 were given.



        EDIT: Also allow an optional = in between #1 and #2.



        documentclassarticle

        makeatletter
        newcommandsumx%>>>
        %
        @ifnextcharbgroup
        sumx@braces@a% if sumx is followed by
        sumx@spaces@a%
        %<<<
        newcommandsumx@ifempty[1]%>>>
        %
        ifrelaxdetokenize#1relax
        expandafter@firstoftwo
        else
        expandafter@secondoftwo
        fi
        %<<<
        newcommandsumx@if@equal@contained@a[1]%>>>
        %
        sumx@if@equal@contained@b#1=end
        %<<<
        newcommandsumx@if@equal@contained@b%>>>
        defsumx@if@equal@contained@b#1=#2end
        %
        sumx@ifempty#2@secondoftwo@firstoftwo%
        %<<<
        newcommandsumx@braces@a[1]%>>>
        %
        sumx@after@a#1%
        %<<<
        newcommandsumx@spaces@a%>>>
        defsumx@spaces@a #1
        %
        sumx@after@a#1%
        %<<<
        newcommandsumx@after@a[1]%>>>
        %
        sumx@if@equal@contained@a#1
        sumx@after@b#1
        %
        @ifnextchart
        sumx@to@a@after@a#1
        %
        @ifnextchar=
        sumx@equal@after@a#1
        sumx@after@after@a#1
        %
        %
        %<<<
        newcommandsumx@equal@after@a%>>>
        defsumx@equal@after@a #1=%
        %
        sumx@after@after@a#1%
        %<<<
        newcommandsumx@after@after@a[1]%>>>
        %
        @ifnextcharbgroup
        sumx@braces@b#1
        sumx@spaces@b#1%
        %<<<
        newcommandsumx@to@a@after@a%>>>
        defsumx@to@a@after@a #1t%
        %
        @ifnextcharo
        sumx@to@b@after@a#1
        sumx@braces@b#1t%
        %<<<
        newcommandsumx@to@b@after@a%>>>
        defsumx@to@b@after@a #1o%
        %
        sumx@to@c@after@a#10% CHANGE DEFAULT START HERE
        %<<<
        newcommandsumx@to@c@after@a[2]%>>>
        %
        @ifnextcharbgroup
        sumx@braces@c#1#2
        sumx@spaces@c#1#2%
        %<<<
        newcommandsumx@braces@b[2]%>>>
        %
        sumx@after@b#1#2%
        %<<<
        newcommandsumx@spaces@b%>>>
        defsumx@spaces@b #1#2
        %
        sumx@after@b#1#2%
        %<<<
        newcommandsumx@after@b[2]%>>>
        %
        @ifnextcharbgroup
        sumx@braces@c#1#2
        %
        @ifnextchart
        sumx@to@a#1#2
        sumx@spaces@c#1#2%
        %
        %<<<
        newcommandsumx@braces@c[3]%>>>
        %
        sumx@output#1#2#3%
        %<<<
        newcommandsumx@spaces@c%>>>
        defsumx@spaces@c #1#2#3
        %
        sumx@output#1#2#3%
        %<<<
        newcommandsumx@to@a%>>>
        defsumx@to@a #1#2t%
        %
        @ifnextcharo
        sumx@to@b#1#2
        sumx@output#1#2t%
        %<<<
        newcommandsumx@to@b%>>>
        defsumx@to@b #1#2o%
        %
        @ifnextcharbgroup
        sumx@braces@c#1#2
        sumx@spaces@c#1#2%
        %<<<
        newcommandsumx@output[3]%>>>
        %
        sum
        sumx@ifempty#1#2#3% if all arguments are empty
        % do nothing more
        %
        limits
        sumx@ifempty#1#2% if both 1 and 2 are empty
        % do nothing here
        %
        _%
        sumx@ifempty#1
        #2
        %
        sumx@ifempty#2
        #1
        #1=#2%
        %
        %
        %
        sumx@ifempty#3^#3

        %<<<
        makeatother


        begindocument
        $
        sumxij1030
        sumxij10to30
        sumx ij 10 to 30
        sumx ij 10 30
        sumx ij 10 30
        sumx ij 10 to 30
        sumx ij 10 30
        sumx ij 10 30
        sumx ij 10 30$par
        $
        sumx i 1 t %no o follows the t so it is the third argument
        sumx i 1 t o fail %spaces between "t" and "o" are parsed as "to" :(
        sumx110
        sumxi
        sumxi10
        sumx i t a
        sumx i to a
        sumx i t o a
        sumx i to a % if you really need t and o as two arguments group one or both
        sumx i=1 to a
        sumx i = 1 to a
        $
        enddocument


        the many uses of sumx



        The %>>> and %<<< are just the fold marks of my VIM, you can ignore them.






        share|improve this answer














        Are that enough weird use cases? The default behaviour for empty arguments could be changed though.



        I've added the special case that you use only two arguments with a to in between. In that case it is assumed you did mean sumx#10#2, you can change the default start (0 in the above example) at the lines marked with % CHANGE DEFAULT START HERE.



        EDIT: Allowing and parsing = contained in #1 as if both #1 and #2 were given.



        EDIT: Also allow an optional = in between #1 and #2.



        documentclassarticle

        makeatletter
        newcommandsumx%>>>
        %
        @ifnextcharbgroup
        sumx@braces@a% if sumx is followed by
        sumx@spaces@a%
        %<<<
        newcommandsumx@ifempty[1]%>>>
        %
        ifrelaxdetokenize#1relax
        expandafter@firstoftwo
        else
        expandafter@secondoftwo
        fi
        %<<<
        newcommandsumx@if@equal@contained@a[1]%>>>
        %
        sumx@if@equal@contained@b#1=end
        %<<<
        newcommandsumx@if@equal@contained@b%>>>
        defsumx@if@equal@contained@b#1=#2end
        %
        sumx@ifempty#2@secondoftwo@firstoftwo%
        %<<<
        newcommandsumx@braces@a[1]%>>>
        %
        sumx@after@a#1%
        %<<<
        newcommandsumx@spaces@a%>>>
        defsumx@spaces@a #1
        %
        sumx@after@a#1%
        %<<<
        newcommandsumx@after@a[1]%>>>
        %
        sumx@if@equal@contained@a#1
        sumx@after@b#1
        %
        @ifnextchart
        sumx@to@a@after@a#1
        %
        @ifnextchar=
        sumx@equal@after@a#1
        sumx@after@after@a#1
        %
        %
        %<<<
        newcommandsumx@equal@after@a%>>>
        defsumx@equal@after@a #1=%
        %
        sumx@after@after@a#1%
        %<<<
        newcommandsumx@after@after@a[1]%>>>
        %
        @ifnextcharbgroup
        sumx@braces@b#1
        sumx@spaces@b#1%
        %<<<
        newcommandsumx@to@a@after@a%>>>
        defsumx@to@a@after@a #1t%
        %
        @ifnextcharo
        sumx@to@b@after@a#1
        sumx@braces@b#1t%
        %<<<
        newcommandsumx@to@b@after@a%>>>
        defsumx@to@b@after@a #1o%
        %
        sumx@to@c@after@a#10% CHANGE DEFAULT START HERE
        %<<<
        newcommandsumx@to@c@after@a[2]%>>>
        %
        @ifnextcharbgroup
        sumx@braces@c#1#2
        sumx@spaces@c#1#2%
        %<<<
        newcommandsumx@braces@b[2]%>>>
        %
        sumx@after@b#1#2%
        %<<<
        newcommandsumx@spaces@b%>>>
        defsumx@spaces@b #1#2
        %
        sumx@after@b#1#2%
        %<<<
        newcommandsumx@after@b[2]%>>>
        %
        @ifnextcharbgroup
        sumx@braces@c#1#2
        %
        @ifnextchart
        sumx@to@a#1#2
        sumx@spaces@c#1#2%
        %
        %<<<
        newcommandsumx@braces@c[3]%>>>
        %
        sumx@output#1#2#3%
        %<<<
        newcommandsumx@spaces@c%>>>
        defsumx@spaces@c #1#2#3
        %
        sumx@output#1#2#3%
        %<<<
        newcommandsumx@to@a%>>>
        defsumx@to@a #1#2t%
        %
        @ifnextcharo
        sumx@to@b#1#2
        sumx@output#1#2t%
        %<<<
        newcommandsumx@to@b%>>>
        defsumx@to@b #1#2o%
        %
        @ifnextcharbgroup
        sumx@braces@c#1#2
        sumx@spaces@c#1#2%
        %<<<
        newcommandsumx@output[3]%>>>
        %
        sum
        sumx@ifempty#1#2#3% if all arguments are empty
        % do nothing more
        %
        limits
        sumx@ifempty#1#2% if both 1 and 2 are empty
        % do nothing here
        %
        _%
        sumx@ifempty#1
        #2
        %
        sumx@ifempty#2
        #1
        #1=#2%
        %
        %
        %
        sumx@ifempty#3^#3

        %<<<
        makeatother


        begindocument
        $
        sumxij1030
        sumxij10to30
        sumx ij 10 to 30
        sumx ij 10 30
        sumx ij 10 30
        sumx ij 10 to 30
        sumx ij 10 30
        sumx ij 10 30
        sumx ij 10 30$par
        $
        sumx i 1 t %no o follows the t so it is the third argument
        sumx i 1 t o fail %spaces between "t" and "o" are parsed as "to" :(
        sumx110
        sumxi
        sumxi10
        sumx i t a
        sumx i to a
        sumx i t o a
        sumx i to a % if you really need t and o as two arguments group one or both
        sumx i=1 to a
        sumx i = 1 to a
        $
        enddocument


        the many uses of sumx



        The %>>> and %<<< are just the fold marks of my VIM, you can ignore them.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 8 at 1:55

























        answered Aug 8 at 1:25









        Skillmon

        17.1k11534




        17.1k11534



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f445033%2fhow-can-this-command-be-altered-to-work-in-more-cases%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            One-line joke