ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Pablo Rodriguez <oinos@gmx.es>
To: ntg-context@ntg.nl
Subject: Re: page ranges in \markpage
Date: Thu, 19 Jul 2018 21:56:02 +0200	[thread overview]
Message-ID: <1ee0ec6d-9f38-fc47-eb89-8ce73b806047@gmx.es> (raw)
In-Reply-To: <5B4F9014.7050208@gmail.com>

On 07/18/2018 09:08 PM, Wolfgang Schuster wrote:
> 
> [...]
> Afterwards you can use a loop where you add the markpage commands at
> the begin and end of the range, below is a simple example but it’s easy
> to write a better loop with Lua.
> 
> \setuplayout[page]
> \setupinteraction[state=start]
> \setupinteractionscreen[option={portrait, paper}, print=pages]
> \starttext
> \getfiguredimensions[i-context.pdf]
> \dostepwiserecurse{1}{99}{1}{\externalfigure[i-context.pdf][height=\textheight,page=\recurselevel]}
> \startmarkpages[page]
> \dostepwiserecurse{100}{300}{1}{\externalfigure[i-context.pdf][height=\textheight,page=\recurselevel]}
> \stopmarkpages
> \dostepwiserecurse{301}{\noffigurepages}{1}{\externalfigure[i-context.pdf][height=\textheight,page=\recurselevel]}
> \stoptext

Wolfgang

a different approach would be (code was mainly provided by anoter person):

    \startluacode
    function document.splitarray(inputstr, sep)
      local t={}
      for str in inputstr:gmatch("([^"..sep.."]+)") do
        table.insert(t, str)
      end
      return t
    end

    function document.getpagearray(page_ranges)
      local page_array={}
      local ranges = document.splitarray(page_ranges, ",")
      for _, pp in ipairs(ranges) do
        if string.find(pp, "-") then
          aux = document.splitarray(pp, "-")
          for i=tonumber(aux[1]), tonumber(aux[2]), 1 do
            table.insert(page_array, i)
          end
        else
           table.insert(page_array, tonumber(pp))
        end
      end
      return page_array
    end

    function document.printmarkedpageranges(tag, page_ranges)
      page_array = document.getpagearray(page_ranges)
      context("\\markpage[" .. tag .. "][" ..
          table.concat(page_array, ", ") .. "]")
    end
    \stopluacode

    \def\getmarkedpageranges#1#2{%
        \ctxlua{document.printmarkedpageranges("#1","#2")}}
    \setuplayout[page]
    \setupinteraction[state=start]
    \setupinteractionscreen[option={portrait, paper}, print=pages]
    \getmarkedpageranges{pages}{5, 25-30, 100-200, 235, 298, 304}
    \starttext
    \insertpages[i-context.pdf][width=0pt]
    \stoptext

This makes easier to add more complex page intervals (such as the one
above).

Before adding this to the wiki, my question would be whether it might
not be easier to add page ranges to \markpage.

I mean, as a standard user I think there is too much code (which may be
improved and made part of ConTeXt) for such a simple need.

Of course, I may be missing the whole point in this issue.

I would really appreciate, if someone could explain me what is wrong in
my assumption that \markpages need also page intervals.

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2018-07-19 19:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-18 16:19 Pablo Rodriguez
2018-07-18 17:40 ` Wolfgang Schuster
2018-07-18 18:44   ` Pablo Rodriguez
2018-07-18 19:08     ` Wolfgang Schuster
2018-07-18 19:38       ` Pablo Rodriguez
2018-07-19 19:56       ` Pablo Rodriguez [this message]
2018-07-19 22:19         ` Hans Hagen
2018-07-22 11:28           ` Pablo Rodriguez

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=1ee0ec6d-9f38-fc47-eb89-8ce73b806047@gmx.es \
    --to=oinos@gmx.es \
    --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).