4
$\begingroup$

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!

$\endgroup$
2
  • $\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, 2014 at 6:04
  • 2
    $\begingroup$ Related: How can I add drop shadows and specular highlights to 2D graphics? $\endgroup$
    – LCarvalho
    Jun 7, 2017 at 23:01

1 Answer 1

5
$\begingroup$

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, [email protected]], 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.

$\endgroup$

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.