The goal

To create a notebook whose options, when the notebook is opened, are fixed regardless of edits done to the notebook.

E.g. WindowSize -> Automatic and WindowMargins -> 30 should be a starting value even if one has saved that notebook from full screen mode.

The motivation

Notebooks are shared, e.g. through Google Drive, and opened on different devices. It is annoying to open a notebook, which was previously used with 250% magnification, taking half of 4K screen, on a 13" laptop.

The question

Is there a good approach which is flexible, doesn't trigger dynamic warning and if possible works from a stylesheet?

I've thought that maybe something like WindowSize -> Dynamic[dynamic, Initialization :> (dynamic = init)] where dynamic and init are references to specific TaggingRules.

It won't work because notebook options are overwritten. Moreover, Initialization can be triggered when the Kernel is restarted which is not desirable.


I have not received any answers so I'm moving tests I've done to an answer. I think they fit there and the goal is to reduce unanswered stack. But I will gladly accept any answer that fulfills all stated requirements.

  • $\begingroup$ Like the notebooks in Documentation Center? $\endgroup$
    – Silvia
    Sep 6, 2016 at 10:35
  • $\begingroup$ @Silvia they are not saveable at all. I want to use them normally. $\endgroup$
    – Kuba
    Sep 6, 2016 at 10:38
  • $\begingroup$ Oh sorry I misunderstood your purpose... The FileChangeProtection option (for Notebook) looks interesting, might lead to a solution for your question. $\endgroup$
    – Silvia
    Sep 6, 2016 at 10:56
  • $\begingroup$ @Silvia no worries. I can't find any info about that option :) $\endgroup$
    – Kuba
    Sep 6, 2016 at 10:58
  • $\begingroup$ I saw it in Doc notebooks. They use it as FileChangeProtection -> None, I'm guessing maybe it also accepts a function value. $\endgroup$
    – Silvia
    Sep 6, 2016 at 11:09

1 Answer 1


Approaches (none is perfect):

  1. NotebookDynamicExpression, something along those lines:

    NotebookDynamicExpression :> Refresh[
      SetOptions[EvaluationNotebook[], WindowSize -> Automatic], 

    I don't like it. The reasons are:

At the end the method is poor because it triggers Enable Dynamic Updating warning in the notebook (on an untrusted path) while nothing serious is going on.

  1. NotebookEventActions

    NotebookEventActions :> {"WindowClose" :> (
      SetOptions[EvaluationNotebook[], WindowSize -> Automatic, WindowMargins -> 30];
      PassEventsDown -> True

    Is not general enough as it misses things like NotebookClose[]. It also flashes before it is closed but this is not so important.

  • $\begingroup$ The "WindowClose" approach could instead be done on {"MenuCommand", "Save"}? That way any time it is saved that will fire (although I suppose this might be super annoying...). It might be a bit more robust. $\endgroup$
    – b3m2a1
    Jul 20, 2018 at 21:11
  • $\begingroup$ @b3m2a1 yes, I do not want to readjust the window after each save :) $\endgroup$
    – Kuba
    Jul 21, 2018 at 6:19
  • 1
    $\begingroup$ One other option is to add a context-menu item that would do this. That way people could just right-click and apply via the menu. It still requires a bit of work on their part, but is totally applicable via stylesheet, isn't dynamic, and is robust. $\endgroup$
    – b3m2a1
    Jul 21, 2018 at 6:27
  • $\begingroup$ @b3m2a1 sounds useful. My use case involves people that can be bothered with such stuff :) that is why I aim in a more automatc solution here. $\endgroup$
    – Kuba
    Jul 21, 2018 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.