[NTG-context] Foonotes in Captions ... again
Max Chernoff
mseven at telus.net
Thu Jun 16 01:31:37 CEST 2022
> What's the current state of affairs regarding footnotes in floats? Both version in the example below don't quite work...
> (Ideally, the note should be on the page with the float and the caption, but the numbering should also be adjusted.)
We can completely abuse a bunch of different ConTeXt features to ensure
that the footnote numbers are always in the page order.
% New Code
\unprotect
\startluacode
userdata.visual_order = 0
userdata.input_order = 0
userdata.save_data = job.passes.define("saved_footnotes")
userdata.previous_data = job.passes.getcollected("saved_footnotes")
interfaces.implement {
name = "set_footnote_number",
actions = function ()
userdata.input_order = userdata.input_order + 1
local input_index = userdata.input_order
local page_index = userdata.previous_data[input_index]
if page_index then
structures.counters.set("footnote", 1, page_index - 1)
end
end
}
\stopluacode
\def\save_footnote_data#1{%
\latelua{
userdata.visual_order = userdata.visual_order + 1
userdata.save_data[#1] = userdata.visual_order
}%
}
\let\old_footnote=\footnote
\starttexdefinition protected footnote #1
\begingroup
\clf_set_footnote_number
\def\insert##1\bgroup##2\egroup{
\normalexpanded{
\noexpand\save_footnote_data
{\cldcontext{userdata.input_order}}
}
\normalinsert##1{##2}
}
\old_footnote{#1}
\endgroup
\stoptexdefinition
\protect
% Original Example
\starttext
\footnote{asdf} \footnote{asdf} \footnote{asdf}
\input ward
\startplacefigure[title={asdfasdf\footnote{test 1}}]
\externalfigure[cow.pdf]
\stopplacefigure
\footnote{asdf} \footnote{asdf} \footnote{asdf}
\startplacefigure[title={asdfasdf\footnote{test 2}}]
\externalfigure[cow.pdf][height=10cm]
\stopplacefigure
\footnote{asdf} \footnote{asdf} \footnote{asdf}
\page
\footnote{asdf} \footnote{asdf} \footnote{asdf}
\input ward
\startplacefigure[title={asdfasdf\footnote{test 1}}]
\externalfigure[cow.pdf]
\stopplacefigure
\footnote{asdf} \footnote{asdf} \footnote{asdf}
% (Can't use postponingnotes)
% \startpostponingnotes
\startplacefigure[title={asdfasdf\footnote{test 2}}]
\externalfigure[cow.pdf][height=10cm]
\stopplacefigure
% \stoppostponingnotes
\footnote{asdf} \footnote{asdf} \footnote{asdf}
\stoptext
Here, we save a mapping between each footnote's index in the input and
its index in the output to the .tuc file. The code is definitely not
pretty, but works well enough for the sample file provided.
-- Max
More information about the ntg-context
mailing list