# TeXForm handling of derivative higher than two

When the expression is only up to second derivative, TeXForm works correctly:

ode = y''[x] == 0;
TeXForm[ode] But when the order is higher than 2, it does this:

ode = y'''[x] == 0;
TeXForm[ode] Which does not look as nice in my $\LaTeX$ report when compiled to PDF. It can also confuses with thinking it is y raised to power of 3 instead of third derivative.

Is there a way to tell Mathematica to keep ''' as is? As in this screen shot Having to edit this by hand inside my Latex editor is not really an option for many reason. I'd like to do this inside Mathematica, when I export the expressions to $\LaTeX$.

My current workflow is this: Use TeXForm, convert to string, save to the $\LaTeX$ file, then compile the file to PDF.

• – Jens Jan 9 '17 at 20:29

Somewhat hacky:

TeXForm[y'''''[t] + 2 x'''[t] - y'[t] == x[t] /.
Derivative[k_Integer][f_] /; k > 2 :>
Superscript[f, Symbol[StringJoin[ConstantArray["′", k]]]]]

(* 2 x'''(t)+y'''''(t)-y'(t)=x(t) *)


An alternative to transforming an expression before applying TeXForm is to modify the TraditionalForm formatting rules for Derivative:

Derivative /: MakeBoxes[Derivative[n_Integer?Positive][h_],TraditionalForm] := SuperscriptBox[
StringJoin@ConstantArray["\[Prime]",n]
]


Then, TeXForm will use this new FormatValue:

TeXForm[y'''''[t] + 2 x'''[t] - y'[t] == x[t]]


2 x'''(t)+y'''''(t)-y'(t)=x(t)

and ToString[.., TeXForm] as well:

ToString[y'''''[t] + 2 x'''[t] - y'[t] == x[t], TeXForm]


2 x'''(t)+y'''''(t)-y'(t)=x(t)