Skip to main content
Tweeted twitter.com/StackTeX/status/1037309499697184768
added 744 characters in body
Source Link
L Mascolo
  • 327
  • 1
  • 10

I tried to read other topics regarding \newcommand*\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 Let me explain better: I would like to create a \newcommand\newcommand that simply by typing \repsum{9}{F}{u}\repsum{9}{F}{u}, 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 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)

\documentclass{article}
\newcommand*{\repsum}[3]{
    for i=1:#1
        if i~=#1
            #2_i#3_i+
        else
            #2_i#3_i
        end
    end
\begin{document}

The CUF Refined theory expands the summation as

\begin{equation}
u=\repsum{9}{F}{u}=F_\tau u_\tau
\end{equation}

where the last expression exploits the Einstein notation. 

\end{document}

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 \repsum{9}{F}{u}, 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.

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 \repsum{9}{F}{u}, 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)

\documentclass{article}
\newcommand*{\repsum}[3]{
    for i=1:#1
        if i~=#1
            #2_i#3_i+
        else
            #2_i#3_i
        end
    end
\begin{document}

The CUF Refined theory expands the summation as

\begin{equation}
u=\repsum{9}{F}{u}=F_\tau u_\tau
\end{equation}

where the last expression exploits the Einstein notation. 

\end{document}
added 8 characters in body
Source Link
Sebastiano
  • 68.8k
  • 18
  • 124
  • 279

I tried to read other topics regarding \newcommand*\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

Let me explain better: I would like to create a \newcommand\newcommand that simply by typing \repsum{9}{F}{u}\repsum{9}{F}{u}, 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_9F_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 :).

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 \repsum{9}{F}{u}, 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 :)

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 \repsum{9}{F}{u}, 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.

Source Link
L Mascolo
  • 327
  • 1
  • 10

Loop code for repeated sums

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 \repsum{9}{F}{u}, 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 :)