From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: Re: How to display the pages of a particular section in another PDF?
Date: Mon, 5 Dec 2022 13:13:48 +0100 [thread overview]
Message-ID: <884a450e-832f-71fa-7098-0778455cd973@freedom.nl> (raw)
In-Reply-To: <1550657480.592642.1670193056410@mail.yahoo.com>
[-- Attachment #1: Type: text/plain, Size: 1037 bytes --]
On 12/4/2022 11:30 PM, Joel via ntg-context wrote:
> I can use this code to display page 5 from a PDF:
>
> \externalfigure[filename.pdf][page=5]
>
> I am making a teacher's guide for a workbook (workbook.pdf). I need to
> be able to display on the page all pages of a particular section.
>
> The teacher's guide uses the same section titles as the workbook, e.g.:
>
> 17-A: Title
> 17-B: Title
>
> In other words, there is 1:1 pairing of section titles in the teacher's
> guide and the workbook.
>
> Is there any way to tell ConTeXt to display all of the pages for a
> particular section?
>
> \externalfigure[filename.pdf][section=17A]
prototype attached (first process crap, then load)
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
[-- Attachment #2: load.tex --]
[-- Type: text/plain, Size: 2459 bytes --]
\startluacode
document.foundsection = { first = 0, last = 0 }
function document.loadsection(filename,reference)
local data = job.loadother(file.addsuffix(filename,"tuc"))
if data then
local lists = data.structures.lists.collected
local pages = data.structures.pages.collected
if lists and pages then
for i=1,#lists do
local li = lists[i]
if li.references.reference == reference then
local first = 1
local last = pages[#pages].number
local level = li.metadata.level
first = li.references.realpage
for j=i+1,#lists do
local lj = lists[j]
if lj.metadata.level == level then
last = lj.references.realpage - 1
break
end
end
document.foundsection.first = first
document.foundsection.last = last
end
end
end
end
end
\stopluacode
% it depends what interface one wants ... we could have
%
% \externalfigure[crap.pdf][section=<reference>] % takes from crap
%
% but we need more inpiut and discussion for that
\starttexdefinition DoWithSection #1#2
\startpagemakeup
\externalfigure[#1.pdf][page=#2]
\stoppagemakeup
\stoptexdefinition
\starttexdefinition LoadSectionsA #1#2
\ctxlua{document.loadsection("#1","#2")}
\doifnot{\cldcontext{document.foundsection.first}} {0} {
\dostepwiserecurse
{\cldcontext{document.foundsection.first}}
{\cldcontext{document.foundsection.last}}
{1}
{
\DoWithSection{#1}{\recurselevel}
}
}
\stoptexdefinition
\starttexdefinition spaces LoadSectionsB #1#2
\ctxlua{
document.loadsection("#1","#2")
if document.foundsection.first > 0 then
for i=document.foundsection.first,document.foundsection.last do
context.DoWithSection("#1",i)
end
end
}
\stoptexdefinition
\starttext
\LoadSectionsA{crap}{chapter:3}
\LoadSectionsB{crap}{chapter:2}
\stoptext
[-- Attachment #3: crap.tex --]
[-- Type: text/plain, Size: 417 bytes --]
\starttext
\dorecurse{10}{
\startchapter[title=Chapter #1,reference=chapter:#1]
\dorecurse{10}{
\startsubject[title=Subject #1]
\dorecurse{2}{\samplefile{tufte}\par}
\stopsubject
\startsection[title=Section #1.##1,reference=#1.##1]
\dorecurse{10}{\samplefile{tufte}\par}
\stopsection
}
\stopchapter
}
\stoptext
[-- Attachment #4: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2022-12-05 12:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1550657480.592642.1670193056410.ref@mail.yahoo.com>
2022-12-04 22:30 ` Joel via ntg-context
2022-12-05 9:42 ` Denis Maier via ntg-context
2022-12-05 10:03 ` Henning Hraban Ramm via ntg-context
2022-12-05 12:13 ` Hans Hagen via ntg-context [this message]
2022-12-05 16:39 ` Pablo Rodriguez via ntg-context
2022-12-05 17:30 ` Hans Hagen via ntg-context
2022-12-05 18:23 ` Pablo Rodriguez via ntg-context
2022-12-05 20:22 ` Hans Hagen via ntg-context
2022-12-06 0:39 ` Joel via ntg-context
2022-12-06 8:05 ` Hans Hagen via ntg-context
2022-12-06 17:33 ` Pablo Rodriguez via ntg-context
2022-12-06 19:02 ` Hans Hagen via ntg-context
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=884a450e-832f-71fa-7098-0778455cd973@freedom.nl \
--to=ntg-context@ntg.nl \
--cc=j.hagen@freedom.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).