This is a follow-up question to a previous ConTeXt solution. That solution dealt with wrapped figures in a ConTeXt document generated from Pandoc Markdown.

without short caption

Now, I would like to extend that solution to allow for a short caption below a wrapped figure. Moreover, I would like to have the short caption typeset differently, say small-sized bold sans-serif.

Below is a minimal working example that shows how the layout of the original solution gets messed up when adding the short caption text. What do I need to change to the description definition to allow for short captions under wrapped figures?

\setuptolerance[horizontal, tolerant, stretch]

\setuppapersize [A4][A4]
\setuplayout    [width=middle,  backspace=1.5in, cutspace=1.5in,
                 height=middle, topspace=0.75in, bottomspace=0.75in]


% Inter-paragraph spacing

% Break at hyphens


% Remaining code is for descriptions with a left floating figure
% https://tex.stackexchange.com/a/133372/26348

\startsetups placefigure

% Floats do not have "before=" nor a setup key
\appendtoks \setups{placefigure} \to \everyinsidefloat




\input douglas.tex

\startdescription{{\externalfigure[cow]}Short caption}
  \input linden.tex

\input bryson.tex

with short caption

  • After a while, it is easier to use XML or TEX as the input format rather than markdown. Markdown just does not have enough configuration options.
    – Aditya
    Nov 13, 2013 at 1:33
  • Hi Aditya. Nope, sorry to say that \hbox{\box\scratchbox} does not work. As for MarkDown, it really is the best way to get easily maintainable output in both HTML and PDF. See for yourself. Nov 13, 2013 at 2:12
  • 1
    If you are only targeting HTML output (no epub or docbook), you could also give a short to ConTeXt's XML export (which works with most modern browsers).
    – Aditya
    Nov 13, 2013 at 4:10
  • To give a concrete example this tex file generates this html and other css files that are included in the gist.
    – Aditya
    Nov 13, 2013 at 4:40

2 Answers 2


The standard way to place a caption on a wrapped figure is as follows:


      title={A short caption}, 
      location={left, nonumber},

\input knuth


which gives:


If you want to use this in an automated way with Pandoc, one option is to redefine the \startdescription macro as follows:


   \startplacefigure[location={left,high,nonumber}, style=\ss\bfxx\setupinterlinespace, title={#2}]


which works correctly with the example posted in the question.

However, I am not convinced that this is the right approach to this problem. Personally, I find it easier to preprocess the markdown input. See this blog post for my views.

  • I edited your great answer to include the caption styling and updated the image accordingly. Nov 13, 2013 at 20:34
  • I have a quite long comment concerning spacing below the image. The comment would not fit here. Please, see my tentative answer below. Nov 13, 2013 at 21:33

The accepted answer can be still improved upon

The height of the wrapped text is off by one line, or stated differently, the space below the image is too big. This happens independently of whether a caption is present or not. Here is an even more dramatic example made using the same code:

extra linebreak

I think, I also found a reason why, over at ConTeXtGarden:

Images at the beginning of a paragraph

Using \externalfigure[...] at the beginning of a paragraph results in a line break after the image. This is because \externalfigure is a \vbox. > When a \vbox is encountered at (what appears to be) the beginning of a paragraph, vertical mode is maintained. To prevent this, add \dontleavehmode before \externalfigure, like this:

\externalfigure[...] ... first line ...

The problem now is that —despite many desperate attempts— I am not succeeding at integrating this \dontleavehmode in the code of the accepted answer.

Edit: Improved solution with reduced spacing under the caption

The code referred to in Aditya's comment below, correctly reduces the white space under wrapped figure captions. Here is the result for the original example:

improved solution

  • 1
    Add the following code to your preamble. ConTeXt adds structht to the height of the side float while determining the number of lines to hang. This works well under the assumption that the captions are typeset in the same size as the main content. If captions are typeset in a smaller font, then the structht is not needed.
    – Aditya
    Nov 14, 2013 at 0:37
  • Your code performs wonderfully! With all we have learned here, you should really start to consider wrapping things up and contributing this code to the ConTeXt developers as a new description environment. The only issue which remains is the unfortunate page breaking between section titles and this description environment. I will create a last question out of this and point the other developers in the newsgroup to it. Stay put! Nov 14, 2013 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .