Package Usage and Development » Paclet Development
Paclet Development
Now that we know how a paclet should be structured, we can get into the details of developing a paclet. We'll make a paclet that has a bit of everything in it to see how it all works.
Directory Structure
Our basic structure will start out looking like
MyPaclet
+ PacletInfo.m
And the PacletInfo.m
will look like:
Paclet[
Name -> "MyPaclet",
Version -> "0.0.1",
Creator -> "b3m2a1 <b3m2a1@gmail.com>",
Description -> "A sample paclet to show the paclet developement process"
]
Kernel and Main Package
The first thing we'll need to add to the paclet is a "Kernel"
folder and a primary implementation package. For simplicity, we'll have our paclet provide a context "MyPaclet`"
, and so our main package will have to create this context.
We'll change our structure to look like:
MyPaclet
+ PacletInfo.m
Kernel
+ init.m
MyPaclet.m
And the info will look like:
Paclet[
Name -> "MyPaclet",
Version -> "0.0.1",
Creator -> "b3m2a1 <b3m2a1@gmail.com>",
Description -> "A sample paclet to show the paclet developement process",
Extensions -> {
{"Kernel", "Root"->".", "Context"->{"MyPaclet`"}}
}
]
Now we'll need to make the init.m
file load MyPaclet.m
, but this is no different than the standard way we might do this, e.g. via:
<<MyPaclet`MyPaclet`
Any other packages we provide should then be loaded in turn via MyPaclet.m
. We won't get into the details of how to write a paclet with interacting piceces here, as there are many different ways people like to do this and we're trying to take a high-level overview, but we will return to that theme later.
After we do this it's possible to load the paclet with
<<MyPaclet`
FrontEnd Resources
Let's say we have some front-end resources we'd like to bundle with our paclet:
- A stylesheet called
MyPacletStyles.nb
- An icon in
MyPacletIconResource.png
- A helper palette in
MyPacletHelper.nb
We'll add the following folder to our main directory:
FrontEnd
StyleSheets
MyPaclet
+ MyPacletStyles.nb
Palettes
MyPaclet
+ MyPacletHelper.nb
SystemResources
Bitmaps
MyPaclet
+ MyPacletIconResource.png
And the info will look like:
Paclet[
Name -> "MyPaclet",
Version -> "0.0.1",
Creator -> "b3m2a1 <b3m2a1@gmail.com>",
Description -> "A sample paclet to show the paclet developement process",
Extensions -> {
{"Kernel", "Root"->".", "Context"->{"MyPaclet`"}},
{"FrontEnd"}
}
]
We can then link to this stylesheet by setting
StyleDefinitions->FrontEnd`FileName[{"MyPaclet"}, "MyPacletStyles.nb"]
Or if we want to use the paclet icon we can do so with the appropriate FrontEnd`FileName
. This time we'll want FrontEnd`FileName[{"MyPaclet"}, "MyPacletIconResource.png"]
. Here's an example of this:
RawBoxes@
DynamicBox[
FEPrivate`ImportImage@
FrontEnd`FileName[{"MyPaclet"}, "MyPacletIconResource.png"]
]
Documentation
If we have some documentation pages we have either built with Workbench or any of a number of third-part interfaces ( here's mine ), we can add these to our package too. Assuming we have the following English-language documentation pages to add:
- A symbol page,
MyPacletSym.nb
- A guide,
MyPaclet.nb
- A tutorial,
MyPacletOverview.nb
We'll add the following folder to our directory
Documentation
English
ReferencePages
Symbols
+ MyPacletSym.nb
Guides
+ MyPaclet.nb
Tutorials
+ MyPacletOverview.nb
And we'll add the following extension to the paclet info:
{
"Documentation",
"Language" -> "English",
"MainPage" -> "Guides/MyPaclet",
"LinkBase" -> "MyPaclet"
}
After this is installed, when people search for MyPacletSym
the page will appear.
Resources
Finally, let's say we want to bundle resources with our paclet, maybe we have a template notebook, MyTemplate.nb
and a bunch of data stored in .mx files, MyDat1.mx
, MyDat2.mx
, and MyDat3.mx
We can add the following folder structure:
Resources
+ MyTemplate.nb
Data
+ MyDat1.mx
+ MyDat2.mx
+ MyDat3.mx
And then add the extension:
{
"Resource",
"Resources" -> {
{"Template", "MyTemplate.nb"},
{"Data1", "Data/MyDat1.mx"},
{"Data2", "Data/MyDat2.mx"},
{"Data3", "Data/MyDat3.mx"}
}
}
Now we can use
PacletResource["MyPaclet", "Template"]
and we'll get the file path to the template notebook