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.

Why are the messages almost always defined like this (at least in packages):

If[Not@ValueQ[function::usage], function::usage = "Usage message"]

and not just like this?

function::usage = "Usage message";

Is this some sort of safety measure in case of double loading of the package?
I also notice that error messages, coming after usage messages, are usually defined the second way.
I cannot imagine a reason why I would do that.
Are there situations when someone would like to import a package, redefine some usage messages and be sure they are not reset in case of reloading of the package?

share|improve this question
You do not need to do this when writing your own packages. It is a hack to have formatted (and I suppose localised) messages for standard packages. –  Szabolcs Mar 22 '13 at 14:57

1 Answer 1

up vote 21 down vote accepted

If you look carefully, you'll notice that the usage messages of package functions are nicely formatted.

Mathematica graphics

Notice the nice italicised and subscripted $x_1$. If you actually look in the package, you'll find a usage message that doesn't have any formatting at all, and even differs from the version ?DelaunayTriangulation gives us.

If[Not@ValueQ[DelaunayTriangulation::usage],DelaunayTriangulation::usage =
"DelaunayTriangulation[{{x1,y1},{x2,y2},...,{xn,yn}}] yields the (planar) \
Delaunay triangulation of the points. The triangulation is represented as a \
vertex adjacency list, one entry for each unique point in the original \
coordinate list indicating the adjacent vertices in counterclockwise order."];

So where did the formatting come from? It turns out that Mathematica includes an alternate set of usage messages defined elsewhere. These are nicely formatted. The Not@ValueQ[...] is there to prevent the nicely formatted messages from being overwritten by the package.

The file that contains the formatted messages is located at



  "SystemFiles", "Kernel", "TextResources", "English", "Usage.m"}]

to get an absolute path from Mathematica.

Regrettably, it seems some errors have slipped in and sometimes the formatted messages contain less information than the original ones... just like in the example above.

share|improve this answer
I didn't know about that, +1! I only used the ValueQ method to inject new info to existing messages, for example when using built-in symbols for option names in own package. –  István Zachar Mar 22 '13 at 15:17
I wonder why there is an unformatted form of the usage string stored in the package. In wich case will Mathematica use them? I recognized that in documentation center the unformatted usages are displayed, but i wonder where they come from. The question seems to be what is loaded first, the formatted usage or the unformatted one? –  sacratus Apr 8 at 17:56
@sacratus I don't know. My arbitrary guess is that when the package is being developed, they just use the usual way to do it. When Mathematica is ready for polishing and release, someone else than the developer goes through the messages and creates formatted versions. And maybe translations for other language versions. –  Szabolcs Apr 8 at 18:01
that might be a good explanation. I found out, that the summary that can be seen on a reference page of a symbol with CurrentValue[ EvaluationNotebook[], {TaggingRules, "Metadata", "summary"}] is an unformatted form of the formated usage string. Its actually not the original usagestring stored in the package. Its seems they are never used again after developing. –  sacratus Apr 8 at 18:10

Your Answer


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.