-
Notifications
You must be signed in to change notification settings - Fork 18
/
swa-document-scrbook.sty
142 lines (131 loc) · 4.21 KB
/
swa-document-scrbook.sty
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
%
% KOMA-Book specific properties
%
\@ifclassloaded{scrbook}{}%
{% not koma
\PackageError{swa-document-scrbook}%
{This package should only be used with KOMA script}%
{You might consider loading swa-document.}}
\newif\if@swa@birdseye
\DeclareOption{birdseyeview}{\@swa@birdseyetrue}
\DeclareOption{birdseyeview=true}{\@swa@birdseyetrue}
\DeclareOption{birdseyeview=false}{\@swa@birdseyefalse}
\ProcessOptions\relax
\KOMAoptions{
pagesize,
% DIV=8,
open=right,
appendixprefix=true,
% headinclude=true,
% footinclude=true
}
\newif\if@swa@bindingcorrection@set
\@swa@bindingcorrection@setfalse
\newcommand*\bindingcorrection[3][1]{
% #1 -> "Volumen", typically 1
% #2 -> pages
% #3 -> grammage
%
% Kohm: Die Bindekorrektur macht bei guter Bindung und gutem Papier maximal die
% Hälfte des Buchblocks aus.
%
% BCOR_max = (grammage/1000 * sheets * volume) / 2
% = grammage/1000 * pages/2 * volume/1 * 1/2
% = grammage * pages / 4000 * volume
% = grammage * pages * volume * 0.00025
% Will:
% Empfohlen wird ein Drittel bis die Hälfte der Buchrückenstärke (teilweise sogar die komplette Buchrückenstärke).
% Die Buchrückenstärke berechnet sich nach folgender Formel:
% (Grammatur x Volumen x Seitenzahl) : 2000
%
% We guess BCOR = .8 * BCOR_max
\if@swa@bindingcorrection@set\relax
\message{^^J Binding correction already set. ignoring}
\else
\csdimdef{tempcorrection}{.8\dimexpr#2\dimexpr #1\dimexpr 0.00025\dimexpr #3mm\relax}
% Set and force recalculation
\message{^^J Binding correction determined as \tempcorrection}
\ifcsdef{settypearea}%
{\csuse{settypearea}{\tempcorrection}}%
{\KOMAoptions{DIV=8,BCOR=\tempcorrection}%
\areaset[current]{\textwidth}{1.61803399\textwidth}}
\@swa@bindingcorrection@settrue
\fi
}
\csletcs{bindekorrektur}{bindingcorrection}
\providecommand*\papergrammage{80}
\providecommand*\papervolume{1}
\providecommand*\BCORTotPages{0}
\newcommand*\setbindingcorrection{%
\ifnumcomp{\BCORTotPages}{=}{0}{
\bindingcorrection[\papervolume]{60}{\papergrammage}
}{%
\bindingcorrection[\papervolume]{\BCORTotPages}{\papergrammage}
}
}
\AfterEndDocument{
%
% We cannot rely on the aux file here (where totpages writes TotPages)
% beacuse when the aux file is read, the page dimesions are already set,
% which is too late.
%
\if@filesw
\newwrite\swa@pagesfile
\immediate\openout\swa@pagesfile=\jobname.pgs\relax
\immediate\write\swa@pagesfile{\relax}
\immediate\write\swa@pagesfile{\string\xdef\string\BCORTotPages{\theTotPages}}
\immediate\write\swa@pagesfile{\relax}
\immediate\closeout\swa@pagesfile
\fi
}
\AtEndPreamble{%
\@input{\jobname.pgs}
\setbindingcorrection
}
\RequirePackage{swa-document-koma}
%\def\signed #1{{\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
% \hbox{}\nobreak\hfil{#1}%
% \parfillskip=0pt \finalhyphendemerits=0 \endgraf}}
\ifcsstring{swa@degree}{phd}%
{%
\newsavebox{\chaptersummarybox}%
\newenvironment{chaptersummary}[1][]%
{\begingroup%
\setlength{\fboxsep}{4pt}%
\begin{lrbox}{\chaptersummarybox}% capture
\begin{minipage}{\dimexpr\linewidth - 2\fboxsep\relax}%
\addsec*{Summary}\phantomsection\vspace*{-.5\baselineskip}\ignorespaces}%
{\end{minipage}\end{lrbox}%
\par\unskip\nobreak% hmode -> vmode, no pg break
\vfill% fill vertically. this is end of page if no space
\penalty50\vskip\baselineskip% make pg break point, try to squeze a line in
\vbox{}\nobreak\vfill% empty box + no pg break + fill; this is fill to e o page if page break at penalty 50
\noindent% vmode -> hmode
\colorbox[gray]{.9}{{\usebox{\chaptersummarybox}}}%
\endgroup%
\vspace*{2\fboxsep}%
\clearpage}}%
{}
\AtEndPreamble{
% redo document stuff:
\ifcsvoid{hypersetup}{}{%
\hypersetup{
pdftitle={\@title{}\ifdefempty{\@subtitle}{}{:\space\@subtitle}},
pdfauthor={\@author},
pdfsubject={\@subject}
}
}
\ifboolexpr{bool{@swa@birdseye}}{
\KOMAoptions{
twocolumn=true,
twoside=semi,
fontsize=8pt,
headings=small,
footinclude=false,
headinclude=false,
DIV=calc,
BCOR=0pt,
}
}{}
}
% EOF