Creating and Editing New Stylesheets

Embed Size (px)

Citation preview

  • 7/27/2019 Creating and Editing New Stylesheets

    1/4

    Creating and editing new stylesheets

    I'm try ing 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 sty lesheet. To explain my problem better I will describe the s teps 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"->{"",#&,"\n"}

    },

    FontSize->26,

    FontWeight->"Bold",

    FontColor->RGBColor[0,0,0]

    ]

    },

    StyleDefinitions->"StylesheetFormatting.nb",

    Editable->True,

    Saveable->True

    ]

    The new notebook that appears w ill contain two 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 . I name this notebook . Once you have this enter this

    command:

    $UserBaseDirectory/SystemFiles/FrontEnd/StyleSheets/ Style01.nb

    MathLink`CallFrontEnd[FrontEnd`ResetMenusPacket[{Automatic,Automatic}]]

    I found that command , this command resets the menu so that 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 cell. Save this notebook as in a directory of your choice.

    Go to .

    here Mathematica

    Title TestNb.nb

    Format > Stylesheet > Style01

    Test 1:

    The current view should be this:

    Now w e select the cell in and w e show the express ion by going to . The next screenshot show s

    he view w ith the modifications:

    Title Style01.nb Cell > Show Expression

  • 7/27/2019 Creating and Editing New Stylesheets

    2/4

    Now w e change back the title cell to how it w as originally by doing again. In a mac w e can press

    . Now w e see that the changes took effect.

    Cell > Show Expression command + shift +

    E

    No problem there. We can repeat this procedure to keep adjusting the cell.Title

    Test 2:

    Now lets see if our convers ions rules w ork. Lets create a new notebook called in the same directory as . Put the

    follow ing in it:

    ExportNb.nb TestNb.nb

    nb =NotebookOpen[NotebookDirectory[]"TestNb.nb"];

    ExportString[nb,"HTML","FullDocument"->False]

    This is what I obtained after evaluating those commands:

    The conversion rules took ef fec t. But, I made a mistake (purposely made w hen I created the sty le sheet). The angle bracket should have been

    on the top. In any case, let us correct this mistake:

  • 7/27/2019 Creating and Editing New Stylesheets

    3/4

    Af ter w e revert back, and save , w e try to see if the new convers ion rules w ill w ork.Style01.nb

    Unfortunately, the changes in the do not take eff ect. I have found that if I quit the Kernel by going to

    and then I run the commands again then it w orks:

    ConversionRules Evaluation > Quit

    Kernel > local

    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 sty lesheet as I described in Test1. But, if you are to export your notebook as an HTML file or Tex, then you better bew are of the

    . I'm sure you w ill keep making many mistakes w hen you change the but you w ill not be able to see the

    change of this unless you restart the kernel.

    ConversionRules ConversionRules

    Questions: Is there any w ay f or 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 restar ting the kernel is the only w ay, is there a command to

    restart it? I'm getting tired of having turning it off and on all the time manually.

    front-end kernel conversionasked May 26 '12 at 21:38

    mlopez

    1,860 5 22

    Have y ou tried ? If it does not help y ou could try to f ind aff ected sy mbols byClearSystemCache[]

    monitoring the (or even and ) f or the all non-protected sy mbols in allByteCount OwnValues DownValues

    context s using something like the code I provided .here Alexey Popkov May 28 '12 at 5:27

    @AlexeyPopkov, I tried but that does not work. I guess at this point the best is toClearSystemCache[]

    just evaluate the quit command and then ev aluate the code I s howed. I 'll look more into y our f unction later.

    Seems useful. jmlopez May 28 '12 at 16:43

  • 7/27/2019 Creating and Editing New Stylesheets

    4/4

    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 sess ion. That's it!

    answered May 27 '12 at 13:42

    magma

    1,840 4 24

    I f igured that much but it just s eems like a little too much to restart ev ery thing when there's probably

    something else that takes care of the sty le definitions. Anyway, +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 restart ing used to be a slow and painful process with the f irst v ersions of MMA, partly because

    PCs were comparatively s low back then, but now it takes a f ew millisecs t o restart the whole thing and have

    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 diff 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 m y

    imression is that Quit only c loses 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. I n my opinion this is wrong.

    magma Oct 17 '12 at 22:41

    @magma as far as I know Quit[] c loses the master kernel and so also all slave kernels. RMMA Oct 19 '12at 12:27