1
$\begingroup$
ToExpression["$ \\frac{\\partial ^{n} f}{\\partial x^{n}} $ ", 
TeXForm]

It outputs 0 instead of the partial derivative: $$ \frac{\partial ^{n} f}{\partial x^{n}} $$

$\endgroup$
0

2 Answers 2

3
$\begingroup$

This happens because D[f, {x, n}] evaluates to 0. Mathematica does not find x in the expression f so it assumes that f does not depend on x.

The result of the following might be closer to you goal:

ToExpression["$ \\frac{\\partial ^{n} f(x)}{\\partial x^{n}} $ ", TeXForm]

Derivative[n][f][x]

$\endgroup$
8
  • $\begingroup$ Can output to a standform format like ToString? $\endgroup$ Jan 25, 2020 at 7:53
  • $\begingroup$ I do not get what you try to say. Please, use full sentences. $\endgroup$ Jan 25, 2020 at 7:54
  • $\begingroup$ Can we output the result of texform as a string like ToString["\!\(\*FractionBox[\(\*SuperscriptBox[\(\[PartialD]\), \ \(n\)]f\), \(\[PartialD]\*SuperscriptBox[\(x\), \(n\)]\),\n\ MultilineFunction->None]\)", StandardForm]. $\endgroup$ Jan 25, 2020 at 7:59
  • $\begingroup$ What about ToString[ ToExpression["$ \\frac{\\partial ^{n} f(x)}{\\partial x^{n}} $ ", TeXForm], InputForm ]? $\endgroup$ Jan 25, 2020 at 8:03
  • 1
    $\begingroup$ ToLaTeXString is not a built-in function. I don't understand what you want. $\endgroup$ Jan 25, 2020 at 8:04
4
$\begingroup$

Another possibility is to use the 3-arg version of ToExpression to prevent evaluation:

ToExpression["$ \\frac{\\partial ^{n} f}{\\partial x^{n}} $ ", TeXForm, HoldForm]

D[f,{x,n}]

You can use TraditionalForm to format the output as desired:

TraditionalForm[%]

[PartialD]^nf/[PartialD]x^n

If you really want a string, you can use ToString:

ToString[
    ToExpression["$ \\frac{\\partial ^{n} f}{\\partial x^{n}} $ ", TeXForm, HoldForm],
    TraditionalForm
]
"\!\(\*FormBox[TagBox[FractionBox[
RowBox[{SuperscriptBox[\"\[PartialD]\", \"n\"], \"f\"}], 
RowBox[{\"\[PartialD]\", SuperscriptBox[\"x\", \"n\"]}],\n\
MultilineFunction->None],
HoldForm],
TraditionalForm]\)"
$\endgroup$
1

Your Answer

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

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