summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-collatingmarks/t-collatingmarks/tex/context/third/collationg-marks/t-collatingmarks.tex
blob: 5b340243a583e2aa7904bec80f2332bad2cd10a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%D \module
%D   [       file=t-collatingmarks,
%D        version=\currentdate,
%D          title=\CONTEXT\ User Module,
%D       subtitle=Environment for collating marks,
%D         author={W. Egger},
%D           date=\currentdate,
%D      copyright={W. Egger},
%D          email=w.egger@boede.nl,
%D        license=Public Domain]
%D
%D The documentation can be generated with:
%D mtxrun --script modules --process t-collatingmarks.tex

\startmodule[collatingmarks]

\writestatus{loading}{Context Module for collating marks}

%D\enablemode[demo]

%D \subject{Introduction} 
%D
%D This code is based on the work of Thomas A. Schmitz, who created the module for
%D different crop marks.
%D
%D If a book consists of multiple sections, each section should be marked
%D along the spine with a collating mark. This mark moves down along the spine
%D according to the number of the section. After collating the book it becomes
%D easy tho check whether the sequence of the sections is correct. One should
%D see a \quotation{stair case} on the spine of the book.
%D
%D \subject{Using the module}
%D 
%D If the collating marks should be placed, then the system should be setup with
%D \type{\setupMPvariables[pages=8,sheets=2,shift=0mm,frenchdoors=false,wickel=false]} Note that the
%D collating marks-setup needs to know how many pages are placed on a
%D doublesided printed sheet of paper and how many such sheets result in a
%D section i.e. these values depend on the \type{\setuparranging} command.  The
%D shift-option is 0mm if no horizontal page shifting is issued during
%D imposition.  If a horizontal page shifting is used, then the shift option is
%D used to position the collating mark precisely on the spine. 
%D
%D The two keys \quotation{frenchdoors} and \quotation{wickel} are used for
%D special purposes. These are not intended for general use.
%D For the preparation of a binding called
%D French doors, where there is a left (normal) and a right book, which opens
%D from left to right the MPvariable \quotation{frenchdoors} must be set to true
%D (boolean).
%D For preparing a section with parallelfolding/letterfolding/Wickelfalz the
%D MPvariable \quotation{wickel} must be set to true (boolean).
%D
%D Be aware that the use of collating marks in MKII causes a lot of calls to 
%D Metapost, resulting in very long compilation times.
%D So better use MKIV where Metapost is included as a
%D library. In this case the time overhead is absolutely minimal.
%D
%D \section{Vocabulary}
%D
%D EN: Collating mark, DE: Kollationiermarke, NL: collationeerblokje
%D


\unprotect

\setupmodule[Collatingmarks=yes]

\setupMPvariables
    [Collatingmarks]
    [pages=16, %pages per sheet doublesided
		sheets=1,% number of sheets forming one section
		horpageshift=0,
	  frenchdoors=false,
	  wickel=false]

%D We prepare collating marks:

\processaction[\currentmoduleparameter{Collatingmarks}]
	[yes=>\def\Collatingmarks{Collatingmarks},
	no=>\def\Collatingmarks{},
	\v!unknown=>\def\Collatingmarks{},
	\v!default=>\def\Collatingmarks{}]

%D The newly prepared macros go into the page background:

\setupbackgrounds[page][state=repeat,background={\Collatingmarks}]

%D We define an overlay for the collating marks.

\defineoverlay[Collatingmarks][\useMPgraphic{Collatingmarks}]

%D We let \METAPOST do the calculations and draw de collating marks. 

\startusableMPgraphic{Collatingmarks}
StartPage;

numeric offset, sectionno, pages, sheets, factor, correction, offset, pageshift;
path p,q;
boolean frenchdoors,wickel;

pages       := \MPvar{pages};
sheets      := \MPvar{sheets};
pageshift   := \MPvar{horpageshift};
frenchdoors := \MPvar{frenchdoors};
wickel      := \MPvar{wickel};

z5colm = ulcorner Page;
z6colm = (x5colm, y5colm-10mm);

p := unitsquare xscaled 1mm yscaled 7mm;

if \realpagenumber mod 2 = 1 : % on uneven pages only
		sectionno := \realpagenumber div (sheets*pages)+1;
      label.lrt(textext("\switchtobodyfont[5pt]"& decimal sectionno &""),llcorner Page shifted (1mm,-2mm));
	if \realpagenumber mod (sheets*pages) = 1 : % on the first page of a section only
		nofmarkings := (y6colm-7mm) div 7mm;
		offset := y6colm-sectionno*7mm;
		if sectionno > nofmarkings : 
			correction := sectionno div nofmarkings;
			offset := y6colm-(sectionno-correction*nofmarkings)*7mm; 
		fi;
		if frenchdoors or wickel :
			p := p shifted ((PaperWidth),offset);
		else :
			p := p shifted (-1mm-2pageshift,offset);
		fi;
		fill p withcolor black;
		if sectionno < 9 : 
			label.rt(textext("\switchtobodyfont[3pt] \white "& decimal sectionno &""), center p shifted (-1.3mm,0));
		else :
			label.rt(textext("\switchtobodyfont[3pt] \white "& decimal sectionno &""), center p shifted (-1.5mm,0));
		fi;
	fi;
fi;
\stopusableMPgraphic

\protect
\stopmodule

\doifnotmode{demo}{\endinput}



%D Example:
%D \usemodule[collatingmarks][Collatingmarks=yes]
%D \setuppapersize[A5][A2]
%D \setuplayout[location=middle,marking=on]
%D \setuppagenumbering[alternative=doublesided]
%D \setuparranging[2*4]
%D 
%D \setupMPvariables
%D 	[pages=8,  % pages per sheet of paper doublesided
%D 	sheets=1,  % sheets of paper used per section
%D 	horpageshift=0mm, % used for correction if horizontal page-shifting is used
%D  frenchdoors=false,
%D  wickel=false]
%D
%D \starttext
%D 	\dorecurse{10}{\section{Text \recurselevel}\input tufte \par\subject{Ward} \input ward\par}
%D \stoptext


\usemodule[collatingmarks][Collatingmarks=yes]
\setuppapersize[A5][A2]
\setuplayout[location=middle,marking=on]
\setuppagenumbering[alternative=doublesided]
\setuparranging[2*4*2]

\setupMPvariables
	[pages=8,  % pages per sheet of paper doublesided
	sheets=2,  % sheets of paper used per section
	horpageshift=0mm, % used for correction if horizontal page-shifting is used
	frenchdoors=false,
	wickel=false]
	
\starttext
	\dorecurse{10}{\section{Text \recurselevel}\input tufte \par\subject{Ward} \input ward\par}
\stoptext