TeXForm handling of derivative higher than two

10

1

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

ode = y''[x] == 0;
TeXForm[ode]

Mathematica graphics

But when the order is higher than 2, it does this:

ode = y'''[x] == 0;
TeXForm[ode]

Mathematica graphics

Which does not look as nice in my $\LaTeX$ report when compiled to PDF.

Mathematica graphics

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

Mathematica graphics

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.

Nasser

Posted 2017-01-08T06:18:26.603

Reputation: 92 661

1

Related: How to make traditional output for derivatives

– Jens – 2017-01-09T20:29:51.960

Answers

8

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) *)

J. M.'s ennui

Posted 2017-01-08T06:18:26.603

Reputation: 115 520

@Mr. Wizard, I forgot that had a Unicode codepoint! Thanks. – J. M.'s ennui – 2017-01-08T14:29:29.767

8

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[
    MakeBoxes[h,TraditionalForm],
    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)

Carl Woll

Posted 2017-01-08T06:18:26.603

Reputation: 112 778