Mathematica generates an expression sometimes using \[Formal] symbols. This is causing a problem with the TeXForm code generated as $\LaTeX$ is not able to process it. To clarify: The generated TeXForm should not include Unicode. The problem is that these are causing problem. So the solution should be such that, the result of applying TeXForm to the expression, should not produce Unicode.

Is there a way to make these expressions use normal symbols (normal x and y) so that I can generate $\LaTeX$ code from them that will work in my $\LaTeX$ document

 f = DifferentialRoot[Function[{y, x}, {y''[x] + y[x] == 0, y[0] == 0, y'[0] == 1}]]

Mathematica graphics

If I do TeXForm[f] on the above, the $\LaTeX$ code generated is not valid with TeXLive. I just need the expression f not to contain those dots above and below the symbols. Just normal symbols. One way is to use

f = DifferentialRoot[Function[{y, x}, {y''[x] + y[x] == 0, y[0] == 0, y'[0] == 1}]]
    // OutputForm

Mathematica graphics

which $\LaTeX$ can handle after TeXForm is applied to the above. But it will be nice to have x and y there instead.

  • 1
    $\begingroup$ An undocumented way of doing it (which I learned from this answer) is: MapThread[Set, {Table[System`Convert`TeXFormDump`maketex[FromCharacterCode[63488 + i]], {i, 0, 25 + 26}], Table[FromCharacterCode[97 + i], {i, 0, 25}]~Join~Table[FromCharacterCode[65 + i], {i, 0, 25}]}]; It seems to work from v8.0.4 all the way through 11.0.0. $\endgroup$
    – QuantumDot
    Sep 22, 2016 at 1:49

1 Answer 1


Interesting question with more complications than I anticipated.

If it is not necessary to replace every formal Symbol with the equivalent plain version, but instead arbitrarily with specified Symbols, you can use something like this:

SetAttributes[formalQ, HoldFirst]
formalQ[s_Symbol] := StringMatchQ[ToString@HoldForm@FullForm@s, "\\[Formal*]"]

expr = DifferentialRoot[Function[{y, x}, {y''[x] + y[x] == 0, y[0] == 0, y'[0] == 1}]];

rep = {a, b, c, d, e};  (* new Symbols to use *)

old = Union @ Cases[expr, _Symbol?formalQ, {-1}]
new = Take[rep, Length @ old]
HoldForm @@ {expr} /. Thread[old -> new]

Note that I had to wrap expr in HoldForm as otherwise it automatically puts the Formal Symbols right back!

I am still working on the larger problem of replacing every Formal Symbol with its plain equivalent.
If I cannot find an internal look-up table I may have to build my own.

If you are only dealing with automatically-generated Formal Symbols you may only have a few to replace:


{\[FormalY], \[FormalN]}

{\[FormalY], \[FormalX]}

Therefore I would start with:

fix = {\[FormalY] :> y, \[FormalN] :> n, \[FormalX] :> x}
  • $\begingroup$ The generated code (from TeXForm) still contain those trouble invalid code) which are the \unicode. When I do TeXForm[%] on the result from your code, it still shows up with invlaid latex code that uses \unicode. The main reason I wanted to remove those \Formal and replace them with normal symbols is to avoid this unicode being generated. I'll update the question to make it more clear. You have removed all the other unicode, good, but one is still there. !Mathematica graphics $\endgroup$
    – Nasser
    Jul 22, 2014 at 9:36
  • $\begingroup$ @Nasser My mistake: that is \[Function]. Please try: HoldForm @@ {expr} /. Thread[old -> new] // StandardForm // TeXForm $\endgroup$
    – Mr.Wizard
    Jul 22, 2014 at 9:40
  • $\begingroup$ Thanks, yes, that is good. no unicode. It is not critical that x and y are being replaced by a and b. (x,y just happened to be more common to use) but will live with this solution. thank you $\endgroup$
    – Nasser
    Jul 22, 2014 at 9:44
  • $\begingroup$ @Nasser Are all the formal symbols you're dealing with automatically generated? If that's the case there may be only a few to replace, i.e. y, n, x. $\endgroup$
    – Mr.Wizard
    Jul 22, 2014 at 9:47
  • $\begingroup$ yes. These are solutions from a set of differential equations that I am processing. So it will really include x and y as these are the same symbols used for each equation. It is just that M sometimes returns solutions using \Formal which causes problem for Latex. I am not using the solution for anything other than converting it to Latex. $\endgroup$
    – Nasser
    Jul 22, 2014 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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