I'm trying to create a stylesheet, but the process has become painful. I'm sure that this has to do something with resetting something in Mathematica everytime I make changes to the stylesheet. To explain my problem better I will describe the steps I take to create a very simple stylesheet with only one style defined.
In a new notebook enter the following:
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 will contain two cells. It will have the style as all the stylesheets that you have seen and you will 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 we 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 we select the Title
cell in Style01.nb
and we show the expression by going to Cell > Show Expression
. The next screenshot shows the view with the modifications:
Now we change back the title cell to how it was originally by doing Cell > Show Expression
again. In a mac we can press command + shift + E
. Now we 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 work. Lets create a new notebook called ExportNb.nb
in the same directory as TestNb.nb
. Put the following in it:
nb = NotebookOpen[NotebookDirectory[] <> "TestNb.nb"];
ExportString[nb, "HTML", "FullDocument" -> False]
This is what I obtained after evaluating those commands:
The conversion rules took effect. But, I made a mistake (purposely made when I created the style sheet). The angle bracket should have been on the top. In any case, let us correct this mistake:
After we revert back, and save Style01.nb
, we try to see if the new conversion rules will work.
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 works:
Conclusion and Questions:
It seems that if we want to the way your notebook looks like you can create styles and you will see how the changes take effect after you modify your stylesheet as I described in Test1. But, if you are to export your notebook as an HTML file or Tex, then you better beware of the ConversionRules
. I'm sure you will keep making many mistakes when you change the ConversionRules
but you will not be able to see the change of this unless you restart the kernel.
Questions: Is there any way for Mathematica to know that there has been changes in the conversion rules? Is there something that we need to restart other than the Kernel to see that this changes have been made? If restarting the kernel is the only way, is there a command to restart it? I'm getting tired of having turning it off and on all the time manually.
ClearSystemCache[]
? If it does not help you could try to find affected symbols by monitoring theByteCount
(or evenOwnValues
andDownValues
) for the all non-protected symbols in all contexts using something like the code I provided here. $\endgroup$ClearSystemCache[]
but that does not work. I guess at this point the best is to just evaluate the quit command and then evaluate the code I showed. I'll look more into your function later. Seems useful. $\endgroup$