Hello all, Having used MkII to make a nicely formatted version of a document, I now need to make a draft version document in order to submit it to a journal. They want the figure captions as a list at the end of the document and the figures collected on pages at the end too. The draft version will need to be double spaced. Obviously, I'd rather use the existing source to generate both draft and well-formatted versions, so it sounds like a job for modes. Before I start hacking, has someone done this already or is ther an alternative method of accomplishing this? Thanks, Roger This electronic communication is governed by the terms and conditions at http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2012.php
Hi Roger, Firstly: drafts are indeed the way to go. \completelistoffigures places a complete list of figure *captions*, so that takes care of that. % No need to define a mode: you can simply enable it with % \enablemode[draft] % or % context --mode=draft \enablemode[draft] \startmode[draft] \completelistoffigures \stopmode Figure images, unlike figure captions, are not saved to a list. A pity, as this makes it difficult to get the associated figure image given a figure number (or figure label). I would do this: (1) make it so you can call the figure image with \externalfigure[img:fig:mylabel]. Use \useexternalfigure for this. (2) then label the figure with [fig:mylabel] (3) then simply manually make an entry in the figures section for each figure label. Perhaps some ConTeXt user more familiar with lists can provide a better, list-based, solution? \useexternalfigure[img:fig:pointy graph][pointy-graph.png] \placefigure [here] [fig:pointy graph] {caption of the pointy graph} {\externalfigure[img:fig:pointy graph][width=4cm]} \startmode[draft] \section{Just the figures} \in{Figure}[fig:pointy graph] \externalfigure[img:fig:pointy graph] \stopmode If you want to automate this, you'll want something like this. Untested and probably needs debugging first, but the table names are correct: \startluacode -- we won't need the keys k, but still. for k,v in pairs(structures.lists.ordered.float.figure) do label_string = v.references.reference -- `..` is Lua for string concatenation image_string = "img" .. label_string -- arguments to TeX commands: -- get [stuff] in TeX with { 'stuff' } in Lua -- get [stuff=bother] in TeX with { stuff = 'bother' } in Lua -- get {stuff} in TeX with 'stuff' in Lua context.in("Figure", { label_string }) context.externalfigure( { image_string } ) end \stopluacode I have made this reply long because I lack the time to make it short. Cheers, Sietse
Hello Sietse, On 08/06/12 13:44, Sietse Brouwer wrote:
Hi Roger,
Firstly: drafts are indeed the way to go. \completelistoffigures places a complete list of figure *captions*, so that takes care of that.
I have made this reply long because I lack the time to make it short.
Cheers, Sietse
Many thanks for your thorough reply. I will try it out over the next few days. Best wishes, Roger (who is glad you did not have the time to make it shorter, if you see what I mean :-) ) This electronic communication is governed by the terms and conditions at http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2012.php
Hi Robert, Debugged and all, here you go. Cheers, Sietse \useexternalfigure[img:fig:cow][cow.pdf] \useexternalfigure[img:fig:mill][mill.png] \starttext \section{Pictures} % The externalfigure names HAVE TO take the form 'img:FIGURELABEL', % or the automatic image list at the end on won't be able to % guess the image names from the figure labels. \placefigure[here][fig:cow] {cap-cow} {\externalfigure[img:fig:cow]} \section{More pictures} \placefigure[here][fig:mill] {cap-mill} {\externalfigure[img:fig:mill]} %%%% Lists start here %%%%%%% \enablemode[draft] \startmode[draft] % Better list heading --- the captions are what matters \setupheadtext[figures=List of Captions] \completelistoffigures % Now for printing all the images \section{List of Pictures} \startluacode -- we won't need the keys k, but still. for k,v in pairs(structures.lists.ordered.float.figure) do label_string = v.references.reference -- `..` is Lua for string concatenation image_string = "img:" .. label_string -- TeX <--> Lua, passing arguments to commands -- [stuff] <--> { 'stuff' } -- [stuff=bother] <--> { stuff = 'bother' } -- {stuff} <--> 'stuff' -- context.in() seems to have some Lua meaning -- so we print the command string directly, instead context("\\in{Figure}[" .. label_string .. "]") context.page( { 'no' } ) context.externalfigure( { image_string }, { 'here' } ) context.hairline() context.par() -- end paragraph end \stopluacode \stopmode \stoptext
On 7-8-2012 14:51, Sietse Brouwer wrote:
Hi Robert, Debugged and all, here you go. Cheers, Sietse
\useexternalfigure[img:fig:cow][cow.pdf] \useexternalfigure[img:fig:mill][mill.png]
\starttext
\section{Pictures} % The externalfigure names HAVE TO take the form 'img:FIGURELABEL', % or the automatic image list at the end on won't be able to % guess the image names from the figure labels. \placefigure[here][fig:cow] {cap-cow} {\externalfigure[img:fig:cow]}
\section{More pictures} \placefigure[here][fig:mill] {cap-mill} {\externalfigure[img:fig:mill]}
%%%% Lists start here %%%%%%% \enablemode[draft] \startmode[draft]
% Better list heading --- the captions are what matters \setupheadtext[figures=List of Captions] \completelistoffigures
% Now for printing all the images \section{List of Pictures} \startluacode -- we won't need the keys k, but still. for k,v in pairs(structures.lists.ordered.float.figure) do label_string = v.references.reference -- `..` is Lua for string concatenation image_string = "img:" .. label_string
-- TeX <--> Lua, passing arguments to commands -- [stuff] <--> { 'stuff' } -- [stuff=bother] <--> { stuff = 'bother' } -- {stuff} <--> 'stuff'
-- context.in() seems to have some Lua meaning -- so we print the command string directly, instead context("\\in{Figure}[" .. label_string .. "]") context.page( { 'no' } ) context.externalfigure( { image_string }, { 'here' } ) context.hairline() context.par() -- end paragraph end \stopluacode \stopmode
\stoptext
\starttext \placefigure{}{\externalfigure[mill]} \placefigure{}{\externalfigure[cow]} \page \startluacode context.bTABLE { spit = "yes", offset = "1ex" } for k, v in next, figures.found do inspect(v) context.bTR() context.bTD { width = "4cm", align = "middle" } context.dontleavehmode() context.externalfigure( { v.foundname }, { height = "2cm" } ) context.eTD() context.bTD() context(v.askedname) context.eTD() context.bTD() context(file.basename(v.foundname)) context.eTD() context.eTR() end context.eTABLE() \stopluacode \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 7-8-2012 14:51, Sietse Brouwer wrote:
Hi Robert, Debugged and all, here you go. Cheers, Sietse
\useexternalfigure[img:fig:cow][cow.pdf] \useexternalfigure[img:fig:mill][mill.png]
\starttext
Actually, this is something that should be doable with user data weren't it that for floats that's not yet available. So I've added it to the core (will be in next upload) ... % macros=mkvi \unprotect % let's pick up two arguments \unexpanded\def\strc_floats_start_place#tag% {\flushnotes \page_otr_command_flush_side_floats % here ! \strc_floats_begin_group \strc_floats_set_current_tag{#tag}% \dodoubleempty\strc_floats_start_place_indeed} % and store the user data for a while \def\strc_floats_start_place_indeed[#settings][#userdata]% {\strc_floats_reset_variables \edef\savedfloatlocation{\floatcaptionparameter\c!location}% \setupcurrentfloatcaption[\c!location=,\c!reference=,\c!title=,\c!marking=,\c!list=,\c!bookmark=,#settings]% \def\savedfloatuserdata{#2}% \edef\floatlocation{\floatcaptionparameter\c!location}% \setupcurrentfloatcaption[\c!location=\savedfloatlocation]% \ifx\floatlocation\empty \edef\floatlocation{\floatparameter\c!default}% \fi \doifinsetelse\v!split\floatlocation\strc_floats_place_next_box_split\strc_floats_place_next_box_normal \bgroup \ignorespaces} % here we need to expand it one level (else detokenize will spoil it) \def\strc_floats_place_packaged_boxes {\expandafter\strc_floats_place_packaged_boxes_indeed\expandafter{\savedfloatuserdata}} \def\strc_floats_place_packaged_boxes_indeed#userdata% {\bgroup \ifconditional\usesamefloatnumber \globallet\currentfloatnumber \previousfloatnumber \globallet\currentfloatattribute \empty \globallet\currentfloatsynchronize\relax \else \ifnofloatnumber \else \ifnofloatcaption \else \strc_counters_increment{\strc_counters_the\currentfloat}% \fi \fi \strc_counters_register_component {float}% \setupcurrentfloatcaption \floatcaptionparameter \detokenizedfloatcaptionparameter \relax \relax \relax [\c!name=\currentfloat,% \s!counter=\strc_counters_the\currentfloat,% \s!hascaption=\ifnofloatcaption \v!no\else\v!yes\fi,% \s!hasnumber=\ifnofloatnumber \v!no\else\v!yes\fi,% \s!hastitle=\ifemptyfloatcaption\v!no\else\v!yes\fi]% [#userdata]% \globallet\previousfloatnumber \m_strc_counters_last_registered_index \globallet\currentfloatnumber \m_strc_counters_last_registered_index \globallet\currentfloatattribute \m_strc_counters_last_registered_attribute \globallet\currentfloatsynchronize\m_strc_counters_last_registered_synchronize \fi % \global\setfalse\usesamefloatnumber % one shot % check float box \strc_floats_set_natural_dimensions\nextbox \global\setbox\floatbox\vbox{\floatparameter\c!command{\box\nextbox}}% \strc_floats_set_natural_dimensions\floatbox \ifdim\htdp\floatbox=\zeropoint \showmessage\m!floatblocks{11}\empty \global\setbox\floatbox\vbox {\dostarttagged\t!floatcontent\empty \strc_floats_place_empty_box \dostoptagged}% \fi % deal with lack of caption \global\setbox\floatbox\vbox \floatcaptionattribute {\doifelsemainfloatbody\currentfloatsynchronize\donothing \unvbox\floatbox \ifnofloatcaption \vss \fi}% gets rid of the depth (unless tabulate) \egroup % place the float \strc_floats_set_box \strc_floats_get_box \global\insidefloatfalse} % we need a raw untagged and expandable fetch: \def\rawstructurelistuservariable#name% {\ctxcommand{listuserdata("\currentlist",\currentlistindex,"#name")}} \protect % so, after some 5 lines patching we can do: \starttext \startplacefigure[reference=fig:mill,title={A Mill}][resource=mill] \externalfigure[mill] \stopplacefigure \startplacefigure[reference=fig:cow,title={A Cow}][resource=cow] \externalfigure[cow] \stopplacefigure \page \unexpanded\def\FigureListEntry#1#2#3% {\dontleavehmode \tbox{\hbox to 2cm{\externalfigure[\rawstructurelistuservariable{resource}][height=1cm]\hss}}% \hbox to 2em{#1\hss}% #2\hfill \hbox to 2em{\hss#3}% \blank} \setuplist[figure][alternative=command,command=\FigureListEntry] \placelist[figure] \stoptext Of course, the 'command' is not that nice looking but that's for others to improve. (In a similar fashion one can associate a resource or whatever to a section head and use it in a toc.) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
@Roger: I just realised I called you Robert. Sorry about that, moment of inattention. Hi Hans,
Actually, this is something that should be doable with user data weren't it that for floats that's not yet available. So I've added it to the core (will be in next upload) ...
Ah, nifty; and fantastically quick, as always. I've not heard of ConTeXt's "user data" feature before. Where can I find more on that? Is there a list e-mail I should search for? I'm trying to work out how to describe the new feature, so I can add that to the documentation. I think I see two features, but I'm not sure. Can you tell me if the below is correct? New feature 1: previously we could only do \startplacefigure[reference=fig:mill, title={A Mill}] or \startsection[reference=sec:sheep, title={The Sheep}] but now we can do \startplacefigure[reference=fig:mill, title={A Mill}][resource=mill] or \startsection[reference=sec:sheep, title={The Sheep}][mykey=myvalue] Nothing is done with the parameters in the second key=value list, but they are stored as part of the object when the object is written to its figures/sections/whatever list; and there they can be used in constructing the Table of figures/contents/whatever. -------- New feature 2: the command \rawstructurelistuservariable{#1} . This command can be used by custom list entry macros like \mylistentrymacro below: \setuplist[somelist][alternative=command, command=\mylistentrymacro] The command gets a property from the current list entry object, like so: \rawstructurelistuservariable{resource} %--> mill Question: does this work, too, or can we only access values in the *second* key=value list? \rawstructurelistuservariable{reference} %--> fig:mill Cheers, Sietse
Am 08.08.2012 um 17:04 schrieb Sietse Brouwer
I'm trying to work out how to describe the new feature, so I can add that to the documentation. I think I see two features, but I'm not sure. Can you tell me if the below is correct?
New feature 1: previously we could only do \startplacefigure[reference=fig:mill, title={A Mill}] or \startsection[reference=sec:sheep, title={The Sheep}]
but now we can do \startplacefigure[reference=fig:mill, title={A Mill}][resource=mill] or \startsection[reference=sec:sheep, title={The Sheep}][mykey=myvalue]
Nothing is done with the parameters in the second key=value list, but they are stored as part of the object when the object is written to its figures/sections/whatever list; and there they can be used in constructing the Table of figures/contents/whatever.
Yes, the user variables are only stored in the utility file and can be used when you print the list entries.
New feature 2: the command \rawstructurelistuservariable{#1} . This command can be used by custom list entry macros like \mylistentrymacro below: \setuplist[somelist][alternative=command, command=\mylistentrymacro]
The command gets a property from the current list entry object, like so: \rawstructurelistuservariable{resource} %--> mill
Question: does this work, too, or can we only access values in the *second* key=value list? \rawstructurelistuservariable{reference} %--> fig:mill
The arguments you give with the first argument are processed by context before they are written to the utility file and only three values can be used when you create your own list layout, the user variables on the other side are written to the utility file without any modification and whatever you write here can be used in the list. Wolfgang
On 8-8-2012 19:48, Wolfgang Schuster wrote:
The arguments you give with the first argument are processed by context before they are written to the utility file and only three values can be used when you create your own list layout, the user variables on the other side are written to the utility file without any modification and whatever you write here can be used in the list.
Here is a few lines extension that provides access (will be in next beta): % macros=mkvi \unprotect \installcorenamespace{floatuserdata} \installsetuponlycommandhandler \??floatuserdata {floatuserdata} \def\strc_floats_start_place_indeed[#settings][#userdata]% {\strc_floats_reset_variables \edef\savedfloatlocation{\floatcaptionparameter\c!location}% \setupcurrentfloatcaption[\c!location=,\c!reference=,\c!title=,\c!marking=,\c!list=,\c!bookmark=,#settings]% \def\savedfloatuserdata{#2}% \edef\floatlocation{\floatcaptionparameter\c!location}% \setupcurrentfloatcaption[\c!location=\savedfloatlocation]% \ifx\floatlocation\empty \edef\floatlocation{\floatparameter\c!default}% \fi \ifsecondargument \setupcurrentfloatuserdata[#userdata]% \fi \doifinsetelse\v!split\floatlocation\strc_floats_place_next_box_split\strc_floats_place_next_box_normal \bgroup \ignorespaces} \protect \starttext \startplacefigure[title=oeps][subtitle=whatever] \framed[width=10cm,height=5cm]{\floatuserdataparameter{subtitle}} \stopplacefigure \stoptext (a few more mechanisms will get a \*userdataparameter .. no time for that now) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (4)
-
Hans Hagen
-
Roger Mason
-
Sietse Brouwer
-
Wolfgang Schuster