47
$\begingroup$

Is there a way to open one notebook in two (or more) different windows? This can be helpful when working with a long notebook and one wants to edit one part of it while looking at a different part. Otherwise, you have to jump back and forth...

Edit: Per @Guillochon comment, splitting the window where the notebook is open is indeed a nice option.

Edit 2: Having a secondary "read-only" window can also be a nice compromise.

$\endgroup$
8
  • 3
    $\begingroup$ I like this question. I would expect the behavior to mirror (clone) the Notebook, such that a change in one is made to the other; optionally only one would be directly editable. I don't know how to do this but I'd like to find out. $\endgroup$
    – Mr.Wizard
    Aug 10, 2012 at 8:10
  • 3
    $\begingroup$ Isn't @Dror just asking for a split-screen window? Almost all modern text editors have that feature... $\endgroup$
    – Guillochon
    Aug 10, 2012 at 8:20
  • $\begingroup$ @Guillochon Yes, but the mathematica interface is not a modern text editor:) All modern text editors have tab-indent as well, but try doing that in the notebook interface. I guess using Workbench is always an option, although I never got used to it... $\endgroup$
    – Ajasja
    Aug 10, 2012 at 9:23
  • 4
    $\begingroup$ I asked this split screen question to Wolfram in 1994! He tried and convince me I didn't need it. $\endgroup$
    – chris
    Aug 10, 2012 at 9:28
  • 1
    $\begingroup$ Tell us what you want and we ll explain to you why you don't need it! :-) The answer bellow works fine for me though. $\endgroup$
    – chris
    Nov 28, 2013 at 10:44

1 Answer 1

35
$\begingroup$

Here's a rather unsophisticated approach. The code below creates a toolbar in the current notebook, with buttons to create, refresh and close a replica notebook. The replica is given a gray background and cannot be edited or evaluated.

I tried to do something with Dynamic to automatically refresh the replica notebook, but without success.

Update

Here is a neater implementation. The code below creates a palette (which can be installed using the menu: Palettes/Install Palette) containing a single button to create a duplicate of the active notebook. The update button for the duplicate is now located in the duplicate itself, leaving the original notebook unchanged. The duplicate is closed using the normal window close button, but it has "ClosingSaveDialog" set to False so you won't get a save prompt.

CreatePalette[Button["Duplicate Active Notebook",
   NotebookPut[NotebookGet[InputNotebook[]] /. 
   {Rule[DockedCells, _] :> Sequence[], 
    Rule[WindowMargins, _] :> Rule[WindowMargins, {{0, Automatic}, {0, Automatic}}], 
    Cell[x___] :> Cell[x, Evaluatable -> False]}, 
    Background -> GrayLevel[0.95], Editable -> False, "ClosingSaveDialog" -> False, 
    DockedCells -> With[{sourcenb = InputNotebook[]}, 
      Cell[BoxData[ToBoxes[Button["Update", 
          SelectionMove[InputNotebook[], All, Notebook]; 
          NotebookWrite[InputNotebook[], 
           NotebookGet[sourcenb] /. Cell[x___] :> Cell[x, Evaluatable -> False]]]]],
       "DockedCell", CellContext -> Cell]],
    WindowTitle -> "Duplicate of " <> AbsoluteOptions[InputNotebook[], WindowTitle][[1, 2]]];
   SetSelectedNotebook[InputNotebook[]]], WindowTitle -> "Duplicate"];
$\endgroup$
18
  • $\begingroup$ +1 Great idea. I did notice that syntax highlighting doesn't work, which is a big minus. $\endgroup$
    – Ajasja
    Aug 10, 2012 at 13:58
  • $\begingroup$ @Ajasja: That's not quite right; There is some degree of highlighting. For example internal variables of modules - do get colored in green. $\endgroup$
    – Dror
    Aug 10, 2012 at 14:41
  • $\begingroup$ @SimonWoods: The Close toolbar doesn't work for me - I get SetOptions::optnf: DockedCells is not a known option for thisnb. >> error. Any idea? $\endgroup$
    – Dror
    Aug 10, 2012 at 14:44
  • 1
    $\begingroup$ @Dror, see update. $\endgroup$ Aug 21, 2012 at 21:56
  • 3
    $\begingroup$ @Dror, It sounds like you have installed the notebook containing the CreatePalette code, rather than the palette it creates. Open a fresh notebook, paste my code into it and execute it. This should create a palette window titled "Duplicate" at the top right of the screen. You can now close the notebook window - you don't need to save it, the code has done its job. Now go to Palettes/Install Palette on the menu, select "Duplicate" as the Source and provide an install name (e.g. Duplicate). Then click Finish. You should now have the new item in the Palette menu. $\endgroup$ Aug 22, 2012 at 7:58

Your Answer

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

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