# ToExpression to Latex Parenthesis

Everytime I use ToExpression to transform a TeX expression into mathematica input form, Mathematica always interprets parenthesis ('(' and ')') as square brackets, which has a differente meaning for expressions. I always have to manually change the expression. Also, it doesn't happen all the time. Does anybody know what is going on and what can I do to fix this? An Example:

ToExpression["A - \\frac{B (2+F)}{(1+C)} D", TeXForm]


This yields:

A - (D B[2 + F])/(1 + C)


I would like:

A - (D B(2 + F))/(1 + C)


Thanks.

• In practice it may be easier to just fix the resulting Mathematica expression rather than get Mathematica to use the desired interpretation ... i.e. do a replacement similar to s_[a_] :> s*a. Where do your TeX snippets come from? Can you get MathML instead of TeX? – Szabolcs Oct 21 '15 at 11:49

You can use a LaTeX thin space \, as a multiplication symbol to enforce what you want:

ToExpression["A - \\frac{B\\,(2+F)}{(1+C)} D", TeXForm]

(* A-(B D (2+F))/(1+C) *)


As noted by rhermans, standard mathematical notation is ambiguous -- do the parentheses signify multiplication or function arguments? -- so the thin space is needed to remove the ambiguity.

As noted by march, if you want to consistently use parentheses for multiplication, you could define a function like

fromTeX[str_] := ToExpression[StringReplace[str, "(" -> "\\,("], TeXForm]


Now you can do

fromTeX["A - \\frac{B(2+F)}{(1+C)} D"]

(* A - (B D (2 + F))/(1 + C) *)

• Can you imagine a systematic way of telling Mathematica to do this? I am aware that I may be asking for too much. – user191919 Oct 20 '15 at 17:02
• You need a way to differentiate the arguments of the function and the factorizing parenthesis. I guess that is why the space matters. – rhermans Oct 20 '15 at 17:12
• @user191919. You could do StringReplace["A - \\frac{B (2+F)}{(1+C)} D", "(" -> "\\,("] before converting the expression. – march Oct 20 '15 at 22:48