Take the 2-minute tour ×

In Mathematica, Format can be used to alter the output formats like TeXForm, OutputForm or TraditionalForm. This is an example of how one can redefine the TeXForm of a function T.

In[1]:= Format[T[a_], TeXForm] := "\[Del]" a

The result is

In[2]:= TeXForm[T[x]]
Out[1]= x \nabla

This is what I expected. Now apply the same format on T[T[x]]

In[3]:= TeXForm[T[T[x]]]
Out[2]= \nabla  T(x)

However, the output I would like is

Out[2]= \nabla \nabla x

Why does Mathematica not give this output? And what can I change to get this as output? I tried to find more information about formatting in the Mathematica Help and on Stack Overflow, but I could not find many clues.

share|improve this question

4 Answers 4

up vote 2 down vote accepted

You may want to do the formatting manually.

myTeX = TeXForm[# /. T -> (Row[{"\[Del]", #}] &)]&;

T[T[a]] //myTeX
\n abla \n abla a
share|improve this answer

It will work if you don't restrict to TeXForm.

In[100] := Format[T[a_]] := \[Del] a

In[101] := TeXForm[T[T[x]]]
Out[101]//TexForm =
           \nabla \nabla x

Why use T when you could use Del?

In[7] := Del[a]
Out[7] = ∇a

In[8] := TeXForm[Del[Del[a]]]
Out[8]//TeXForm =
         \nabla \nabla a
share|improve this answer
In the TeX code I would like to use a different symbol than in the Mathematica output. –  sjdh Dec 7 '11 at 8:03

The reason this fails is that the Format[arg, TeXForm] pattern doesn't recursively distribute Format over the arguments. This isn't unusual. Consider:

f[T[a_]] := "\[Del]" a;

yields f[T[T[a]]] = "\[Del]" T[a], but

f[T[a_]] := "\[Del]" f[a];

yields f[T[T[a]]] = ("\[Del]")^2 f[a], which is closer to what you want.

So define

Format[T[a_], TeXForm] := f[T[a]]

using the second choice of f[T[a_]] above, and you'll be off to a good start.

share|improve this answer

Type the following:


(or choose "Notation" from the palette that opens when you load the package) In the first placeholder, insert


In the second placeholder, enter


Before the closing bracket of the Notation line, insert the option

, WorkingForm -> TraditionalForm

Now you can try your example:


and it should give you what you want, except with parentheses (which is advisable in order to maintain your sanity in most cases, anyway):

\nabla (\nabla a)

You may be able to go further by looking at the Help documents under "Notation/tutorial/OptionsAndAuxiliaryFunctions"

share|improve this answer
I'm sure the OP used ESCAPE del ESCAPE in his notebook. When you cut and paste the result into StackOverflow you get the \Del form. –  Codie CodeMonkey Dec 7 '11 at 7:55
??? I don't think there is any way to get a \Del form... I'm sure you typed ESCAPE del ESCAPE and got \[Del], exactly as I intended. I'm guessing you're somehow worried that my text can't be cut and pasted. Sorry, but I wanted to be more descriptive for the benefit of readers who may not know the shortcuts. –  Jens Dec 7 '11 at 22:03

Your Answer


