Message Boards Message Boards

0
|
10840 Views
|
12 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Changing the Notebook Stylesheet

Posted 9 years ago

Hi: I try to understand Stylesheet setup.

Issue #1: When Mathematica is launched with new Notebook the Default stylesheet is checked ( I access this by clicking Format/Stylesheet). The Input Font is set to Bold. I would like to change this to Regular. By selecting Format/Edit Stylesheet I see the message "Inheriting base definitions from stylesheet Default.nb". I make the changes to the Input Font but I see no way to save the changes made to update Default.nb.

Issue #2: A workaround for Issue #1 is to select Format/Edit Stylesheet and make the desired Font changes. Then click Install Stylesheet. Enter a new Install name and click ok. This changes the Notebook Stylesheet and makes an entry of the new Install name in the Format/Stylesheet selection list. However, a change to the Font name is ignored and the Font name reverts to Courier New. So selecting this new Install name in the Format/Stysesheet listis an extra step when opening a new Notebook.

Thoughts about this would be appreciated...

POSTED BY: John Steigerwalt
12 Replies

You can't edit or change the Default.nb, or at least you shouldn't. It's part of the Wolfram Mathematica Installation and probably protected.. You can edit the stylesheet initially attached to your working notebook. Then install it under a different name, SteigerwaitDefault.nb say.

I'm not sure what's going wrong with issue#2. I just edited the Input style to Verdana Regular (which Mathematica changed to Plain) and it was recognized in the stylesheet and in the notebook. But I tried Lucida Calligraphy and that was recognized in the stylesheet but not in the notebook. When I added FontFamily -> "Lucida Calligraphy" to the underlying options in the notebook cell it did recognize the font. So here I think you did find a bug. Some fonts work and some don't.

Once you attach a stylesheet to a notebook it will automatically be used. But new notebooks will use the WRI Default.nb. I think you can change that by using the Option Inspector. Select Global Preferences. Then look in Global Options, File Locations, DefaultStyleDefinitions and change "Default.nb" to your preferred stylesheet. I think you have to click on the little gray square and then go to the installed stylesheet.

It seems to me that it should be fairly easy to change the settings of Default.nb used as the Stylesheet for new Notebook sessions. But apparently it is more of a big deal to do this than I anticipated. As you state the Option Inspector seems to be a good place to do this. Attached is a screen sheet of Option Inspector, not quite the same as you indicated. Unfortunately, searching the menu is rather cumbersome in that the menu window is very small and cannot be expanded. I went through the entire menu but was unable to locate DefaultStyleDefinitions. But maybe I am missing something very obvious. The initial step of attaching a customized Stylesheet (created with Menu/EditStylesheet/Install Stylesheet and accessed by Menu/Stylesheet) to each new Notebook is no big deal. Just didn't want to do that extra step if it could easily be avoided. Again, thank you for your efforts...

Attachments:
POSTED BY: John Steigerwalt

The process of editing stylesheets is a bit cumbersome at first, if it is helpful there is a tutorial that guides you through the process in the documentation at http://reference.wolfram.com/language/tutorial/WorkingWithStylesheets.html.

POSTED BY: Kyle Keane

You can't edit or change the Default.nb, or at least you shouldn't. It's part of the Wolfram Mathematica Installation and probably protected.. You can edit the stylesheet initially attached to your working notebook. Then install it under a different name, SteigerwaitDefault.nb say.

I'm not sure what's going wrong with issue#2. I just edited the Input style to Verdana Regular (which Mathematica changed to Plain) and it was recognized in the stylesheet and in the notebook. But I tried Lucida Calligraphy and that was recognized in the stylesheet but not in the notebook. When I added FontFamily -> "Lucida Calligraphy" to the underlying options in the notebook cell it did recognize the font. So here I think you did find a bug. Some fonts work and some don't.

Once you attach a stylesheet to a notebook it will automatically be used. But new notebooks will use the WRI Default.nb. I think you can change that by using the Option Inspector. Select Global Preferences. Then look in Global Options, File Locations, DefaultStyleDefinitions and change "Default.nb" to your preferred stylesheet. I think you have to click on the little gray square and then go to the installed stylesheet.

Thanks for the ideas... However, my conclusions: Issue #1: There is no way to edit the file Default.nb that is used for the default StyleSheet for a new Notebook. I use Menu/Format/EditStylesheet to create a new Stylesheet (this inherits from Stylesheet Default.db and includes edits) and save it using Install Stylesheet. Then rename this new Stylesheet to Default.nb and copy into FrontEnd\Stylesheets\ folder. Mathematica then will not launch after this change.

Issue#2: There is some bug in Menu/Format/EditStylesheet so that it refuses to recognize the edited Fonts and reverts back to Courier New. The other edited parameters, Face, Size, Background Color etc. are recognized.

POSTED BY: John Steigerwalt

Use Menu, Format, Edit Stylesheet and make your change. But I think you want the Face to be Plain, not Regular. This change should alter the look of the entry in the Stylesheet and also in the notebook. If you just want to attach the style to the specific notebook you can close the stylesheet at that point.

If you want to Save the stylesheet for general use in other notebooks, then use Install. This will install the notebook in your

$UserBaseDirectory/Mathematica/SystemFiles/FrontEnd/StyleSheets 

folder. It will appear on your Format, Stylesheet menu.

But the stylesheet will still be attached to your notebook. Now use the Stylesheet menu to specify the new installed stylesheet.

If you are sending your notebook to someone then you will also have to send the stylesheet (and tell them where to put it) or you will have to attach it again to your notebook.

