ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Draft version of document
Date: Tue, 07 Aug 2012 16:41:41 +0200	[thread overview]
Message-ID: <50212925.3050900@wxs.nl> (raw)
In-Reply-To: <CAF=dkzxa88YnERqyMD_8z=MmgXiE2=9=K9nBQMQ8WN=L1_1PBA@mail.gmail.com>

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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


  parent reply	other threads:[~2012-08-07 14:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-04 11:18 Roger Mason
2012-08-06 16:14 ` Sietse Brouwer
2012-08-07  9:19   ` Roger Mason
2012-08-07 12:51   ` Sietse Brouwer
2012-08-07 14:37     ` Hans Hagen
2012-08-07 14:41     ` Hans Hagen [this message]
2012-08-08 15:04       ` Sietse Brouwer
2012-08-08 17:48         ` Wolfgang Schuster
2012-08-08 21:36           ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50212925.3050900@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).