Académique Documents
Professionnel Documents
Culture Documents
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:
Now w e change back the title cell to how it w as originally by doing Cell > Show Expression again. In a mac w e can press command + shift + E . Now w e see that the changes took effect.
No problem there. We can repeat this procedure to keep adjusting the Title cell.
Test 2:
Now lets see if our conversions rules w ork. Lets create a new notebook called ExportNb.nb in the same directory as TestNb.nb . Put the follow ing in it:
nb = NotebookOpen[NotebookDirectory[] <> "TestNb.nb"]; ExportString[nb, "HTML", "FullDocument" -> False]
The conversion rules took effect. But, I made a mistake (purposely made w hen I created the style sheet). The angle bracket should have been on the top. In any case, let us correct this mistake:
After w e revert back, and save Style01.nb , w e try to see if the new conversion rules w ill w ork. Unfortunately, the changes in the ConversionRules do not take effect. 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:
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. Alexey Popkov May 28 '12 at 5:27 @Alexey Popkov, I tried ClearSystemCache[] but that does not work. I guess at this point the best is to just ev aluate the quit command and then ev aluate the code I showed. I'll look more into y our f unction later. Seems usef ul. jmlopez May 28 '12 at 16:43
1 Answer
Instead of going to Evaluation > Quit Kernel > local, you simply type Quit and the kernel stops, then run the commands again in the new session. That's it!
answered May 27 '12 at 13:42 magma 1,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. Any way, +1 f or answering. jmlopez May 27 '12 at 14:58 I answered this way because, f rom y our question, it seemed like y ou were not aware of the Quit command. Quitting and restarting used to be a slow and painf ul process with the f irst v ersions of MMA, partly because PCs were comparativ ely slow back then, but now it takes a f ew millisecs to restart the whole thing and hav e a clean slate, so why bother? magma May 28 '12 at 8:46 @magma may be here is not the right place to post a question. But I just wondered if there is a dif f erence between Quit[] and CloseKernels[]. RMMA Oct 17 '12 at 12:02 @Frink good question! I am not sure since I nev er really experimented with parallel computations, but my imression is that Quit only closes one kernel, while CloseKernels closes all open kernels. Other ideas? I also f ind strange that Quit and CloseKernels are not related in the documentation. In my opinion this is wrong. 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. RMMA Oct 19 '12 at 12:27