0

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.
Charlotte Hadley
  • 2,364
  • 19
  • 17
  • 1
    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). – rm -rf May 27 '13 at 15:09
  • @rm-rf thanks! Changing styles with Mike's stylesheetChanger will definitely be useful for other things I'm trying to do. – Charlotte Hadley May 27 '13 at 15:53
  • @Kuba thanks for reviving this! I think that should be considered a duplicate, yes. Should I close this as duplicate? Not sure of procedure. – Charlotte Hadley Dec 19 '15 at 08:42
  • @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. – Kuba Dec 19 '15 at 08:44
  • Which was my intention but it's your call :) – Kuba Dec 19 '15 at 08:44
  • @Kuba Ha! I was using the mobile app and only saw the comment, didn't see the "that solved my problem" button that you get in the website proper. Yes, I'll accept. – Charlotte Hadley Dec 19 '15 at 08:46

0 Answers0