Images for documentation examples

ConTeXt users tend to use the famous Dutch cow as a place holder image for documentation examples. At times, it gets annoying. One alternative is to use random figures:


    {\externalfigure[whatever][width=0.5\textwidth, height=0.3\textheight]}
  \input knuth

which gives an image as shown below:

The image is draws random circles with random colors using metapost.

In a recent discussion on, Sharpie mentioned a website:, that provides pictures of kittens as placeholders for images. Those kittens are definitely cuter than the Dutch cow. Using these kittens as placeholder images is easy: if you want a 300pt x 400pt images, just type:


ConTeXt takes care of downloading and caching the image. However, to use this approach, you need to know the required image dimensions in postscript points. Many a times, the image dimensions are known in relative terms like the above example where we asked for an image that is 0.5\textwidth wide and 0.3\textheight high. To convert a arbitrary TeX dimention to points, we can use \dimexpr which reports its result in points. So, to know how much is 0.5\textwidth we can use


For the default setup, this reports 213.3937pt. To use this dimension with place kitten website, we need to get rid of the pt suffix—a freqeuntly needed feature for which ConTeXt, like almost all other macro packages, provides a built-in macro: \withoutpt. Thus, we can use


to get the value of 0.5\textwidth without the pt suffix. However, this is not enough: the place kitten website does not provide images with fractional sizes. So, we need to round (or truncate) the value to a whole number. I don’t know if ConTeXt has a built-in macro for that; neither do I care enough to write such a macro in TeX. Truncating a float to an integer is easy in Lua, and that is what I will use. Combining all this, here is a macro that places an image of a kitten that is of a particular size:

    {\getparameters[kitten][width=10pt, height=10pt, #1]
        [#1, method=jpg]}

This can be used as:

    {\externalkitten[width=0.5\textwidth, height=0.3\textheight]}
  \input knuth

which gives the following result:

I think that this looks much nicer than the random image above. Below is an example that uses the place kitten images to show how the location key works.

  {\externalkitten[width=0.2\textwidth, height=0.15\textheight, location=top]}{}
  {\externalkitten[width=0.2\textwidth, height=0.20\textheight, location=top]}{}
  {\externalkitten[width=0.2\textwidth, height=0.25\textheight, location=top]}{}
  {\externalkitten[width=0.2\textwidth, height=0.15\textheight, location=middle]}{}
  {\externalkitten[width=0.2\textwidth, height=0.20\textheight, location=middle]}{}
  {\externalkitten[width=0.2\textwidth, height=0.25\textheight, location=middle]}{}
  {\externalkitten[width=0.2\textwidth, height=0.15\textheight, location=bottom]}{}
  {\externalkitten[width=0.2\textwidth, height=0.20\textheight, location=bottom]}{}
  {\externalkitten[width=0.2\textwidth, height=0.25\textheight, location=bottom]}{}

Note that all three images are of different sizes. The first row is top aligned, the second row is middle aligned, and the third row is bottom aligned. Now imagine how this would have looked if all three images were scaled cows!

2 thoughts on “Images for documentation examples

  1. Pingback: Context: Placing float (figure) and text-top at same height | Q&A System

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s