3
$\begingroup$

I built a setterbar that allows me to quickly apply stylesheets to a notebook. Here is the code:

SetterBar[Dynamic[temp], {"Lecture", "Testing"}],

Dynamic[If[temp == "Lecture",
  SetOptions[InputNotebook[], 
   StyleDefinitions -> 
    "/Users/michaelmccain/Library/Mathematica/SystemFiles/FrontEnd/\
StyleSheets/MyLectureStyles.nb"], 
  SetOptions[InputNotebook[], 
   StyleDefinitions -> 
    "/Users/michaelmccain/Library/Mathematica/SystemFiles/FrontEnd/\
StyleSheets/Testing.nb"]]]

When the code is located in the target notebook it works perfectly. See gif below.

enter image description here

However, if I put the code above into a palette, then I get an annoying hiccup when I try and use it... The styles in the notebook don't update immediately. If I type at least one character in any cell, then the styles update. Strange. Below is gif illustrating the issue.

enter image description here

I'm not sure why. What is going on here? Is there a fix you can think of?

$\endgroup$
  • 1
    $\begingroup$ A workaround is to add NotebookWrite[InputNotebook[],""] after SetOptions[]. This resets everything. I'm interested if anyone thinks this is a bug. $\endgroup$ – Michael McCain Dec 19 '16 at 0:17
  • 1
    $\begingroup$ I've faced it too. I'm doing SetOptions[nb, StyleDefinitions->"Default.nb"] as an intermediate step and it works. That day it was one of minor problems so I forgot to report it. You can do that. $\endgroup$ – Kuba Dec 19 '16 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.