Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
I remember looking for this once. There isn't an option for it. You can only change the background color. –  Searke Jun 18 '12 at 15:00
    
I don't see anything in the Option Inspector. I also don't think it can be done programatically. –  becko Jun 29 '12 at 1:48
4  
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. –  John Fultz Oct 25 '12 at 12:57

2 Answers 2

up vote 24 down vote accepted

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

share|improve this answer
    
In John's comment above he said this option is undocumented. Is that the case? Looks nice though. –  Mike Honeychurch Nov 30 '12 at 22:56
    
@MikeHoneychurch If it is documented it's hidden well. –  Sjoerd C. de Vries Nov 30 '12 at 23:10

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.

share|improve this answer
    
Great! This seems a good method to simulate a transparent background for notebooks! –  Silvia Dec 2 '12 at 14:23
    
It seems to be unnecessary to transform the image in v9.0.1. Was that added in that update? –  Sjoerd C. de Vries Mar 13 '13 at 13:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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