17
$\begingroup$

I have defined a function foo in some complicated way. But now I would like to add a little documentation that gives the user information on how it is to be used.

I know that the ? symbol could be placed before a built-in function to generate useful information about that built-in function. Is there a way I can add helpful information about my foo function in a similar way?

$\endgroup$

2 Answers 2

20
$\begingroup$

You can include usage info using the ::usage tag as follows

foo::usage = "foo[x] takes one argument and returns nothing"

Using Information[foo] or ?foo will display the string in the above message

?foo
(* "foo[x] takes one argument and returns nothing" *)

In addition, in version 8 (and some older versions), using CmdShiftK will complete the template if you start the usage message with foo[x] .... Unfortunately, this doesn't work in version 9.

$\endgroup$
2
  • $\begingroup$ It is safe to say that Mathematica's ::usage and template system is best described as "kludgy". For the benefit of others I provide a link to a question that summarizes the various problems and possible workarounds: mathematica.stackexchange.com/questions/58669/… $\endgroup$
    – QuantumDot
    Commented Feb 7, 2016 at 15:45
  • $\begingroup$ How do I change the message in the floating message which appears when the function name is typed? $\endgroup$ Commented Jun 5, 2020 at 23:55
7
$\begingroup$

The simplest way for a short documentation is by adding a usage to a function, as described in the other answer above.

For a more in depth documentation (as in the Mathematica help) you can use Wolfram Workbench, a tutorial can be found there
http://www.wolfram.co.uk/products/workbench/.

Alternatively you can have a look at this answer.
https://stackoverflow.com/questions/6574710/integrating-notebooks-to-mathematicas-documentation-center

$\endgroup$
2
  • 2
    $\begingroup$ it might be the best way, but for sure not the simplest. $\endgroup$
    – Yves Klett
    Commented Jan 3, 2013 at 8:51
  • $\begingroup$ Yes I agree, I modified my answer accordingly. $\endgroup$
    – faysou
    Commented Jan 3, 2013 at 10:10

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.