I have some calculations with arbitrary functions. In the output, Mathematica always shows the functions with its arguments. I would like to tidy the notation a bit, by hiding the arguments in the output.

For example, I have something like this:

f[x,y] + (g[x,y])^2 = ...

and prefer like this:

f + g^2 = ...

I would like to create a function to do this work on any expression, involving all functions... is that possible?


I had outputs like this:

enter image description here

I then found a function to transform in a more human way:

pdConv[f_] := TraditionalForm[f /. Derivative[inds__][g_][vars__] :> 
    Apply[Defer[D[g[vars], ##]] &, Transpose[{{vars}, {inds}}] /. {{var_, 0} :> 
    Sequence[], {var_, 1} :> {var}}]];

Much better now:

enter image description here

Then I modified it, by taking out the [vars] from g[vars]:

pdConv[f_] := TraditionalForm[f /. Derivative[inds__][g_][vars__] :> 
    Apply[Defer[D[g, ##]] &, Transpose[{{vars}, {inds}}] /. {{var_, 0} :> 
    Sequence[], {var_, 1} :> {var}}]];

It now looks like this (notice that the functions arguments don't appear on functions inside the derivatives):

enter image description here

Now the last step would be to take off the arguments that appear on the functions outside derivates. The code above was able to do some of the work in a general way... that's what I'm looking for.

  • 3
    $\begingroup$ Try adding the rule f /: Format[f[___]] := f; and similarly for g. $\endgroup$ Nov 24, 2012 at 17:04
  • $\begingroup$ Isn't there a general expression? Thanks for the help. $\endgroup$ Nov 24, 2012 at 17:17
  • $\begingroup$ It is possible, but you need to know yourself clearly what you want before you can tell Mathematica. If you were given an output to format, how would you decide what's a function and what's not? Say Plus[x, f[y,z]] $\endgroup$
    – Rojo
    Nov 24, 2012 at 17:17
  • $\begingroup$ Why, do you want this to happen for built-in functions as well? $\endgroup$ Nov 24, 2012 at 17:18
  • 3
    $\begingroup$ For reference, the function pdConv comes from this page on the Wolfram Blog. $\endgroup$
    – Jens
    Nov 25, 2012 at 0:31

3 Answers 3


I propose a whitelist approach for functions you do want to display the contents of:

clean[expr_] :=
  HoldForm[expr] /.
    (h : Except[HoldForm | Equal | Power | Times | Plus | Log | Subscript])[args___] :> h

eqn = Subscript[R, ttϕ]^ϕ == 
   D[ξ[r, z], r] D[ξ[r, z], z] Exp[4 ψ[r, z] - 2 ν[r, z]]/ξ[r, z];

eqn // clean

Mathematica graphics

You have already shown how to handle the special case of Derivative which can be combined with this method.

Alternatively you could show only full expressions for functions in a given context, e.g. System`:

clean2[expr_] :=
  HoldForm[expr] /.
    h_Symbol[args___] /; Context@Unevaluated@h =!= "System`" :> h

eqn // clean2

Mathematica graphics

Again this doesn't handle the case of Derivative or SubValues functions.

  • $\begingroup$ Perfect! It's working very well. Thank you! :) $\endgroup$ Nov 25, 2012 at 0:56
  • $\begingroup$ I added Log so that Log[f[x, y]] // clean works $\endgroup$
    – chris
    Nov 25, 2012 at 7:39
  • $\begingroup$ @chris That's okay, but I intended this only as an example. Only Giovanni knows which functions he wants fully displayed. $\endgroup$
    – Mr.Wizard
    Nov 25, 2012 at 7:43
  • $\begingroup$ @Mr.Wizard yes; I don't see why its better to specify functions you don't want because its as endless as functions you want; right now BesselY[2, f[x, y]] // clean does to work either ;-) $\endgroup$
    – chris
    Nov 25, 2012 at 7:45
  • $\begingroup$ In fact its probably less open-ended(?) to list variables you introduced rather than functions that might occur. $\endgroup$
    – chris
    Nov 25, 2012 at 7:46

Restrict on arguments

As others have mentioned replacing all functions with arguments with just their names wouldn't leave you with something very useful, so you have to make some restrictions. It has been shown how you can restrict for which functions such replacements should be made. What I would like to add is the possibility to make such redefinitions only for certain kinds of arguments. This could be as simple as:

eqn = Subscript[R, ttϕ]^ϕ == 
   D[ξ[r, z], r] D[ξ[r, z], 
     z] Exp[4 ψ[r, z] - 2 ν[r, z]]/ξ[r, z];
(eqn // pdConv) /. {f_[r, z] :> f}

for the example you gave.

Formal Parameters

A feature that is available since Mathematica 7 are special names for "formal parameters" which are Protected so you can be reasonably sure they won't have values. I think it's just such formula type expressions as yours that these were introduced, so you might want to use them for your arguments. If you do so you could make this approach somewhat more general: First define the helper function:

formalQ[___] = False;
formalQ[x_Symbol] := StringMatchQ[
   ToString[x, CharacterEncoding -> "ASCII"], "\\[Formal" ~~ __

and then define your expressions using those formal parameters (which you can enter with e.g. Esc-$-x-Esc).

eqn = Subscript[R, ttϕ]^ϕ == 
   D[ξ[\[FormalR], \[FormalZ]], \[FormalR]] D[ξ[\[FormalR], \
\[FormalZ]], \[FormalZ]] Exp[
      4 ψ[\[FormalR], \[FormalZ]] - 
       2 ν[\[FormalR], \[FormalZ]]]/ξ[\[FormalR], \[FormalZ]];

and now use something like this to get the desired simplification:

(eqn // pdConv) /. {f_[__?formalQ] /; Context[f] =!= "System`" :> f}


Another thing I would like to mention is that you could make your results look the way you want but still evaluate correctly by using Interpretation. The following does this for a combination of pdConv, the above replacement and some additional formatting so one can immediately see which of the variables are actually functions with left out parameters:

formatEqn[expr_] := Interpretation[TraditionalForm[
    expr /. {
       Derivative[inds__][g_][vars__] :> Interpretation[Apply[
          HoldForm[D[g[vars], ##]] &, Transpose[{{vars}, {inds}}] /. {
            {var_, 0} :> Sequence[],
            {var_, 1} :> {var}
       } /. {
      \[FormalF]_Symbol[\[FormalA]__?formalQ] /; 
        Context[\[FormalF]] =!= "System`" -> 
        Style[\[FormalF], RGBColor[0, 0.6, 0], 
         Bold], \[FormalF][\[FormalA]]]

You should now be able to copy the result (or parts of it), paste to a new input cell and evaluate that new cell. It would also be possible to programmatically do further work with the result given above with something like this:

formattedEqn = eqn // formatEqn
(ToExpression[ToBoxes[formattedEqn]] /. ξ->Function[Sin[#1]*Cos[#2]])// formatEqn

I'm guess that this will not exactly match your needs but think with this and the information others gave and some further reading of the documentation of the functions used/mentioned above you should be well prepared to exactly build what you need...

  • $\begingroup$ Interesting. Worked well too. Thank you. $\endgroup$ Nov 25, 2012 at 18:04

As suggested in the comments

eqn = 
 Subscript[R, ttϕ]^ϕ == 
  D[ξ[r, z], r] D[ξ[r, z], 
    z] Exp[4 ψ[r, z] - 2 ν[r, z]]/ξ[r, z]

Using a Format rule:

Format[ξ[r, z]] = ξ;
Format[ψ[r, z]] = ψ;
Format[ν[r, z]] = ν;


Mathematica graphics

  • $\begingroup$ Yes, it works, but again, I would like to know if there is a general expression that converts everything at once. I use different symbols from time to time and if this needs to be done every time, I prefer not doing it and leaving in the original format. Thanks anyway. $\endgroup$ Nov 24, 2012 at 20:25
  • 1
    $\begingroup$ One would need to exclude Built in symbols as you probably don't want e.g. Log[f[r,z]] to become Log $\endgroup$
    – chris
    Nov 24, 2012 at 21:31

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.