36
$\begingroup$

Is it possible to set a notebook's background to a nonscrolling image?

$\endgroup$
3
  • 1
    $\begingroup$ I remember looking for this once. There isn't an option for it. You can only change the background color. $\endgroup$
    – Searke
    Jun 18, 2012 at 15:00
  • $\begingroup$ I don't see anything in the Option Inspector. I also don't think it can be done programatically. $\endgroup$
    – a06e
    Jun 29, 2012 at 1:48
  • 4
    $\begingroup$ The closest I can think of is a scrollable Pane on top of a background, which isn't very good. Note that this will be possible in v9, but not documented (see the chat log in the Mathematica chat room for evening, Oct. 21, where I discuss why that's the case). When v9 ships, I'll swing back around and answer this question. $\endgroup$
    – John Fultz
    Oct 25, 2012 at 12:57

2 Answers 2

32
$\begingroup$

In version 9 there is a new option called BackgroundAppearance that can be used to set the notebook's background.

The picture below was made by setting this option in the option inspector to FrontEnd`FileName[{"SlideShow"}, "WaterTitleBackground.png"]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ In John's comment above he said this option is undocumented. Is that the case? Looks nice though. $\endgroup$ Nov 30, 2012 at 22:56
  • $\begingroup$ @MikeHoneychurch If it is documented it's hidden well. $\endgroup$ Nov 30, 2012 at 23:10
25
$\begingroup$

In version 9, Mathematica includes a feature for doing background images which was implemented for slide shows. However, it wasn't documented because, although enough support was included for slide shows, the feature has distinct limitations which shouldn't be enshrined in documentation, and its usage is not the most straightforward at this point. I'll discuss its usage, but I must emphasize that it was left undocumented for a reason. Slide show notebooks will certainly be forward compatible with future versions of Mathematica, but edge cases experimentally discovered by users may not be forward compatible.

The option is BackgroundAppearance, and it can take either an Image or a fully qualified filename reference. However, it can't accept just any image. It accepts an image following the nine-patch convention defined by the Android SDK. I won't fully explain nine-patch here, but in brief, it's a very nice convention for customizing the scaling behavior of bitmaps which can be used to produce near-vector-quality resizable graphics from bitmap specifications. A nice tutorial describing the principles can be found here. For the purposes of notebook backgrounds, the "fill" specifications are ignored, but they must still be present in the image.

The most trivial form of a nine-patch image is one that scales the entire image. Such an image would have a fully black frame with white pixels in each of the corners. Here's a function which modifies an image to a nine-patch which scales the entire image:

ConvertImageToFullyScaledNinePatch[img_] :=
 Module[{paddedImage = ImagePad[img, 1, Black]},
  ReplaceImageValue[paddedImage,
   Flatten[
     Outer[List, {0, #1}, {0, #2}] & @@ ImageDimensions[paddedImage], 
     1] -> White]]

And here's an example of the function's usage:

NotebookPut[
 Notebook[{}, 
  System`BackgroundAppearance -> 
   ConvertImageToFullyScaledNinePatch[
    ExampleData[{"TestImage", "JellyBeans"}]]]]

Additionally, the front end only presently understands a limited subset of possible color spaces for the image, which may exclude, for example, images which are imported from some types of external files.

Some of the images used for slide shows have more customized scaling behaviors than the one I demonstrated here. Those images can be listed by the following command:

FileNames["*", {FileNameJoin[{$InstallationDirectory, "SystemFiles", 
    "FrontEnd", "SystemResources", "SlideShow"}]}]

I would expect that, in a future version of Mathematica, you may see a different option name, a much more flexible specification of possible right-hand side values, and first-class support for nine-patch bitmaps.

$\endgroup$
4
  • $\begingroup$ Great! This seems a good method to simulate a transparent background for notebooks! $\endgroup$
    – Silvia
    Dec 2, 2012 at 14:23
  • 1
    $\begingroup$ It seems to be unnecessary to transform the image in v9.0.1. Was that added in that update? $\endgroup$ Mar 13, 2013 at 13:30
  • $\begingroup$ This solution has stopped working in v11.1. John can you confirm this? $\endgroup$
    – M.R.
    Oct 24, 2016 at 22:03
  • $\begingroup$ @M.R., do you mean v11.0, or v11.0.1? What platform? Just tried on Mac, and the above code worked fine for me. $\endgroup$
    – John Fultz
    Oct 25, 2016 at 17:55

Your Answer

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

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