2
$\begingroup$

This is not a critical bug yet another issue that I should not waste time on.

Evaluate

SetOptions[EvaluationNotebook[]
 , WindowSize -> Automatic
 , WindowMargins -> 50
]

Question

I want to set the same options for a notebook that was saved with WindowSize -> Full (F12) without noticing it was saved in full screen. So via Visible->False.

path = FileNameJoin[{$TemporaryDirectory, "test.nb"}];
Export[path, Notebook[{}, WindowSize -> Full]]

nb = NotebookOpen[path, Visible -> False];

SetOptions[nb
 , WindowSize -> Automatic
 , WindowMargins -> 50     
 ];
SetOptions[nb, Visible -> True];

Problem on Win10

This does not work for me, nb is located on the left side of my screen with size of a default new notebook.

Commenters suggested doing SetOptions sequentially, which works, however

Problem persists on MacOSX 10.13+

and all my experiments lead me to a conclusion that:

In this OS you can't toggle full screen more when the notebook is Visible->False.


Can you reproduce this problem? Any tips?

$\endgroup$
  • $\begingroup$ I have reproduced the problem for both approaches using V11.2 on Win10. Note, however, that if I run either command, adjust the size or position of the newly opened window, and then run the command again (in either the old or new notebook), then the new notebook is resized properly. $\endgroup$ – jjc385 Oct 21 '17 at 14:31
  • $\begingroup$ SetOptions[nb, WindowSize -> Automatic]; SetOptions[nb, WindowMargins -> 50] also works. $\endgroup$ – Rolf Mertig Oct 21 '17 at 15:56
1
$\begingroup$

The probable reason is that the Notebook FrontEnd and the Kernel do (historically) not wait for each other enough. Adding a Pause[] will slow things down and let the FronEnd (and probably the operating system) finish its work before the kernel interferes. You may have to use 1 second, but on my machine it works with 0.7. Not sure if this is a real satisfactory workaround, but it may give the good Wolfram folks an idea of how to fix it.

The following works for me on Windows and Mac OS 10.13 and Mathematica 11.2, no luck on Linux however.

path = FileNameJoin[{$TemporaryDirectory, "test.nb"}];
Export[path, Notebook[{}, WindowSize -> Full]];

nb = NotebookOpen[path, Visible -> False];

If[$OperatingSystem === "MacOSX", Pause[.8]];

SetOptions[nb
 , WindowSize -> Automatic
 , WindowMargins -> 50]; SetOptions[nb, Visible -> True
 ];
$\endgroup$
1
$\begingroup$

Here is what I do and works everywhere so far.

Import notebook and filter options manually.

open[path_, opts___?OptionQ] := Module[{nbExpr, nb}
, nbExpr = Import[path, "NB"]
; nb = NotebookPut @ Notebook[
    First @ nbExpr
  , Sequence @@ (Normal @ <|Association @@ Rest[nbExpr], opts|>)
  ]
; NotebookSave[nb, path]
; nb
]

open[path, WindowSize -> Automatic, WindowMargins -> 50]
$\endgroup$
  • $\begingroup$ Isn't Sequence @@ Rest[nbExpr] equivalent to Sequence @@ (Normal @ <|Association @@ Rest[nbExpr]|>)? $\endgroup$ – Alexey Popkov Nov 4 '17 at 10:21
  • $\begingroup$ @AlexeyPopkov yes, forgot opts. $\endgroup$ – Kuba Nov 4 '17 at 10:23
  • 1
    $\begingroup$ Probably then Flatten[{opts, List @@ Rest[nbExpr]] should do the same, because opts will have higher precedence than Rest[nbExpr]. $\endgroup$ – Alexey Popkov Nov 4 '17 at 10:25
  • $\begingroup$ @AlexeyPopkov good alternative for pre associations era. The only difference will be that here old opts are filtered out, not a major problem. $\endgroup$ – Kuba Nov 4 '17 at 10:27
  • 1
    $\begingroup$ And more readable too, in my view. $\endgroup$ – Alexey Popkov Nov 4 '17 at 10:28

Your Answer

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

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