# What is the purpose of tags like :Name:, :Context:, etc. in packages?

I noticed that all of the packages that come with Mathematica start with a header that is in a standard format. (See e.g. the header of NIntegrateUtilities at the end.)

There are several commented sections, each starting with a word surrounded by colons.

Question: What is the purpose of these colon-surrounded words? Do they have any meaning to Mathematica? They look like they were made for a machine to parse. Does Mathematica have any functions/tools that can read these?

(* :Name: NIntegrateUtilities *)

(* :Title: Utility functions for NIntegrate. *)

(* :Author: Anton Antonov *)

(* :Summary:
This package provides a number of supporting functions for NIntegrate.
*)

(* :Context: DifferentialEquationsNIntegrateUtilities *)

(* :Package Version: 1.0 *)

(* :History:
Version 1.0 by Anton Atnonov, March 2007.
*)

(* :Keywords:
NIntegrate, integration, evaluations, profiling.
*)

(* :Source:
*)

(* :Mathematica Version: 6.0 *)

(* :Limitation:
*)

(* :Discussion:
*)

-

Old versions of Mathematica featured the package UtilitiesPackage. This had the function Annotation[] that read those commented lines in packages so that one could see those annotations without having to explicitly open those packages in the front end.

Needs["UtilitiesPackage"]

Annotation["StatisticsNonlinearFit"]
{"Title", "Context", "Name", "Author", "Summary", "Copyright", "Package Version", "Mathematica Version", "History", "Keywords", "Sources", "Discussion", "Warning", "Example", "Example", "Example"}

Annotation["StatisticsNonlinearFit", "Mathematica Version"]
{"(* :Mathematica Version: 5.0 *)"}


If you want to still use this function, it's available here. I would say those specific delimiters allowed the package to pick out annotations instead of code comments.

-
+1. I knew about this once, but my memory didn't hold it. Oh well. –  Leonid Shifrin Jan 26 '12 at 0:08

An excerpt from "Programming in Mathematica" by Roman Maeder, 3rd edition, section 2.4 Package Framework and Documentation:

Another important tool for documentation is the reference section of the package. This section consists of a number of standard comments, identified by keywords with colons next to them:

(* :header: text... *)


The standard format of these comments allows document classification tools to extract this information in a machine - readable form. ... If you plan to submit your package to MathSource, these headers are important to properly classify and retrieve your package among the gigabytes of information present.

So, at least some automated tools were developed and used to read these, as you have guessed. How much this is in use currently I don't know. One fact which I find indicative is that new packages auto-generated with WorkBench do not contain these headers (may be this is just a setting which is switched off by default, I did not dig into this particular issue deep enough).

-
Ah, so the tool that can read these tags is some script they use to organize MathSource then. I've been looking at these for years, and never knew what they were for! –  Szabolcs Jan 25 '12 at 23:42
@Szabolcs Yes, I suppose these tools are still at work on MathSource (or, Wolfram Library Archive, as it is called now). –  Leonid Shifrin Jan 25 '12 at 23:45

(* :Edit:
I just noticed that the packages created by the Mathematica package editor use double-colon-surrounded words - not the single colon-surrounded words asked in the question.
So Leonid's answer is the correct one...
The package editor does not care about structures like (* :header: text... *)
*)

These are how Mathematica package files .m denote their metadata.

If you start a new package by going File ► New ► Package (.m) then you get into the Mathematica package editor. It looks almost like a normal notebook, you can have Section cells, Text cells, etc, but the default cell is a Code cell. When you save this file, only the Code cells are used to create the package. Everything else is commented out. The colon-surrounded words tell the Mathematica package editor what to do with commented out parts of the file.

Here's a simple example - save it as a .m file and view using the Mathematica package editor:

(* ::Package:: *)

(* ::Section:: *)
(*Section 1*)

(* ::Subsection:: *)
(*Subsection 1*)

(* ::Text:: *)
(*some text*)

some code

(* ::Subsection:: *)
(*Subsection 2*)

(* ::Text:: *)
(*some more text*)

-
Ah, these things you mention are a bit different: they are double-colon-surrounded. I was not aware of this. Maybe I should use Mathematica to tinker with m-files instead of Vim ... But note: Mathematica doesn't seem to parse the single-colon-surrounded words I mentioned in the question. It just shows them as plain text. And they have been around long before M- had a code editor for .m files. Leonid mentioned these were used on MathSource. –  Szabolcs Jan 25 '12 at 23:46
@Szabolcs: Yep! see my edit (posted before you finished your comment) –  Simon Jan 25 '12 at 23:47
I didn't know about the ::Section:: thingies either, I'm glad you mentioned them –  Szabolcs Jan 25 '12 at 23:49