2
$\begingroup$

The following code (found here on stack exchange) creates a docked cell which contains a slider that can be used to change the magnification of the entire notebook.

SetOptions[EvaluationNotebook[], 
 DockedCells -> 
  Cell[BoxData[
    ToBoxes[DynamicModule[{m = 1}, 
      Slider[Dynamic[m, 
        SetOptions[EvaluationNotebook[], 
          Magnification -> (m = #)] &], {0.5, 2.0}]]]], "DockedCell"]]

I would like to modify this to a slider that controls the magnification of the output cells only. Everything else in the document should remain the same.

I'm not sure how to isolate the cells with "Output" style only. Any ideas?

$\endgroup$
  • 1
    $\begingroup$ maybe changing your Slider[...] to Slider[Dynamic[ m, (NotebookFind[EvaluationNotebook[], "Output", All, CellStyle]; SetOptions[NotebookSelection[], Magnification -> (m = #)]; SelectionMove[EvaluationNotebook[], Before, Notebook]) &], {0.5, 2.0}]? $\endgroup$ – kglr May 24 '18 at 4:11
  • $\begingroup$ That's it! Thank you. $\endgroup$ – Michael McCain May 24 '18 at 4:13
  • $\begingroup$ You can do one better by manipulating the actual stylesheet notebook. It's linked in via the NotebookInformation. $\endgroup$ – b3m2a1 May 24 '18 at 5:01
4
$\begingroup$

In general I like to use stylesheets for style specification and link it to a controller with notebook's tagging rules:

SetOptions[
  EvaluationNotebook[]
, DockedCells -> {
    Cell @ BoxData @ ToBoxes @ SetterBar[
      Dynamic @ CurrentValue[
        FrontEnd`EvaluationNotebook[], {TaggingRules, "OutputMagnification"}
      ]
    , {.5, Inherited, 2}
    , BaseStyle -> ControlsRendering -> "Generic"
    ]
  }
, StyleDefinitions -> Notebook[{
    Cell[StyleData[StyleDefinitions -> "Default.nb"]]
  , Cell[StyleData["Output"]
    , Magnification -> FrontEnd`CurrentValue[
        EvaluationNotebook[], {TaggingRules, "OutputMagnification"}, 1
      ]
    ]
  }]
]

This should be faster than editing cells on change and you will not loose selection.

$\endgroup$
  • $\begingroup$ Let us continue this discussion in chat. $\endgroup$ – Kuba May 24 '18 at 8:10
  • $\begingroup$ I figured out why it was crashing. It appears that if I use the magnification to make the output bigger than the window currently available in the output cell, then mathematica doesn't know what to do and crashes. As long as I don't magnify too large I'm ok. But makes it a little difficult because all of my output are different sizes. I may have to resort to not using the stylesheet method. your method is faster and smoother though. : ( $\endgroup$ – Michael McCain May 24 '18 at 9:13
  • $\begingroup$ @MichaelMcCain what if you replace {.5, Inherited, 2} with # Inherited -> # & /@ {.5,1,2}? $\endgroup$ – Kuba May 24 '18 at 9:15
  • $\begingroup$ Nope. Interesting though.... if resize the mathematic application window so it is large and then use magnification 2 in the docked cell we've created, then it works because the output now fits in the window. Then if I simply try resizing the mathematica application window smaller and smaller it works until the output does not fit in the window. Then mathematica crashes. $\endgroup$ – Michael McCain May 24 '18 at 9:28
  • 1
    $\begingroup$ Yep it's a bug. I was using output centered in my stylesheet using TextAlignment->Center. When I turned it off, everything works great. Now the mathematica application window can be resized to any size even if the output doesn't fit in the window and doesn't crash. I will report it. $\endgroup$ – Michael McCain May 24 '18 at 9:40

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.