The title pretty much says it...

I would like to retrieve the caption of a figure I placed earlier in the document.

\placefigure[][fig:foo]{My caption}{\externalfigure[foo.png]}

\input knuth

\getcaption{fig:foo} %Output: My caption
  • Ups, thought it would be easier and the caption stored in some sort of data structure. In that case I'm way out of my depth
    – Christoph
    Oct 30 '18 at 8:25
  • Is it possible to code this in lua?
    – Christoph
    Oct 30 '18 at 8:27
  • @Christoph The reference for a float goes into the second optional argument and not the first like you have it in your example. Even when you don’t have a placement option you need the first optional argument when you add a reference, e.g. \placefigure[][fig:foo]{...}{...}. Oct 30 '18 at 16:53
  • @WolfgangSchuster Thank you, I just corrected it
    – Christoph
    Oct 30 '18 at 16:57
  • @Christoph: You can also use \startplacefigure[reference=fig:foo, location=..., title=....] \externalfigure[...] \stopplacefigure
    – Aditya
    Oct 31 '18 at 4:35

You can show the text of a float title or a section header with the \about command. Another way is to use the \getreference command with the title keyword.

To remove the quotation marks from the \about command change the values of the left and right keys of the \setupreferencing command.


% \setupreferencing[left=,right=]


\placefigure[][fig:foo]{My caption}{\externalfigure[foo.png]}


\NC \tex{about}        \EQ \about[fig:foo]               \NC\NR
\NC \tex{getreference} \EQ \getreference[title][fig:foo] \NC\NR


enter image description here

  • Thanks for the answer. I saw those macros in the Wiki when I looked for my answer, but couldn't use it properly. I found definedataset only later on.
    – sztruks
    Oct 30 '18 at 17:38

Digging into ConTeXt wiki helped me found an answer using datasets

%create a data set with figure captions

%macro that will place figure and store its caption data
    %title is store in Captions data set under the figure label key
   %call for dataset with the figure label
\Myfigure{fig:foo}{a retrievable caption}{\externalfigure[cow]}

\input knuth

\bf \Getcaption{fig:foo}

compilation output

  • Thank you. Exactly what I needed. And much more beautiful than Lua ;-)
    – Christoph
    Oct 30 '18 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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