Changes

Jump to navigation Jump to search
2,576 bytes added ,  10:15, 3 November 2010
== Imposition by signatures ==
 
Sometimes you want a booklet, but the pages are too many to be folded together. This is true especially when the number of pages rises above 80. So you need to pass the output PDF to an imposer, like pdfjam or psbook or pdfpages. The problem is that you need to get the "right" number of pages.
 
E.g., if the original pages are 128, no problem, the signature is 64 and you can impose it without problems.
 
But, if the original pages are 129, the optimal signature is 44, so
you need to add 3 pages during the PDF compiling.
 
First, create the following imposer.lua file
 
<pre>
 
local maxsignature = 80 -- define the maximum of the signature
local minsignature = 20 -- define the minimum of the signature
function optimize_signature(pages)
local originalpages = pages
-- be sure we don't mess up
assert(numberpage ~= 0, "I can't work with 0 pages")
 
--set needed pages to and and signature to 0
local neededpages, signature = 0,0
 
-- this means that we have to work with n*4, if not, add them to
-- needed pages
local modulo = pages % 4
if modulo==0 then
signature=pages
else
neededpages = 4 - modulo
end
 
-- add the needed pages to pages
pages = pages + neededpages
-- give a try with the signature
signature = find_signature(pages)
-- if the pages, are more than the max signature, find the right one
if pages>maxsignature then
while signature<minsignature do
pages = pages + 4
neededpages = 4 + neededpages
signature = find_signature(pages)
end
end
print("ImposerMessage:: Original pages: " .. originalpages .. "; " ..
"Signature is " .. signature .. ", " ..
neededpages .. " pages are needed, " ..
pages .. " of output")
-- let's do it
tex.print("\\dorecurse{" .. neededpages .. "}{\\page[empty]}")
 
end
 
function find_signature(number)
assert(number ~= 0, "I can't find the signature for 0 pages")
assert((number % 4) == 0, "I suppose something is wrong, not a n*4")
local i = maxsignature
while i>0 do
if (number % i) == 0 then
return i
end
i = i - 4
end
end
 
</pre>
 
The ImposerMessage is important if you want to pass the output of the ConTeXt run to a script to do the imposing.
 
Then the master file
 
<texcode>
\def\fillthesignature#1{
\directlua{dofile("imposer.lua")
optimize_signature(#1)}}
\starttext
 
\dorecurse{53}{
\chapter{test}
\input tufte
\section{\the\realpageno}}
 
 
\page[yes] % reset the page
\fillthesignature{\the\realpageno}
 
And this is the last page (the backcover)
 
\stoptext
 
</texcode>
43

edits

Navigation menu