moglen work in progress
[librarian.git] / librarian / pdf / wlpub.cls
1 % -*- coding: utf-8 -*-
2 \NeedsTeXFormat{LaTeX2e}
3 \ProvidesClass{wlpub}[2011/11/28 wolnelektury.pl book style]
4
5 % PDF customizations
6 %
7 % nofootnotes - disable generation of footnotes
8 % nothemes - disable generation of themes
9 % defaultleading - default leading
10 % onehalfleading - leading of 1.5 (interlinia)
11 % doubleleading - double leading (interlinia)
12 % a4paper,... - paper size as required by LaTeX
13 % nowlfont - don't use customized WL font
14
15 %\RequirePackage{geometry}
16
17 \RequirePackage{setspace}
18 \RequirePackage{type1cm}
19 \RequirePackage{amssymb}
20 \RequirePackage{amsmath}
21 \RequirePackage{paralist}
22 \RequirePackage[normalem]{ulem}
23 \RequirePackage{xifthen}
24 \RequirePackage{environ} % environments with \BODY, for wyimek
25
26 %\DeclareOption{13pt}{%
27 %\AtEndOfClass{%
28 % font size definitions, similar to ones in /usr/share/texmf-texlive/tex/latex/base/
29 %% \renewcommand\normalsize{%
30 %%    \@setfontsize\normalsize{13pt}{14.5pt}%
31 %%    \abovedisplayskip 12\p@ \@plus3\p@ \@minus7\p@
32 %%    \abovedisplayshortskip \z@ \@plus3\p@
33 %%    \belowdisplayshortskip 6.5\p@ \@plus3.5\p@ \@minus3\p@
34 %%    \belowdisplayskip \abovedisplayskip
35 %%    \let\@listi\@listI}\normalsize%
36 %% \renewcommand\footnotesize{%
37 %%    \@setfontsize\footnotesize\@xpt\@xiipt
38 %%    \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
39 %%    \abovedisplayshortskip \z@ \@plus3\p@
40 %%    \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
41 %%    \def\@listi{\leftmargin\leftmargini
42 %%                \topsep 6\p@ \@plus2\p@ \@minus2\p@
43 %%                \parsep 3\p@ \@plus2\p@ \@minus\p@
44 %%                \itemsep \parsep}%
45 %%    \belowdisplayskip \abovedisplayskip
46 %}%
47 %}%
48 %}
49
50 %% \DeclareOption{14pt}{\renewcommand{\normalsize}{\AtEndOfClass{\fontsize{14}{17}\selectfont}}}
51
52 \DeclareOption{defaultleading}{}
53 \DeclareOption{doubleleading}{\AtBeginDocument{\doublespacing}}%\setlength{\leading}{1em plus 0.5ex minus 0.2ex}}
54 \DeclareOption{onehalfleading}{\AtBeginDocument{\onehalfspacing}}%\setlength{\leading}{1em plus 0.5ex minus 0.2ex}}
55
56 %% This does not really work, since dvipdfm(x) will use it's configuration in /etc/texmf/dvipdfm(x) and force a global paper size setting.
57 \DeclareOption{a5paper}{%
58       \setlength{\paperheight}{210mm}%
59       \setlength{\paperwidth}{148mm}}
60 % a5paper dropped down size
61 \newif\ifcutafivepaper \cutafivepaperfalse
62 \DeclareOption{a5paperdd}{%
63   \setlength{\paperheight}{225mm}%
64   \setlength{\paperwidth}{160mm}%
65   \cutafivepapertrue
66 }
67
68 \newif\ifshowfootnotes \showfootnotestrue
69 \DeclareOption{nofootnotes}{\showfootnotesfalse}
70
71 \newif\ifshowthemes \showthemestrue
72 \DeclareOption{nothemes}{\showthemesfalse}
73
74 \newif\ifenablewlfont \enablewlfonttrue
75 \DeclareOption{nowlfont}{\enablewlfontfalse}
76
77
78 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{extbook}}
79 \ProcessOptions\relax
80 \LoadClass{extbook}
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 \usepackage{trace}
84 \usepackage{caption}
85 \usepackage{tabularx}
86 \usepackage[MeX]{polski}
87 \usepackage{icomma}
88 \usepackage[xetex]{graphicx}
89 \usepackage{fontspec}
90 \usepackage{xunicode}
91 \usepackage{xltxtra}
92 %\usepackage{trimspaces} % imported by something else?
93 \usepackage{color}
94 \usepackage[overload]{textcase}
95 \usepackage{scalefnt}
96 \usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=black,xetex]{hyperref}
97 \usepackage{fancyhdr}
98 \usepackage[explicit]{titlesec}
99 %\usepackage{fnpos}
100 \usepackage{printlen}
101 \usepackage{calc}
102 \usepackage[stable]{footmisc}
103
104 %% Wyimki - placing them on correct pages
105 \usepackage{changepage}
106 %\usepackage{fltpage}
107 \usepackage{float}
108
109 \pagestyle{plain}
110 % bottom figure below footnotes
111 %\makeFNabove
112
113
114 %%%%%%%%%%%%%%%%%%%%%%% Paper size
115 \setlength\baselineskip{7.14pt}
116 \ifcutafivepaper
117   \usepackage[%
118     paperwidth=160mm,%
119     paperheight=225mm,%
120     text={117mm,162mm},% 
121     top=30mm,% 
122     headsep=8mm,%
123     left=23mm,%
124     right=30mm]{geometry}%
125 \else
126   \usepackage[%
127     top=\dimexpr14.5mm+\baselineskip-16pt\relax, % margin will be smaller to accomodate for bigger header (16pt) 
128     headsep=3\baselineskip,
129     headheight=16pt,
130     bottom=26.3mm,%
131     inner=14.5mm,%
132     outer=22.5mm,%
133     textheight=\dimexpr7.14pt*(32*2+1)\relax,%
134     includehead]{geometry}
135 \fi
136
137 %%%%%%%%%%%%%%%%%%%%%%%% Fonts
138
139 \setmainfont[
140 ItalicFont = CrimsonText-Italic,
141 BoldFont = CrimsonText-Bold,
142 BoldItalicFont = CrimsonText-BoldItalic,
143 Ligatures={Common, Contextual},
144 SmallCapsFont = CrimsonText-Roman,
145 SmallCapsFeatures={Letters=SmallCaps},
146 Mapping=tex-text
147 ]{CrimsonText-Roman}
148 \newfontface\sb{CrimsonText-Semibold}
149 \newfontface\intro{Archivo-Black}
150
151 %% For faking small caps You burn in typographic hell.
152 \makeatletter
153 \newlength\fake@f
154 \newlength\fake@c
155 \def\fakesc#1{%
156   \begingroup%
157   \xdef\fake@name{\csname\curr@fontshape/\f@size\endcsname}%
158   \fontsize{\fontdimen8\fake@name}{\baselineskip}\selectfont%
159   \uppercase{#1}%
160   \endgroup%
161 }
162 \makeatother
163
164 \setlength{\parindent}{3mm}
165 \setlength{\parskip}{0mm}
166
167 \renewcommand{\normalsize}{\fontsize{10.4}{14.28}\addfontfeature{LetterSpace=0.3}\selectfont}
168 \renewcommand{\large}{\fontsize{14}{14.28}\addfontfeature{LetterSpace=0.3}\selectfont} % srodtytul
169 \renewcommand{\small}{\fontsize{8}{14.28}\addfontfeature{LetterSpace=0.5}\selectfont} % paginy
170 \renewcommand{\Large}{\fontsize{15}{21.42}\addfontfeature{LetterSpace=0.1}\selectfont} % tytuł rozdziału
171 \renewcommand{\huge}{\fontsize{18}{28.56}\addfontfeature{LetterSpace=0.1}\selectfont} % wyimek
172 \renewcommand{\Huge}{\fontsize{24}{40}\selectfont} % cover
173 \renewcommand{\footnotesize}{\fontsize{9}{10.74}\selectfont}
174
175
176
177 \definecolor{stoK}{cmyk}{0,0,0,1}
178 \definecolor{theme}{gray}{.3}
179 %\color{stoK}
180
181
182 %%%%%%%%%%%%%%%%%%%%%% Headings.
183 \pagestyle{fancy}
184 \fancyhf{}
185 \renewcommand{\headrulewidth}{0pt}
186 \renewcommand{\footrulewidth}{0pt}
187 \makeatletter
188 %%%%%%%%%% Nagłówek normalny
189 \cfoot{}
190 % this will go to \leftmark
191 \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}}
192 \fancyhead[CE]{{\small\MakeUppercase{\@title}}}
193 \fancyhead[CO]{{\small\leftmark}}
194 \fancyhead[LE,RO]{{\small\intro\thepage}}
195 %%%%%%%%%% Nagłówek pierwszej strony rozdziału
196 \fancypagestyle{plain}{%
197 \fancyhf{}
198 \fancyhead[LE,RO]{{\small\intro\thepage}}
199 \renewcommand{\headrulewidth}{0pt}
200 \renewcommand{\footrulewidth}{0pt}}
201 \makeatother
202
203 %%%%%%%%%%%%%%%%%%%%%% Section title styles.
204 %% Chapters
205 \titleformat{\chapter}[block]%
206 {\Large\intro\addfontfeature{LetterSpace=0.5,Kerning={Uppercase}}}%
207 {}{0pt}{\parbox{80mm}{\raggedright\MakeUppercase{#1}}}
208 \newlength{\chapterposcorrection}\newlength{\chapterspaceafter}
209 \setlength{\chapterposcorrection}{-\headsep-2\baselineskip}
210 \setlength{\chapterspaceafter}{14\baselineskip-14pt}%\f@size of large
211 \titlespacing*{\chapter}{0pt}{\chapterposcorrection}{\chapterspaceafter}
212
213 %% Sections
214 \titleformat{\section}%
215 {\addfontfeature{LetterSpace=0.3}\large}%
216 {\thesection{}.}{.5em}{\MakeUppercase{#1}}
217
218 \renewcommand{\thesection}{\Roman{section}}
219
220 \titleformat{\subsection}[runin]%
221 {}%
222 {\thesubsection{}.}{.5em}{\MakeUppercase{#1}.}[]
223
224 \renewcommand{\thesubsection}{\Alph{subsection}}
225 \titlespacing*{\subsection}{0pt}{0pt}{.5em}
226
227 \newcommand{\typosubsubsection}[1]{%
228 {\textsc{#1}}
229 }
230
231 %% XXX delete them
232 \newcommand{\typosubsection}[1]{%
233 {\MakeUppercase{#1}}
234 }
235
236 \newcommand{\typosection}[1]{%
237 {\addfontfeature{FakeStretch=0.96, LetterSpace=-4.0}\emph{\scalefont{2}#1}}
238 %{\addfontfeature{Scale=2.0, FakeStretch=0.98, LetterSpace=-2.0}\emph{#1}}
239 }
240 %%%%%%%%%%%%%%%%%% ^^
241
242 %%%%% Footnotes (works with footmisc) %%%%%%%%
243 \newlength{\footnoteindent}\newlength{\footnoteprespace}
244 \setlength{\footnoteindent}{6mm}%{3.5mm}
245 \setlength{\footnoteprespace}{0em}
246 \makeatletter
247
248 \renewcommand\@makefnmark{%
249 \hspace{\footnoteprespace}
250 \hbox{{\normalfont \@thefnmark}}%
251 }
252 \renewcommand\thefootnote{[\arabic{footnote}]}
253
254 \setlength{\footnotemargin}{-\footnoteindent-\footnoteprespace-.3em}
255 \renewcommand\footnotelayout[1]{%
256   \setlength{\leftskip}{\footnoteindent}#1}
257
258 %% \long\def\@makefntext#1{%
259 %% \setlength{\leftskip}{\footnoteindent}%
260 %% \setlength{\hskip}{-\footnoteindent-\footnoteprespace-.1em}%
261 %% \hb@xt@ \dimexpr\footnoteindent+\footnoteprespace%
262 %% {\@makefnmark}#1
263 %% %  \parindent 1em\noindent \hb@xt@ 1.8em{\hss \@makefnmark \enskip}#1
264 %% }
265
266 % make public
267 \def\trimspace#1{\trim@spaces{#1}}
268
269 \makeatother
270
271 %%%%%%%%%%%%%%%%%%%%%% Wyimki
272 %% \floatstyle{plain}
273 %% \newfloat{wyimekbox}{p}{wmk}
274 %% \floatname{wyimekbox}{Wyimek}
275
276 \NewEnviron{wyimek}{%
277   \checkoddpage
278   \ifoddpage
279     \PackageWarning{wlpub}{Wyimek on odd page, omitting it.}
280   \else
281     \begin{figure}[tp]
282       \begin{center}
283         \begin{minipage}[t][\textheight][c]{70mm}
284           \huge\it\BODY
285         \end{minipage}
286       \end{center}
287     \end{figure}
288   \fi
289   \BODY
290 }
291
292
293
294
295
296 %%%%%%%%%%%%%%%%%%%%%%%%%%
297
298
299 \clubpenalty=100000
300 \widowpenalty=100000
301
302
303 % see http://osdir.com/ml/tex.xetex/2005-10/msg00003.html
304 \newsavebox{\ximagebox}\newlength{\ximageheight}
305 \newsavebox{\xglyphbox}\newlength{\xglyphheight}
306 \newcommand{\xbox}[1]
307 {\savebox{\ximagebox}{#1}\settoheight{\ximageheight}{\usebox {\ximapgebox}}%
308 \savebox{\xglyphbox}{\char32}\settoheight{\xglyphheight}{\usebox {\xglyphbox}}%
309 \raisebox{\ximageheight}[0pt][0pt]{%\raisebox{-\xglyphheight}[0pt] [0pt]{%
310 \makebox[0pt][l]{\usebox{\xglyphbox}}}%}%
311 \usebox{\ximagebox}%
312 \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}
313
314
315 \newcommand{\makecover}{
316   %\pdfpagewidth=#1
317   %\pdfpageheight=#2
318
319   \thispagestyle{empty}
320   \newlength{\PictHOffset}
321   \newlength{\PictVOffset}
322   \setlength{\PictHOffset}{1in}
323   \addtolength{\PictHOffset}{\hoffset}
324   \addtolength{\PictHOffset}{\oddsidemargin}
325
326   \setlength{\PictVOffset}{1in}
327   \addtolength{\PictVOffset}{\voffset}
328   \addtolength{\PictVOffset}{\topmargin}
329   \addtolength{\PictVOffset}{\headheight}
330   \addtolength{\PictVOffset}{\headsep}
331   \addtolength{\PictVOffset}{\topskip}
332
333   \addtolength{\PictVOffset}{-\paperheight}
334
335   \noindent\hspace*{-\PictHOffset}%
336   \raisebox{\PictVOffset}[0pt][0pt]{\makebox[0pt][l]{%
337       \includegraphics[height=\paperheight,width=\paperwidth]{cover.jpg}}}
338
339   }
340
341 \renewcommand{\maketitle}{
342   %\vspace{\paperheight}
343   \newpage
344   \thispagestyle{empty}
345   \begin{center}
346   \intro
347   {
348     \begin{spacing}{1.4}
349     \Huge \noindent \thetitle
350     \end{spacing}
351   }
352   \end{center}
353
354   \vspace{\baselineskip}
355   
356   \begin{center}
357     \intro
358     {
359       \huge \noindent 
360       \theauthor
361       
362     }
363   \end{center}
364                   %\emph{\thankyou}\\
365                   %\indent\emph{You made this book possible.}
366   \vspace{7\baselineskip}
367
368   \begin{center}
369     \includegraphics[scale=.2]{logo.eps}
370   \end{center}
371   
372 }
373
374
375 \newcommand{\editorialsection}{
376   \newpage
377   \thispagestyle{empty}
378   \input{editorial}
379 }
380
381 \renewcommand*\contentsname{Table of Contents}
382 \newcommand{\spistresci}{
383 {
384   \intro
385   \setcounter{tocdepth}{0}
386   \tableofcontents
387   \newpage
388 }
389 }
390
391
392
393
394 \newcommand{\tytul}[1]{%
395 #1%
396 \vspace{1em}%
397 }
398
399 \newcommand{\nazwapodutworu}[1]{%
400 \section*{#1}%
401 }
402
403 \newcommand{\autorutworu}[1]{%
404 #1
405 %\subsection*{\typosubsection{#1}}%
406 }
407
408 \newcommand{\dzielonadrzedne}[1]{%
409 \subsection*{#1}%
410 }
411
412 \newcommand{\nazwautworu}[1]{%
413 \section*{#1}%
414 }
415
416 \newcommand{\podtytul}[1]{%
417 \subsection*{\typosubsubsection{#1}}%
418 }
419
420 \newcommand{\podtytulpodutworu}[1]{%
421 \subsection*{\typosubsubsection{#1}}%
422 }
423
424 \newcommand{\translator}[1]{%
425 \subsection*{\typosubsubsection{tłum. #1}}%
426 }
427 \newcommand{\translatorsline}[1]{%
428 #1
429 }
430
431 \newcommand{\powiesc}[1]{#1}
432 \newcommand{\opowiadanie}[1]{#1}
433 \newcommand{\lirykal}[1]{#1}
434 \newcommand{\lirykalp}[1]{#1}
435 \newcommand{\dramatwierszowanyl}[1]{#1}
436 \newcommand{\dramatwierszowanylp}[1]{#1}
437 \newcommand{\dramatwspolczesny}[1]{#1}
438
439 \newcommand{\nota}[1]{%
440 \begin{em}%
441 \begin{flushleft}%
442 \noindent #1%
443 \end{flushleft}%
444 \end{em}%
445 }
446
447 \newcommand{\dedykacja}[1]{%
448 \begin{em}%
449 \begin{flushright}%
450 #1%
451 \end{flushright}%
452 \end{em}%
453 }
454
455 \newcommand{\dlugicytat}[1]{%
456 \begin{quotation}%
457 #1%
458 \end{quotation}%
459 }
460
461 \newcommand{\poezjacyt}[1]{%
462 \begin{verse}%
463 #1%
464 \end{verse}%
465 }
466 \newcommand{\motto}[1]{%
467 \begin{em}%
468 #1%
469 \end{em}%
470 }
471 \newcommand{\listaosob}[2]{%
472 \par{#1}%
473 \begin{itemize}%
474 #2%
475 \end{itemize}%
476 }
477
478 \newcommand{\nagloweklisty}[1]{%
479 \typosubsubsection{#1}%
480 }
481
482 \newcommand{\listaosoba}[1]{%
483 \item{#1}%
484 }
485
486 \newcommand{\kwestia}[1]{%
487 \par{#1}%
488 }
489
490 \newcommand{\naglowekakt}[1]{%
491 \pagebreak
492 \subsection*{\typosubsection{#1}}%
493 }
494 \newcommand{\naglowekczesc}[1]{%
495 \pagebreak
496 \part{#1}%
497 }
498 \newcommand{\srodtytul}[1]{%
499 \subsection{#1}%
500 }
501
502 \newcommand{\naglowekscena}[1]{%
503 \subsubsection*{\typosubsubsection{#1}}%
504 }
505
506 \newcommand{\theautorrozdzialu}{}
507
508 \newcommand{\autorrozdzialu}[1]{%
509 \renewcommand{\theautorrozdzialu}{\newline{}{\normalfont by}\newline#1}
510 }
511
512 \newcommand{\naglowekrozdzial}[1]{%
513 \chapter[#1]{#1\theautorrozdzialu{}}\renewcommand{\theautorrozdzialu}{}%
514 }
515
516 \newcommand{\naglowekosoba}[1]{%
517 \par{\textsc{#1}}\nopagebreak%
518 }
519 \newcommand{\naglowekpodrozdzial}[1]{%
520 \section{#1}\nopagebreak%
521 }
522
523 \newcommand{\miejsceczas}[1]{%
524 \par{\emph{#1}}%
525 }
526 \newcommand{\didaskalia}[1]{%
527 \par{\emph{#1}}%
528 }
529
530 \newcommand{\akap}[1]{%
531 \par{#1}%
532 }
533 \newcommand{\akapdialog}[1]{%
534 \par{#1}%
535 }
536 \newcommand{\akapcd}[1]{%
537 \par{#1}%
538 }
539
540 \newcommand{\mottopodpis}[1]{%
541 \begin{em}%
542 \begin{flushright}%
543 #1%
544 \end{flushright}%
545 \end{em}%
546 }
547
548 \newcommand{\strofa}[1]{%
549 \par{\noindent{\ignorespaces#1\vspace{1em}}}%
550 }
551
552 \newcommand{\wers}[1]{#1}
553
554 \newcommand{\wersakap}[1]{%
555 \hspace*{1em}#1%
556 }
557 \newcommand{\werscd}[1]{%
558 \hspace*{8em}#1%
559 }
560 \newcommand{\werswciety}[2][1em]{%
561 \hspace*{#1}#2%
562 }
563
564 \ifshowfootnotes
565   \newcommand{\pa}[1]{\NoCaseChange{\footnote{#1 [przypis autorski]}}}
566   \newcommand{\pe}[1]{\NoCaseChange{\footnote{#1}}}
567   \newcommand{\pr}[1]{\NoCaseChange{\footnote{#1}}}
568   \newcommand{\pt}[1]{\NoCaseChange{\footnote{#1}}}
569 \else
570   \newcommand{\pa}[1]{}
571   \newcommand{\pe}[1]{}
572   \newcommand{\pr}[1]{}
573   \newcommand{\pt}[1]{}
574 \fi
575
576 \newcommand{\mat}[1]{$#1$}
577
578 \newcommand{\didasktekst}[1]{%
579 \emph{#1}%
580 }
581 \newcommand{\slowoobce}[1]{%
582 \emph{#1}%
583 }
584 \newcommand{\tytuldziela}[1]{%
585 \emph{#1}%
586 }
587 \newcommand{\wyroznienie}[1]{%
588 \emph{#1}%
589 }
590
591 \newcommand{\osoba}[1]{%
592 #1%
593 }
594
595 \newcommand{\sekcjaswiatlo}{%
596 \vspace{30pt}%
597 }
598
599 \newcommand{\sekcjaasterysk}{%
600 \vspace{10pt}%
601 \begin{center}%
602 \par{*}%
603 \end{center}%
604 }
605
606 \newcommand{\separatorlinia}{%
607 \vspace{10pt}%
608 \hrule{}%
609 \vspace{10pt}%
610 }
611
612 \newcommand{\ilustrscale}[0]{1}
613 \newcommand{\setilustrscale}[1]{\renewcomand{\ilustrscale}{#1}}
614
615 \newcommand{\ilustr}[3][]{
616   \vspace{2\baselineskip}%
617   \begin{center}%
618     \ifthenelse{\isempty{#1}}%
619     {\par{\includegraphics{\trimspace{#2}}\\#3}}%
620     {\par{\includegraphics[#1]{\trimspace{#2}}\\#3}}%
621   \end{center}%
622   \vspace{2\baselineskip}%
623 }
624
625
626 \newcommand{\motyw}[2][0]{%
627 \ifshowthemes
628 \mbox{}%
629 \marginpar{%
630 \vspace{-8pt}%
631 \vspace{-#1\baselineskip}%
632 \raggedright{\hspace{0pt}%
633 \footnotesize{\color{theme}{#2}}}%
634 \vspace{\baselineskip}%
635 }%
636 \fi
637 }
638
639 \newcommand{\lista}[1]{%
640 \begin{compactitem}
641 #1
642 \end{compactitem}
643 }
644
645 \newcommand{\punkt}[1]{%
646 \item #1
647 }
648 \newcommand{\link}[2]{\href{#1}{\uline{#2}\footnote{#1}}}
649
650 \newcommand{\www}[1]{{\normalfont\small\href{#1}{#1}}}
651