-
Notifications
You must be signed in to change notification settings - Fork 0
/
kartei.tableofcontents.tex
134 lines (132 loc) · 4.33 KB
/
kartei.tableofcontents.tex
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
%
% * ----------------------------------------------------------------
% * "THE BEER-WARE LICENSE" (Revision 42/023):
% * Ronny Bergmann <[email protected]> wrote this file. As long as
% * you retain this notice you can do whatever you want with this
% * stuff. If we meet some day and you think this stuff is worth it,
% * you can buy me a beer or a coffee in return.
% * ----------------------------------------------------------------
%
%
% Kartei Source Code of the table of contents
% provided by the class option 'toc'
%
% Last Change: Kartei 1.9, 2012/01/04
%
\makeatletter
% Collect the entries
%\newcommand{\card@tocinner}{}
%\newtoks\card@tocinner
%\newcommand*\card@InitTOC{\card@tocinner{}}
\newcommand{\card@tocinner}{}
% count for midrules
\newcounter{card@toccount}
\setcounter{card@toccount}{0} % zero for noninitialized
% general head used in the first line
\newcommand{\card@tochead}{
\begin{longtable}{>{\raggedleft}m{2.5em}m{\textwidth-6\tabcolsep-8em}m{5.5em}}%
\toprule\textbf{\#}&\textbf{Karte}&\textbf{Notizen}\\\midrule%
\endfirsthead%
\toprule\textbf{\#}&\textbf{Karte}&\textbf{Notizen}\\\midrule%
\endhead%
\addlinespace[3\cmidrulesep]\bottomrule%
\endfoot
}
% foot used by every section and at the end of the TOC
\newcommand{\card@tocfoot}{\end{longtable}}
%
% Internal command to fix the layout of the cells, such that the first cell stays vertically middle.
%
\newcommand{\card@titlecell}[1]{%
\begingroup\sbox0{\begin{minipage}{\textwidth-6\tabcolsep-8em}\raggedright#1\end{minipage}}%
\xdef\finalheight{\the\dimexpr\ht0+\dp0%+\smallskipamount
\relax}%
\endgroup
% \vspace{1.5\cmidrulesep}
\begin{minipage}[t][\finalheight][t]{\textwidth-6\tabcolsep-8em}\raggedright#1\end{minipage}%&
% \vspace{\cmidrulesep}
}
% Add one Card (line of TOC) to the complete TOC
% Call this for adding a line.
%
% Parameter 1: Number of the card
% Parameter 2: Title of the card
% older with tokens
%\newcommand\card@addentry[2]{%
%\begingroup\edef\x{\endgroup%
% \noexpand\card@tocinner{\the\card@tocinner%
% #1 & \unexpanded{#2} &}}\x%
%}
\newcommand\card@addentry[2]{%
\protected@edef\@tempa{#1 & \unexpanded{\card@titlecell{#2}} &}%
\expandafter\g@addto@macro\expandafter\card@tocinner\expandafter{\@tempa}%
}
\newcommand{\card@add}[2]{%
\ifnum\value{card@toccount}=0%
% Init
\g@addto@macro\card@tocinner{\card@tochead}%
\setcounter{card@toccount}{1}%
\card@addentry{#1}{#2}% Works if called directly but not if called from a newcommand ?!
\else%
\addtocounter{card@toccount}{1}%
\ifnum\value{card@toccount}>6% section started
\setcounter{card@toccount}{1}% Don't midrule nor end line after section
\else
\ifnum\value{card@toccount}>5%
\g@addto@macro\card@tocinner{\\\addlinespace[3\cmidrulesep]\cmidrule{2-3}}%
\setcounter{card@toccount}{1}%
\else%
\g@addto@macro\card@tocinner{\\\addlinespace[3\cmidrulesep]}%
\fi%
\fi
\card@addentry{#1}{#2}%
\fi%
}
% Command building one TOC line of a section
% (and starting the toc if neccessary)
%
% Parameter 1: section title
\newcommand{\card@addsec}[2]{%
\ifnum\value{card@toccount}=0%
\setcounter{card@toccount}{6}% force no new line
\else%
\setcounter{card@toccount}{6}%
\g@addto@macro\card@tocinner{\card@tocfoot}%
\fi
\protected@edef\@tempb{{\Large #1 \noexpand{#2}}}
\expandafter\g@addto@macro\expandafter\card@tocinner\expandafter{\@tempb}%
\g@addto@macro\card@tocinner{\card@tochead}
}
% Command building one TOC line of a subsection
% (and starting the toc if neccessary)
%
% only for internal use
%
% Parameter 1: subsection title
\newcommand{\card@addsubsec}[2]{%
\ifnum\value{card@toccount}=0%
\setcounter{card@toccount}{5}%
\g@addto@macro\card@tocinner{\card@tochead}%
\g@addto@macro\card@tocinner{&&\\}
\else%
\ifnum\value{card@toccount}<6%
\g@addto@macro\card@tocinner{\\&&\\}%
\else
\g@addto@macro\card@tocinner{\\}%
\fi%
\setcounter{card@toccount}{5}%
\fi%
\protected@edef\@tempc{& #1 \noexpand{#2}&}
\expandafter\g@addto@macro\expandafter\card@tocinner\expandafter{\@tempc}%
%\g@addto@macro\card@tocinner{&}
}
\newcommand{\card@makeTOC}{
{\centering\Large%\textsc
{Karten\"ubersicht}}
\ifnum\value{card@toccount}>0%
\card@tocinner
\end{longtable}
\else
{\emph{Es liegen keine Karten vor.}}
\fi%
}