5
$\begingroup$

I want to display a variable with multiple subscripts (divided by commas) and a superscript surrounded by parentheses.

Namely, I want something like this:

rulesForDisplaying = { a[n_,i_,k_] -> _____________ }

where the _____ is something that will make a[n,i,k]//rulesForDisplaying show up as

$$ a_{n,i}^{(k)} \ \ , $$

where $n$,$i$, and $k$ can be anything.

I've tried doing something like Superscript[Subscript[a,n,i],k], but there's two issues: (1) I don't know how to get artifical parentheses around k and (2) the k ends up displayed far off to the right as opposed to on top of the "n,i".

I apologize if this question has been asked before, but I haven't been able to find the relevant post. I'm using Mathematica 10.1, if that's relevant.

Thanks!

$\endgroup$
5
$\begingroup$
rulesForDisplaying[x_, n_, j_, z_] := 
\!\(\*SubsuperscriptBox[\(x\), \(n, 
  j\), \("\<(\>" <> ToString[z] <> "\<)\>"\)]\)

rulesForDisplaying[x, n, j, z]

$x_{n,j}^{\text{(z)}}$

or....

rulesForDisplaying2[a[n_, j_, z_]] := 
\!\(\*SubsuperscriptBox[\(a\), \(n, 
  j\), \("\<(\>" <> ToString[z] <> "\<)\>"\)]\)

rulesForDisplaying2[a[n, j, z]]

$a_{n,j}^{\text{(z)}}$

$\endgroup$
  • $\begingroup$ Thanks! I think that last edit did it. :) $\endgroup$ – nukeguy Sep 23 '15 at 18:51
  • 1
    $\begingroup$ a little variation: Subsuperscript[a, Row[{n, j}, ","], MatrixForm[{z}]] $\endgroup$ – george2079 Sep 23 '15 at 18:57
5
$\begingroup$

Format automatically formats for display

Format[a[n_, i_, k_]] :=
 Subsuperscript[a,
  ToString[n] <> "," <> ToString[i],
  "(" <> ToString[k] <> ")"]

{a[n, i, j], a[1, 2, 3]}

enter image description here

$\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.