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.

I've tried searching here and in the WRI documentation, but I haven't found what I'm looking for in either place.

I'm defining a dx operator to act as a shorthand for D[#,x], based on this question. In my case, I want Mathematica to produce an output form with the text d/dx expression = [...], where by [...] I mean the actual symbolic meaning of my dx operator (i.e., D[#, x]).

I have tried this:

Format[dx[a_] := "\!\(\*FractionBox[\(d\), \(dx\)]\)"  a  "="  D[a, x]]

I've also tried

Format[dx[#], TraditionalForm] := 
  DisplayForm[
    RowBox[{FractionBox["\DifferentialD]", "\[DifferentialD]x"],
    #, "=", D[#, x]}]];

and various other similar things, none of which produce the correct expression.

I would appreciate help with getting this right.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You can use something like this

dx /: MakeBoxes[dx[a_], fmt_] := 
  RowBox[{FractionBox["\[PartialD]", "\[PartialD]x"], 
    MakeBoxes[a, fmt], "=", MakeBoxes[#, fmt] &@D[a, x]}];

dx[Sin[x]]

enter image description here

dx[Sin[x]] // TraditionalForm

enter image description here

I prefer MakeBoxes but it also can be implemented with Format

ClearAll[dx]

Format[dx[a_]] := 
  DisplayForm@RowBox[{FractionBox["\[PartialD]", "\[PartialD]x"], MakeBoxes[a], 
     "=", MakeBoxes[#] &@D[a, x]}];

dx[Sin[x]]

enter image description here

share|improve this answer
    
What does the MakeBoxes[#] refer to? Does it refer to the result supplied by the later @D function? –  Trevor Oct 7 '13 at 13:33
1  
@Trevor MakeBoxes[#]&@D[a, x] inserts evaluated D[a, x] into MakeBoxes. Evaluate doesn't work here because MakeBoxes has HoldAllComplete attribute. –  ybeltukov Oct 7 '13 at 13:40
    
Thanks a lot. I will learn your answer. It has great value for me. –  Trevor Oct 7 '13 at 14:10
add comment

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.