Loop code for repeated sums

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











up vote
8
down vote

favorite












I tried to read other topics regarding newcommand* to create a macros in order to have repeated summations with a single command but I was not able to understand the logic behind it.
Let me explain better:
I would like to create a newcommand that simply by typing repsum9Fu, where 9 is the repetition number, can create an output like



F_1u_1+F_2u_2+F_3u_3+...+F_8u_8+F_9u_9.



Can someone help me with this matter? Thank you very much :)



EDIT



Thank you for your answers. I am sorry if I did not post a MWE. The answer provided by current user and zarko does the trick but it uses tikzpicture, while I'd like to use it in Math mode. I'll add an example to show you what I'd like to do (in pseudo code the newcommand)



documentclassarticle
newcommand*repsum[3]{
for i=1:#1
if i~=#1
#2_i#3_i+
else
#2_i#3_i
end
end
begindocument

The CUF Refined theory expands the summation as

beginequation
u=repsum9Fu=F_tau u_tau
endequation

where the last expression exploits the Einstein notation.

enddocument






share|improve this question






















  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass... and ending with enddocument.
    – albert
    Sep 5 at 9:56














up vote
8
down vote

favorite












I tried to read other topics regarding newcommand* to create a macros in order to have repeated summations with a single command but I was not able to understand the logic behind it.
Let me explain better:
I would like to create a newcommand that simply by typing repsum9Fu, where 9 is the repetition number, can create an output like



F_1u_1+F_2u_2+F_3u_3+...+F_8u_8+F_9u_9.



Can someone help me with this matter? Thank you very much :)



EDIT



Thank you for your answers. I am sorry if I did not post a MWE. The answer provided by current user and zarko does the trick but it uses tikzpicture, while I'd like to use it in Math mode. I'll add an example to show you what I'd like to do (in pseudo code the newcommand)



documentclassarticle
newcommand*repsum[3]{
for i=1:#1
if i~=#1
#2_i#3_i+
else
#2_i#3_i
end
end
begindocument

The CUF Refined theory expands the summation as

beginequation
u=repsum9Fu=F_tau u_tau
endequation

where the last expression exploits the Einstein notation.

enddocument






share|improve this question






















  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass... and ending with enddocument.
    – albert
    Sep 5 at 9:56












up vote
8
down vote

favorite









up vote
8
down vote

favorite











I tried to read other topics regarding newcommand* to create a macros in order to have repeated summations with a single command but I was not able to understand the logic behind it.
Let me explain better:
I would like to create a newcommand that simply by typing repsum9Fu, where 9 is the repetition number, can create an output like



F_1u_1+F_2u_2+F_3u_3+...+F_8u_8+F_9u_9.



Can someone help me with this matter? Thank you very much :)



EDIT



Thank you for your answers. I am sorry if I did not post a MWE. The answer provided by current user and zarko does the trick but it uses tikzpicture, while I'd like to use it in Math mode. I'll add an example to show you what I'd like to do (in pseudo code the newcommand)



documentclassarticle
newcommand*repsum[3]{
for i=1:#1
if i~=#1
#2_i#3_i+
else
#2_i#3_i
end
end
begindocument

The CUF Refined theory expands the summation as

beginequation
u=repsum9Fu=F_tau u_tau
endequation

where the last expression exploits the Einstein notation.

enddocument






share|improve this question














I tried to read other topics regarding newcommand* to create a macros in order to have repeated summations with a single command but I was not able to understand the logic behind it.
Let me explain better:
I would like to create a newcommand that simply by typing repsum9Fu, where 9 is the repetition number, can create an output like



F_1u_1+F_2u_2+F_3u_3+...+F_8u_8+F_9u_9.



Can someone help me with this matter? Thank you very much :)



EDIT



Thank you for your answers. I am sorry if I did not post a MWE. The answer provided by current user and zarko does the trick but it uses tikzpicture, while I'd like to use it in Math mode. I'll add an example to show you what I'd like to do (in pseudo code the newcommand)



