You are on page 1of 4

Creating and editing new stylesheets

I'm trying to create a stylesheet, but the process has become painful. I'm sure that this has to do something w ith resetting something in Mathematica everytime I make changes to the stylesheet. To explain my problem better I w ill describe the steps I take to create a very simple stylesheet w ith only one style defined. In a new notebook enter the follow ing:
CreateDocument[{ Cell[StyleData[StyleDefinitions -> "Core.nb"]], Cell[StyleData["Title"], ConversionRules -> { "TeX" -> {"\\title{", # &, "}"}, "HTML" -> {"<h1 class=\"Title\"\n>", # &, "\n</h1>"} }, FontSize -> 26, FontWeight -> "Bold", FontColor -> RGBColor[0, 0, 0] ] }, StyleDefinitions -> "StylesheetFormatting.nb", Editable -> True, Saveable -> True ]

The new notebook that appears w ill contain tw o cells. It w ill have the style as all the stylesheets that you have seen and you w ill be able to edit and save it. Save this notebook in $UserBaseDirectory/SystemFiles/FrontEnd/StyleSheets/ . I name this notebook Style01.nb . Once you have this enter this command:
MathLink`CallFrontEnd[FrontEnd`ResetMenusPacket[{Automatic, Automatic}]]

I found that command here, this command resets the menu so that Mathematica can list your stylesheet in the menu. At this point w e are ready to use the stylesheet. Open a new notebook and create a Title cell. Save this notebook as TestNb.nb in a directory of your choice. Go to Format > Stylesheet > Style01 .

Test 1:
The current view should be this:

Now w e select the Title cell in Style01.nb and w e show the expression by going to Cell > Show Expression . The next screenshot show s the view w ith the modifications:

ExportString[nb. Now w e see that the changes took effect. "HTML". But.nb . In any case. Put the follow ing in it: nb = NotebookOpen[NotebookDirectory[] <> "TestNb. In a mac w e can press command + shift + E .nb"]. Test 2: Now lets see if our conversions rules w ork. "FullDocument" -> False] This is w hat I obtained after evaluating those commands: The conversion rules took effect. We can repeat this procedure to keep adjusting the Title cell. Lets create a new notebook called ExportNb. let us correct this mistake: .nb in the same directory as TestNb. No problem there.Now w e change back the title cell to how it w as originally by doing Cell > Show Expression again. I made a mistake (purposely made w hen I created the style sheet). The angle bracket should have been on the top.

– jmlopez May 28 '12 at 16:43 . if you are to export your notebook as an HTML file or Tex. I guess at this point the best is to just ev aluate the quit command and then ev aluate the code I showed. – Alexey Popkov May 28 '12 at 5:27 @Alexey Popkov. w e try to see if the new conversion rules w ill w ork. the changes in the ConversionRules do not take effect. Questions: Is there any w ay for Mathematica to know that there has been changes in the conversion rules? Is there something that w e need to restart other than the Kernel to see that this changes have been made? If restarting the kernel is the only w ay. Unfortunately. and save Style01. I'll look more into y our f unction later. front-end kernel conversion asked May 26 '12 at 21:38 jmlopez 1.nb . then you better bew are of the ConversionRules . I'm sure you w ill keep making many mistakes w hen you change the ConversionRules but you w ill not be able to see the change of this unless you restart the kernel.860 5 22 Hav e y ou tried ClearSystemCache[] ? If it does not help y ou could try to f ind af f ected sy mbols by monitoring the ByteCount (or ev en OwnValues and DownValues ) f or the all non-protected sy mbols in all contexts using something like the code I prov ided here.After w e revert back. Seems usef ul. But. is there a command to restart it? I'm getting tired of having turning it off and on all the time manually. I have found that if I quit the Kernel by going to Evaluation > Quit Kernel > local and then I run the commands again then it w orks: Conclusion and Questions: It seems that if w e w ant to the w ay your notebook looks like you can create styles and you w ill see how the changes take effect after you modify your stylesheet as I described in Test1. I tried ClearSystemCache[] but that does not work.

Any way. it seemed like y ou were not aware of the Quit command. f rom y our question. you simply type Quit and the kernel stops. That's it! answered May 27 '12 at 13:42 magma 1. partly because PCs were comparativ ely slow back then. – RMMA Oct 17 '12 at 12:02 @Frink good question! I am not sure since I nev er really experimented with parallel computations.840 4 24 I f igured that much but it just seems like a little too much to restart ev ery thing when there's probably something else that takes care of the sty le def initions. +1 f or answering. – jmlopez May 27 '12 at 14:58 I answered this way because. In my opinion this is wrong. But I just wondered if there is a dif f erence between Quit[] and CloseKernels[]. Other ideas? I also f ind strange that Quit and CloseKernels are not related in the documentation. so why bother? – magma May 28 '12 at 8:46 @magma may be here is not the right place to post a question. – RMMA Oct 19 '12 at 12:27 . but now it takes a f ew millisecs to restart the whole thing and hav e a clean slate.1 Answer Instead of going to Evaluation > Quit Kernel > local. Quitting and restarting used to be a slow and painf ul process with the f irst v ersions of MMA. while CloseKernels closes all open kernels. then run the commands again in the new session. – magma Oct 17 '12 at 22:41 @magma as f ar as I know Quit[] closes the master kernel and so also all slav e kernels. but my imression is that Quit only closes one kernel.