Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Hello again after some pause. i have a problem how to present partial derivatives in traditional form, not as Mathematica gave it to me in its notation. So I want to present this

Subscript[S, 1]* (F1^(4,0))[x,y]+Subscript[S, 2]* (F1^(2,2))[x,y]

to have a look $S_1\frac{\partial ^4F_1(x,y)}{\partial x^4}+S_2\frac{\partial ^4F_1(x,y)}{\partial x^2\partial y^2}$

And if I have for example lot of different combination of derivatives terms I want to do this automatically . Is it possible?

share|improve this question
2  
I posted a solution to this problem as part of my answer here. Its advantage is that it is more compact and that it automatically uses straight derivative symbols (instead of curly ones) when you're not doing partial derivatives. –  Jens Apr 20 '13 at 16:13

2 Answers 2

up vote 9 down vote accepted

Besides of TraditionalForm you should use Defer to stop automatic evaluation of the underlying expression, so it should look like this :

TraditionalForm @ Defer[   Subscript[S, 1] D[F1[x, y], {x, 4}]
                         + Subscript[S, 2]*D[F1[x, y], {x, 2}, {y, 2}]]

enter image description here

In order to change the order of terms one could use also undocumented
PolynomialForm[..., TraditionalOrder -> True]:

PolynomialForm[ 
    Defer[ Subscript[S, 1] D[Subscript[F, 1][x, y], {x, 4}] + 
           Subscript[S, 2] D[Subscript[F, 1][x, y], {x, 2}, {y, 2}]], 
    TraditionalOrder -> True] // TraditionalForm

enter image description here

For more comprehensive discussion I recommend to read this Wolfram blog post by Vitaliy Kaurov:
Mathematica Q&A Series: Converting to Conventional Mathematical Typesetting.

share|improve this answer
    
Thank you very much Artes. –  Pipe Apr 20 '13 at 15:12

The problem with using TraditionalForm@Defer is that it won't work as soon as the Defer is gone. So you always need an additional wrapper, different from the simple TraditionalForm wrapper, to get the desired output. It can sometimes be desirable to have the derivative formatted automatically for all TraditionalForm environments, e.g., in Graphics labels etc.

If, as you mention in the question, you have numerous combinations of derivatives, then the output quickly becomes cluttered if you keep writing out all the function arguments in a partial derivative. This is why I formatted the derivative without arguments in this answer.

An additional formatting requirement in traditional form would be to write ordinary derivatives with a straight derivative symbol to distinguish them from partial derivatives. This isn't automatically done by Mathematica in TraditionalForm output, so I added that case distinction in the linked answer.

The downside of the shortened notation in that answer was that you can't copy the formatted output and re-use it as input by pasting it back into a new line.

Here is a way to get the advantages of more readable short-hand notation in the displayed output while at the same time maintaining the ability to evaluate the output later:

Derivative /: MakeBoxes[
  Derivative[\[Alpha]__][f1_][vars__Symbol],
  TraditionalForm
  ] := Module[
  {bb, dd, sp},
  MakeBoxes[dd, _] ^= 
   If[Length[{\[Alpha]}] == 1, "\[DifferentialD]", "\[PartialD]"];
  MakeBoxes[sp, _] ^= "\[ThinSpace]";
  bb /: MakeBoxes[bb[x__], _] := RowBox[Map[ToBoxes[#] &, {x}]];
  TemplateBox[{
    ToBoxes[bb[dd^Plus[\[Alpha]], f1]],
    ToBoxes[
     Apply[bb, 
      Riffle[Map[bb[dd, #] &, 
        Select[({vars}^{\[Alpha]}), (# =!= 1 &)]], sp]]],
    ToBoxes[Derivative[\[Alpha]][f1][vars]]
    }, "ShortFraction",
   DisplayFunction :> (FractionBox[#1, #2] &),
   InterpretationFunction :> (#3 &),
   Tooltip -> Automatic
   ]
  ]

TraditionalForm[D[f[x], x]]

$\frac{d f}{d x}$

TraditionalForm[D[f[x, y], x, x]]

$\frac{\partial^2 f}{\partial x^2}$

Note the absence of arguments $(x)$ and $(x,y)$, respectively, and the different symbols for partial and ordinary derivatives. Also, you can now copy any of the above outputs and paste them into an Input cell. The result is again recognized as the original derivative, without loss of information.

What I added to the original solution linked above is a TemplateBox that specifies both a DisplayFunction (using the original formatting in the previous answer), and an IntepretationFunction which simply contains the box form of the original derivative expression. The latter is used when you try to evaluate the output. Since the function arguments are kept in that expression, it can be evaluated without problems.

share|improve this answer
    
Defer is stripped on input, but if you don't want that why not use HoldForm instead? I don't think I understand where you're going with this answer. (That doesn't mean it's wrong!) –  Mr.Wizard Sep 4 '13 at 2:34
    
Maybe this blog entry which is linked in the earlier answers I linked to will answer this. Defer is discussed as an alternative there, too. –  Jens Sep 4 '13 at 2:58
1  
I find this very useful. :) May I ask how do you handle arbitrary dimensions? When I have to do this I'm using D[t[##], #] & @@ Array[x, 3] where 3 can be replaced. But x[i] is not a symbol, so I have to delete __Symbol from your code. Then it is ok, but the question is, since you've given this constraint I'm assuming you handle this in different way, is there better than Array? –  Kuba Nov 28 '13 at 14:28
2  
@Kuba The reason I put the Symbol constraint in the definition is that I didn't want this short notation to be used when the chain rule is needed. In that case, I want to retain the clearer formal notation to avoid confusion. So for example TraditionalForm[D[f[g[x], y], x]] will be displayed in the standard way. By the way, the chain rule wouldn't even be use at all if you use the other method, TraditionalForm@Defer[D[f[g[x], y], x]]. But this may be a matter of taste and depends on your needs. You could also use Symbolize on your variables and leave the __Symbol constraint in. –  Jens Nov 28 '13 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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