documentclassarticle
newcommand*repsum[3]{
for i=1:#1
if i~=#1
#2_i#3_i+
else
#2_i#3_i
end
end
begindocument

The CUF Refined theory expands the summation as

beginequation
u=repsum9Fu=F_tau u_tau
endequation

where the last expression exploits the Einstein notation.

enddocument








share|improve this question













share|improve this question




share|improve this question








edited Sep 5 at 10:05

























asked Sep 5 at 9:53









L Mascolo

576




576











  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass... and ending with enddocument.
    – albert
    Sep 5 at 9:56
















  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass... and ending with enddocument.
    – albert
    Sep 5 at 9:56















Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass... and ending with enddocument.
– albert
Sep 5 at 9:56




Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass... and ending with enddocument.
– albert
Sep 5 at 9:56










4 Answers
4






active

oldest

votes

















up vote
10
down vote



accepted










To use it in math mode you could simply use a foreach outside a tikzpicture. This would require the pgffor package (only if you're not using Tikz already):



enter image description here



documentclassarticle

usepackagemathtools
usepackagepgffor

newcommandrepsum[3]%
foreach i in 1,...,#1
ifnumi>1
+ #2_i #3_i
else
#2_i #3_i
fi



begindocument
beginequation*
mathbfFbulletmathbfu = repsum9Fu
endequation*
enddocument





share|improve this answer






















  • Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
    – L Mascolo
    Sep 5 at 10:11






  • 1




    @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
    – Max
    Sep 5 at 10:17






  • 1




    I didn't know it was simply an image, I can do that :) Thank you!
    – L Mascolo
    Sep 5 at 10:27

















up vote
7
down vote













You can use xparse:



documentclassarticle
usepackageamsmath
usepackagexparse

ExplSyntaxOn
NewDocumentCommandrepsumO3mmm
% #1 = optional number of starting summands
% #2 = final number
% #3 = first symbol
% #4 = second symbol
int_step_inline:nn #1 #3sb##1#4sb##1 +
dotsb
int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1

ExplSyntaxOff

begindocument

First test: $repsum9Fu$

Second test: $repsum[2]6Fu$

The CUF Refined theory expands the summation as
beginequation
u=repsum9Fu=F_tau u_tau
endequation
where the last expression exploits the Einstein notation.

enddocument


The idea is to make a cycle from 1 to 3 (or the number specified in the optional argument), printing the summands with their subscripts followed by +; then print the dots and + followed by the summands from #2-1 (#2 is the final number of summands) to #2.



With this implementation, you are responsible for ensuring no overlap. So you can do repsum[1]4Fu, but with less than four summands it won't work.



enter image description here



A different version that automatically skips the dots if they're not needed.



documentclassarticle
usepackageamsmath
usepackagexparse

ExplSyntaxOn
NewDocumentCommandrepsumO3mmm
% #1 = optional number of starting summands
% #2 = final number
% #3 = first symbol
% #4 = second symbol
int_compare:nTF #2 - #1 < 3
% no dots necessary
#3sb1#4sb1
int_step_inline:nnn 2 #2 + #3sb##1#4sb##1


int_step_inline:nn #1 #3sb##1#4sb##1 +
dotsb
int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1


ExplSyntaxOff

begindocument

First test: $repsum9Fu$

Second test: $repsum[2]6Fu$

Third test: $repsum5Fu$

Fourth test: $repsum3Fu$

Fifth test: $repsum2Fu$

Sixth test: $repsum1Fu$

The CUF Refined theory expands the summation as
beginequation
u=repsum9Fu=F_tau u_tau
endequation
where the last expression exploits the Einstein notation.

enddocument


enter image description here






share|improve this answer





























    up vote
    3
    down vote













    Maybe this?



    documentclassarticle
    usepackagetikz
    newcommandcussum[1]
    begintikzpicture[baseline=-.1cm]
    foreach x in 1,2,...,#1

    ifnumx<#1
    node at (x,0) $F_xu_x+$;
    fi
    ifnumx=#1
    node at (x-.1,0) $F_xu_x$;
    fi

    endtikzpicture

    begindocument
    cussum9 Minimal Working Examples are nice, aren't they ldots
    enddocument


    Here is the output:



    Screenshot






    share|improve this answer





























      up vote
      0
      down vote













      Re-using my replaceiandreplicate-macro from the discussion How to make a command to automate creation of prime factorization-like products?, a possibility of approaching the matter could be:



      documentclassarticle

      makeatletter
      %%=============================================================================
      %% Paraphernalia:
      %% UD@firstoftwo, UD@secondoftwo,
      %% UD@PassFirstToSecond, UD@Exchange, UD@removespace
      %% UD@CheckWhetherNull, UD@CheckWhetherBrace,
      %% UD@CheckWhetherLeadingSpace, UD@ExtractFirstArg
      %%=============================================================================
      newcommandUD@firstoftwo[2]#1%
      newcommandUD@secondoftwo[2]#2%
      newcommandUD@PassFirstToSecond[2]#2#1%
      newcommandUD@Exchange[2]#2#1%
      newcommandUD@removespaceUD@firstoftwodefUD@removespace %
      %%-----------------------------------------------------------------------------
      %% Check whether argument is empty:
      %%.............................................................................
      %% UD@CheckWhetherNull<Argument which is to be checked>%
      %% <Tokens to be delivered in case that argument
      %% which is to be checked is empty>%
      %% <Tokens to be delivered in case that argument
      %% which is to be checked is not empty>%
      %%
      %% The gist of this macro comes from Robert R. Schneck's ifempty-macro:
      %% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
      newcommandUD@CheckWhetherNull[1]%
      romannumeral0expandafterUD@secondoftwostringexpandafter
      UD@secondoftwoexpandafterexpandafterstring#1expandafter
      UD@secondoftwostringexpandafterUD@firstoftwoexpandafterexpandafter
      UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
      UD@secondoftwoexpandafterexpandafterUD@firstoftwo UD@firstoftwo%
      %
      %%-----------------------------------------------------------------------------
      %% Check whether argument's first token is a catcode-1-character
      %%.............................................................................
      %% UD@CheckWhetherBrace<Argument which is to be checked>%
      %% <Tokens to be delivered in case that argument
      %% which is to be checked has leading
      %% catcode-1-token>%
      %% <Tokens to be delivered in case that argument
      %% which is to be checked has no leading
      %% catcode-1-token>%
      newcommandUD@CheckWhetherBrace[1]%
      romannumeral0expandafterUD@secondoftwoexpandafterexpandafter%
      string#1.expandafterUD@firstoftwoexpandafterexpandafter
      UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
      UD@firstoftwoexpandafterexpandafterUD@firstoftwo UD@secondoftwo%
      %
      %%-----------------------------------------------------------------------------
      %% Check whether brace-balanced argument starts with a space-token
      %%.............................................................................
      %% UD@CheckWhetherLeadingSpace<Argument which is to be checked>%
      %% <Tokens to be delivered in case <argument
      %% which is to be checked>'s 1st token is a
      %% space-token>%
      %% <Tokens to be delivered in case <argument
      %% which is to be checked>'s 1st token is not
      %% a space-token>%
      newcommandUD@CheckWhetherLeadingSpace[1]%
      romannumeral0UD@CheckWhetherNull#1%
      expandafterexpandafterUD@firstoftwo UD@secondoftwo%
      expandafterUD@secondoftwostringUD@CheckWhetherLeadingSpaceB.#1 %
      %
      newcommandUD@CheckWhetherLeadingSpaceB%
      longdefUD@CheckWhetherLeadingSpaceB#1 %
      expandafterUD@CheckWhetherNullexpandafterUD@secondoftwo#1%
      UD@ExchangeUD@firstoftwoUD@ExchangeUD@secondoftwo%
      UD@Exchange expandafterexpandafterexpandafterexpandafter
      expandafterexpandafterexpandafterexpandafterexpandafter
      expandafterexpandafterUD@secondoftwoexpandafterstring%
      %
      %%-----------------------------------------------------------------------------
      %% Extract first inner undelimited argument:
      %%
      %% UD@ExtractFirstArgABCDE yields A
      %%
      %% UD@ExtractFirstArgABCDE yields AB
      %%.............................................................................
      newcommandUD@RemoveTillUD@SelDOm%
      longdefUD@RemoveTillUD@SelDOm#1#2UD@SelDOm#1%
      newcommandUD@ExtractFirstArg[1]%
      romannumeral0%
      UD@ExtractFirstArgLoop#1UD@SelDOm%
      %
      newcommandUD@ExtractFirstArgLoop[1]%
      expandafterUD@CheckWhetherNullexpandafterUD@firstoftwo#1%
      #1%
      expandafterUD@ExtractFirstArgLoopexpandafterUD@RemoveTillUD@SelDOm#1%
      %
      %%=============================================================================
      %% DefineReplacementMacro<replacement-macro>%
      %% <internal helper-macro>%
      %% <item to replace>%
      %%
      %% defines <replacement-macro> to fetch two arguments,
      %% #1 = <replacement for item to replace>
      %% #2 = <token sequence with item to replace>
      %% , and -- after two expansion-steps to deliver:
      %% <token sequence with all instances of <item to replace> replaced
      %% by <replacement for item to replace>. >
      %%
      %% Internally an <internal helper-macro> is needed.
      %%
      %% (!!! <replacement-macro> does also replace all pairs of matching
      %% explicit character tokens of catcode 1/2 by matching braces!!!)
      %%-----------------------------------------------------------------------------
      newcommandDefineReplacementMacro[3]%
      newcommand#2longdef#2##1#3%
      newcommand#1[2]%
      romannumeral0UD@ReplaceAllLoop##2##1#2#3%
      %
      %
      newcommandUD@ReplaceAllLoop[5]%
      UD@CheckWhetherNull#1 #3%
      UD@CheckWhetherLeadingSpace#1%
      expandafterUD@ReplaceAllLoop
      expandafterUD@removespace#1#2#3 #4#5%
      %
      UD@CheckWhetherBrace#1%
      expandafterexpandafterexpandafterUD@PassFirstToSecond
      expandafterexpandafterexpandafter%
      expandafterUD@PassFirstToSecondexpandafter%
      romannumeral0expandafterUD@ReplaceAllLoop
      romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#2#4#5%
      #3%
      expandafterUD@ReplaceAllLoopexpandafterUD@firstoftwo#1#2%
      #4#5%
      %
      expandafterUD@CheckWhetherNoReplacement
      romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#1#2#3#4#5%
      %
      %
      %
      %
      newcommandUD@CheckWhetherNoReplacement[6]%
      expandafterUD@CheckWhetherNullexpandafter#5#1#6%
      %
      expandafterUD@ReplaceAllLoop
      expandafterUD@firstoftwo#2#3#4#1#5#6%
      %
      expandafterUD@ReplaceAllLoop
      expandafterUD@firstoftwo#2#3#4#3#5#6%
      %
      %
      %%=============================================================================
      %% UD@ReplaceAlli -- Replace all "i" in undelimited Argument:
      %%
      %% UD@ReplaceAlli<replacement for i><token sequence with i>
      %% yields <token sequence with all i replaced by replacement for i>
      %%
      %% <replacement for i> may contain i.
      %%
      %% (This routine does also replace all pairs of matching explicit
      %% character tokens of catcode 1/2 by matching braces!!!)
      %%
      %% The letter "i" as item to replace is hard-coded.
      %% You cannot replace öetters other than I with this macro.
      %%.............................................................................
      DefineReplacementMacroUD@ReplaceAlliUD@gobbletoii%
      %%
      %%=============================================================================
      %% replaceiandreplicate<term with i>%
      %% <loop-start-index>%
      %% <loop-end-index>%
      %%
      %% e.g.,
      %%
      %% replaceiandreplicatep_i^epsilon_i13
      %%.............................................................................
      newcommandreplaceiandreplicate[3]%
      romannumeral0replaceiandreplicateloop#3#2#1%
      %
      newcommandreplaceiandreplicateloop[4]%
      ifnum#1<#2 %
      expandafterUD@firstoftwo
      else
      expandafterUD@secondoftwo
      fi
      #4%
      expandafterexpandafterexpandafterUD@PassFirstToSecond
      expandafterexpandafterexpandafter%
      UD@ReplaceAlli#1#3#4%
      %
      expandafterreplaceiandreplicateloop
      expandafternumbernumexprnumber#1-1relax#2#3%
      %
      %
      %

      makeatother

      parindent=0ex

      begindocument

      beginverbatim
      $replaceiandreplicateifnum i>1+fi F_iu_i19$
      endverbatim

      yields:bigskip

      $replaceiandreplicateifnum i>1+fi F_iu_i19$


      beginverbatim
      $csname @gobbleexpandafterexpandafter
      expandafter endcsname
      replaceiandreplicate+F_iu_i19$
      endverbatim

      yields:bigskip

      $csname @gobbleexpandafterexpandafter
      expandafter endcsname
      replaceiandreplicate+F_iu_i19$

      enddocument


      enter image description here






      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%2f449414%2floop-code-for-repeated-sums%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        10
        down vote



        accepted










        To use it in math mode you could simply use a foreach outside a tikzpicture. This would require the pgffor package (only if you're not using Tikz already):



        enter image description here



        documentclassarticle

        usepackagemathtools
        usepackagepgffor

        newcommandrepsum[3]%
        foreach i in 1,...,#1
        ifnumi>1
        + #2_i #3_i
        else
        #2_i #3_i
        fi



        begindocument
        beginequation*
        mathbfFbulletmathbfu = repsum9Fu
        endequation*
        enddocument





        share|improve this answer






















        • Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
          – L Mascolo
          Sep 5 at 10:11






        • 1




          @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
          – Max
          Sep 5 at 10:17






        • 1




          I didn't know it was simply an image, I can do that :) Thank you!
          – L Mascolo
          Sep 5 at 10:27














        up vote
        10
        down vote



        accepted










        To use it in math mode you could simply use a foreach outside a tikzpicture. This would require the pgffor package (only if you're not using Tikz already):



        enter image description here



        documentclassarticle

        usepackagemathtools
        usepackagepgffor

        newcommandrepsum[3]%
        foreach i in 1,...,#1
        ifnumi>1
        + #2_i #3_i
        else
        #2_i #3_i
        fi



        begindocument
        beginequation*
        mathbfFbulletmathbfu = repsum9Fu
        endequation*
        enddocument





        share|improve this answer






















        • Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
          – L Mascolo
          Sep 5 at 10:11






        • 1




          @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
          – Max
          Sep 5 at 10:17






        • 1




          I didn't know it was simply an image, I can do that :) Thank you!
          – L Mascolo
          Sep 5 at 10:27












        up vote
        10
        down vote



        accepted







        up vote
        10
        down vote



        accepted






        To use it in math mode you could simply use a foreach outside a tikzpicture. This would require the pgffor package (only if you're not using Tikz already):



        enter image description here



        documentclassarticle

        usepackagemathtools
        usepackagepgffor

        newcommandrepsum[3]%
        foreach i in 1,...,#1
        ifnumi>1
        + #2_i #3_i
        else
        #2_i #3_i
        fi



        begindocument
        beginequation*
        mathbfFbulletmathbfu = repsum9Fu
        endequation*
        enddocument





        share|improve this answer














        To use it in math mode you could simply use a foreach outside a tikzpicture. This would require the pgffor package (only if you're not using Tikz already):



        enter image description here



        documentclassarticle

        usepackagemathtools
        usepackagepgffor

        newcommandrepsum[3]%
        foreach i in 1,...,#1
        ifnumi>1
        + #2_i #3_i
        else
        #2_i #3_i
        fi



        begindocument
        beginequation*
        mathbfFbulletmathbfu = repsum9Fu
        endequation*
        enddocument






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 5 at 10:19

























        answered Sep 5 at 10:06









        Max

        6,13311727




        6,13311727











        • Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
          – L Mascolo
          Sep 5 at 10:11






        • 1




          @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
          – Max
          Sep 5 at 10:17






        • 1




          I didn't know it was simply an image, I can do that :) Thank you!
          – L Mascolo
          Sep 5 at 10:27
















        • Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
          – L Mascolo
          Sep 5 at 10:11






        • 1




          @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
          – Max
          Sep 5 at 10:17






        • 1




          I didn't know it was simply an image, I can do that :) Thank you!
          – L Mascolo
          Sep 5 at 10:27















        Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
        – L Mascolo
        Sep 5 at 10:11




        Thank you, this solved perfectly my issue. Thanks also to the other guy who helped me, probably his answer was not strictly what I wanted because I explained it poorly. For the next time, could you please tell me how to include the output of the code I post? So I can show you directly the expected output I'd like to have. Thank you a lot!
        – L Mascolo
        Sep 5 at 10:11




        1




        1




        @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
        – Max
        Sep 5 at 10:17




        @LMascolo Do you mean how to upload an image? Have a look at this page. At the bottom there is a section on uploading images.
        – Max
        Sep 5 at 10:17




        1




        1




        I didn't know it was simply an image, I can do that :) Thank you!
        – L Mascolo
        Sep 5 at 10:27




        I didn't know it was simply an image, I can do that :) Thank you!
        – L Mascolo
        Sep 5 at 10:27










        up vote
        7
        down vote













        You can use xparse:



        documentclassarticle
        usepackageamsmath
        usepackagexparse

        ExplSyntaxOn
        NewDocumentCommandrepsumO3mmm
        % #1 = optional number of starting summands
        % #2 = final number
        % #3 = first symbol
        % #4 = second symbol
        int_step_inline:nn #1 #3sb##1#4sb##1 +
        dotsb
        int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1

        ExplSyntaxOff

        begindocument

        First test: $repsum9Fu$

        Second test: $repsum[2]6Fu$

        The CUF Refined theory expands the summation as
        beginequation
        u=repsum9Fu=F_tau u_tau
        endequation
        where the last expression exploits the Einstein notation.

        enddocument


        The idea is to make a cycle from 1 to 3 (or the number specified in the optional argument), printing the summands with their subscripts followed by +; then print the dots and + followed by the summands from #2-1 (#2 is the final number of summands) to #2.



        With this implementation, you are responsible for ensuring no overlap. So you can do repsum[1]4Fu, but with less than four summands it won't work.



        enter image description here



        A different version that automatically skips the dots if they're not needed.



        documentclassarticle
        usepackageamsmath
        usepackagexparse

        ExplSyntaxOn
        NewDocumentCommandrepsumO3mmm
        % #1 = optional number of starting summands
        % #2 = final number
        % #3 = first symbol
        % #4 = second symbol
        int_compare:nTF #2 - #1 < 3
        % no dots necessary
        #3sb1#4sb1
        int_step_inline:nnn 2 #2 + #3sb##1#4sb##1


        int_step_inline:nn #1 #3sb##1#4sb##1 +
        dotsb
        int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1


        ExplSyntaxOff

        begindocument

        First test: $repsum9Fu$

        Second test: $repsum[2]6Fu$

        Third test: $repsum5Fu$

        Fourth test: $repsum3Fu$

        Fifth test: $repsum2Fu$

        Sixth test: $repsum1Fu$

        The CUF Refined theory expands the summation as
        beginequation
        u=repsum9Fu=F_tau u_tau
        endequation
        where the last expression exploits the Einstein notation.

        enddocument


        enter image description here






        share|improve this answer


























          up vote
          7
          down vote













          You can use xparse:



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn
          NewDocumentCommandrepsumO3mmm
          % #1 = optional number of starting summands
          % #2 = final number
          % #3 = first symbol
          % #4 = second symbol
          int_step_inline:nn #1 #3sb##1#4sb##1 +
          dotsb
          int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1

          ExplSyntaxOff

          begindocument

          First test: $repsum9Fu$

          Second test: $repsum[2]6Fu$

          The CUF Refined theory expands the summation as
          beginequation
          u=repsum9Fu=F_tau u_tau
          endequation
          where the last expression exploits the Einstein notation.

          enddocument


          The idea is to make a cycle from 1 to 3 (or the number specified in the optional argument), printing the summands with their subscripts followed by +; then print the dots and + followed by the summands from #2-1 (#2 is the final number of summands) to #2.



          With this implementation, you are responsible for ensuring no overlap. So you can do repsum[1]4Fu, but with less than four summands it won't work.



          enter image description here



          A different version that automatically skips the dots if they're not needed.



          documentclassarticle
          usepackageamsmath
          usepackagexparse

          ExplSyntaxOn
          NewDocumentCommandrepsumO3mmm
          % #1 = optional number of starting summands
          % #2 = final number
          % #3 = first symbol
          % #4 = second symbol
          int_compare:nTF #2 - #1 < 3
          % no dots necessary
          #3sb1#4sb1
          int_step_inline:nnn 2 #2 + #3sb##1#4sb##1


          int_step_inline:nn #1 #3sb##1#4sb##1 +
          dotsb
          int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1


          ExplSyntaxOff

          begindocument

          First test: $repsum9Fu$

          Second test: $repsum[2]6Fu$

          Third test: $repsum5Fu$

          Fourth test: $repsum3Fu$

          Fifth test: $repsum2Fu$

          Sixth test: $repsum1Fu$

          The CUF Refined theory expands the summation as
          beginequation
          u=repsum9Fu=F_tau u_tau
          endequation
          where the last expression exploits the Einstein notation.

          enddocument


          enter image description here






          share|improve this answer
























            up vote
            7
            down vote










            up vote
            7
            down vote









            You can use xparse:



            documentclassarticle
            usepackageamsmath
            usepackagexparse

            ExplSyntaxOn
            NewDocumentCommandrepsumO3mmm
            % #1 = optional number of starting summands
            % #2 = final number
            % #3 = first symbol
            % #4 = second symbol
            int_step_inline:nn #1 #3sb##1#4sb##1 +
            dotsb
            int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1

            ExplSyntaxOff

            begindocument

            First test: $repsum9Fu$

            Second test: $repsum[2]6Fu$

            The CUF Refined theory expands the summation as
            beginequation
            u=repsum9Fu=F_tau u_tau
            endequation
            where the last expression exploits the Einstein notation.

            enddocument


            The idea is to make a cycle from 1 to 3 (or the number specified in the optional argument), printing the summands with their subscripts followed by +; then print the dots and + followed by the summands from #2-1 (#2 is the final number of summands) to #2.



            With this implementation, you are responsible for ensuring no overlap. So you can do repsum[1]4Fu, but with less than four summands it won't work.



            enter image description here



            A different version that automatically skips the dots if they're not needed.



            documentclassarticle
            usepackageamsmath
            usepackagexparse

            ExplSyntaxOn
            NewDocumentCommandrepsumO3mmm
            % #1 = optional number of starting summands
            % #2 = final number
            % #3 = first symbol
            % #4 = second symbol
            int_compare:nTF #2 - #1 < 3
            % no dots necessary
            #3sb1#4sb1
            int_step_inline:nnn 2 #2 + #3sb##1#4sb##1


            int_step_inline:nn #1 #3sb##1#4sb##1 +
            dotsb
            int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1


            ExplSyntaxOff

            begindocument

            First test: $repsum9Fu$

            Second test: $repsum[2]6Fu$

            Third test: $repsum5Fu$

            Fourth test: $repsum3Fu$

            Fifth test: $repsum2Fu$

            Sixth test: $repsum1Fu$

            The CUF Refined theory expands the summation as
            beginequation
            u=repsum9Fu=F_tau u_tau
            endequation
            where the last expression exploits the Einstein notation.

            enddocument


            enter image description here






            share|improve this answer














            You can use xparse:



            documentclassarticle
            usepackageamsmath
            usepackagexparse

            ExplSyntaxOn
            NewDocumentCommandrepsumO3mmm
            % #1 = optional number of starting summands
            % #2 = final number
            % #3 = first symbol
            % #4 = second symbol
            int_step_inline:nn #1 #3sb##1#4sb##1 +
            dotsb
            int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1

            ExplSyntaxOff

            begindocument

            First test: $repsum9Fu$

            Second test: $repsum[2]6Fu$

            The CUF Refined theory expands the summation as
            beginequation
            u=repsum9Fu=F_tau u_tau
            endequation
            where the last expression exploits the Einstein notation.

            enddocument


            The idea is to make a cycle from 1 to 3 (or the number specified in the optional argument), printing the summands with their subscripts followed by +; then print the dots and + followed by the summands from #2-1 (#2 is the final number of summands) to #2.



            With this implementation, you are responsible for ensuring no overlap. So you can do repsum[1]4Fu, but with less than four summands it won't work.



            enter image description here



            A different version that automatically skips the dots if they're not needed.



            documentclassarticle
            usepackageamsmath
            usepackagexparse

            ExplSyntaxOn
            NewDocumentCommandrepsumO3mmm
            % #1 = optional number of starting summands
            % #2 = final number
            % #3 = first symbol
            % #4 = second symbol
            int_compare:nTF #2 - #1 < 3
            % no dots necessary
            #3sb1#4sb1
            int_step_inline:nnn 2 #2 + #3sb##1#4sb##1


            int_step_inline:nn #1 #3sb##1#4sb##1 +
            dotsb
            int_step_inline:nnn #2 - 1 #2 + #3sb##1#4sb##1


            ExplSyntaxOff

            begindocument

            First test: $repsum9Fu$

            Second test: $repsum[2]6Fu$

            Third test: $repsum5Fu$

            Fourth test: $repsum3Fu$

            Fifth test: $repsum2Fu$

            Sixth test: $repsum1Fu$

            The CUF Refined theory expands the summation as
            beginequation
            u=repsum9Fu=F_tau u_tau
            endequation
            where the last expression exploits the Einstein notation.

            enddocument


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 5 at 10:51

























            answered Sep 5 at 10:36









            egreg

            681k8318103058




            681k8318103058




















                up vote
                3
                down vote













                Maybe this?



                documentclassarticle
                usepackagetikz
                newcommandcussum[1]
                begintikzpicture[baseline=-.1cm]
                foreach x in 1,2,...,#1

                ifnumx<#1
                node at (x,0) $F_xu_x+$;
                fi
                ifnumx=#1
                node at (x-.1,0) $F_xu_x$;
                fi

                endtikzpicture

                begindocument
                cussum9 Minimal Working Examples are nice, aren't they ldots
                enddocument


                Here is the output:



                Screenshot






                share|improve this answer


























                  up vote
                  3
                  down vote













                  Maybe this?



                  documentclassarticle
                  usepackagetikz
                  newcommandcussum[1]
                  begintikzpicture[baseline=-.1cm]
                  foreach x in 1,2,...,#1

                  ifnumx<#1
                  node at (x,0) $F_xu_x+$;
                  fi
                  ifnumx=#1
                  node at (x-.1,0) $F_xu_x$;
                  fi

                  endtikzpicture

                  begindocument
                  cussum9 Minimal Working Examples are nice, aren't they ldots
                  enddocument


                  Here is the output:



                  Screenshot






                  share|improve this answer
























                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    Maybe this?



                    documentclassarticle
                    usepackagetikz
                    newcommandcussum[1]
                    begintikzpicture[baseline=-.1cm]
                    foreach x in 1,2,...,#1

                    ifnumx<#1
                    node at (x,0) $F_xu_x+$;
                    fi
                    ifnumx=#1
                    node at (x-.1,0) $F_xu_x$;
                    fi

                    endtikzpicture

                    begindocument
                    cussum9 Minimal Working Examples are nice, aren't they ldots
                    enddocument


                    Here is the output:



                    Screenshot






                    share|improve this answer














                    Maybe this?



                    documentclassarticle
                    usepackagetikz
                    newcommandcussum[1]
                    begintikzpicture[baseline=-.1cm]
                    foreach x in 1,2,...,#1

                    ifnumx<#1
                    node at (x,0) $F_xu_x+$;
                    fi
                    ifnumx=#1
                    node at (x-.1,0) $F_xu_x$;
                    fi

                    endtikzpicture

                    begindocument
                    cussum9 Minimal Working Examples are nice, aren't they ldots
                    enddocument


                    Here is the output:



                    Screenshot







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Sep 5 at 10:01

























                    answered Sep 5 at 9:58









                    current_user

                    2,5541428




                    2,5541428




















                        up vote
                        0
                        down vote













                        Re-using my replaceiandreplicate-macro from the discussion How to make a command to automate creation of prime factorization-like products?, a possibility of approaching the matter could be:



                        documentclassarticle

                        makeatletter
                        %%=============================================================================
                        %% Paraphernalia:
                        %% UD@firstoftwo, UD@secondoftwo,
                        %% UD@PassFirstToSecond, UD@Exchange, UD@removespace
                        %% UD@CheckWhetherNull, UD@CheckWhetherBrace,
                        %% UD@CheckWhetherLeadingSpace, UD@ExtractFirstArg
                        %%=============================================================================
                        newcommandUD@firstoftwo[2]#1%
                        newcommandUD@secondoftwo[2]#2%
                        newcommandUD@PassFirstToSecond[2]#2#1%
                        newcommandUD@Exchange[2]#2#1%
                        newcommandUD@removespaceUD@firstoftwodefUD@removespace %
                        %%-----------------------------------------------------------------------------
                        %% Check whether argument is empty:
                        %%.............................................................................
                        %% UD@CheckWhetherNull<Argument which is to be checked>%
                        %% <Tokens to be delivered in case that argument
                        %% which is to be checked is empty>%
                        %% <Tokens to be delivered in case that argument
                        %% which is to be checked is not empty>%
                        %%
                        %% The gist of this macro comes from Robert R. Schneck's ifempty-macro:
                        %% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
                        newcommandUD@CheckWhetherNull[1]%
                        romannumeral0expandafterUD@secondoftwostringexpandafter
                        UD@secondoftwoexpandafterexpandafterstring#1expandafter
                        UD@secondoftwostringexpandafterUD@firstoftwoexpandafterexpandafter
                        UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                        UD@secondoftwoexpandafterexpandafterUD@firstoftwo UD@firstoftwo%
                        %
                        %%-----------------------------------------------------------------------------
                        %% Check whether argument's first token is a catcode-1-character
                        %%.............................................................................
                        %% UD@CheckWhetherBrace<Argument which is to be checked>%
                        %% <Tokens to be delivered in case that argument
                        %% which is to be checked has leading
                        %% catcode-1-token>%
                        %% <Tokens to be delivered in case that argument
                        %% which is to be checked has no leading
                        %% catcode-1-token>%
                        newcommandUD@CheckWhetherBrace[1]%
                        romannumeral0expandafterUD@secondoftwoexpandafterexpandafter%
                        string#1.expandafterUD@firstoftwoexpandafterexpandafter
                        UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                        UD@firstoftwoexpandafterexpandafterUD@firstoftwo UD@secondoftwo%
                        %
                        %%-----------------------------------------------------------------------------
                        %% Check whether brace-balanced argument starts with a space-token
                        %%.............................................................................
                        %% UD@CheckWhetherLeadingSpace<Argument which is to be checked>%
                        %% <Tokens to be delivered in case <argument
                        %% which is to be checked>'s 1st token is a
                        %% space-token>%
                        %% <Tokens to be delivered in case <argument
                        %% which is to be checked>'s 1st token is not
                        %% a space-token>%
                        newcommandUD@CheckWhetherLeadingSpace[1]%
                        romannumeral0UD@CheckWhetherNull#1%
                        expandafterexpandafterUD@firstoftwo UD@secondoftwo%
                        expandafterUD@secondoftwostringUD@CheckWhetherLeadingSpaceB.#1 %
                        %
                        newcommandUD@CheckWhetherLeadingSpaceB%
                        longdefUD@CheckWhetherLeadingSpaceB#1 %
                        expandafterUD@CheckWhetherNullexpandafterUD@secondoftwo#1%
                        UD@ExchangeUD@firstoftwoUD@ExchangeUD@secondoftwo%
                        UD@Exchange expandafterexpandafterexpandafterexpandafter
                        expandafterexpandafterexpandafterexpandafterexpandafter
                        expandafterexpandafterUD@secondoftwoexpandafterstring%
                        %
                        %%-----------------------------------------------------------------------------
                        %% Extract first inner undelimited argument:
                        %%
                        %% UD@ExtractFirstArgABCDE yields A
                        %%
                        %% UD@ExtractFirstArgABCDE yields AB
                        %%.............................................................................
                        newcommandUD@RemoveTillUD@SelDOm%
                        longdefUD@RemoveTillUD@SelDOm#1#2UD@SelDOm#1%
                        newcommandUD@ExtractFirstArg[1]%
                        romannumeral0%
                        UD@ExtractFirstArgLoop#1UD@SelDOm%
                        %
                        newcommandUD@ExtractFirstArgLoop[1]%
                        expandafterUD@CheckWhetherNullexpandafterUD@firstoftwo#1%
                        #1%
                        expandafterUD@ExtractFirstArgLoopexpandafterUD@RemoveTillUD@SelDOm#1%
                        %
                        %%=============================================================================
                        %% DefineReplacementMacro<replacement-macro>%
                        %% <internal helper-macro>%
                        %% <item to replace>%
                        %%
                        %% defines <replacement-macro> to fetch two arguments,
                        %% #1 = <replacement for item to replace>
                        %% #2 = <token sequence with item to replace>
                        %% , and -- after two expansion-steps to deliver:
                        %% <token sequence with all instances of <item to replace> replaced
                        %% by <replacement for item to replace>. >
                        %%
                        %% Internally an <internal helper-macro> is needed.
                        %%
                        %% (!!! <replacement-macro> does also replace all pairs of matching
                        %% explicit character tokens of catcode 1/2 by matching braces!!!)
                        %%-----------------------------------------------------------------------------
                        newcommandDefineReplacementMacro[3]%
                        newcommand#2longdef#2##1#3%
                        newcommand#1[2]%
                        romannumeral0UD@ReplaceAllLoop##2##1#2#3%
                        %
                        %
                        newcommandUD@ReplaceAllLoop[5]%
                        UD@CheckWhetherNull#1 #3%
                        UD@CheckWhetherLeadingSpace#1%
                        expandafterUD@ReplaceAllLoop
                        expandafterUD@removespace#1#2#3 #4#5%
                        %
                        UD@CheckWhetherBrace#1%
                        expandafterexpandafterexpandafterUD@PassFirstToSecond
                        expandafterexpandafterexpandafter%
                        expandafterUD@PassFirstToSecondexpandafter%
                        romannumeral0expandafterUD@ReplaceAllLoop
                        romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#2#4#5%
                        #3%
                        expandafterUD@ReplaceAllLoopexpandafterUD@firstoftwo#1#2%
                        #4#5%
                        %
                        expandafterUD@CheckWhetherNoReplacement
                        romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#1#2#3#4#5%
                        %
                        %
                        %
                        %
                        newcommandUD@CheckWhetherNoReplacement[6]%
                        expandafterUD@CheckWhetherNullexpandafter#5#1#6%
                        %
                        expandafterUD@ReplaceAllLoop
                        expandafterUD@firstoftwo#2#3#4#1#5#6%
                        %
                        expandafterUD@ReplaceAllLoop
                        expandafterUD@firstoftwo#2#3#4#3#5#6%
                        %
                        %
                        %%=============================================================================
                        %% UD@ReplaceAlli -- Replace all "i" in undelimited Argument:
                        %%
                        %% UD@ReplaceAlli<replacement for i><token sequence with i>
                        %% yields <token sequence with all i replaced by replacement for i>
                        %%
                        %% <replacement for i> may contain i.
                        %%
                        %% (This routine does also replace all pairs of matching explicit
                        %% character tokens of catcode 1/2 by matching braces!!!)
                        %%
                        %% The letter "i" as item to replace is hard-coded.
                        %% You cannot replace öetters other than I with this macro.
                        %%.............................................................................
                        DefineReplacementMacroUD@ReplaceAlliUD@gobbletoii%
                        %%
                        %%=============================================================================
                        %% replaceiandreplicate<term with i>%
                        %% <loop-start-index>%
                        %% <loop-end-index>%
                        %%
                        %% e.g.,
                        %%
                        %% replaceiandreplicatep_i^epsilon_i13
                        %%.............................................................................
                        newcommandreplaceiandreplicate[3]%
                        romannumeral0replaceiandreplicateloop#3#2#1%
                        %
                        newcommandreplaceiandreplicateloop[4]%
                        ifnum#1<#2 %
                        expandafterUD@firstoftwo
                        else
                        expandafterUD@secondoftwo
                        fi
                        #4%
                        expandafterexpandafterexpandafterUD@PassFirstToSecond
                        expandafterexpandafterexpandafter%
                        UD@ReplaceAlli#1#3#4%
                        %
                        expandafterreplaceiandreplicateloop
                        expandafternumbernumexprnumber#1-1relax#2#3%
                        %
                        %
                        %

                        makeatother

                        parindent=0ex

                        begindocument

                        beginverbatim
                        $replaceiandreplicateifnum i>1+fi F_iu_i19$
                        endverbatim

                        yields:bigskip

                        $replaceiandreplicateifnum i>1+fi F_iu_i19$


                        beginverbatim
                        $csname @gobbleexpandafterexpandafter
                        expandafter endcsname
                        replaceiandreplicate+F_iu_i19$
                        endverbatim

                        yields:bigskip

                        $csname @gobbleexpandafterexpandafter
                        expandafter endcsname
                        replaceiandreplicate+F_iu_i19$

                        enddocument


                        enter image description here






                        share|improve this answer
























                          up vote
                          0
                          down vote













                          Re-using my replaceiandreplicate-macro from the discussion How to make a command to automate creation of prime factorization-like products?, a possibility of approaching the matter could be:



                          documentclassarticle

                          makeatletter
                          %%=============================================================================
                          %% Paraphernalia:
                          %% UD@firstoftwo, UD@secondoftwo,
                          %% UD@PassFirstToSecond, UD@Exchange, UD@removespace
                          %% UD@CheckWhetherNull, UD@CheckWhetherBrace,
                          %% UD@CheckWhetherLeadingSpace, UD@ExtractFirstArg
                          %%=============================================================================
                          newcommandUD@firstoftwo[2]#1%
                          newcommandUD@secondoftwo[2]#2%
                          newcommandUD@PassFirstToSecond[2]#2#1%
                          newcommandUD@Exchange[2]#2#1%
                          newcommandUD@removespaceUD@firstoftwodefUD@removespace %
                          %%-----------------------------------------------------------------------------
                          %% Check whether argument is empty:
                          %%.............................................................................
                          %% UD@CheckWhetherNull<Argument which is to be checked>%
                          %% <Tokens to be delivered in case that argument
                          %% which is to be checked is empty>%
                          %% <Tokens to be delivered in case that argument
                          %% which is to be checked is not empty>%
                          %%
                          %% The gist of this macro comes from Robert R. Schneck's ifempty-macro:
                          %% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
                          newcommandUD@CheckWhetherNull[1]%
                          romannumeral0expandafterUD@secondoftwostringexpandafter
                          UD@secondoftwoexpandafterexpandafterstring#1expandafter
                          UD@secondoftwostringexpandafterUD@firstoftwoexpandafterexpandafter
                          UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                          UD@secondoftwoexpandafterexpandafterUD@firstoftwo UD@firstoftwo%
                          %
                          %%-----------------------------------------------------------------------------
                          %% Check whether argument's first token is a catcode-1-character
                          %%.............................................................................
                          %% UD@CheckWhetherBrace<Argument which is to be checked>%
                          %% <Tokens to be delivered in case that argument
                          %% which is to be checked has leading
                          %% catcode-1-token>%
                          %% <Tokens to be delivered in case that argument
                          %% which is to be checked has no leading
                          %% catcode-1-token>%
                          newcommandUD@CheckWhetherBrace[1]%
                          romannumeral0expandafterUD@secondoftwoexpandafterexpandafter%
                          string#1.expandafterUD@firstoftwoexpandafterexpandafter
                          UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                          UD@firstoftwoexpandafterexpandafterUD@firstoftwo UD@secondoftwo%
                          %
                          %%-----------------------------------------------------------------------------
                          %% Check whether brace-balanced argument starts with a space-token
                          %%.............................................................................
                          %% UD@CheckWhetherLeadingSpace<Argument which is to be checked>%
                          %% <Tokens to be delivered in case <argument
                          %% which is to be checked>'s 1st token is a
                          %% space-token>%
                          %% <Tokens to be delivered in case <argument
                          %% which is to be checked>'s 1st token is not
                          %% a space-token>%
                          newcommandUD@CheckWhetherLeadingSpace[1]%
                          romannumeral0UD@CheckWhetherNull#1%
                          expandafterexpandafterUD@firstoftwo UD@secondoftwo%
                          expandafterUD@secondoftwostringUD@CheckWhetherLeadingSpaceB.#1 %
                          %
                          newcommandUD@CheckWhetherLeadingSpaceB%
                          longdefUD@CheckWhetherLeadingSpaceB#1 %
                          expandafterUD@CheckWhetherNullexpandafterUD@secondoftwo#1%
                          UD@ExchangeUD@firstoftwoUD@ExchangeUD@secondoftwo%
                          UD@Exchange expandafterexpandafterexpandafterexpandafter
                          expandafterexpandafterexpandafterexpandafterexpandafter
                          expandafterexpandafterUD@secondoftwoexpandafterstring%
                          %
                          %%-----------------------------------------------------------------------------
                          %% Extract first inner undelimited argument:
                          %%
                          %% UD@ExtractFirstArgABCDE yields A
                          %%
                          %% UD@ExtractFirstArgABCDE yields AB
                          %%.............................................................................
                          newcommandUD@RemoveTillUD@SelDOm%
                          longdefUD@RemoveTillUD@SelDOm#1#2UD@SelDOm#1%
                          newcommandUD@ExtractFirstArg[1]%
                          romannumeral0%
                          UD@ExtractFirstArgLoop#1UD@SelDOm%
                          %
                          newcommandUD@ExtractFirstArgLoop[1]%
                          expandafterUD@CheckWhetherNullexpandafterUD@firstoftwo#1%
                          #1%
                          expandafterUD@ExtractFirstArgLoopexpandafterUD@RemoveTillUD@SelDOm#1%
                          %
                          %%=============================================================================
                          %% DefineReplacementMacro<replacement-macro>%
                          %% <internal helper-macro>%
                          %% <item to replace>%
                          %%
                          %% defines <replacement-macro> to fetch two arguments,
                          %% #1 = <replacement for item to replace>
                          %% #2 = <token sequence with item to replace>
                          %% , and -- after two expansion-steps to deliver:
                          %% <token sequence with all instances of <item to replace> replaced
                          %% by <replacement for item to replace>. >
                          %%
                          %% Internally an <internal helper-macro> is needed.
                          %%
                          %% (!!! <replacement-macro> does also replace all pairs of matching
                          %% explicit character tokens of catcode 1/2 by matching braces!!!)
                          %%-----------------------------------------------------------------------------
                          newcommandDefineReplacementMacro[3]%
                          newcommand#2longdef#2##1#3%
                          newcommand#1[2]%
                          romannumeral0UD@ReplaceAllLoop##2##1#2#3%
                          %
                          %
                          newcommandUD@ReplaceAllLoop[5]%
                          UD@CheckWhetherNull#1 #3%
                          UD@CheckWhetherLeadingSpace#1%
                          expandafterUD@ReplaceAllLoop
                          expandafterUD@removespace#1#2#3 #4#5%
                          %
                          UD@CheckWhetherBrace#1%
                          expandafterexpandafterexpandafterUD@PassFirstToSecond
                          expandafterexpandafterexpandafter%
                          expandafterUD@PassFirstToSecondexpandafter%
                          romannumeral0expandafterUD@ReplaceAllLoop
                          romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#2#4#5%
                          #3%
                          expandafterUD@ReplaceAllLoopexpandafterUD@firstoftwo#1#2%
                          #4#5%
                          %
                          expandafterUD@CheckWhetherNoReplacement
                          romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#1#2#3#4#5%
                          %
                          %
                          %
                          %
                          newcommandUD@CheckWhetherNoReplacement[6]%
                          expandafterUD@CheckWhetherNullexpandafter#5#1#6%
                          %
                          expandafterUD@ReplaceAllLoop
                          expandafterUD@firstoftwo#2#3#4#1#5#6%
                          %
                          expandafterUD@ReplaceAllLoop
                          expandafterUD@firstoftwo#2#3#4#3#5#6%
                          %
                          %
                          %%=============================================================================
                          %% UD@ReplaceAlli -- Replace all "i" in undelimited Argument:
                          %%
                          %% UD@ReplaceAlli<replacement for i><token sequence with i>
                          %% yields <token sequence with all i replaced by replacement for i>
                          %%
                          %% <replacement for i> may contain i.
                          %%
                          %% (This routine does also replace all pairs of matching explicit
                          %% character tokens of catcode 1/2 by matching braces!!!)
                          %%
                          %% The letter "i" as item to replace is hard-coded.
                          %% You cannot replace öetters other than I with this macro.
                          %%.............................................................................
                          DefineReplacementMacroUD@ReplaceAlliUD@gobbletoii%
                          %%
                          %%=============================================================================
                          %% replaceiandreplicate<term with i>%
                          %% <loop-start-index>%
                          %% <loop-end-index>%
                          %%
                          %% e.g.,
                          %%
                          %% replaceiandreplicatep_i^epsilon_i13
                          %%.............................................................................
                          newcommandreplaceiandreplicate[3]%
                          romannumeral0replaceiandreplicateloop#3#2#1%
                          %
                          newcommandreplaceiandreplicateloop[4]%
                          ifnum#1<#2 %
                          expandafterUD@firstoftwo
                          else
                          expandafterUD@secondoftwo
                          fi
                          #4%
                          expandafterexpandafterexpandafterUD@PassFirstToSecond
                          expandafterexpandafterexpandafter%
                          UD@ReplaceAlli#1#3#4%
                          %
                          expandafterreplaceiandreplicateloop
                          expandafternumbernumexprnumber#1-1relax#2#3%
                          %
                          %
                          %

                          makeatother

                          parindent=0ex

                          begindocument

                          beginverbatim
                          $replaceiandreplicateifnum i>1+fi F_iu_i19$
                          endverbatim

                          yields:bigskip

                          $replaceiandreplicateifnum i>1+fi F_iu_i19$


                          beginverbatim
                          $csname @gobbleexpandafterexpandafter
                          expandafter endcsname
                          replaceiandreplicate+F_iu_i19$
                          endverbatim

                          yields:bigskip

                          $csname @gobbleexpandafterexpandafter
                          expandafter endcsname
                          replaceiandreplicate+F_iu_i19$

                          enddocument


                          enter image description here






                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            Re-using my replaceiandreplicate-macro from the discussion How to make a command to automate creation of prime factorization-like products?, a possibility of approaching the matter could be:



                            documentclassarticle

                            makeatletter
                            %%=============================================================================
                            %% Paraphernalia:
                            %% UD@firstoftwo, UD@secondoftwo,
                            %% UD@PassFirstToSecond, UD@Exchange, UD@removespace
                            %% UD@CheckWhetherNull, UD@CheckWhetherBrace,
                            %% UD@CheckWhetherLeadingSpace, UD@ExtractFirstArg
                            %%=============================================================================
                            newcommandUD@firstoftwo[2]#1%
                            newcommandUD@secondoftwo[2]#2%
                            newcommandUD@PassFirstToSecond[2]#2#1%
                            newcommandUD@Exchange[2]#2#1%
                            newcommandUD@removespaceUD@firstoftwodefUD@removespace %
                            %%-----------------------------------------------------------------------------
                            %% Check whether argument is empty:
                            %%.............................................................................
                            %% UD@CheckWhetherNull<Argument which is to be checked>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked is empty>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked is not empty>%
                            %%
                            %% The gist of this macro comes from Robert R. Schneck's ifempty-macro:
                            %% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
                            newcommandUD@CheckWhetherNull[1]%
                            romannumeral0expandafterUD@secondoftwostringexpandafter
                            UD@secondoftwoexpandafterexpandafterstring#1expandafter
                            UD@secondoftwostringexpandafterUD@firstoftwoexpandafterexpandafter
                            UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                            UD@secondoftwoexpandafterexpandafterUD@firstoftwo UD@firstoftwo%
                            %
                            %%-----------------------------------------------------------------------------
                            %% Check whether argument's first token is a catcode-1-character
                            %%.............................................................................
                            %% UD@CheckWhetherBrace<Argument which is to be checked>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked has leading
                            %% catcode-1-token>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked has no leading
                            %% catcode-1-token>%
                            newcommandUD@CheckWhetherBrace[1]%
                            romannumeral0expandafterUD@secondoftwoexpandafterexpandafter%
                            string#1.expandafterUD@firstoftwoexpandafterexpandafter
                            UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                            UD@firstoftwoexpandafterexpandafterUD@firstoftwo UD@secondoftwo%
                            %
                            %%-----------------------------------------------------------------------------
                            %% Check whether brace-balanced argument starts with a space-token
                            %%.............................................................................
                            %% UD@CheckWhetherLeadingSpace<Argument which is to be checked>%
                            %% <Tokens to be delivered in case <argument
                            %% which is to be checked>'s 1st token is a
                            %% space-token>%
                            %% <Tokens to be delivered in case <argument
                            %% which is to be checked>'s 1st token is not
                            %% a space-token>%
                            newcommandUD@CheckWhetherLeadingSpace[1]%
                            romannumeral0UD@CheckWhetherNull#1%
                            expandafterexpandafterUD@firstoftwo UD@secondoftwo%
                            expandafterUD@secondoftwostringUD@CheckWhetherLeadingSpaceB.#1 %
                            %
                            newcommandUD@CheckWhetherLeadingSpaceB%
                            longdefUD@CheckWhetherLeadingSpaceB#1 %
                            expandafterUD@CheckWhetherNullexpandafterUD@secondoftwo#1%
                            UD@ExchangeUD@firstoftwoUD@ExchangeUD@secondoftwo%
                            UD@Exchange expandafterexpandafterexpandafterexpandafter
                            expandafterexpandafterexpandafterexpandafterexpandafter
                            expandafterexpandafterUD@secondoftwoexpandafterstring%
                            %
                            %%-----------------------------------------------------------------------------
                            %% Extract first inner undelimited argument:
                            %%
                            %% UD@ExtractFirstArgABCDE yields A
                            %%
                            %% UD@ExtractFirstArgABCDE yields AB
                            %%.............................................................................
                            newcommandUD@RemoveTillUD@SelDOm%
                            longdefUD@RemoveTillUD@SelDOm#1#2UD@SelDOm#1%
                            newcommandUD@ExtractFirstArg[1]%
                            romannumeral0%
                            UD@ExtractFirstArgLoop#1UD@SelDOm%
                            %
                            newcommandUD@ExtractFirstArgLoop[1]%
                            expandafterUD@CheckWhetherNullexpandafterUD@firstoftwo#1%
                            #1%
                            expandafterUD@ExtractFirstArgLoopexpandafterUD@RemoveTillUD@SelDOm#1%
                            %
                            %%=============================================================================
                            %% DefineReplacementMacro<replacement-macro>%
                            %% <internal helper-macro>%
                            %% <item to replace>%
                            %%
                            %% defines <replacement-macro> to fetch two arguments,
                            %% #1 = <replacement for item to replace>
                            %% #2 = <token sequence with item to replace>
                            %% , and -- after two expansion-steps to deliver:
                            %% <token sequence with all instances of <item to replace> replaced
                            %% by <replacement for item to replace>. >
                            %%
                            %% Internally an <internal helper-macro> is needed.
                            %%
                            %% (!!! <replacement-macro> does also replace all pairs of matching
                            %% explicit character tokens of catcode 1/2 by matching braces!!!)
                            %%-----------------------------------------------------------------------------
                            newcommandDefineReplacementMacro[3]%
                            newcommand#2longdef#2##1#3%
                            newcommand#1[2]%
                            romannumeral0UD@ReplaceAllLoop##2##1#2#3%
                            %
                            %
                            newcommandUD@ReplaceAllLoop[5]%
                            UD@CheckWhetherNull#1 #3%
                            UD@CheckWhetherLeadingSpace#1%
                            expandafterUD@ReplaceAllLoop
                            expandafterUD@removespace#1#2#3 #4#5%
                            %
                            UD@CheckWhetherBrace#1%
                            expandafterexpandafterexpandafterUD@PassFirstToSecond
                            expandafterexpandafterexpandafter%
                            expandafterUD@PassFirstToSecondexpandafter%
                            romannumeral0expandafterUD@ReplaceAllLoop
                            romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#2#4#5%
                            #3%
                            expandafterUD@ReplaceAllLoopexpandafterUD@firstoftwo#1#2%
                            #4#5%
                            %
                            expandafterUD@CheckWhetherNoReplacement
                            romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#1#2#3#4#5%
                            %
                            %
                            %
                            %
                            newcommandUD@CheckWhetherNoReplacement[6]%
                            expandafterUD@CheckWhetherNullexpandafter#5#1#6%
                            %
                            expandafterUD@ReplaceAllLoop
                            expandafterUD@firstoftwo#2#3#4#1#5#6%
                            %
                            expandafterUD@ReplaceAllLoop
                            expandafterUD@firstoftwo#2#3#4#3#5#6%
                            %
                            %
                            %%=============================================================================
                            %% UD@ReplaceAlli -- Replace all "i" in undelimited Argument:
                            %%
                            %% UD@ReplaceAlli<replacement for i><token sequence with i>
                            %% yields <token sequence with all i replaced by replacement for i>
                            %%
                            %% <replacement for i> may contain i.
                            %%
                            %% (This routine does also replace all pairs of matching explicit
                            %% character tokens of catcode 1/2 by matching braces!!!)
                            %%
                            %% The letter "i" as item to replace is hard-coded.
                            %% You cannot replace öetters other than I with this macro.
                            %%.............................................................................
                            DefineReplacementMacroUD@ReplaceAlliUD@gobbletoii%
                            %%
                            %%=============================================================================
                            %% replaceiandreplicate<term with i>%
                            %% <loop-start-index>%
                            %% <loop-end-index>%
                            %%
                            %% e.g.,
                            %%
                            %% replaceiandreplicatep_i^epsilon_i13
                            %%.............................................................................
                            newcommandreplaceiandreplicate[3]%
                            romannumeral0replaceiandreplicateloop#3#2#1%
                            %
                            newcommandreplaceiandreplicateloop[4]%
                            ifnum#1<#2 %
                            expandafterUD@firstoftwo
                            else
                            expandafterUD@secondoftwo
                            fi
                            #4%
                            expandafterexpandafterexpandafterUD@PassFirstToSecond
                            expandafterexpandafterexpandafter%
                            UD@ReplaceAlli#1#3#4%
                            %
                            expandafterreplaceiandreplicateloop
                            expandafternumbernumexprnumber#1-1relax#2#3%
                            %
                            %
                            %

                            makeatother

                            parindent=0ex

                            begindocument

                            beginverbatim
                            $replaceiandreplicateifnum i>1+fi F_iu_i19$
                            endverbatim

                            yields:bigskip

                            $replaceiandreplicateifnum i>1+fi F_iu_i19$


                            beginverbatim
                            $csname @gobbleexpandafterexpandafter
                            expandafter endcsname
                            replaceiandreplicate+F_iu_i19$
                            endverbatim

                            yields:bigskip

                            $csname @gobbleexpandafterexpandafter
                            expandafter endcsname
                            replaceiandreplicate+F_iu_i19$

                            enddocument


                            enter image description here






                            share|improve this answer












                            Re-using my replaceiandreplicate-macro from the discussion How to make a command to automate creation of prime factorization-like products?, a possibility of approaching the matter could be:



                            documentclassarticle

                            makeatletter
                            %%=============================================================================
                            %% Paraphernalia:
                            %% UD@firstoftwo, UD@secondoftwo,
                            %% UD@PassFirstToSecond, UD@Exchange, UD@removespace
                            %% UD@CheckWhetherNull, UD@CheckWhetherBrace,
                            %% UD@CheckWhetherLeadingSpace, UD@ExtractFirstArg
                            %%=============================================================================
                            newcommandUD@firstoftwo[2]#1%
                            newcommandUD@secondoftwo[2]#2%
                            newcommandUD@PassFirstToSecond[2]#2#1%
                            newcommandUD@Exchange[2]#2#1%
                            newcommandUD@removespaceUD@firstoftwodefUD@removespace %
                            %%-----------------------------------------------------------------------------
                            %% Check whether argument is empty:
                            %%.............................................................................
                            %% UD@CheckWhetherNull<Argument which is to be checked>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked is empty>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked is not empty>%
                            %%
                            %% The gist of this macro comes from Robert R. Schneck's ifempty-macro:
                            %% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
                            newcommandUD@CheckWhetherNull[1]%
                            romannumeral0expandafterUD@secondoftwostringexpandafter
                            UD@secondoftwoexpandafterexpandafterstring#1expandafter
                            UD@secondoftwostringexpandafterUD@firstoftwoexpandafterexpandafter
                            UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                            UD@secondoftwoexpandafterexpandafterUD@firstoftwo UD@firstoftwo%
                            %
                            %%-----------------------------------------------------------------------------
                            %% Check whether argument's first token is a catcode-1-character
                            %%.............................................................................
                            %% UD@CheckWhetherBrace<Argument which is to be checked>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked has leading
                            %% catcode-1-token>%
                            %% <Tokens to be delivered in case that argument
                            %% which is to be checked has no leading
                            %% catcode-1-token>%
                            newcommandUD@CheckWhetherBrace[1]%
                            romannumeral0expandafterUD@secondoftwoexpandafterexpandafter%
                            string#1.expandafterUD@firstoftwoexpandafterexpandafter
                            UD@secondoftwostringexpandafterexpandafterUD@firstoftwo %
                            UD@firstoftwoexpandafterexpandafterUD@firstoftwo UD@secondoftwo%
                            %
                            %%-----------------------------------------------------------------------------
                            %% Check whether brace-balanced argument starts with a space-token
                            %%.............................................................................
                            %% UD@CheckWhetherLeadingSpace<Argument which is to be checked>%
                            %% <Tokens to be delivered in case <argument
                            %% which is to be checked>'s 1st token is a
                            %% space-token>%
                            %% <Tokens to be delivered in case <argument
                            %% which is to be checked>'s 1st token is not
                            %% a space-token>%
                            newcommandUD@CheckWhetherLeadingSpace[1]%
                            romannumeral0UD@CheckWhetherNull#1%
                            expandafterexpandafterUD@firstoftwo UD@secondoftwo%
                            expandafterUD@secondoftwostringUD@CheckWhetherLeadingSpaceB.#1 %
                            %
                            newcommandUD@CheckWhetherLeadingSpaceB%
                            longdefUD@CheckWhetherLeadingSpaceB#1 %
                            expandafterUD@CheckWhetherNullexpandafterUD@secondoftwo#1%
                            UD@ExchangeUD@firstoftwoUD@ExchangeUD@secondoftwo%
                            UD@Exchange expandafterexpandafterexpandafterexpandafter
                            expandafterexpandafterexpandafterexpandafterexpandafter
                            expandafterexpandafterUD@secondoftwoexpandafterstring%
                            %
                            %%-----------------------------------------------------------------------------
                            %% Extract first inner undelimited argument:
                            %%
                            %% UD@ExtractFirstArgABCDE yields A
                            %%
                            %% UD@ExtractFirstArgABCDE yields AB
                            %%.............................................................................
                            newcommandUD@RemoveTillUD@SelDOm%
                            longdefUD@RemoveTillUD@SelDOm#1#2UD@SelDOm#1%
                            newcommandUD@ExtractFirstArg[1]%
                            romannumeral0%
                            UD@ExtractFirstArgLoop#1UD@SelDOm%
                            %
                            newcommandUD@ExtractFirstArgLoop[1]%
                            expandafterUD@CheckWhetherNullexpandafterUD@firstoftwo#1%
                            #1%
                            expandafterUD@ExtractFirstArgLoopexpandafterUD@RemoveTillUD@SelDOm#1%
                            %
                            %%=============================================================================
                            %% DefineReplacementMacro<replacement-macro>%
                            %% <internal helper-macro>%
                            %% <item to replace>%
                            %%
                            %% defines <replacement-macro> to fetch two arguments,
                            %% #1 = <replacement for item to replace>
                            %% #2 = <token sequence with item to replace>
                            %% , and -- after two expansion-steps to deliver:
                            %% <token sequence with all instances of <item to replace> replaced
                            %% by <replacement for item to replace>. >
                            %%
                            %% Internally an <internal helper-macro> is needed.
                            %%
                            %% (!!! <replacement-macro> does also replace all pairs of matching
                            %% explicit character tokens of catcode 1/2 by matching braces!!!)
                            %%-----------------------------------------------------------------------------
                            newcommandDefineReplacementMacro[3]%
                            newcommand#2longdef#2##1#3%
                            newcommand#1[2]%
                            romannumeral0UD@ReplaceAllLoop##2##1#2#3%
                            %
                            %
                            newcommandUD@ReplaceAllLoop[5]%
                            UD@CheckWhetherNull#1 #3%
                            UD@CheckWhetherLeadingSpace#1%
                            expandafterUD@ReplaceAllLoop
                            expandafterUD@removespace#1#2#3 #4#5%
                            %
                            UD@CheckWhetherBrace#1%
                            expandafterexpandafterexpandafterUD@PassFirstToSecond
                            expandafterexpandafterexpandafter%
                            expandafterUD@PassFirstToSecondexpandafter%
                            romannumeral0expandafterUD@ReplaceAllLoop
                            romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#2#4#5%
                            #3%
                            expandafterUD@ReplaceAllLoopexpandafterUD@firstoftwo#1#2%
                            #4#5%
                            %
                            expandafterUD@CheckWhetherNoReplacement
                            romannumeral0UD@ExtractFirstArgLoop#1UD@SelDOm#1#2#3#4#5%
                            %
                            %
                            %
                            %
                            newcommandUD@CheckWhetherNoReplacement[6]%
                            expandafterUD@CheckWhetherNullexpandafter#5#1#6%
                            %
                            expandafterUD@ReplaceAllLoop
                            expandafterUD@firstoftwo#2#3#4#1#5#6%
                            %
                            expandafterUD@ReplaceAllLoop
                            expandafterUD@firstoftwo#2#3#4#3#5#6%
                            %
                            %
                            %%=============================================================================
                            %% UD@ReplaceAlli -- Replace all "i" in undelimited Argument:
                            %%
                            %% UD@ReplaceAlli<replacement for i><token sequence with i>
                            %% yields <token sequence with all i replaced by replacement for i>
                            %%
                            %% <replacement for i> may contain i.
                            %%
                            %% (This routine does also replace all pairs of matching explicit
                            %% character tokens of catcode 1/2 by matching braces!!!)
                            %%
                            %% The letter "i" as item to replace is hard-coded.
                            %% You cannot replace öetters other than I with this macro.
                            %%.............................................................................
                            DefineReplacementMacroUD@ReplaceAlliUD@gobbletoii%
                            %%
                            %%=============================================================================
                            %% replaceiandreplicate<term with i>%
                            %% <loop-start-index>%
                            %% <loop-end-index>%
                            %%
                            %% e.g.,
                            %%
                            %% replaceiandreplicatep_i^epsilon_i13
                            %%.............................................................................
                            newcommandreplaceiandreplicate[3]%
                            romannumeral0replaceiandreplicateloop#3#2#1%
                            %
                            newcommandreplaceiandreplicateloop[4]%
                            ifnum#1<#2 %
                            expandafterUD@firstoftwo
                            else
                            expandafterUD@secondoftwo
                            fi
                            #4%
                            expandafterexpandafterexpandafterUD@PassFirstToSecond
                            expandafterexpandafterexpandafter%
                            UD@ReplaceAlli#1#3#4%
                            %
                            expandafterreplaceiandreplicateloop
                            expandafternumbernumexprnumber#1-1relax#2#3%
                            %
                            %
                            %

                            makeatother

                            parindent=0ex

                            begindocument

                            beginverbatim
                            $replaceiandreplicateifnum i>1+fi F_iu_i19$
                            endverbatim

                            yields:bigskip

                            $replaceiandreplicateifnum i>1+fi F_iu_i19$


                            beginverbatim
                            $csname @gobbleexpandafterexpandafter
                            expandafter endcsname
                            replaceiandreplicate+F_iu_i19$
                            endverbatim

                            yields:bigskip

                            $csname @gobbleexpandafterexpandafter
                            expandafter endcsname
                            replaceiandreplicate+F_iu_i19$

                            enddocument


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 5 at 15:33









                            Ulrich Diez

                            3,250414




                            3,250414



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449414%2floop-code-for-repeated-sums%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

                                Confectionery