aboutsummaryrefslogtreecommitdiff
path: root/template/kautools.dtx
blob: 307b643b134d49fdcc7167d9d53d7bd859b2d188 (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
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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
% \iffalse meta-comment
%% kautools.dtx
%% Copyright (c) 2011-2015 Stefan Berthold <stefan.berthold@kau.se>
%
% This file is part of the kauthesis bundle.
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer and author of this work is Stefan Berthold.
%
% This work consists of all files listed in manifest.txt.
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{\jobname.dtx}
%</driver>
%<title|meta|list|clear|environments|parts|paper|studies|crop>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<title>\ProvidesPackage{kautitle}
%<meta>\ProvidesPackage{kaumeta}
%<list>\ProvidesPackage{kaulist}
%<clear>\ProvidesPackage{kauclear}
%<environments>\ProvidesPackage{kauenvironments}
%<parts>\ProvidesPackage{kauparts}
%<paper>\ProvidesPackage{kaupaper}
%<studies>\ProvidesPackage{kaustudies}
%<language>\ProvidesPackage{kaulanguage}
%<crop>\ProvidesPackage{pgfcropmarks}
%<*title|meta|list|clear|environments|parts|paper|studies|language|crop>
    [2014/10/22 v1.15 Karlstad University kautools bundle]
%</title|meta|list|clear|environments|parts|paper|studies|language|crop>
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{707}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2011/02/01}{SBe's licentiate version}
% \changes{v1.1}{2011/05/06}{Initial public release}
% \changes{v1.2}{2012/12/14}{Support for babel.sty,\\Documentation added}
% \changes{v1.3}{2012/12/15}{Merged the classes' dtx files}
% \changes{v1.4}{2012/12/20}{Fixed babel.sty support}
% \changes{v1.5}{2012/12/20}{Added templates for kaucollection and kaureport}
% \changes{v1.6}{2012/12/22}{Merged the styles' dtx files}
% \changes{v1.7}{2013/04/16}{Added macros for supervisor and examiner in kaumeta}
% \changes{v1.8}{2013/04/18}{Added macros pretty printing lists in kaulist}
% \changes{v1.9}{2013/05/03}{Version bump without changes}
% \changes{v1.10}{2013/05/28}{Version bump without changes}
% \changes{v1.11}{2013/09/17}{Fixed missing file in babel support}
% \changes{v1.14}{2014/10/20}{Added refnote}
% \changes{v1.15}{2014/10/22}{Added refprefix}
%
% \GetFileInfo{\jobname.dtx}
%
% \DoNotIndex{\newcommand,\renewcommand,\newenvironment,\let}
%
% \StopEventually{}
%
% \title{The \textsf{\jobname} bundle\thanks{This document
%   corresponds to \textsf{\jobname}~\fileversion, dated \filedate.}}
% \author{Stefan Berthold \\ \texttt{stefan.berthold@kau.se}}
%
% \maketitle
% \begin{abstract}
%   The \textsf{\jobname} bundle provides tools (\LaTeX{} style files) for the \textsf{kauthesis} bundle.
% \end{abstract}
% \tableofcontents
%
% \section{Introduction}
%
% \subsection{The \textsf{kautitle} package}
%
% The \textsf{kautitle} package defines an alternative title page using the logo of Karlstad University. Note that this is not an implementation of the Karlstad University Studies title page, i.\,e., this alternative title page won't be used for your thesis.
% The logo is available from
% \begin{quote}
%   http://www.kau.se/sites/default/files/image/press/kau-logo-tryck.pdf
% \end{quote}
% and must be available in \LaTeX's search path before using this package.
%
% At the moment, this package uses a manually installed font called \textsf{aun} and it's bold version \textsf{aub}. It might not be available on your system, though, and since the font is licensed, I may not distribute it. If you do not possess the font, you have to switch to another one.
%
% Load the package without options. The title page can be created using \DescribeMacro{\maketitle}|\maketitle|. Note that the previous definition of |\maketitle| is not destroyed, but preserved in the macro \DescribeMacro{\kut@maketitle}|\kut@maketitle|. You can use it in your document as follows:
% \begin{quote}\begin{verbatim}\makeatletter
%\kut@maketitle
%\makeatother\end{verbatim}\end{quote}
%
% Two fonts are used on the title page and can be changed using the macro \DescribeMacro{\setkautitlefont}|\setkautitlefont|\marg{font}. The argument \meta{font} accepts key-value pairs where keys are |normalfont| and |titlefont| and values are any sequence of \LaTeX's font commands. For switching to your standard sans-serif font, you should add these lines to your preamble: 
% \begin{quote}\begin{verbatim}\setkautitle%
%  { normalfont=\sffamily\LARGE
%  , titlefont=\sffamily\bfseries\Huge }\end{verbatim}\end{quote}
%
% \subsection{The \textsf{kaumeta} package}
%
% The \textsf{kaumeta} package defines three macros, |\subject|, |\institute|, and |\place|, for providing additional meta data about the document and it's author. This meta data can be used, e.\,g., on the title page of the document.
%
% \subsection{The \textsf{kaulist} package}
%
% The \textsf{kaulist} package defines pretty printing macros for lists. For instance, a list ``1,2,3'' is transformed to ``1, 2, and 3''.
%
% \subsection{The \textsf{kauclear} package}
%
% This package replaces the macro |\cleardoublepage|. Empty pages with odd page numbers will not print the page number. Also, the macro |\pagestyle| is redefined. The new behaviour is to stores the page style for being able to restore it later on.
%
% \subsection{The \textsf{kauenvironments} package}
%
% This package defines the environments |researchquestions| and |contributions|.
%
% \subsection{The \textsf{kauparts} package}
%
% This packages defines a new |\part| macro, |\kaupart|. It is independend of |\part|, but you should decide yourself for one alternative only. The |\kaupart| macro adds a cover page for the new part.
%
% Use the package options |vshift| and |vstep| to adjust the placement of the thumb indices on the cover pages.
%
% \DescribeMacro{\kaupart} 
% Use |\kaupart|\oarg{meta}\marg{title} to create a numbered part with the given \meta{title}. You may use the optional argument \meta{arg} for adding meta data. This includes |body| for typing additional material on the cover page and |label| for creating a label such as usually created by |\label|. In addition, the switch |tocentry| may be set to false, if the macro should not add an entry to the table of contents.
%
% \DescribeMacro{\kaupart*}
% The starred version of |\kaupart| works exactly like the unstarred version, but creates an unnumbered part.
%
% \subsection{The \textsf{kaupaper} package}
%
% \emph{Yet no description.}
%
% \subsection{The \textsf{kaustudies} package}
%
% This package sets the page dimensions so that your document does not need to be scaled for printing. It also chooses Garamond as the standard font.
%
% You can use the package option |tinyfontswitch=false| in order to avoid the switch to sans-serif fonts when using |\tiny|. The switch is recommended by Karlstad University Studies, though, it is rather debatable whether this is necessary when using \LaTeX{} and the correct page dimensions.
%
% \subsection{The \textsf{kaulanguage} package}
%
% This packages defines a macro for supporting names in English and Swedish depending on the chosen language in \textsf{babel}.
%
% \subsection{The \textsf{pgfcropmarks} package}
%
% The package \textsf{pgfcropmarks} draws crop marks on A4~paper. This is supposed to be the last step after creating all tables, indices, and glosseries. When the package is loaded, \LaTeX{} will not create or update any auxiliary files.
%
% \section{Implementation}
%
% \subsection{The \textsf{kautitle} package}
%
% No package options are accepted.
%    \begin{macrocode}
%<*title>
\ProcessOptions\relax
%    \end{macrocode}
%
% \noindent Load dependencies.
%    \begin{macrocode}
\RequirePackage{xkeyval}
\RequirePackage{tikz}
\RequirePackage{hyphenat}
\RequirePackage{kaumeta}
%    \end{macrocode}
%
% \begin{macro}{\setkautitlefont}
% The macro |\setkautitlefont| allows to choose another than the default font for the title page. The title page has only two different font settings, |titlefont| which is used for the title text and |normalfont| which is used otherwise.
%    \begin{macrocode}
\define@cmdkeys[kut]{pkg}[kut@]{normalfont,titlefont}
\setkeys[kut]{pkg}%
  { normalfont=\fontfamily{aun}\fontsize{18}{21.6}\selectfont\bfseries
  , titlefont=\fontfamily{aub}\fontsize{28}{33.6}\selectfont }
\newcommand\setkautitlefont[1]{\setkeys[kut]{pkg}{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kut@maketitle}
% Preserve the previous version of |\maketitle|.
%    \begin{macrocode}
\let\kut@maketitle\maketitle
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\maketitle}
% The title page will consist of two background images (the Karlstad University logo), title, subject, author, and author's institute. Everything will be shaded except the title. 
%    \begin{macrocode}
\renewcommand\maketitle{%
  \thispagestyle{empty}
  \begin{tikzpicture}[remember picture, overlay]%
%    \end{macrocode}
% Clipping the title page to the dimensions of the logical page. This is interesting when the physical and the logical page do not have the same dimensions.
%    \begin{macrocode}
    \path (current page.north west) +(-4pt,4pt) node (NW) {};
    \path (current page.south east) +(4pt,-4pt) node (SE) {};
    \path (current page.north west) +(-3pt,3pt) node (NWC) {};
    \path (current page.south east) +(3pt,-3pt) node (SEC) {};
    \path[clip] (NWC) rectangle (SEC);
%    \end{macrocode}
% Background images.
%    \begin{macrocode}
    \path (current page.south west) node[rotate=243.5] {\pgfimage{kau-logo-tryck}};%
    \path (current page.north east) node[rotate=175] {\pgfimage{kau-logo-tryck}};%
%    \end{macrocode}
% Subject in the upper left corner of the page.
%    \begin{macrocode}
    \path (current page.north west) node
      [shift={(10pt,-12pt)},anchor=south west,rotate=270
      ,font=\kut@normalfont\vphantom{Xy}]
      {\@subject};
%    \end{macrocode}
% Institute in the lower right corner of the page.
%    \begin{macrocode}
    \path (current page.south east) node
      [shift={(-8pt,6pt)},anchor=north east,rotate=270
      ,rounded corners,fill=black,text=white,inner sep=8pt
      ,font=\kut@normalfont\vphantom{Xy}]
      {\@shortinstitute};
%    \end{macrocode}
% Title bar on vertically centered on the left side of the page.
%    \begin{macrocode}
    \path
      (current page.east) node[shift={(-10,0)}] (A) {}
      (current page.east) node[shift={(0,-2.5)}] (B) {}
      [shading=axis,left color=white,right color=black] (A) rectangle (B.south east)
    ;
%    \end{macrocode}
% Author below the title bar.
%    \begin{macrocode}
    \path (B) node
      [anchor=north east
      ,inner sep=8pt
      ,text=black
      ,font=\kut@normalfont\vphantom{Xy}
      ,text width=14cm,text ragged left]
      {\@author};
%    \end{macrocode}
% Shading over the entire page (slightly bigger than the clipping).
%    \begin{macrocode}
    \path[fill=white,opacity=0.90,transparency group] (NW) rectangle (SE);
%    \end{macrocode}
% Title text on the title bar. No hyphens are allowed in the title text.
%    \begin{macrocode}
    \path (B) node
      [anchor=south east,shift={(-3pt,0)}
      ,text=yellow!75!red
      ,font=\kut@titlefont\vphantom{Xy}
      ,text width=14cm,text ragged left]
      {\nohyphens{\@title}};
  \end{tikzpicture}%
  \clearpage%
}
%</title>
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{kaumeta} package}
%
% No package options are parsed.
%    \begin{macrocode}
%<*meta>
\ProcessOptions\relax
%    \end{macrocode}
%
% \noindent Dependencies are loaded.
%    \begin{macrocode}
\usepackage{ifthen}
%    \end{macrocode}
%
% \begin{macro}{\subject}
% The macro |\subject|\marg{subject} can be used to set the subject of the document. The last \meta{subject} set will be available in the macro \DescribeMacro{\@subject}|\@subject|.
%    \begin{macrocode}
\newcommand*\@subject{}
\newcommand\subject[1]{\renewcommand*\@subject{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\institute}
% The macro |\institute|\oarg{short}\marg{institute} can be used to set the institute of the document's author. It is possible to provide a shorter version of the institue in the optional argument \meta{short}. If not explicitly set, the short version is the same as the long version \meta{institute}. The values are available in the macros \DescribeMacro{\@institute}|\@institute| and \DescribeMacro{\@shortinstitute}|\@shortinstitute|.
%    \begin{macrocode}
\newcommand*\@institute{}
\newcommand*\@shortinstitute{}
\newcommand\institute[2][]{%
  \renewcommand*\@institute{#2}%
  \ifthenelse{\equal{#1}{}}{%
    \renewcommand*\@shortinstitute{#2}%
  }{%
    \renewcommand*\@shortinstitute{#1}%
  }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\place}
% The macro |\place|\marg{place} can be used to set the place of the document's author. The last \meta{place} set will be available in the macro \DescribeMacro{\@place}|\@place|.
%    \begin{macrocode}
\newcommand*\@place{}
\newcommand\place[1]{\renewcommand*\@place{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\supervisor}
% \marg{name} sets the supervisor's name for the \textsf{kaumasters} class.
%    \begin{macrocode}
\newcommand\@supervisor{}
\newcommand\supervisor[1]{\renewcommand*\@supervisor{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\examiner}
% \marg{name} sets the examiner's name for the \textsf{kaumasters} class.
%    \begin{macrocode}
\newcommand\@examiner{}
\newcommand\examiner[1]{\renewcommand*\@examiner{#1}}
%</meta>
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{kaulist} package}
%
% No options are parsed.
%
%    \begin{macrocode}
%<*list>
\ProcessOptions\relax
\RequirePackage{kaulanguage}
%    \end{macrocode}
%
% For |\prettylist|, the packages \textsf{pgffor}, \textsf{pgfmath}, and \textsf{pgfkeys} are required.
%
%    \begin{macrocode}
\RequirePackage{tikz}
%    \end{macrocode}
%
% \begin{macro}{\commasign}
% defines a comma (``,''), if one is to be used before ``and''.
%    \begin{macrocode}
\AtBeginDocument{%
  \setname{commasign}{}{,}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\andname}
% definses the word used as ``and''.
%    \begin{macrocode}
\AtBeginDocument{%
  \setname{andname}{and}{och}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\prettylist}
% \marg{list} transformes a comma separated list into a list in natural language.
%    \begin{macrocode}
\newcommand\prettylist[1]{%
%    \end{macrocode}
% The number of list elements is stored in |\num|.
%    \begin{macrocode}
  \foreach[count=\xi] \x in #1 {}%
  \let\num=\xi%
%    \end{macrocode}
% The first element is just printed without any changes.
%    \begin{macrocode}
  \foreach[count=\xi] \x in #1 {%
    \ifnum \xi=1%
      \x%
%    \end{macrocode}
% The last element is printed with preceding |\commasign|, if there are more than two elements in the list, and otherwise without.
%    \begin{macrocode}
    \else%
      \ifnum \xi=\num%
        \ifnum \num=2%
          {} \andname{} \x%
        \else%
          \commasign{} \andname{} \x%
        \fi%
%    \end{macrocode}
% Elements in between the first and the last one are printed with a preceding hard-coded comma sign (not |\commasign|).
%    \begin{macrocode}
      \else%
        , \x%
      \fi%
    \fi%
  }%
}%
%</list>
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{kauclear} package}
%
% No options are parsed.
%
%    \begin{macrocode}
%<*clear>
\ProcessOptions\relax
%    \end{macrocode}
%
% \begin{macro}{\kuc@currentpagestyle}
% The page style is stored in |\kuc@currentpagestyle|. Default: |plain|
%    \begin{macrocode}
\newcommand\kuc@currentpagestyle{plain}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pagestyle}
% The macro |\pagestyle| is redefined to update the page style in |\kuc@currentpagestyle|.
%    \begin{macrocode}
\let\pagestyle@orig\pagestyle
\renewcommand\pagestyle[1]{%
  \renewcommand\kuc@currentpagestyle{#1}%
  \pagestyle@orig{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\kuc@restorepagestyle}
% The page style can be restored with |\kuc@restorepagestyle| after (temporarily) switching to another one using |\pagestyle@orig|.
%    \begin{macrocode}
\newcommand\kuc@restorepagestyle{%
  \pagestyle@orig{\kuc@currentpagestyle}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cleardoubpage@orig}
% The previous definition of |\cleardoublepage| is preserved in |\cleardoublepage@orig|.
%    \begin{macrocode}
\let\cleardoubpage@orig\cleardoublepage
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cleardoublepage}
% The macro |\cleardoublepage| is redefined. The new definition switches temporarily to the page style |empty|.
%    \begin{macrocode}
\renewcommand\cleardoublepage{%
  \clearpage%
  \pagestyle@orig{empty}%
  \cleardoubpage@orig%
  \kuc@restorepagestyle%
}
%</clear>
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{kauenvironments} package}
%
% No package options are parsed.
%
%    \begin{macrocode}
%<*environments>
\ProcessOptions\relax
%    \end{macrocode}
%
% \noindent Load dependencies.
%    \begin{macrocode}
\RequirePackage{xspace}
\RequirePackage{xcolor}
%    \end{macrocode}
%
% \begin{environment}{researchquestions}
% The environment is an enumeration derived from |enumerate|. The argument of |\item|\oarg{question} is used to formulate the research question.
%    \begin{macrocode}
\newenvironment{researchquestions}%
  {\begin{enumerate}%
    \let\kue@item\item%
    \renewcommand\item[1][Research question]%
      {\kue@item\emph{##1}\nopagebreak\par}%
  }%
  {\end{enumerate}}%
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{contributions}
% The environment is an enumeration derived from |enumerate|. The argument of |\item|\oarg{contrib} is used to formulate the contribution.
%    \begin{macrocode}
\newenvironment{contributions}%
  {\begin{enumerate}%
    \let\kue@item\item%
    \renewcommand\item[1][%
      \textcolor{red}{\emph{write your contribution between brackets 
        as optional argument of \texttt{\string\item}.}}]%
      {\kue@item\emph{##1}\xspace}%
  }%
  {\end{enumerate}}%
%</environments>
%    \end{macrocode}
% \end{environment}
%
% \subsection{The \textsf{kauparts} package}
%
%    \begin{macrocode}
%<*parts>
\RequirePackage{xkeyval}

\define@cmdkeys[kup]{pkg}[kup@]{vshift,vstep}
\setkeys[kup]{pkg}{vshift=2,vstep=0.8}

\ProcessOptionsX[kup]<pkg>

\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage{suffix}
\RequirePackage{tikz}
\usetikzlibrary{positioning}

\define@cmdkeys[kup]{part}[kup@]{body,label}
\define@boolkeys[kup]{part}[kup@]{tocentry}

\newcounter{kup@part}
\newcounter{kup@vertical}
\setcounter{kup@vertical}{0}

\newcommand*\@titlepagestyle{empty}
\newcommand\titlepagestyle[1]{\renewcommand*\@titlepagestyle{#1}}

\newcommand\kup@partheadline[2]{%
  \path[node distance=1ex] (current page.north east) +(3pt,\kup@vshift+\kup@vstep*\arabic{kup@vertical}) %
    node%
      [ anchor=north east%
      , minimum width=2cm+3pt%
      %, minimum height=7mm%
      %, draw=black%
      %, fill=black%
      , left color=white%
      , right color=black%
      , text=white%
      , font=\LARGE\bfseries%
      ] (bar) {#1}%
    node[base left=of bar,font=\LARGE\bfseries] {#2};%
}
%    \end{macrocode}
% \begin{macro}{\kaupart}
%    \begin{macrocode}
\newcommand\kaupart[2][]{%
  \cleardoublepage%
  \thispagestyle{\@titlepagestyle}%
  \stepcounter{kup@part}%
  \setkeys[kup]{part}{body=\relax,label=,tocentry=true,#1}%
  \providecommand\phantomsection{}%
  \phantomsection%
  \ifkup@tocentry%
    \addcontentsline{toc}{part}{\numberline{\Roman{kup@part}}\textsc{#2}}%
  \fi%
  \renewcommand\@currentlabel{\Roman{kup@part}}%
  \ifthenelse{\equal{\kup@label}{}}{}{\label{\kup@label}}%
  \begin{tikzpicture}[remember picture,overlay,yscale=-1]%
    \kup@partheadline{\Roman{kup@part}}{#2}%
  \end{tikzpicture}%
  \kup@body
  \stepcounter{kup@vertical}%
  \cleardoublepage%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\kaupart*}
%    \begin{macrocode}
\WithSuffix\newcommand\kaupart*[2][]{%
  \cleardoublepage%
  \thispagestyle{\@titlepagestyle}%
  \setkeys[kup]{part}{body=\relax,tocentry=true,#1}%
  \providecommand\phantomsection{}%
  \phantomsection%
  \ifkup@tocentry%
    \addcontentsline{toc}{part}{\textsc{#2}}%
  \fi%
  \begin{tikzpicture}[remember picture,overlay,yscale=-1]%
    \kup@partheadline{\vphantom{X}}{#2}%
  \end{tikzpicture}%
  \kup@body
  \stepcounter{kup@vertical}%
  \cleardoublepage%
}
%</parts>
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{kaupaper} package}
%
%    \begin{macrocode}
%<*paper>
\RequirePackage{xkeyval}
\PassOptionsToPackage{hypertexnames=false}{hyperref}

\define@cmdkeys[kua]{paper}[kua@]{author,title,subtitle,refprefix,reference,refnote,email,refstr,vanity,subdelimiter,label,summary,limitations,participation}
\define@cmdkeys[kua]{paperlist}[kua@]{printparticipation,tocline}
\setkeys[kua]{paper}{refstr=\reprintedname}

\ProcessOptionsX[kua]<paper>

\RequirePackage{kauparts}
\RequirePackage{ifthen}
\RequirePackage{tikz}

\RequirePackage{ragged2e}
\RequirePackage{hyphenat}

\RequirePackage{kaulanguage}

\AtBeginDocument{%
  \setname{reprintedname}{Reprinted from}{Ursprungligen publicertad i}%
  \setname{appendedpapersname}{List of Appended Papers}{Bifogade publiceringar}%
  \setname{participationname}{Comments on my Participation}{Kommentarer p\aa{} min medverka}%
  \setname{papername}{Paper}{Publicering}%
}

\newcounter{kua@section}
\newcounter{kua@equation}
\newcounter{kua@figure}
\newcounter{kua@table}

\newcounter{kua@paper}

\providecommand\thepaper{}
\providecommand\thepapertitle{}

\newcommand\kua@warning\relax
\newcommand\kua@dowarn{\gdef\kua@warning{\@latex@warning@no@line{List data created from the kaupaper environment was outdated. Rerun to get the lists right}}}
\AtEndDocument{\kua@warning}

\newcommand\kua@listof[4]{%
  \IfFileExists{\jobname.#1}%
    {% check whether empty file
      \newread\reader%
      \openin\reader\jobname.#1%
      \read\reader to \readmacro%
      \ifeof\reader%
        \textcolor{red}{\ldots{} will be available after the next \LaTeX{} run.}%
        \@starttoc{#1}%
        %\AtEndDocument{\@latex@warning@no@line{Rerun to get the list of #2 right}}%
        \kua@dowarn%
      \else% file not empty -> create list
        #3\@starttoc{#1}#4%
      \fi%
    }%
    {% file does not exist
      \textcolor{red}{\ldots{} will be available after the next \LaTeX{} run.}%
      \@starttoc{#1}%
      %\AtEndDocument{\@latex@warning@no@line{Rerun to get the list of #2 right}}%
      \kua@dowarn%
    }%
}
%    \end{macrocode}
% \begin{macro}{\listofpapers}
%    \begin{macrocode}
\newcommand\listofpapers[1][]{%
  \setkeys[kua]{paperlist}{printparticipation=yes,tocline=yes,#1}
  \section*{\appendedpapersname}%
  \ifthenelse{\equal{\kua@tocline}{yes}}{%
    \addcontentsline{toc}{section}{\appendedpapersname}%
  }{}%
  \kua@listof{pap}{appended papers}{%
    \begin{enumerate}%
    \renewcommand\theenumi{\textbf{\Roman{enumi}}}%
  }{\end{enumerate}}%
  \ifthenelse{\equal{\kua@printparticipation}{yes}}{%
    \subsection*{\participationname}%
    \kua@listof{pcp}{participation in appended papers}{}{}%
  }{}%
}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}

\newcommand\l@paper[2]{%
  \item #1%
}

\newcommand\listofsummaries{%
  \kua@listof{sum}{paper summaries}{}{}%
}

\newcommand\l@summary[2]{%
  #1%
}

\newcommand\l@limit[2]{%
  %\paragraph{Limitations.}
  #1%
}

\newcommand\l@participation[2]{%
  #1%
}

\newcommand\papercover{%
  \begin{tikzpicture}[remember picture,overlay]%
    \path (current page.center)%
      node%
        [ node distance=\baselineskip%
        , text width=\textwidth%
        , text centered%
        ] (refstr) {\kua@refstr};%
      \ifthenelse{\equal{\kua@subtitle}{}}{%
        \node%
          [ node distance=1.5\baselineskip%
          , above=of refstr%
          , text width=\textwidth%
          , text centered%
          , font=\LARGE\bfseries%
          ] {\nohyphens{\kua@title}};%
      }{%
        \node%
          [ node distance=1.5\baselineskip%
          , above=of refstr%
          , text width=\textwidth%
          , text centered%
          , font=\large\bfseries%
          ] (sub) {\nohyphens{\kua@subtitle}};%
        \node%
          [ node distance=1pt%
          , above=of sub%
          , text width=\textwidth%
          , text centered%
          , font=\LARGE\bfseries%
          ] {\nohyphens{\kua@title}};%
      }%
      \node%
        [ node distance=\baselineskip%
        , below=of refstr%
        , text width=\textwidth%
        , text centered%
        , font=\large%
        ] {\nohyphens{\kua@reference}\ifthenelse{\equal{\kua@refnote}{}}{}{\mbox{}\\\medskip\nohyphens{\kua@refnote}}}%
    ;%
  \end{tikzpicture}%
}

\newenvironment{kaupaper}[1][]{%
  \setcounter{kua@section}{\value{section}}%
  \setcounter{kua@equation}{\value{equation}}%
  \setcounter{kua@figure}{\value{figure}}%
  \setcounter{kua@table}{\value{table}}%
  \setcounter{section}{0}%
  \setcounter{equation}{0}%
  \setcounter{figure}{0}%
  \setcounter{table}{0}%
  \setkeys[kua]{paper}{subtitle=,vanity=,subdelimiter={---},refprefix=,refnote=,label=,summary={\string\textcolor{red}{Use the \string\texttt{summary} key in the \string\texttt{kaupaper} environment to add a summary.}},participation={\string\textcolor{red}{Use the \string\texttt{participation} key in the \string\texttt{kaupaper} environment to add a comment.}},limitations={},#1}%
  \setcounter{kua@paper}{\value{kup@part}}\stepcounter{kua@paper}%
  \kaupart[tocentry=false,label=\kua@label,body=\papercover\kua@vanity]{\papername}%
  \ifthenelse{\equal{\kua@subtitle}{}}%
    {\ifthenelse{\equal{\kua@refnote}{}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title. \kua@refprefix\kua@reference.}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title. \kua@refprefix\kua@reference.\smallskip\\\kua@refnote}}%
     \addcontentsline{toc}{part}{\textsc{\papername} \Roman{kua@paper}: \\\kua@title}}%
    {\ifthenelse{\equal{\kua@refnote}{}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title\kua@subdelimiter\kua@subtitle. \kua@refprefix\kua@reference.}}%
      {\addcontentsline{pap}{paper}{\kua@author. \kua@title\kua@subdelimiter\kua@subtitle. \kua@refprefix\kua@reference.\smallskip\\\kua@refnote}}%
     \addcontentsline{toc}{part}{\textsc{\papername} \Roman{kua@paper}: \\\kua@title\kua@subdelimiter\kua@subtitle}}%
  \addcontentsline{sum}{summary}{\string\subsubsection*{\papername~\Roman{kua@paper} -- \kua@title}\kua@summary}%
  \ifthenelse{\equal{\kua@limitations}{}}{}{%
    \addcontentsline{sum}{limit}{\kua@limitations}}%
  \addcontentsline{pcp}{participation}{\string\paragraph{\papername~\Roman{kua@paper}}\kua@participation}%
  \renewcommand*\thepaper{\papername~\Roman{kua@paper}}%
  \renewcommand*\thepapertitle{\kua@title}%
  \renewcommand\maketitle{%
    \thispagestyle{plain}%
    \centering%
      \Large\bfseries%
      \vspace*{0.15\textheight}%
      \kua@title\par%
      \addvspace{1ex}%
      \ifthenelse{\equal{\kua@subtitle}{}}{}{\large\kua@subtitle}%
      \par\addvspace{\baselineskip}%
      \normalsize%
      \kua@author\\[0.25\baselineskip]%
      \normalfont%
      \kua@email%
    \par\addvspace{2\baselineskip}\justifying%
  }%
}{%
  \setcounter{section}{\value{kua@section}}%
  \setcounter{equation}{\value{kua@equation}}%
  \setcounter{figure}{\value{kua@figure}}%
  \setcounter{table}{\value{kua@table}}%
  \clearpage%
}
%</paper>
%    \end{macrocode}
%
% \subsection{The \textsf{kaustudies} package}
%
%    \begin{macrocode}
%<*studies>
\RequirePackage{xkeyval}

\define@boolkey[kus]{pkg}[kus@]{tinyfontswitch}[true]{}

\presetkeys[kus]{pkg}{tinyfontswitch}{}
\ProcessOptionsX[kus]<pkg>

\RequirePackage[twoside]{geometry}
\RequirePackage{garamondx}
\RequirePackage[garamondx,cmbraces]{newtxmath}

\geometry
  { paperwidth=165mm
  , paperheight=242mm
  , inner=27mm
  , outer=27mm
  , top=24mm
  , bottom=22mm
  }

\ifkus@tinyfontswitch
  \let\kus@tiny@orig\tiny
  \renewcommand*\tiny{\sffamily\kus@tiny@orig}
\fi
%</studies>
%    \end{macrocode}
%
% \subsection{The \textsf{kaulanguage} package}
%
%    \begin{macrocode}
%<*language>
\ProcessOptions\relax
\newif\ifbabel
\babelfalse
\AtBeginDocument{%
  \@ifpackageloaded{babel}%
    {\babeltrue}%
    {\babelfalse}%
}
%    \end{macrocode}
% \begin{macro}{\setname}\marg{macro name}\marg{english}\marg{swedish}
%    \begin{macrocode}
\newcommand\setname[3]{%
  \IfFileExists{swedish.ldf}{%
    \ifbabel%
      \expandafter\edef\csname #1\endcsname{\noexpand\iflanguage{swedish}{#3}{#2}}%
    \else%
      \expandafter\edef\csname #1\endcsname{#2}%
    \fi%
  }%
  {\expandafter\edef\csname #1\endcsname{#2}}%
}
%</language>
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{pgfcropmarks} package}
%
% No options are parsed.
%
%    \begin{macrocode}
%<*crop>
\ProcessOptions\relax
\RequirePackage{pgfpages}%
%    \end{macrocode}
%
% \noindent No files are created or updated.
%    \begin{macrocode}
\nofiles%
%    \end{macrocode}
%
% \noindent Boolean, true on odd pages.
%    \begin{macrocode}
\newif\if@kus@isodd%
\@kus@isoddtrue%
%    \end{macrocode}
%
% \begin{macro}{\cropmarklen}
% The length of the crop mark lines.
%    \begin{macrocode}
\newlength{\cropmarklen}\setlength{\cropmarklen}{40pt}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cropmarksep}
% The space between cropmark and paper edge.
%    \begin{macrocode}
\newlength{\cropmarksep}\setlength{\cropmarksep}{15pt}%
%    \end{macrocode}
% \end{macro}
%
% \noindent The cropmark page layout.
%    \begin{macrocode}
\pgfpagesdeclarelayout{cropmarks}%
{%
}%
{%
  \pgfpagesphysicalpageoptions%
  {%
    logical pages=1,%
    physical height=297mm,%
    physical width=210mm%
  }%
  \pgfpageslogicalpageoptions{1}%
  {%
    border code=%
      \if@kus@isodd
        \global\@kus@isoddfalse
        \pgfsetlinewidth{0.6pt}%
        \pgfusepath{discard}%
        \pgfmoveto{\pgfpoint{-\cropmarksep}{0pt}}%
          \pgflineto{\pgfpoint{-\cropmarklen}{0pt}}%
        \pgfmoveto{\pgfpoint{0pt}{-\cropmarksep}}%
          \pgflineto{\pgfpoint{0pt}{-\cropmarklen}}%
        \pgfmoveto{\pgfpoint{\paperwidth+\cropmarksep}{0pt}}%
          \pgflineto{\pgfpoint{\paperwidth+\cropmarklen}{0pt}}%
        \pgfmoveto{\pgfpoint{\paperwidth}{-\cropmarksep}}%
          \pgflineto{\pgfpoint{\paperwidth}{-\cropmarklen}}%
        \pgfmoveto{\pgfpoint{-\cropmarksep}{\paperheight}}%
          \pgflineto{\pgfpoint{-\cropmarklen}{\paperheight}}%
        \pgfmoveto{\pgfpoint{0pt}{\paperheight+\cropmarksep}}%
          \pgflineto{\pgfpoint{0pt}{\paperheight+\cropmarklen}}%
        \pgfmoveto{\pgfpoint{\paperwidth}{\paperheight+\cropmarksep}}%
          \pgflineto{\pgfpoint{\paperwidth}{\paperheight+\cropmarklen}}%
        \pgfmoveto{\pgfpoint{\paperwidth+\cropmarksep}{\paperheight}}%
          \pgflineto{\pgfpoint{\paperwidth+\cropmarklen}{\paperheight}}%
        \pgfusepath{stroke}%
      \else
        \global\@kus@isoddtrue
      \fi,%
    center=\pgfpoint{.5\pgfphysicalwidth}{.5\pgfphysicalheight}%
  }%
}%
%    \end{macrocode}
%
% \noindent Activate the cropmark page layout.
%    \begin{macrocode}
\pgfpagesuselayout{cropmarks}%
%</crop>
%    \end{macrocode}
%
% \Finale
\endinput
% vim: ft=tex:sw=2:sts=2:et:nu:ai