9

A slightly more general version of JasonB's solution: deSubscript[string_] := StringReplace[string, "\!\(\*SubscriptBox[\(" ~~ Shortest[x__] ~~ "\), \(" ~~ Shortest[y__] ~~ "\)]\)" :> x <> y ]; which also works if the string contains something other than a single SubscriptBox: In[243]:= subscriptBoxToString["\!\(\*SubscriptBox[\(aH\), \(...


9

The real solution here is not to use B in a subscript, or better: not to use Subscript at all. If you can't or don't want to do that, you can add an extra transformation rule for all Subscript expressions. Once ReplaceAll processes a subexpression, it won't touch it anymore. expr = Subscript[x, B] + B; expr /. B -> 1 (* 1 + Subscript[x, 1] *) expr /. {...


7

This would need to be modified for other forms, but it does what you are asking deSubscript = StringReplace[#, "\!\(\*SubscriptBox[\(" ~~ var__ ~~ "\), \(" ~~ sub_ ~~ "\)]\)" :> var <> sub] &; gases = {"Air", "He", "Ar", "\!\(\*SubscriptBox[\(N\), \(2\)]\)", "\!\(\*SubscriptBox[\(CO\), \(2\)]\)"}; deSubscript[gases] (* {"Air", ...


7

Subscripts are generally more trouble than they are worth and cannot be used as variables. You can use Format to display variables as if subscripted. Format[c1] := Subscript["c", 1] (* string used to avoid problem if symbol c has assigned value *) Format[c2] := Subscript["c", 2] Format[x1] := Subscript["x", 1] Format[x2] := Subscript["x", 2] Format[y1] := ...


7

When you convert the subscripts to strings be sure to choose StandardForm: "Test " <> ToString[Subscript["x", "21"], StandardForm] <> " test" Here is it again saved as a PDF:


7

You could just save global variables and Subscript: Save[file, {"`*", "Subscript"}] If you really want to use the Notation package, then the problem is that the functions that know how to convert back and forth between the symbolized and unsymbolized forms are not being saved. Here are your definitions: Get["Notation`"] Symbolize[ParsedBoxWrapper[...


7

This can be solved by applying custom formatting to kx rather than using Subscript: kx /: MakeBoxes[kx, TraditionalForm | StandardForm] := SubscriptBox["k", "x"]; Then kx will be output as $k_x$, and the derivative will be correct: D[kx, k] 0 Would highly recommend looking at TagSet (/:) and MakeBoxes in the documentation for further information. Due ...


6

An alternative to subscripts as indices... Instead of: {Subscript[x, 1], Subscript[x, 2]} Let's use: x[1], x[2] And this can be generalized to: Subscript[x, i, j] --> x[i,j] This will uniquely identify any number of variables to any dimension.


6

The most straightforward approach is to convert your string representation of boxes into explicit boxes, and then apply a replacement rule. The internal function which does this was uncovered by John Fultz: stringToBoxes[s_String] := MathLink`CallFrontEnd[FrontEnd`UndocumentedTestFEParserPacket[s, False]][[1, 1]] Now stringToBoxes /@ gases /. ...


6

Mathematica does not evaluate expression like any other language I can think of. To use it successfully you will have to adjust to that fact. Subscript[g, 1] in not interpreted as a variable but as an expression, and is evaluated like any other expression, which is why when g has a value, you get what you see. When g is value free, Subscript[g, 1], a down-...


6

A couple possible alternatives: Use "g" in the subscript instead: Subscript["g", 1] Subscript[g, 1] You can't tell the difference in StandardForm. Give Subscript the HoldFirst attribute: SetAttributes[Subscript, HoldFirst]; g = 2; Subscript[g, 1]


5

This will remove all DownValues of Subscript that contain the symbol aa: DownValues[Subscript] = Cases[DownValues[Subscript], dv_ /; FreeQ[dv, aa]] It won't remove SubValues, but those can be removed in a similar way. You can avoid the trouble with DownValues by using UpValues, as shown in Clear complains that a subscripted variable is not a symbol or a ...


5

ToString /@ ((Row[{##}] & @@ ToExpression[#, InputForm]) & /@ gases) {"Air", "He", "Ar", "N2", "CO2"} Not safe if Air, CO and other symbols have global values. And here is a more flexible method, which should not leak evaluation like the former: CO=4;He=5; Internal`InheritedBlock[{Format, Subscript, Row} , SetAttributes[{Subscript, ...


5

A string replacement method using the two lines obtained from ToString with mainly StringPosition and StringReplacePart. ClearAll[toStringWithSubscript]; toStringWithSubscript[str_String] := Module[{lines = StringSplit[ToString[str], "\n"], subPos}, subPos = StringPosition[Last@lines, Longest[Except[WhitespaceCharacter] ..], Overlaps -> False]...


5

For pedagogical purposes: In general, using Subscripts to define variables is a bad idea in Mathematica. In your problem, I suggest either using k[n] or defining a List ks where each element is one of your matrices. Avoid using capital letters when defining variables. All Mathematica built-ins start with capital letters; for instance, K is a reserved symbol ...


5

When you type in a notebook the expression Style[ Subsuperscript[Subscript["E", 0] [τ], m, a]/ Subsuperscript[Subscript["E", 0][N], m, m], FontSize -> 28 ] the output appears as This is StandardForm. When you use the same expression in a Plot3D the expression prints in TraditionalForm which typically is viewed as more appealing. If you want to ...


5

Rewrite your matrix (notice I'm fixing a the erroneous Subscript[towpx^2, i] that should be Subscript[towpx, i]^2. b = A /. {Subscript[Power[var_, exp_], index_] -> Power[var[index], exp], Subscript[var_, index_] -> var[index]} Define an UpValue rule for displaying var[index] as Subscript[var,index] for the vars of interest. (# /: Format[#[i_]] ...


5

I would strongly recommend not using Subscript. One should think of Subscript as a typographical construct (which can be abused to use subscripting of a variable). Better is to use: L[n] comm[L[n_], L[m_]] := n - m Then you can call the function like this: comm[L[15], L[8]] 7


4

A subscripted symbol is an expression involving the symbol. It is not a new symbol. Here is what you are asking Mma to do: D[Times[2, Subscript[x, p]], x] This is an expression in x, so Mma does exactly what you ask it to: it differentiates an expression in x with respect to x.


4

https://reference.wolfram.com/language/ref/Subscript.html Array[Subscript[a, #1, #2] &, {3, 3}] // MatrixForm


4

Use Equal rather than Set in an equation. I recommend that you use Format to display the output in subscripted form without subsequently having to enter subscripts. Format[W[a_, b_]] := Subscript[W, StringJoin @@ ToString /@ {a, b}] Solve[2 x == W[a, a], x][[1]]


4

Subscripts are evil. Why don't you use an Association? This would get you rid of the whole numbering business. This could look like this: value = Association[ "grav" -> 9.81, "L" -> 100 10^6 ]; help = Association[ "grav" -> "gravitational acc", "L" -> "Length" ]; You need the value of "L"? Call value["L"]. You need help on "...


4

ListPlot[{{0, 0}, {0.125, 0.125}, {0.25, 0.25}, {0.375, 0.375}, {0.5, 0.5}, {0.625, 0.625}, {0.75, 0.75}, {0.875, 0.875}}, InterpolationOrder -> 0, Joined -> True, PlotRange -> {{0, 1}, {0, 1}}, FrameTicks -> {{{{0, "000"}, {0.125, "001"}, {0.25, "010"}, {0.375, "011"}, {0.5, "100"}, {0.625, "101"}, {0.75, "110"}, {0.875, "111"}}, ...


4

Use Subsuperscript: Subsuperscript[f, a, b] // Style[#, 20] & Keyboard shortcut (thanks: BobHanlon):


4

You can use pattern matching for this: expr = {{Subscript[a, 1], Subscript[a, 1] + Subscript[a, 2], Subscript[a, -3]}, {Subscript[a, 1], Subscript[a, -2], Subscript[a, -4]}} expr /. Subscript[a, n_Integer /; n < 0] :> - Subscript[a, -n]


4

I have MA 11 and the problem still persist. Consider the following simplification that works for unsubscripted variables f1=(-p (a-x) ((a-b) P (b-x)+Q (b+x) (a-b+2 x)) +q (a+x) (-(a-b) Q (b+x)+P (b-x) (-a+b+2 x))) /((b-x) (-a+x) (a+x) (b+x)); rule1={(p+q)->1,(P+Q)->1}; FullSimplify[f1]/.rule1 $$\frac{Q}{b-x}+\frac{q}{x-a}-\frac{p}{a+x}+\frac{P}...


4

See Defining Output Formats (tutorial/TextualInputAndOutput#9464). "whenever the Wolfram Language is given an expression to format for output, it first calls Format[expr] to find out whether any special rules for formatting the expression have been defined. By assigning a value to Format[expr] you can therefore tell the Wolfram Language that you want a ...


4

Assuming I understand your question the short answer is to produce your Symbols like this: new = ToExpression[SubscriptBox["s", "3"]]; Head[new] FullForm[new] Symbol s\[UnderBracket]Subscript\[UnderBracket]3 The mechanism of the Notation package is to intercept MakeExpression (called by ToExpression) and MakeBoxes. If these ...


4

You may use, e.g., MapThread[ SubsuperscriptBox["c", ##] &, {Cs, Ss1} ]


4

Cs = {1, 2, 4, 5}; Ss = {1, -1, 1, -1}; Ss1 = Ss /. {1 -> "+", -1 -> "-"}; Thread[Subsuperscript["c", Cs, Ss1]] You can also Apply (@@@) the function Subsuperscript["c", ##]& to pairs of values from Cs and Ss1 (that is, to Transpose[{Cs, Ss1}}]): Subsuperscript["c", ##] & @@@ Transpose[{Cs, ...


Only top voted, non community-wiki answers of a minimum length are eligible