0
$\begingroup$

I want to write the following in mathematica

$$ (\sum_{k=1}^n a^2_k)$$

Now I've written this as an indexed variable

Sum[(a^2)[k], {k, 1, n}]

which in mathematica shows up as $$ \sum_{k=1}^n (a[k])^2$$ But I want this displayed as the Latex form, with the subscripts (but I don't want to use the subscript command) and I tried

(# /: Format[(Power[#[i_], exp_])] := 
 Subscript[(Power[#, exp]), i]) & /@ {a};

But I get an error saying

"Rule for Format of (a^exp_)[i_] can only be attached to Power."

Please guide me on what I am doing wrong with the Format command.

Thanks in advance.

$\endgroup$
6
  • $\begingroup$ "but I don't want to use the subscript command" Why not? (a^2)[k] doesn't make much sense for anything else than displaying an expression in a certain way, anyway. $\endgroup$
    – Szabolcs
    Oct 8, 2017 at 11:28
  • $\begingroup$ @Szabolcs , because I don't the fullform of the expression to have subscripts. But I just want it to be displayed that way. $\endgroup$
    – S. Khan
    Oct 8, 2017 at 11:57
  • $\begingroup$ I don't understand your comment because it is not a full sentence. $\endgroup$
    – Szabolcs
    Oct 8, 2017 at 12:39
  • $\begingroup$ @Szabolcs , there is nothing ambiguous about that sentence. When I use FullForm[expr] on the expression containing things like the one mentioned in the question, I don't want it show subscripts in the fullform. I just want to use the Format command to display it that way. This question relates to the use of the format command. $\endgroup$
    – S. Khan
    Oct 8, 2017 at 13:24
  • $\begingroup$ "I don't the fullform" is not a full sentence. I don't think a reasonable answer can be given unless you explain what you want in very clear terms. (a^2)[k] is plainly incorrect in Mathematica. Redefining the way Power formats is a bad idea. I am not sure what you are trying to achieve with #. For these reasons, I am going to stop here. $\endgroup$
    – Szabolcs
    Oct 8, 2017 at 13:32

1 Answer 1

3
$\begingroup$

Possibly you want to do:

Format[a[k_]] := Subscript[a,k]

Sum[a[k]^2,{k,1,Infinity}]//TeXForm

$$\sum _{k=1}^{\infty } a_k{}^2$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.