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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
|
%
% gentombow.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is part of the gentombow bundle.
% https://github.com/aminophen/gentombow
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gentombow}
[2022/09/10 v0.9m Generate crop mark 'tombow']
\def\pxgtmb@pkgname{gentombow}
\@namedef{ver@pxgentombow.sty}{}% fake
%% error status
\chardef\pxgtmb@errlevel=\z@
%% supported engines
% case 2: pdfLaTeX etc.
% case 1: pLaTeX2e <2018-04-01>+2 or older
% case 0: pLaTeX2e <2018-05-20> or newer
% --- checked plcore.ltx in platex 2020/09/28 v1.3g
\ifx\pfmtname\@undefined
\@ifpackageloaded{luatexja}{}{\chardef\pxgtmb@errlevel=\tw@}
\fi
\ifnum\pxgtmb@errlevel<\tw@
\ifx\@tombowreset@@paper\@undefined
\chardef\pxgtmb@errlevel=\@ne
\fi
\fi
\ifcase\pxgtmb@errlevel
\let\pxgtmb@sel@twoone\@gobble
\let\pxgtmb@sel@two@one\@gobbletwo
\let\pxgtmb@sel@two\@gobble
\or
\let\pxgtmb@sel@twoone\@firstofone
\let\pxgtmb@sel@two@one\@secondoftwo
\let\pxgtmb@sel@two\@gobble
\or
\let\pxgtmb@sel@twoone\@firstofone
\let\pxgtmb@sel@two@one\@firstoftwo
\let\pxgtmb@sel@two\@firstofone
\else
\PackageError{\pxgtmb@pkgname}{%
This cannot happen!
Please report to package author}\@ehc
\expandafter\endinput
\fi
\@onlypreamble\pxgtmb@sel@twoone
\@onlypreamble\pxgtmb@sel@two@one
\@onlypreamble\pxgtmb@sel@two
%%%%% EMULATION BEGIN
% required for patching \@outputpage
\pxgtmb@sel@twoone{\RequirePackage{etoolbox}}
% patch \@outputpage
\begingroup
\def\pxgtmb@emu@status{0}
\let\pxgtmb@emu@outputpage\@outputpage
\pxgtmb@sel@two@one
{%% case 2 begin
\patchcmd\pxgtmb@emu@outputpage % try first patch
{\reset@font\normalsize\normalsfcodes}%
{\@tombowreset@@paper
\reset@font\normalsize\normalsfcodes}%
{}{\def\pxgtmb@emu@status{1}}
\patchcmd\pxgtmb@emu@outputpage % try second patch
{\@begindvi \vskip \topmargin}%
{\@begindvi \@outputtombow \vskip \@@topmargin}%
{}{\def\pxgtmb@emu@status{1}}
}%% case 2 end
{%% case 1 begin
\patchcmd\pxgtmb@emu@outputpage % try patch
{%
\@@topmargin\topmargin
\iftombow
\@@paperwidth\paperwidth \advance\@@paperwidth 6mm\relax
\@@paperheight\paperheight \advance\@@paperheight 16mm\relax
\advance\@@topmargin 1in\relax \advance\@themargin 1in\relax
\fi
\reset@font\normalsize\normalsfcodes}
{\@tombowreset@@paper
\reset@font\normalsize\normalsfcodes}%
{}{\def\pxgtmb@emu@status{1}}
}%% case 1 end
% commit the change only when successful; otherwise
% tombow feature is never enabled, exit right away
\pxgtmb@sel@twoone
{%% case 2 and 1 begin
\if 0\pxgtmb@emu@status\relax
\global\let\@outputpage\pxgtmb@emu@outputpage
\else
\PackageError{\pxgtmb@pkgname}{%
Failed in patching \string\@outputpage!\MessageBreak
Sorry, I can't proceed anymore...}\@ehc
\expandafter\expandafter\expandafter\endinput\expandafter
\fi
}%% case 2 and 1 end
\endgroup
%
% provides equivalent for plcore.ltx
\pxgtmb@sel@two
{%% case 2 begin
\newif\iftombow \tombowfalse
\newif\iftombowdate \tombowdatetrue
\newdimen\@tombowwidth
\setlength{\@tombowwidth}{.1\p@}
}%% case 2 end
\pxgtmb@sel@twoone
{%% case 2 and 1 begin
\setlength{\@tombowwidth}{.1\p@}
\def\@tombowbleed{3mm}
\def\@tombowcolor{\normalcolor}
}%% case 2 and 1 end
\pxgtmb@sel@two
{%% case 2 begin
\newbox\@TL\newbox\@Tl
\newbox\@TC
\newbox\@TR\newbox\@Tr
\newbox\@BL\newbox\@Bl
\newbox\@BC
\newbox\@BR\newbox\@Br
\newbox\@CL
\newbox\@CR
\font\@bannerfont=cmtt9
\newtoks\@bannertoken
\@bannertoken{}
}%% case 2 end
\pxgtmb@sel@twoone
{%% case 2 and 1 begin
\def\maketombowbox{% hide \yoko from all boxes
\setbox\@TL\hbox to\z@{\csname yoko\endcsname\hss
\vrule width\dimexpr 10mm+\@tombowbleed\relax height\@tombowwidth depth\z@
\vrule height10mm width\@tombowwidth depth\z@
\iftombowdate
\raise4pt\hbox to\z@{\hskip5mm\@bannerfont\the\@bannertoken\hss}%
\fi}%
\setbox\@Tl\hbox to\z@{\csname yoko\endcsname\hss
\vrule width10mm height\@tombowwidth depth\z@
\vrule height\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth depth\z@}%
\setbox\@TC\hbox{\csname yoko\endcsname
\vrule width10mm height\@tombowwidth depth\z@
\vrule height10mm width\@tombowwidth depth\z@
\vrule width10mm height\@tombowwidth depth\z@}%
\setbox\@TR\hbox to\z@{\csname yoko\endcsname
\vrule height10mm width\@tombowwidth depth\z@
\vrule width\dimexpr 10mm+\@tombowbleed\relax height\@tombowwidth depth\z@\hss}%
\setbox\@Tr\hbox to\z@{\csname yoko\endcsname
\vrule height\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth depth\z@
\vrule width10mm height\@tombowwidth depth\z@\hss}%
\setbox\@BL\hbox to\z@{\csname yoko\endcsname\hss
\vrule width\dimexpr 10mm+\@tombowbleed\relax depth\@tombowwidth height\z@
\vrule depth10mm width\@tombowwidth height\z@}%
\setbox\@Bl\hbox to\z@{\csname yoko\endcsname\hss
\vrule width10mm depth\@tombowwidth height\z@
\vrule depth\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth height\z@}%
\setbox\@BC\hbox{\csname yoko\endcsname
\vrule width10mm depth\@tombowwidth height\z@
\vrule depth10mm width\@tombowwidth height\z@
\vrule width10mm depth\@tombowwidth height\z@}%
\setbox\@BR\hbox to\z@{\csname yoko\endcsname
\vrule depth10mm width\@tombowwidth height\z@
\vrule width\dimexpr 10mm+\@tombowbleed\relax depth\@tombowwidth height\z@\hss}%
\setbox\@Br\hbox to\z@{\csname yoko\endcsname
\vrule depth\dimexpr 10mm+\@tombowbleed\relax width\@tombowwidth height\z@
\vrule width10mm depth\@tombowwidth height\z@\hss}%
\setbox\@CL\hbox to\z@{\csname yoko\endcsname\hss
\vrule width10mm height.5\@tombowwidth depth.5\@tombowwidth
\vrule height10mm depth10mm width\@tombowwidth}%
\setbox\@CR\hbox to\z@{\csname yoko\endcsname
\vrule height10mm depth10mm width\@tombowwidth
\vrule height.5\@tombowwidth depth.5\@tombowwidth width10mm\hss}%
}
\def\@outputtombow{%
\iftombow
\vbox to\z@{\kern-\dimexpr 10mm+\@tombowbleed\relax\relax
\boxmaxdepth\maxdimen
\moveleft\@tombowbleed \vbox to\@@paperheight{%
\color@begingroup
\@tombowcolor
\hbox to\@@paperwidth{\hskip\@tombowbleed\relax
\copy\@TL\hfill\copy\@TC\hfill\copy\@TR\hskip\@tombowbleed}%
\kern-10mm
\hbox to\@@paperwidth{\copy\@Tl\hfill\copy\@Tr}%
\vfill
\hbox to\@@paperwidth{\copy\@CL\hfill\copy\@CR}%
\vfill
\hbox to\@@paperwidth{\copy\@Bl\hfill\copy\@Br}%
\kern-10mm
\hbox to\@@paperwidth{\hskip\@tombowbleed\relax
\copy\@BL\hfill\copy\@BC\hfill\copy\@BR\hskip\@tombowbleed}%
\color@endgroup
}\vss
}%
\fi
}
}%% case 2 and 1 end
\pxgtmb@sel@two
{%% case 2 begin
\newdimen\@@paperheight
\newdimen\@@paperwidth
\newdimen\@@topmargin
}%% case 2 end
\pxgtmb@sel@twoone
{%% case 2 and 1 begin
\def\@tombowreset@@paper{%
\@@topmargin\topmargin
\iftombow
\@@paperwidth\paperwidth
\advance\@@paperwidth 2\dimexpr\@tombowbleed\relax
\@@paperheight\paperheight \advance\@@paperheight 10mm\relax
\advance\@@paperheight 2\dimexpr\@tombowbleed\relax
\advance\@@topmargin 1in\relax \advance\@themargin 1in\relax
\fi
}
}%% case 2 and 1 end
\pxgtmb@sel@two
{%% case 2 begin
\newcount\hour
\newcount\minute
}%% case 2 end
%%%%% EMULATION END
%% import from jsclasses
\hour\time \divide\hour by 60\relax
\@tempcnta\hour \multiply\@tempcnta 60\relax
\minute\time \advance\minute-\@tempcnta
\ifnum\mag=\@m\else
% if BXjscls is detected and \mag != 1000,
% the layout will be definitely broken
\ifx\bxjs@param@mag\@undefined\else
\PackageError{\pxgtmb@pkgname}{%
It seems you are using Japanese `BXjscls'\MessageBreak
(bxjsarticle, bxjsbook, bxjsreport, etc.) or\MessageBreak
some derived class. Try adding `nomag' or\MessageBreak
`nomag*' to the class option list}\@ehc
\fi
% if \mag != 1000 and \inv@mag is defined, assume jsclasses-style \mag employment
\ifx\inv@mag\@undefined\else
% \pxgtmb@magscale is almost equivalent to \jsc@magscale (introduced around 2016)
% but defined only when \mag is actually employed
\begingroup
% calculation code borrowed from BXjscls
\@tempcnta=\mag
\advance\@tempcnta100000\relax
\def\pxgtmb@tempa#1#2#3#4\@nil{\@tempdima=#2#3.#4\p@}
\expandafter\pxgtmb@tempa\the\@tempcnta\@nil
\xdef\pxgtmb@magscale{\strip@pt\@tempdima}
\endgroup
\fi
\fi
%% this package will use tombo feature in pLaTeX kernel
% if tombow-related option is not included in class option list,
% show info and enable it now
\iftombow\else
% if jsclasses is detected and \mag != 1000, it's too late
% -- When a size option other than `10pt' is specified,
% jsclasses uses \mag and calculates \oddsidemargin and \topmargin
% differently, depending on tombow status.
% In order to force `jsclasses' to calculate correctly,
% `tombow' or `tombo' is required as a class option.
% ... or, you may add `nomag' or `nomag*' instead.
\ifx\pxgtmb@magscale\@undefined\else
\PackageError{\pxgtmb@pkgname}{%
It seems you are using Japanese `jsclasses'\MessageBreak
(jsarticle, jsbook, jsreport, etc.) or some\MessageBreak
derived class. Please add `tombow' or `tombo'\MessageBreak
to the class option list}\@ehc
\fi
% BXjscls is already checked above, no check here
\PackageInfo\pxgtmb@pkgname{tombow feature enabled by \pxgtmb@pkgname}
\fi
\tombowtrue %\tombowdatetrue %% enabled by tombowbanner option
\setlength{\@tombowwidth}{.1\p@}%
%% import from jsclasses
\@bannertoken{%
\jobname\space(\number\year-\two@digits\month-\two@digits\day
\space\two@digits\hour:\two@digits\minute)}
%% prepare dimension
\ifx\stockwidth\@undefined \newdimen\stockwidth \fi
\ifx\stockheight\@undefined \newdimen\stockheight \fi
%% prepare flag
\newif\ifpxgtmb@switch \pxgtmb@switchfalse
\newif\ifpxgtmb@landscape \pxgtmb@landscapefalse
\newif\ifpxgtmb@pdfx@x \pxgtmb@pdfx@xfalse
%% passed from class options
%% should be declared first inside this package (least priority)
\DeclareOption{tombow}{\tombowdatetrue}
\DeclareOption{tombo}{\tombowdatefalse}
\DeclareOption{mentuke}{\tombowdatefalse \setlength{\@tombowwidth}{\z@}}
%% package options part 1
\DeclareOption{tombowbanner}{\tombowdatetrue}
\DeclareOption{notombowbanner}{\tombowdatefalse}
\DeclareOption{tombowdate}{% obsolete since v0.9c (2018/01/11)
\PackageWarning{\pxgtmb@pkgname}{%
Option `tombowdate' is renamed;\MessageBreak
use `tombowbanner' instead}%
\tombowdatetrue}
\DeclareOption{notombowdate}{% obsolete since v0.9c (2018/01/11)
\PackageWarning{\pxgtmb@pkgname}{%
Option `notombowdate' is renamed;\MessageBreak
use `notombowbanner' instead}%
\tombowdatefalse}
%% register a list of candidate papersize
% * \pxgtmb@addpapersize[<tombowname>]{<papername>}{<shorter edge>}{<longer edge>}
% used for declaration of papersize.
% when no option is specified (that is, \ifpxgtmb@switch = \iffalse),
% also used for automatic stocksize determination.
% * if <tombowname> = \@empty, the next <papername> is assumed.
% * if <tombowname> = n, stocksize is set to papersize + 2in.
\def\pxgtmb@addpapersize{\@ifnextchar[{\pxgtmb@addp@persize}{\pxgtmb@addp@persize[\@empty]}}
\def\pxgtmb@addp@persize[#1]#2#3#4{%
% get current papersize and search through known standard in ascending order
\ifx\pxgtmb@guessedtombow\@empty
\ifx\pxgtmb@guessedpaper\@empty
% shorter edge -> \@tempdima, longer edge -> \@tempdimb
\ifdim\paperwidth>\paperheight\relax
\pxgtmb@landscapetrue
\@tempdima\paperheight \@tempdimb\paperwidth
\else
\pxgtmb@landscapefalse
\@tempdima\paperwidth \@tempdimb\paperheight
\fi
% \@ovri and \@ovro are used temporarily (safe enough)
\@ovri=#3\relax
\@ovro=#4\relax
% when jsclasses-style \mag employment is assumed ...
\ifx\pxgtmb@magscale\@undefined\else
\@ovri=\inv@mag\@ovri\relax
\@ovro=\inv@mag\@ovro\relax
\fi
% compare
\ifdim\@tempdima=\@ovri\relax \ifdim\@tempdimb=\@ovro\relax
\def\pxgtmb@guessedpaper{#2}%
\ifx#1\@empty\else
\def\pxgtmb@guessedtombow{#1}%
\if n\pxgtmb@guessedtombow\else
\ExecuteOptions{tombow-#1}% package defaults to tombowdatetrue
\pxgtmb@switchfalse
\fi
\fi
\fi \fi
\else
\def\pxgtmb@guessedtombow{#2}% save for console message
\pxgtmb@setstock{#3}{#4}% set stockwidth/height
\fi\fi
\DeclareOption{tombow-#2}{%
\pxgtmb@switchtrue
\tombowdatetrue
\pxgtmb@setstock{#3}{#4}%
}%
\DeclareOption{tombo-#2}{%
\pxgtmb@switchtrue
\tombowdatefalse
\pxgtmb@setstock{#3}{#4}%
}%
\DeclareOption{mentuke-#2}{%
\pxgtmb@switchtrue
\tombowdatefalse
\setlength{\@tombowwidth}{\z@}%
\pxgtmb@setstock{#3}{#4}%
}%
}
\def\pxgtmb@setstock#1#2{%
\ifpxgtmb@landscape
\setlength\stockwidth{#2}%
\setlength\stockheight{#1}%
\else
\setlength\stockwidth{#1}%
\setlength\stockheight{#2}%
\fi
% when jsclasses-style \mag employment is assumed ...
\ifx\pxgtmb@magscale\@undefined\else
\stockwidth=\inv@mag\stockwidth\relax
\stockheight=\inv@mag\stockheight\relax
\fi
}%
\@onlypreamble\pxgtmb@addpapersize
\@onlypreamble\pxgtmb@addp@persize
\@onlypreamble\pxgtmb@setstock
%% initialize before search
\def\pxgtmb@guessedpaper{}
\def\pxgtmb@guessedtombow{}
\@onlypreamble\pxgtmb@guessedpaper
\@onlypreamble\pxgtmb@guessedtombow
%% package options part 2
% ISO A series <=> JIS B series in the ascending order
\pxgtmb@addpapersize{a10}{26mm}{37mm}
\pxgtmb@addpapersize{b10}{32mm}{45mm}
\pxgtmb@addpapersize{a9}{37mm}{52mm}
\pxgtmb@addpapersize{b9}{45mm}{64mm}
\pxgtmb@addpapersize{a8}{52mm}{74mm}
\pxgtmb@addpapersize{b8}{64mm}{91mm}
\pxgtmb@addpapersize{a7}{74mm}{105mm}
\pxgtmb@addpapersize{b7}{91mm}{128mm}
\pxgtmb@addpapersize{a6}{105mm}{148mm}
\pxgtmb@addpapersize{b6}{128mm}{182mm}
\pxgtmb@addpapersize{a5}{148mm}{210mm}
\pxgtmb@addpapersize{b5}{182mm}{257mm}
\pxgtmb@addpapersize{a4}{210mm}{297mm}
\pxgtmb@addpapersize{b4}{257mm}{364mm}
\pxgtmb@addpapersize{a3}{297mm}{420mm}
\pxgtmb@addpapersize{b3}{364mm}{515mm}
\pxgtmb@addpapersize{a2}{420mm}{594mm}
\pxgtmb@addpapersize{b2}{515mm}{728mm}
\pxgtmb@addpapersize{a1}{594mm}{841mm}
\pxgtmb@addpapersize{b1}{728mm}{1030mm}
\pxgtmb@addpapersize[n]{a0}{841mm}{1189mm}
\pxgtmb@addpapersize[n]{b0}{1030mm}{1456mm}
%% package options part 3
% ISO C series
\pxgtmb@addpapersize[a9]{c10}{28mm}{40mm}
\pxgtmb@addpapersize[a8]{c9}{40mm}{57mm}
\pxgtmb@addpapersize[a7]{c8}{57mm}{81mm}
\pxgtmb@addpapersize[a6]{c7}{81mm}{114mm}
\pxgtmb@addpapersize[a5]{c6}{114mm}{162mm}
\pxgtmb@addpapersize[a4]{c5}{162mm}{229mm}
\pxgtmb@addpapersize[a3]{c4}{229mm}{324mm}
\pxgtmb@addpapersize[a2]{c3}{324mm}{458mm}
\pxgtmb@addpapersize[a1]{c2}{458mm}{648mm}
\pxgtmb@addpapersize[a0]{c1}{648mm}{917mm}
\pxgtmb@addpapersize[n]{c0}{917mm}{1297mm}
% misc
\pxgtmb@addpapersize[b4]{a4j}{210mm}{297mm}
\pxgtmb@addpapersize[b5]{a5j}{148mm}{210mm}
\pxgtmb@addpapersize[a3]{b4j}{257mm}{364mm}
\pxgtmb@addpapersize[a4]{b5j}{182mm}{257mm}
\pxgtmb@addpapersize[b4]{a4var}{210mm}{283mm}
\pxgtmb@addpapersize[a4]{b5var}{182mm}{230mm}
\pxgtmb@addpapersize[a3]{letter}{8.5in}{11in}
\pxgtmb@addpapersize[a3]{legal}{8.5in}{14in}
\pxgtmb@addpapersize[a4]{executive}{7.25in}{10.5in}
\pxgtmb@addpapersize[a5]{hagaki}{100mm}{148mm}
%% package options part 4
\def\pxgtmb@pdfbox@status{0}
\DeclareOption{pdfbox}{\def\pxgtmb@pdfbox@status{1}}
\DeclareOption{dvips}{\def\pxgtmb@driver{s}}
\DeclareOption{dvipdfmx}{\def\pxgtmb@driver{m}}
\DeclareOption{xetex}{\def\pxgtmb@driver{x}}
\DeclareOption{pdftex}{\def\pxgtmb@driver{p}}
\DeclareOption{luatex}{\def\pxgtmb@driver{l}}
%% default options
\ExecuteOptions{tombowbanner}% package defaults to tombowdatetrue
\ProcessOptions
%% display search result
% if any of explicit size option is specified, \ifpxgtmb@switch = \iftrue.
% otherwise, automatic size detection should be successful.
\ifpxgtmb@switch\else
% check status
\@tempcnta=\z@\relax
\ifx\pxgtmb@guessedpaper\@empty
\advance\@tempcnta\@ne\relax
\fi
\ifx\pxgtmb@guessedtombow\@empty
\advance\@tempcnta\tw@\relax
\else\if n\pxgtmb@guessedtombow
\advance\@tempcnta\tw@\relax
\fi\fi
% message
\ifodd\@tempcnta
%\PackageWarningNoLine\pxgtmb@pkgname{%
% No size option specified, and automatic papersize\MessageBreak
% detection also failed}
\else
\typeout{***** Package \pxgtmb@pkgname\space detected \pxgtmb@guessedpaper paper. *****}
\fi
\ifnum\@tempcnta>\@ne\relax
\PackageWarningNoLine\pxgtmb@pkgname{%
Output size cannot be determined. Please add size\MessageBreak
option (e.g. `tombow-a4') to specify output size.\MessageBreak
Falling back to +1in ..}
\stockwidth\paperwidth \advance\stockwidth 2in
\stockheight\paperheight \advance\stockheight 2in
\else
\typeout{***** Now the output size is automatically set to \pxgtmb@guessedtombow. *****}
\fi
\fi
%% warnings
\ifdim\stockwidth<\paperwidth
\PackageWarningNoLine\pxgtmb@pkgname{%
\string\stockwidth\space is smaller than \string\paperwidth!\MessageBreak
Is this really what you want?}
\fi
\ifdim\stockheight<\paperheight
\PackageWarningNoLine\pxgtmb@pkgname{%
\string\stockheight\space is smaller than \string\paperheight!\MessageBreak
Is this really what you want?}
\fi
%% pdf "digital tombo" (driver-dependent)
% the box size calculation is delayed until \AtBeginDocument
% to allow users to change \@tombowbleed in the preamble
% convert pt -> bp
\def\pxgtmb@PDF@setbp#1#2{%
\@tempdima=.996264#2\relax % 0.996264 = 72/72.27 (cf. 1in = 72.27pt = 72bp)
\@tempdima=\pxgtmb@magscale\@tempdima % adjustment for jsclasses-style \mag employment
\edef#1{\strip@pt\@tempdima}}
% calculate and create pdf boxes
\def\pxgtmb@PDF@calcbox{%
\begingroup
% provide fallback definition inside this group
\ifx\pxgtmb@magscale\@undefined
\def\pxgtmb@magscale{1}%
\fi
% set pdf boxes in bp unit
\pxgtmb@PDF@setbp\pxgtmb@PDF@crop@ur@x\stockwidth
\pxgtmb@PDF@setbp\pxgtmb@PDF@crop@ur@y\stockheight
\pxgtmb@PDF@setbp\pxgtmb@PDF@trim@ll@x{\dimexpr(\stockwidth-\paperwidth)/2}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@trim@ll@y{\dimexpr(\stockheight-\paperheight)/2}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@trim@ur@x{\dimexpr(\stockwidth+\paperwidth)/2}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@trim@ur@y{\dimexpr(\stockheight+\paperheight)/2}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@bleed@ll@x{\dimexpr(\stockwidth-\paperwidth)/2-\@tombowbleed}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@bleed@ll@y{\dimexpr(\stockheight-\paperheight)/2-\@tombowbleed}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@bleed@ur@x{\dimexpr(\stockwidth+\paperwidth)/2+\@tombowbleed}%
\pxgtmb@PDF@setbp\pxgtmb@PDF@bleed@ur@y{\dimexpr(\stockheight+\paperheight)/2+\@tombowbleed}%
\xdef\pxgtmb@PDF@CTM{%
%% CropBox: normally implicit (same as MediaBox, large paper size)
%% however, pdfx.sty in PDF/X mode sets /CropBox explicitly, so I need to override it!
\ifpxgtmb@pdfx@x
\noexpand\pxgtmb@PDF@begin
/CropBox [0 0
\pxgtmb@PDF@crop@ur@x\space
\pxgtmb@PDF@crop@ur@y] \noexpand\pxgtmb@PDF@end
\fi
%% BleedBox: explicit (final paper size + surrounding \@tombowbleed)
\noexpand\pxgtmb@PDF@begin
/BleedBox [\pxgtmb@PDF@bleed@ll@x\space
\pxgtmb@PDF@bleed@ll@y\space
\pxgtmb@PDF@bleed@ur@x\space
\pxgtmb@PDF@bleed@ur@y] \noexpand\pxgtmb@PDF@end
%% TrimBox: explicit (final paper size)
\noexpand\pxgtmb@PDF@begin
/TrimBox [\pxgtmb@PDF@trim@ll@x\space
\pxgtmb@PDF@trim@ll@y\space
\pxgtmb@PDF@trim@ur@x\space
\pxgtmb@PDF@trim@ur@y] \noexpand\pxgtmb@PDF@end
%% ArtBox: implicit
%% [Note] PDF/X requires /TrimBox or /ArtBox but not both!
}%
\endgroup
}
% do it
\AtBeginDocument{\pxgtmb@PDF@emit}
\def\pxgtmb@PDF@emit{%
% handle compatibility with pdfx.sty here;
% if pdfx.sty with PDF/X mode detected, force [pdfbox] option!
\pxgtmb@handle@pdfx
\ifpxgtmb@pdfx@x\def\pxgtmb@pdfbox@status{1}\fi
% start actual procedure for [pdfbox] option
\if 1\pxgtmb@pdfbox@status
%% supported drivers: dvips, dvipdfmx, XeTeX, pdfTeX, LuaTeX
\ifnum0\ifx\pdfvariable\@undefined\else\the\outputmode\fi=0\relax
\ifnum0\ifx\pdfpageattr\@undefined\else\the\pdfoutput\fi=0\relax
%% for DVI output or XeTeX
\ifx\XeTeXversion\@undefined
\chardef\pxgtmb@errlevel=\z@
% check graphics/graphicx/color status
\ifx\Gin@driver\@undefined
\ifx\pxgtmb@driver\@undefined % driver option unavailable
\PackageError{\pxgtmb@pkgname}{%
Option `pdfbox' is driver-dependent!\MessageBreak
Please add a driver option}\@ehc
\def\pxgtmb@driver{s}% fallback
\fi
\else
% check consistency
\def\pxgtmb@tempa{dvips.def}\ifx\Gin@driver\pxgtmb@tempa
\ifx\pxgtmb@driver\@undefined
\def\pxgtmb@driver{s}% pass
\else
\if s\pxgtmb@driver\else \chardef\pxgtmb@errlevel=\@ne \fi
\fi
\else\def\pxgtmb@tempa{dvipdfmx.def}\ifx\Gin@driver\pxgtmb@tempa
\ifx\pxgtmb@driver\@undefined
\def\pxgtmb@driver{m}% pass
\else
\if m\pxgtmb@driver\else \chardef\pxgtmb@errlevel=\@ne \fi
\fi
\else
\ifx\pxgtmb@driver\@undefined
\PackageError{\pxgtmb@pkgname}{%
Option `pdfbox' is driver-dependent!\MessageBreak
Please add a driver option}\@ehc
\def\pxgtmb@driver{s}% fallback
\fi
\fi\fi
\ifnum\pxgtmb@errlevel>\z@
\PackageWarningNoLine{\pxgtmb@pkgname}{%
Inconsistent driver option detected!\MessageBreak
Package `graphics' or `color' already\MessageBreak
loaded with different driver option}\@ehc
\fi
\fi
\else
\def\pxgtmb@driver{x}
\fi
% required for putting \special to every page
\RequirePackage{atbegshi}
\ifx\pfmtname\@undefined\else
\ifx\AtBegShi@Output\@undefined
% LaTeX2e 2020-10-01: an emulation by ``atbegshi-ltx.sty''
% => pLaTeX2e 2020-10-01 natively supports it
\else
% older: the real ``atbegshi.sty'' is loaded
\IfFileExists{pxatbegshi.sty}{\RequirePackage{pxatbegshi}}{}
\fi
\fi
% do it
\if x\pxgtmb@driver
%% for XeTeX (similar to dvipdfmx, except for paper size)
\AtBeginDocument{%
\pxgtmb@PDF@calcbox
\def\pxgtmb@PDF@begin{}\def\pxgtmb@PDF@end{}%
\edef\pxgtmb@PDF@CTM{{pdf:put @thispage << \pxgtmb@PDF@CTM >>}}}
% force paper size
\pdfpagewidth\stockwidth \pdfpageheight\stockheight
% emit pdf boxes
\AtBeginShipout{\setbox\AtBeginShipoutBox=\vbox{%
\baselineskip\z@skip\lineskip\z@skip\lineskiplimit\z@
\expandafter\special\pxgtmb@PDF@CTM % here!
\copy\AtBeginShipoutBox}}
\else
\if s\pxgtmb@driver
%% for dvips
\AtBeginDocument{%
\pxgtmb@PDF@calcbox
\def\pxgtmb@PDF@begin{[ }\def\pxgtmb@PDF@end{/PAGE pdfmark }%
\edef\pxgtmb@PDF@CTM{{ps:SDict begin \pxgtmb@PDF@CTM end}}}
\else\if m\pxgtmb@driver
%% for dvipdfmx
\AtBeginDocument{%
\pxgtmb@PDF@calcbox
\def\pxgtmb@PDF@begin{}\def\pxgtmb@PDF@end{}%
\edef\pxgtmb@PDF@CTM{{pdf:put @thispage << \pxgtmb@PDF@CTM >>}}}
\else
%% for others (in case graphics option wrong)
\PackageError{\pxgtmb@pkgname}{Sorry, driver unsupported}\@ehc
\def\pxgtmb@PDF@CTM{{}}% dummy
\fi\fi
%% common
\begingroup
% when jsclasses-style \mag employment is assumed ...
% [Note] \special{papersize=<width>,<height>} accepts only non-true units
% and evaluates them as if they were true units!
\ifx\pxgtmb@magscale\@undefined\else
\stockwidth \pxgtmb@magscale\stockwidth
\stockheight\pxgtmb@magscale\stockheight
\fi
\xdef\pxgtmb@PDF@size{{papersize=\the\stockwidth,\the\stockheight}}
\endgroup
\AtBeginShipout{\setbox\AtBeginShipoutBox=\vbox{%
\baselineskip\z@skip\lineskip\z@skip\lineskiplimit\z@
% force paper size
\expandafter\special\pxgtmb@PDF@size
% emit pdf boxes
\expandafter\special\pxgtmb@PDF@CTM % here!
\copy\AtBeginShipoutBox}}
\fi
\else
%% for pdfTeX
\def\pxgtmb@driver{p}
% force paper size
\pdfpagewidth\stockwidth \pdfpageheight\stockheight
% emit pdf boxes
\AtBeginDocument{%
\pxgtmb@PDF@calcbox
\def\pxgtmb@PDF@begin{}\def\pxgtmb@PDF@end{}%
\edef\pxgtmb@PDF@CTM{{\pxgtmb@PDF@CTM}}%
\expandafter\pdfpageattr\pxgtmb@PDF@CTM}
\fi\else
%% for LuaTeX
\def\pxgtmb@driver{l}
% force paper size
\pagewidth\stockwidth \pageheight\stockheight
% emit pdf boxes
\AtBeginDocument{%
\pxgtmb@PDF@calcbox
\def\pxgtmb@PDF@begin{}\def\pxgtmb@PDF@end{}%
\edef\pxgtmb@PDF@CTM{pageattr{\pxgtmb@PDF@CTM}}%
\expandafter\pdfvariable\pxgtmb@PDF@CTM}
\fi
\fi
}
%% make visible tombow box according to the current status of
%% \@bannerfont, \@bannertoken, \@tombowwidth & \@tombowbleed
\maketombowbox
%% shift amount
\hoffset .5\stockwidth
\advance\hoffset -.5\paperwidth
\advance\hoffset-1truein\relax
\voffset .5\stockheight
\advance\voffset -.5\paperheight
\advance\voffset-1truein\relax
%% user interface
\newcommand{\settombowbanner}[1]{%
\iftombowdate\else
\PackageWarning{\pxgtmb@pkgname}{%
Package option `tombowbanner' is not effective.\MessageBreak
The banner may be discarded}%
\fi
\@bannertoken{#1}\maketombowbox}
\newcommand{\settombowbannerfont}[1]{%
\font\@bannerfont=#1\relax \maketombowbox}
\newcommand{\settombowwidth}[1]{%
\setlength{\@tombowwidth}{#1}\maketombowbox}
\newcommand{\settombowbleed}[1]{%
\def\@tombowbleed{#1}\maketombowbox}
\newcommand{\settombowcolor}[1]{%
\def\@tombowcolor{#1}}
% forbid changing \@tombowbleed after \begin{document}
% because pdf boxes are calculated only inside \AtBeginDocument
\@onlypreamble\settombowbleed
%% patch internal of pdfpages.sty to work with tombow
\def\pxgtmb@patch@pdfpages{%
\IfFileExists{pxpdfpages.sty}{\RequirePackage{pxpdfpages}}{}}
\AtBeginDocument{\@ifpackageloaded{pdfpages}{\pxgtmb@patch@pdfpages}{}}
%% patch pdfx.sty
%% (tested on pdfx 2019/02/27 v1.6.3)
\def\pxgtmb@handle@pdfx{\@ifpackageloaded{pdfx}{\let\ifpxgtmb@pdfx@x\ifpdfx@x}{}}
\endinput
|