If you are also going to have other things, such as a package, and are working on some specific application, then you might want to create an application. These also have a place for stylesheets and can include notebooks so you could just zip up the application and send it to another person. The notebooks would automatically use the stylesheet and you wouldn't have to give any special instructions. I describe how to build an application and stylesheets at my web site. A Mathematical Style. Few people seem interested in this however.

Posted 9 days ago

Very useful dialog and discussion. One major question.

Quoting: "If you are sending your notebook to someone then you will also have to send the stylesheet (and tell them where to put it) or you will have to attach it again to your notebook."

This is cumbersome and it's made my life difficult in the past. I've moved a folder of Mathematica notebooks from my work computer to my home computer, moved on from that job and work computer, and years later when I open a notebook, it doesn't look the same and there's no way to get it back with the carefully designed formatting and styles it once had.

Similarly, I've been embarrassed when I've sent a beautifully constructed Mathematica notebook to a boss, but internally it depended on some stylesheet. The boss opens the notebook and it looks amateurish.

Is there a way to embed all styles directly in a notebook, so that only that notebook file needs to be sent or moved?

POSTED BY: Paul Nielan

Long answer: With considerable work, if stylesheets have multiple inheritances.

Short answer: If you have one stylesheet that inherits from a Wolfram stylesheet packaged with Mathematica, then the following will embed the stylesheet myStyleNB in the notebook myNB.

 SetOptions[myNB, StyleDefinitions -> myStyleNB]

The notebook myNB should be an open NotebookObject[], such as returned by EvaluationNotebook[]. I usually execute SetOptions[EvaluationNotebook[]...] and then delete the cell. You could also choose the notebook from the following popup menu:

PopupMenu[Dynamic@myNB, Notebooks[]]

Now, myStyleNB should be a Notebook[] expression, such as returned by NotebookGet[]. Something like this:

Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]], 
  Cell[StyleData["Section"], FontColor -> RGBColor[0, 0, 1]], 
  Cell[StyleData["Input"], FontWeight -> "Plain"]}, 
 WindowSize -> {808, 911}, 
 WindowMargins -> {{-1570, Automatic}, {-102, Automatic}}, 
 FrontEndVersion -> "14.1 for Mac OS X ARM (64-bit) (July 16, 2024)", 
 StyleDefinitions -> "Default.nb"]

If you have both the notebook and the stylesheet open, then you can select each and set the stylesheet with the following:

PopupMenu[Dynamic@myNB, Notebooks[]]
PopupMenu[Dynamic@myStyleNB, Notebooks[]]

(* execute the following AFTER setting both notebooks *)
SetOptions[myNB, StyleDefinitions -> NotebookGet@myStyleNB]
POSTED BY: Michael Rogers
Posted 8 days ago

So I can verify that Mike's answer worked. This is really useful to me--thank you.The clarity about a short answer and a long answer important. Here are the actual steps I used to verify the short answer which Mike provides. I am running 14.1.

• Open Wolfram and set up a notebook the way you want including overriding existing styles and adding new styles.

• Export a stylesheet using Format->Edit Stylesheet Export button.

• Call it StylesheetAlpha.nb

• Close Wolfram and then reopen it

• Open a new notebook called Work.nb

• Open StylesheetAlpha.nb

• In Work.nb, use the commands below to define variables myNB and myStyleNB. This eliminates any file commands other than opening the two notebooks. You have to scroll in the list provided by PopupMenu to get the right notebooks.

• PopupMenu[Dynamic@myNB, Notebooks[]]

• PopupMenu[Dynamic@myStyleNB, Notebooks[]]

• SetOptions[myNB, StyleDefinitions -> NotebookGet@myStyleNB]

• Save Work.nb

• Close Wolfram

• Delete StylesheetAlpha.nb and empty the trash to make sure it isn't being used. And that everyting is truly embedded.

• Open Wolfram

• Open Work.nb

• Check to see if the styles work as expected. Look at them using Format->Edit Stylesheet.

It all worked! And it only has to be done once. From then on Work.nb has the styles in it.

Mike, wonder if you would share your source for learning about this? Was it just the online documentation or is there a tutorial you found useful.

POSTED BY: Paul Nielan

Hi Paul,

About learning about Stylesheets: Honestly I don't remember. I've been using Mma since around 1990. I think I once edited the "Private Style Sheet", and I wondered how the information was stored in the notebook. So I probably looked at an ASCII dump of the notebook and saw they were stored in StyleDefinitions. Now StyleDefinitions has its own doc page, with links to related Guides and Tech Notes.

Using an ASCII editor on the stylesheet notebooks in

FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "StyleSheets"}]

has given me ideas.

The menu command Cell > Show Expression sometimes gives me ideas.

A lot of looking under the hood combined with what shows up in a documentation search.

I use a lot of notebooks in class, and sometimes I want a special style for the class. So I make an empty Work.nb with the embedded stylesheet. Then I copy the notebook and put new content in it.

The first time I went it deep with a stylesheet for class, I left it external and shared it with the students. Most of the students didn't understand how to use, didn't follow my directions, etc. The thing is, there was a button that showed up with the stylesheet, and the button would generate a notebook with the answers to the exercises. And most of the students never saw it. Rather disappointing. So I know what you meant about sending it to your boss.

POSTED BY: Michael Rogers
Posted 17 hours ago

I also found this presentation released this week that had technical difficulties and poor production values, but is nonetheless very helpful.

https://www.youtube.com/watch?v=92Rgzc9KV2w&t=3s

POSTED BY: Paul Nielan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract