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!

  • $\begingroup$ Not a direct answer: you could save the notebook as HTML and edit the CSS style sheet to add text-shadow: gray 3px 3px 3px; to the class definitions for .Section and .Subsection. That way you'll get drop shadows in the HTML output. It's not a solution for the presentation of the notebook itself, but it's so easy that I thought it should be pointed out. $\endgroup$ – Jens Mar 16 '14 at 6:04
  • 2
    $\begingroup$ Related: How can I add drop shadows and specular highlights to 2D graphics? $\endgroup$ – LCarvalho Jun 7 '17 at 23:01

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.


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.