You don't seem to have understood the answers provided already, so let's back up and walk through this slowly. In a Mathematica cell, type exactly this:
2+3
If you evaluate this cell, you'll get an output cell with a 5
in it. Now in another cell, type exactly this:
"2+3"
If you evaluate this cell, you'll get an output cell that displays as 2+3
but in fact the actual data is "2+3"
. You can see this if you use FullForm
, so if you're curious, evaluate
FullForm["2+3"]
Now, the entire point of ToExpression
is to take a string and sort of unbox it and interpret the result as an expression. So if you evaluate
ToExpression["2+3"]
The seqeunce of evaluation will be something like
"2+3" -> 2+3 -> 5
Now, we can get very meta about what's a string and what's not. I mean, you have to type in a sequence of characters to get 2+3
, and isn't a sequence of characters a string? But don't get wrapped around the axle. Just think of the quote characters as special delimiters that say "the stuff inside should be interpreted as a literal sequence of characters with no meaning, and so it shouldn't be parsed at all".
Anyway, the entire point of ToExpression
is to get something that's not a string in the sense I just explained. So, the result of ToExpression
will be parsed as an expression just as if you had typed it without the quote delimiters.
Now, the TeXForm
as the second argument is adding another layer of parsing. It's saying, "once you unbox the string, parse it as a TeX expression, and then map the result into Mathematica with the equivalent semantics. So, if we were to look at the output of your string in a TeX environment, it would look like H
with a subscript 2
adjacent to an O
. In that TeX environment, that's the final form, because TeX is just presenting formatted text, it's not evaluating it. The semantic mapping of that into Mathematica would be
`Subscript[H, 2] O`
But Mathematic doesn't stop there, because Mathematica isn't just presenting things, it's evaluating things. In Mathematica, adjacency is interpreted as multiplication (when it makes sense), and so this is parsed into
`Times[Subscript[H, 2], O]`
Mathematica has a canonical way to sort product terms, and so this becomes
Times[O, Subscript[H, 2]]