Re: [NTG-context] Referring to multiple elements

2012-09-28 Thread Marco Patzer
2012-09-28 Sietse Brouwer sbbrou...@gmail.com:

Hi Sietse,

  \in{figure}[alpha,beta,gamma]
 
  This outputs “figure 1”. What I'd like to have is “figure 1-3”.
 
 The attached quasi-module seems to do it! On my computer, at least. (I
 call it 'quasi' because it is really nothing more than code in a file
 of its own.No configurability whatsoever, except to the extent that I
 tried to comment well, and split things up into functions.) I'd have
 written it so that it properly identifies runs like '1.2.1, 1.2.2,
 1.2.3', too, but I can't find a function that will turn reference
 strings into such a prefixed strings.
 
 I hope it does what you want! Let me know if you want/need any
 alterations, or discover bugs.

Thanks a lot for that. I'd adjust the interface, so that it matches
the behaviour of \in:

\def\inrange
  {\dodoublegroupempty\doinrange}

\def\doinrange#left#right#dummy[#label]
  {\iffirstargument
 {#left }%%
   \fi
   \ctxlua{userdata.inwithranges(#label)}%%
   \ifsecondargument
 {#right}%%
   \fi}

Then you can write:

See \inrange{figures} [fig:a,fig:c,fig:d,fig:e,fig:g,fig:x,fig:h]
See \inrange{figures}{TT} [fig:a,fig:c,fig:d,fig:e,fig:g,fig:x,fig:h]
See \inrange  [fig:a,fig:c,fig:d,fig:e,fig:g,fig:x,fig:h]

Maybe worth mentioning: You need the additional module
`showtable.lua` from http://article.gmane.org/gmane.comp.tex.context/78336


Marco

___
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
___

Re: [NTG-context] Referring to multiple elements

2012-09-28 Thread Sietse Brouwer
Hi Marco,

Marco wrote:
 Maybe worth mentioning: You need the additional module
 `showtable.lua` from http://article.gmane.org/gmane.comp.tex.context/78336

Oops, that was a debugging statement. Removed.

 Thanks a lot for that. I'd adjust the interface, so that it matches
 the behaviour of \in:

 See \inrange{figures} [fig:a,fig:c,fig:d,fig:e,fig:g,fig:x,fig:h]
 See \inrange{figures}{TT} [fig:a,fig:c,fig:d,fig:e,fig:g,fig:x,fig:h]
 See \inrange  [fig:a,fig:c,fig:d,fig:e,fig:g,fig:x,fig:h]

Done. New version uploaded to Github:
https://github.com/sietse/context-inrange

Cheers,
Sietse
___
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
___


Re: [NTG-context] Referring to multiple elements

2012-09-27 Thread Sietse Brouwer
Hi Marco,
(PS for Hans),

Marco wrote:
 \in{figure}[alpha,beta,gamma]

 This outputs “figure 1”. What I'd like to have is “figure 1-3”.

The attached quasi-module seems to do it! On my computer, at least. (I
call it 'quasi' because it is really nothing more than code in a file
of its own. No configurability whatsoever, except to the extent that I
tried to comment well, and split things up into functions.) I'd have
written it so that it properly identifies runs like '1.2.1, 1.2.2,
1.2.3', too, but I can't find a function that will turn reference
strings into such a prefixed strings.

I hope it does what you want! Let me know if you want/need any
alterations, or discover bugs.
Sietse

PS @Hans: if figure numbers have prefix segments, is there any
(combination of) helper function that will return e.g. the string
'1.2.3' given the reference string ref:fig-three? I found
commands.savedlistprefixednumber(nil, numberinlist), but that is a
wrapper around sections.typesetnumber; and that last function injects
the string into the TeX stream instead of returning it. Is there
another function I haven't found yet that will do this, or are
prefixes implemented print-only at the moment?


inwithranges.mkiv
Description: Binary data


inwithranges.lua
Description: Binary data


test-inwithranges.tex
Description: TeX document


test-inwithranges.pdf
Description: Adobe PDF document
___
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
___

Re: [NTG-context] Referring to multiple elements

2012-09-16 Thread Marco Patzer
2012-09-14 Sietse Brouwer sbbrou...@gmail.com:

Hi Sietse,

I'm sorry for my late reply.

 The heart of what you need is a lua function that will take an array
 of numbers, and return an array of consective-number runs, like so:

 […]

 I've written one below, plus the scaffolding required to feed it the
 right input, and print its output to ConTeXt.

I wonder if this function is not already present in ConTeXt. The
register mechanism, for instance, already does something very
similar:

\setupregister
  [index]
  [compress=yes]

\starttext

A\index{A} \page
A\index{A} \page
aaa\page
bbb\page
A\index{A} \page
A\index{A} \page
A\index{A}

\placeindex %% = A 1-2, 5-7

\stoptext

 Only two functions still need writing --- one to turn the context
 argument [fig:f1, fig:f2, fig:f4] into a lua array of strings, and
 one to turn each reference string into a figure number.

I'm quite sure that all the building blocks are already present. I'm
not sure about the case when the float number is preceded by a
chapter number.

 If you're not comfortable with programming LuaTeX, say so and I can
 fill in the two missing functions sometime this weekend. But they
 should be doable, really.

Someone with more expertise and knowledge about the ConTeXt
internals should be able to point to the relevant functions. I guess
the code that produces the index compression is located in
registers.flush() in strc-reg.lua, but apparently it's not a
function and I don't know if it can be adopted for the float
referencing.

 (And, of course, you may be far more experienced in LuaTeX than I,
 I don't know.)

Probably not. I can read and write simple Lua scripts, but I lack
knowledge about the LuaTeX and ConTeXt internals and the data
structures used. For LuaTeX there is a manual that explains a lot,
but it doesn't help figuring out how ConTeXts float referencing
mechanism works.

Thanks for the work you spend on this. I don't need this function
for the current project (I use the workaround), but I would like to
see this feature in ConTeXt. If you have time and expertise to
implement this, it would be great. Otherwise I'll do the range
referencing manually.


Regards
Marco

___
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
___

Re: [NTG-context] Referring to multiple elements

2012-09-14 Thread Marco Patzer
2012-09-13 Andreas Mang m...@imt.uni-luebeck.de:

 I do not know if there is a solution to this. The following would
 work for your example:
 
 \in{figure}[alpha]--\in[gamma]
 
 Of course this is a quite rigid solution, that does not safeguard
 against changes in figure order

That's what I am using at the moment. Apparently there is no such
functionality. This one would go on my wish list.


Marco

___
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
___


Re: [NTG-context] Referring to multiple elements

2012-09-14 Thread Sietse Brouwer
Hi Marco,

The heart of what you need is a lua function that will take an array
of numbers, and return an array of consective-number runs, like so:

fignumarray = {1, 2, 3,5, 6,8,   10, 11, 12}
-- figruns = get_runs(fignumarray)
-- returns a table structured like so:
-- figruns[1].start = 1, figruns[1].stop = 3,
-- figruns[2].start = 5, figruns[2].stop = 6,
-- figruns[3].start = 8, figruns[3].stop = 8,
-- figruns[4].start = 10, figruns[4].stop = 12

I've written one below, plus the scaffolding required to feed it the
right input, and print its output to ConTeXt. Only two functions still
need writing --- one to turn the context argument [fig:f1, fig:f2,
fig:f4] into a lua array of strings, and one to turn each reference
string into a figure number. But this should get you on your way.

If you're not comfortable with programming LuaTeX, say so and I can
fill in the two missing functions sometime this weekend. But they
should be doable, really. (And, of course, you may be far more
experienced in LuaTeX than I, I don't know.)

Cheers,
Sietse

% should be below startluacode block, but clearer like so
\def\inwithranges[#1]%
{\ctxlua{u.inwithranges(#1)}}

\startluacode
u = userdata or { }

function get_runs(a)
runs = { }
run_start = 1
while run_start = #a do
run_stop = run_start
while a[run_stop + 1] == a[run_stop] + 1 do
run_stop = run_stop + 1
end
print(a[run_start] .. - .. a[run_stop])

table.insert(runs, {[start] = a[run_start],
[stop]   = a[run_stop]})
run_start = run_stop + 1
end
return runs
end

function u.inwithranges(ref_string)
-- CTX... means I expect ConTeXt already has this function in a
library somewhere
local ref_array = CTXstring_to_array(refs_string)  --FIXME
local ref_numbers = { }
for _, v in ipairs(ref_array) do
ref_numbers[i] = CTXref_to_fignumber(array)  --FIXME
end
ref_numbers.sort()
runs = get_runs(ref_numbers)
for i, run in ipairs(runs) do
context.in( {run.start} )
context(-)
context.in( {run.stop} )
if i  #runs then context(',') end
end
end

\stopluacode
___
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
___


Re: [NTG-context] Referring to multiple elements

2012-09-13 Thread Andreas Mang
Hi Marco,

I do not know if there is a solution to this. The following would work for your 
example:

\in{figure}[alpha]--\in[gamma]

Of course this is a quite rigid solution, that does not safeguard against 
changes in figure order...So probably not what you were looking for.

Cheers,
Andreas

Am Sep 13, 2012 um 12:15 PM schrieb Marco Patzer:

 Hi,
 
 how can I refer to multiple elements at the same time?
 
 \starttext
 
 \startplacefigure [title=foo, reference=alpha]
 \stopplacefigure
 \startplacefigure [title=bar, reference=beta]
 \stopplacefigure
 \startplacefigure [title=bar, reference=gamma]
 \stopplacefigure
 
 \in{figure}[alpha,beta,gamma]
 
 \stoptext
 
 This outputs “figure 1”. What I'd like to have is “figure 1-3”.
 
 
 Marco
 
 ___
 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
 ___


___
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
___