[NTG-context] How to display the pages of a particular section in another PDF?
Hans Hagen
j.hagen at freedom.nl
Mon Dec 5 13:13:48 CET 2022
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
-----------------------------------------------------------------
-------------- next part --------------
\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
-------------- next part --------------
\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
More information about the ntg-context
mailing list