0
$\begingroup$

I have my own stylesheet that I like using so much I change all my documents to it almost immediately, but as I demo Mathematica to people I cannot use DefaultStyleDefinitions as it unnecessarily confuses people. I therefore have a function (typed verbatim, not loaded) in my init.m file that pastes the definitions from a stylesheet into the EvaluationNotebook[]

BeginPackage["PasteStyles`"]
pasteStyleSheet::usage="pasteStyleSheet[stylesheet, \"Admin\"] pastes the style definitions provided by stylesheet located in $BaseDirectory (etc)"; Begin["`Private`"]
pasteStyleSheet[stylesheet_String,"Admin"]:=SetOptions[EvaluationNotebook[],StyleDefinitions->Get[FileNameJoin[{$BaseDirectory,"FrontEnd","StyleSheets",stylesheet<>".nb"}]]]
pasteStyleSheet[stylesheet_String,"User"]:=SetOptions[EvaluationNotebook[],StyleDefinitions->Get[FileNameJoin[{$UserBaseDirectory,"FrontEnd","StyleSheets",stylesheet<>".nb"}]]]
pasteStyleSheet[stylesheet_String,"System"]:=SetOptions[EvaluationNotebook[],StyleDefinitions->Get[FileNameJoin[{$InstallationDirectory,"SystemFiles","FrontEnd","StyleSheets",stylesheet<>".nb"}]]]
End[]
EndPackage[]

I have an issue in that I use options for cells such as WholeCellGroupOpener and ReturnCreatesNewCell that Mathematica doesn't seem to know anything about when my function is evaluated. I found this out because I used to find $CellContext throughout my pasted style definitions.

Currently, I have shoved the following lines into the package to make sure it works.

System`WholeCellGroupOpener;
System`ReturnCreatesNewCell;

My questions are:

  • Why do I get $CellContext for some functions that should be on `System?
  • How do I ensure my function works as intended? Does it need to live somewhere else?

Justifications:

  • I need to paste the styles, as I email the notebooks out.
  • I spend most of my time making fun things in the front end, I'm expecting this stylesheet to eventually become something that no one else will ever want to use.
$\endgroup$
  • 1
    $\begingroup$ Not an answer to your question, but here's a related question that solves the same problem with using & sharing custom stylesheets (i.e. embed in notebook instead of linking to style file). $\endgroup$ – rm -rf May 27 '13 at 15:09
  • $\begingroup$ @rm-rf thanks! Changing styles with Mike's stylesheetChanger will definitely be useful for other things I'm trying to do. $\endgroup$ – Charlie Joey Hadley May 27 '13 at 15:53
  • $\begingroup$ @Kuba thanks for reviving this! I think that should be considered a duplicate, yes. Should I close this as duplicate? Not sure of procedure. $\endgroup$ – Charlie Joey Hadley Dec 19 '15 at 8:42
  • $\begingroup$ @MartinJohnHadley The question isn't exactly the same but the answer is the answer. If you agree with closing it will be automatically closed as a duplicate an stay here as a road sign for future visitors. $\endgroup$ – Kuba Dec 19 '15 at 8:44
  • $\begingroup$ Which was my intention but it's your call :) $\endgroup$ – Kuba Dec 19 '15 at 8:44

Browse other questions tagged or ask your own question.