# Avoid line break after macro

The following example produces a line break after the second text.

``````\define[2]\smallfigure{\placefigure[margin][#1]{#2}{!}}%

\starttext
text text\smallfigure{fig1}{A}text text
\stoptext
``````

The ConTeXt FAQ addresses this explicitly. However, although the problem seems identical, changing the macro to

``````\define[2]\smallfigure{\dontleavehmode\placefigure[margin][#1]{#2}{!}}%
``````

does not work as intended and avoiding the macro altogether

``````\starttext
text text\dontleavehmode\placefigure[margin][]{A}{!}text text
\stoptext
``````

does not work either. Is there a way to avoid the line break?

-
How about inserting the figure at the beginning of the paragraph? –  Marco May 18 '12 at 13:32
I would normally do that. In this case I prepare documents with different layouts, but the same content. Then it is advantagous to put the figure exactly where it is also mentioned in the text the first time. Otherwise, I would have to tweak every document by itself. It would be great, if that is possible. –  Andy May 18 '12 at 14:34
–  clemens May 18 '12 at 15:11
This is a known property of floats and crops up on the mailing list every now and then. If it’s a problem for you, then you might be able to bypass it using the postponing mechanism. In some cases where you don’t need a caption, the hangaround environment may lead to acceptable results too. –  phg May 18 '12 at 19:02
@phg Could you make your comment an answer? –  Joseph Wright Aug 6 '12 at 20:52

Move the `placefigure` call

One solution would be to place the figure at the beginning of the paragraph. This keeps the text together.

``````\starttext

\startplacefigure [title=Caption,location=margin]
\externalfigure [dummy]
\stopplacefigure
text text
text text

\stoptext
``````

Use the postponing mechanism

The postponing mechanism keeps the text together. However, it influences the float placement. The float appears on the page after the text, which might be undesirable.

``````text text
\startpostponing [+1]
\startplacefigure [title=Caption,location=margin]
\externalfigure [dummy]
\stopplacefigure
\stoppostponing
text text
``````
-