# Adjusting label text and counter for custom floats in ConTeXt?

I am currently working on a book project and have recently decided to switch to ConTeXt (coming from LaTeX). In my quest to re-code what I had already set up in LaTeX I am now stumbling over what I believe must be a simple switch that I'm missing. So, I'm hoping someone on this plattform can offer some help.

Here's a MWE of what I'm working on (the basis of this was discussed here):

\usemodule[visual]

\enableregime [utf-8]
\mainlanguage[de]
\language[de]
\definecolor[lightbrown] [r=0.83, g=0.76, b=0.71]

\setuppapersize[A4][A4]
\setuplayout
[
backspace=11.67mm,        width=131.25mm,
topspace=21.21mm,         height=254.57mm,
footerdistance=13pt,      footer=13pt,
rightmargindistance=13pt, rightmargin=39.5mm,
]

\setuppagenumbering[alternative=doublesided, location=]
\definemeasure[fullwidth][\dimexpr\textwidth+\outermarginwidth+\outermargindistance\relax]

\definefloat[widefloat][widefloats]
\setupfloat[widefloat][
location=inner,
width=\measure{fullwidth},
default={here, top},
]

\setupcaption[widefloat][
width=max,
location=bottom,
style=\tf\it,
align=flushleft,
spaceafter=\lineheight,
]

\definefloat[sidefloat][sidefloats]
\setupfloat[sidefloat][
width=\outermarginwidth,
default=outermargin,
]

\setupcaption[sidefloat][
width=max,
location=bottom,
style=\tf\it,
align=flushleft,
]

\def\WideFigure#1#2%
{\placewidefloat[here, top]{#2}{\framed[width=\measure{fullwidth}, background=color, backgroundcolor=lightbrown]{#1}}}

\def\SideFigure#1#2%
{\placesidefloat[outermargin]{#2}{\framed[width=\outermarginwidth, background=color, backgroundcolor=lightbrown]{#1}}}

\starttext

\chapter{\fakewords{2}{3}}

\fakewords{50}{60}

\fakewords{50}{60}

\WideFigure{This is a wide (external) figure.}{And this is its caption.}

\fakewords{50}{60}

\fakewords{50}{60}

\SideFigure{Side figure.}{And its caption.}

\fakewords{50}{60}

\fakewords{50}{60}

\stoptext


As you can see, I set up two different kinds of floats: widefloat (and the associated definition WideFigure) is intended for (external) figures in landscape format and will span both the textarea and the outer margin area. sidefloat (and SideFigure, respectively), on the other hand, represents a tiny figure that will be positioned in the outer margin. This works reasonably well and looks roughly like this:

However, this solution still has two problems: First, the two kinds of floats now have two separate counters so that there are now two different figures with the same number. Is there a way to make the two floats use the same counter? Or, better yet: Can I make all custom floats that contain external figures use the same counter as the original float?

The second problem is the fact that my custom floats are now labeled with their internal name. I would like to change the labels of "Widefloat" and "Sidefloat" to simply read "Figure". Is this possible?

Any help would be much appreciated.

You are just missing one parameter in your setup that will take care of both the problems. \definefloat takes a third optional argument that sets the parent of the float. If you set the parent to be figure, then the label and counter will be taken from figure. So all you need is:

\definefloat[widefloat][widefloats][figure]
\definefloat[sidefloat][sidefloats][figure]


Here is a complete example (note that I deleted \enableregime[utf-8] because it is not needed in MkIV.

\usemodule[visual]

\mainlanguage[de]
\language[de]
\definecolor[lightbrown] [r=0.83, g=0.76, b=0.71]

\setuppapersize[A4][A4]
\setuplayout
[
backspace=11.67mm,        width=131.25mm,
topspace=21.21mm,         height=254.57mm,
footerdistance=13pt,      footer=13pt,
rightmargindistance=13pt, rightmargin=39.5mm,
]

\setuppagenumbering[alternative=doublesided, location=]

\definemeasure[fullwidth][\dimexpr\textwidth+\outermarginwidth+\outermargindistance\relax]

\definefloat[widefloat][widefloats][figure]
\setupfloat[widefloat]
[
location=inner,
width=\measure{fullwidth},
default={here, top},
]

\setupcaption[widefloat]
[
width=max,
location=bottom,
style=\tf\it,
align=flushleft,
spaceafter=\lineheight,
]

\definefloat[sidefloat][sidefloats][figure]
\setupfloat[sidefloat]
[
width=\outermarginwidth,
default=outermargin,
]

\setupcaption[sidefloat]
[
width=max,
location=bottom,
style=\tf\it,
align=flushleft,
]

\def\WideFigure#1#2%
{\placewidefloat[here, top]{#2}{\framed[width=\measure{fullwidth}, background=color, backgroundcolor=lightbrown]{#1}}}

\def\SideFigure#1#2%
{\placesidefloat[outermargin]{#2}{\framed[width=\outermarginwidth, background=color, backgroundcolor=lightbrown]{#1}}}

\starttext

\chapter{\fakewords{2}{3}}

\fakewords{50}{60}

\fakewords{50}{60}

\WideFigure{This is a wide (external) figure.}{And this is its caption.}

\fakewords{50}{60}

\fakewords{50}{60}

\SideFigure{Side figure.}{And its caption.}

\fakewords{50}{60}

\fakewords{50}{60}

\stoptext


which gives

Note that since you had set \mainlanguage[de], the labeltext for figure (Abbildung) is German.

• thank you very much, that's exactly what I was hoping for. Much appreciated. Do you, by any chance, know any place where I can find such "hidden" information without checking the source code itself? The reference manual doesn't mention that third parameter at all (section 15.2) and on ConTeXt Garden the parameter is mentioned, but not explained. – Marcus C. Oct 16 '16 at 8:16