4

Inspired by simon woods's wonderful shadow function, I want to add drop shadows to all the text of non-input/output cells in a notebook, something like this: enter image description here

By using simon woods's shadow function, I can take some text and add shadow to it:

style["Some text","Text"]//shadow[#,#]&

And then paste the resulting image back. But I can't automate this process.

My question is

  1. how to make a function that take a notebook as input, and output a "shadowed" version with all the text of non-input/output cells having shadow?

  2. If 1 can be done, is it possible to reduce the size of the "shadowed" notebook? As all the text is replaced with images, the notebook may be large.

Thanks very much!

Kuba
  • 136,707
  • 13
  • 279
  • 740
kptnw
  • 1,406
  • 8
  • 15

1 Answers1

5

Here is an idea of how to do this without rasterization. It will only double + fixed offset the size as any text will be replaced with text+text+overlay specification.

You can play with overlay options and styling to get 'better' shadows:

nb = (*whatever notebook object e.g. EvaluationNotebook[]*)

Module[{cell, cellObj}
, cellObj = #
; cell = NotebookRead[cellObj]
; If[
    StringQ @ First @ cell
  , cell = ReplacePart[cell
    , 1 -> Replace[cell[[1]], s_String :> BoxData@ToBoxes@Overlay[
        { s, Pane[Style[s, GrayLevel@.8], FrameMargins -> {{3, 0}, {0, 0}}
               , ImageMargins -> 0
             ]
        }
      , {2, 1}
      , BaseStyle -> {ShowStringCharacters -> False}
      ]]
    ]
  ; NotebookWrite[cellObj, cell]
  ]
] & /@ DeleteCases[
  Cells[nb], Alternatives @@ Cells[nb, CellStyle -> {"Input", "Output"}]
]

This is what I get for a Default.nb stylesheet new notebook template:

enter image description here

Notice I ignored non purely text cells, e.g. those with inline cells, so consider this a proof of concept.

Kuba
  • 136,707
  • 13
  • 279
  • 740