11
$\begingroup$

I'm working on a package that needs to be installed into an arbitrary, "non standard" path (i.e., not $BaseDirectory or $UserBaseDirectory). I have added the package's path to $Path in order to allow Mathematica to load the package via Get or Needs, and this works well.

My problem is that the package also needs to include custom stylesheets and custom palettes, and these are not available in the front-end menus (Format-->Stylesheet and Palettes, respectively) when the package is loaded from a non-standard location.

If I put the package files in $BaseDirectory the custom stylesheet and palette are accessible from the front-end menus, since the package follows the standard structure:

  • package\FrontEnd\StyleSheets\mystyle.nb

  • package\FrontEnd\Palettes\mypalette.nb

but this doesn't seem to work if it is loaded from an arbitrary path.


This Wolfram tutorial says that:

Stylesheet are discovered by the front end in the following locations.

FrontEnd`FileName[{$UserBaseDirectory,"SystemFiles","FrontEnd","StyleSheets"}]

FrontEnd`FileName[{$InstallationDirectory,"SystemFiles","FrontEnd","StyleSheets"}]

Stylesheets contained in directories are grouped under submenus in the Stylesheet menu. Add-on applications following the same layout also add stylesheets to the menu.


How can I install a package in a directory that's not $UserBaseDirectory or $BaseDirectory, and still make the stylesheets and palettes available in the Mathematica menus?

$\endgroup$
6
  • $\begingroup$ Possibly you have to add the packages path to Option Inspector -> Global Options -> File Locations -> PalettePath. $\endgroup$
    – Karsten7
    Commented Oct 16, 2014 at 14:29
  • $\begingroup$ Thanks for that, I was not aware of such option. Unfortunately, it doesn't work. I added my own path inside the init.m file and when running Mathematica my palette is not listed in the menu. However, looking at the $FrontEnd option "PalettePath" I can see the right path to my palette. Now I found a similar option for StyleSheet, let me try and I'll update ehre the result. $\endgroup$
    – bobknight
    Commented Oct 16, 2014 at 15:06
  • $\begingroup$ The same, even StyleSheetPath doesn't accept my path. $\endgroup$
    – bobknight
    Commented Oct 16, 2014 at 15:12
  • $\begingroup$ I found some other hints, for Palette. The tutorial tutorial/CreatingPalettes#1453252323 says "Palettes can also be installed as part of a Wolfram System application. To add a palette to your application, create a FrontEnd\Palettes\ directory within the application folder and save the palette to this location. For example, the palette MyPalette.nb would be placed in MyApplication\FrontEnd\Palettes\." I have done the same steps but no results. $\endgroup$
    – bobknight
    Commented Oct 16, 2014 at 16:00
  • $\begingroup$ Related: 7779. $\endgroup$
    – dionys
    Commented Jul 14, 2015 at 10:39

2 Answers 2

5
$\begingroup$

The supported way to do this is to include a FrontEnd extension in the PacletInfo file, as in this example:

Paclet[
  Name -> "ExamplePackage", 
  Version -> "1.0.0", 
  MathematicaVersion -> "9+", 
  Description -> "An example package.", 
  Creator -> "WEG", 
  Extensions -> {
    {"Kernel", Context -> {"ExamplePackage`"}}, 
    {"Documentation", Language -> "English", LinkBase -> "ExamplePackage", MainPage -> "Guides/ExamplePackage"},
    {"FrontEnd"}
}]

The {"FrontEnd"} extension is the key part for Palettes and StyleSheets.

Add the package to the PacletManager using:

PacletDirectoryAdd["path"] 

Where path is the path to the package folder or the folder that contains the package folder (and potentially other packages).

Once this is run all Palettes and StyleSheets will be added to the menus.

$\endgroup$
13
  • 1
    $\begingroup$ What do you mean by "supported"? $\endgroup$
    – Kuba
    Commented Jul 18, 2016 at 14:36
  • $\begingroup$ @Kuba - This is how Wolfram recommends to set up PacletInfo files for version 9+ (the PacletManager was rewritten for version 9) and PacletDirectoryAdd is how they recommend to add packages in non-standard locations. I worked with Harry Calkins to get this working at my organization. $\endgroup$ Commented Jul 18, 2016 at 16:05
  • $\begingroup$ I see, is there an official tutorial about how to use PacletManager? $\endgroup$
    – Kuba
    Commented Jul 18, 2016 at 16:24
  • $\begingroup$ @Kuba - No, but that would be nice. Todd Gayley helped me out with all of my questions on it. I wanted to make sure that everything that we were doing was reliable, even though it is undocumented. That meant confirming that the functionality we are using is also used internally by Mathematica in the same manner. However Harry Calkins did have a notebook showing an example package setup that was helpful. The code in my answer is based on it. $\endgroup$ Commented Jul 18, 2016 at 17:28
  • $\begingroup$ Thanks for the answer. I'm busy with other stuff in these days, I'll try your suggested solution very soon. $\endgroup$
    – bobknight
    Commented Jul 18, 2016 at 18:46
4
$\begingroup$

About StyleSheets, you can do:

AppendTo[
  CurrentValue[$FrontEnd, "StyleSheetPath"], 
  "packageDir\\FrontEnd\\StyleSheets"
]

which will have an effect as soon as you restart MMA or evaluate

MathLink`CallFrontEnd[
   FrontEnd`ResetMenusPacket[{Automatic, Automatic}]]

credits to: R.M., Refreshing the Menu


Analogically you can add palletes to the menu:

AppendTo[
  CurrentValue[$FrontEnd, "PalettePath"], 
  "packageDir\\FrontEnd\\Palettes"
]

Further readings:

You can learn more from: Front End options by Mr. Wizard

$\endgroup$

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.