16
$\begingroup$

I have searched Mathematica.SE for stylesheet and found a lot of useful information on specific issues but no general introduction. There were 746 hits, and it is very time consuming for anyone to absorb all that info and, for a newbie, rather overwhelming. It would be helpful if there were one Q&A post that could serve as an introduction to someone who has never tackled writing their own stylesheet.

To keep things simple let us assume the custom style sheet will be mostly the same as the Default stylesheet but will have the following changes:

  1. Input cells should be framed.
  2. There should be new style that is the same as Text except all the text typed into it should be colored blue.
  3. The styles Chapter and Subchapter should be removed from the Style menu.
$\endgroup$
12
$\begingroup$

Here are step-by-step instructions for making such a stylesheet.

  1. Make a notebook containing placeholder cells for each cell style that will be defined or modfied in new stylesheet. The exact contents the cells is unimportant. Here is the one I made.

    original[![][1]

This notebook, which I named CustomStyles.nb, has a title and two section heading cells but these are more or less decoration and you can omit them.

  1. Select Edit Stylesheet... from the Format menu. This will create a private stylesheet for CustomStyles.nb.

    private_stylesheet.1

  2. In the private stylesheet click on the Choose a style drop-down menu and choose Input from the menu. This will insert a new cell where you can make modifications to the Input style. Select this cell.

    private_stylesheet.2

  3. Choose Options Inspector... from the Format menu. Make sure Selection show in the left-most drop-down menu and type frame into the search box at on the right. Change Cell Options > Display Options > Cell Frame to True. The selected cell in the private stylesheet now has a frame and so does the Input cell in placeholder notebook.

    private_stylesheet.3

  4. To create the BlueText style, enter BlueText into input box to right of Enter as style name: and press Return. This will insert a cell where you can make define a new style. Select this cell and press Cmnd+Shift+E (Ctrl+Shif+E on Windows other systems) to open the cell.

  5. Edit the open cell so it looks like this,

    private_stylesheet.4

    then close the cell by pressing Cmnd+Shift+E or Ctrl+Shif+E.

  6. Choose Text Color > Blue from the Format menu.

  7. Go to back to CustomStyles.nb. Select the cell with the text "BlueText -- ...". Choose BlueText at the bottom of the Format > Style drop-down menu. (This menu item was created in step 5). The cell now shows blue text.

    private_stylesheet.5

  8. In the private stylesheet click on the Choose a style drop-down menu and choose Chapter from the menu. This will insert a new cell where you can make modifications to the Chapter style. Select this cell.

  9. Choose Options Inspector... from the Format menu. Make sure Selection show in the left-most drop-down menu and type menu into the search box at on the right. Change Cell Options > Generaal Properties > MenuSortingValue to None. Do the same thing for MenuCommandKey.

  10. In the private stylesheet click on the Choose a style drop-down menu and choose Subchapter from the menu. This will insert a new cell where you can make modifications to the Subchapter style. Select this cell. In the Options Inspector perform the same operations as was done for Chapter.

    Chapter and Subchapter are no longer choices on the Style menu.

    private_stylesheet.6


Installing the new stylesheet on the Format > Stylesheet menu.

Simply click on the Install Stylesheet... button at the left-top of private stylesheet window. A dialog will appear. Enter a name for your new stylesheet and click on OK.

installation

Now you can apply this style to any notebook.

stylesheet_menu


Notes

There are two approaches to writing stylesheets. The one discussed in the Wolfram documentation uses the tools in the Format menu (especially the Options Inspector). The other is to simply open a style definition cell with Cmnd+Shift+E and edit the cell -- mostly by adding cell options.

I recommend saving notebook used to build the private stylesheet in case you want to make further modifications. The private stylesheet is embedded in this notebook.

Mathematica is very protective of installed stylesheets. The installation dialog will insist that you give every stylesheet you install a unique name. During stylesheet development you may end up with a series of installed stylesheets each representing a stage in the development. After you have finalized your stylesheet, you will need to clean up the stylesheet directory. This is best done without Mathematica running.

When you need to find where stylesheets are installed, evaluate

FileNameJoin[
 {$UserBaseDirectory, "SystemFiles", "FrontEnd", "StyleSheets"}]
$\endgroup$
  • $\begingroup$ Just a point to add, you can find stylesheets like this: FrontEndExecute@ FrontEnd`FindFileOnPath["Default.nb", "StyleSheetPath" ] which can then be used on ones own stylesheets. e.g. I can find "BTools/CodePackage.nb" which is, of course, not a system file. $\endgroup$ – b3m2a1 Aug 4 '17 at 23:06
  • $\begingroup$ Also this is relevant if you edit your sheets programmatically. And should I start a community wiki for undocumented cell options? $\endgroup$ – b3m2a1 Aug 4 '17 at 23:08
  • $\begingroup$ I would like to change the default text color to brown. I tried to adapt the above method but I failed at steps 4 and 8. So I copied default.nb stylesheet to mydefault.nb. I went to Option Inspector and changed "Editable" to "Yes", and used Cmnd-Shift-E to open the cell "Text". I was hoping to insert "FontColor -> Red", but opening that cell changes "Editable" to "No" and indeed I am unable to edit the cell. What am I doing wrong? $\endgroup$ – Adam Feb 6 '18 at 23:43
  • $\begingroup$ @Adam. To change the default color of text in Text cells, you should skip step 4, which is about changing a cell frame and use the technique discussed in steps 5 to 8, which doesn't involve the Options Inspector. $\endgroup$ – m_goldberg Feb 7 '18 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.