10
$\begingroup$

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.

$\endgroup$
8
$\begingroup$

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) *)
$\endgroup$
  • $\begingroup$ @Mr. Wizard, I forgot that had a Unicode codepoint! Thanks. $\endgroup$ – J. M. will be back soon Jan 8 '17 at 14:29
8
$\begingroup$

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)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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