-
Notifications
You must be signed in to change notification settings - Fork 2
/
plainsection.tex
222 lines (188 loc) · 5.81 KB
/
plainsection.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
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
% plainsection.tex
% Dorai Sitaram
% Last change 2016-12-21
\let\maybeendinput\relax
\ifx\shipout\UnDeFiNeD
\let\maybeendinput\endinput
\fi\maybeendinput
\edef\atcatcodebeforeplainsection{%
\noexpand\catcode`\noexpand\@=\the\catcode`\@}
\catcode`\@11
% Sections
\def\tracksectionchangeatlevel#1{%
\expandafter\let\expandafter\thiscount
\csname sectionnumber#1\endcsname
\ifx\thiscount\relax
\expandafter\expandafter\csname newcount\endcsname
\csname sectionnumber#1\endcsname
\csname sectionnumber#1\endcsname=0
\fi
\expandafter\advance\csname sectionnumber#1\endcsname by 1
\ifx\doingappendix0%
\edef\@currentlabel{\the\csname sectionnumber1\endcsname}%
\else
\edef\@currentlabel{\appendixchar{\the\csname
sectionnumber1\endcsname}}%
\fi
\count255=0
\loop
\advance\count255 by 1
\ifnum\count255=1
\else\edef\@currentlabel{\@currentlabel.\the\csname
sectionnumber\the\count255\endcsname}%
\fi
\ifnum\count255<#1%
\repeat
\loop
\advance\count255 by 1
\expandafter\let\expandafter\nextcount\csname
sectionnumber\the\count255\endcsname
\ifx\nextcount\relax
\let\continue0%
\else
\csname sectionnumber\the\count255\endcsname=0
\let\continue1\fi
\ifx\continue1%
\repeat}
\def\appendixchar#1{\ifcase#1\or A\or B\or C\or D\or E\or F\or
G\or H\or I\or J\or K\or L\or M\or N\or O\or P\or Q\or R\or S\or
T\or U\or V\or W\or X\or Y\or Z\else AA\fi}
\newcount\secnumdepth
\secnumdepth=3
\def\sectiond#1{\count255=#1%
\ifx\usingchapters1\advance\count255 by 1 \fi
\edef\sectiondlvl{\the\count255 }%
\futurelet\sectionnextchar\sectiondispatch}
\def\sectiondispatch{\ifx\sectionnextchar*%
\def\sectioncontinue{\sectionstar{\sectiondlvl}}\else
\ifnum\sectiondlvl>\secnumdepth
\def\sectioncontinue{\sectionhelp{\sectiondlvl}{}}\else
\tracksectionchangeatlevel{\sectiondlvl}%
\def\sectioncontinue{\sectionhelp{\sectiondlvl}%
{\@currentlabel}}\fi\fi
\sectioncontinue}
\def\sectionstar#1*{\sectionhelp{#1}{}}
\def\sectionhelp#1#2{%
\edef\sectiondepth{#1}%
\def\sectionnr{#2}%
\immediate\openout\sectionQscratchfileport Z-sec-temp
\begingroup
\def\do##1{\catcode`##1=11 }\dospecials
\catcode`\{=1 \catcode`\}= 2
\sectionheader}
% Vanilla section-header look -- change this macro for new look
\def\sectionheader#1{\endgroup
\immediate\write\sectionQscratchfileport {#1}%
\immediate\closeout\sectionQscratchfileport
\vskip -\lastskip
\ifnum\sectiondepth>\tocdepth\else
\writenumberedtocline{\sectiondepth}{\sectionnr}{#1}%
\fi
\vskip1.5\bigskipamount
\goodbreak %???
\noindent
\hbox{\vtop{\pretolerance 10000
\raggedright
\noindent\bf
\ifx\sectionnr\empty\else
\sectionnr\enspace\fi
\input Z-sec-temp }}%
\nobreak
\smallskip
%\noindent
}
% \edef\temp{\write\tocout{\string\hskip#1\space em\string\relax\space #2%
% \string\vtop{\string\hsize=.7\string\hsize
% \string\noindent\string\raggedright\space #3}\string\par}}\temp
\def\section{\sectiond1}
\def\subsection{\sectiond2}
\def\subsubsection{\sectiond3}
\def\paragraph{\sectiond4}
\def\subparagraph{\sectiond5}
\let\usingchapters0
\def\chapter{\global\let\usingchapters1%
\global\footnotenumber=0
\futurelet\chapternextchar\chapterdispatch}
\def\chapterdispatch{\ifx\chapternextchar*%
\let\chaptercontinue\chapterstar\else
\tracksectionchangeatlevel{1}%
\def\chaptercontinue{\chapterhelp{\@currentlabel}}\fi
\chaptercontinue}
\def\chapterstar*{\chapterhelp{}}
\def\chapterhelp#1{%
% #1=number #2=heading-text
\def\chapternr{#1}%
\immediate\openout\sectionQscratchfileport Z-sec-temp
\begingroup
\def\do##1{\catcode`##1=11 }\dospecials
\catcode`\{=1 \catcode`\}=2
\chapterheader}
\def\chapterheader#1{\endgroup
\immediate\write\sectionQscratchfileport {#1}%
\immediate\closeout\sectionQscratchfileport
\writenumberedtocline{1}{\chapternr}{#1}%
\vfill\eject
\null\vskip3em
\noindent
\ifx\chapternr\empty\hbox{~}\else
\ifx\doingappendix0%
\hbox{\bf Chapter \chapternr}\else
\hbox{\bf Appendix \chapternr}\fi\fi
\vskip 1em
\noindent
\hbox{\bf\vtop{%\hsize=.7\hsize
\pretolerance 10000
\noindent\raggedright\input Z-sec-temp }}%
\nobreak\vskip3em
%\noindent
}
\let\doingappendix=0
\def\appendix{\let\doingappendix=1
\csname sectionnumber1\endcsname=0
\relax}
% enumerate
\def\enumerate{\par\begingroup
\advance\@itemdepth by 1
\expandafter\csname newcount\endcsname\enumeratenumber
\enumeratenumber=0
\advance\leftskip\parindent
\smallbreak
\def\item{\smallbreak\noindent
\advance\enumeratenumber by 1
\ifnum\@itemdepth=1
\edef\enumeratemark{\the\enumeratenumber.}\else
\ifnum\@itemdepth=2
\count255=\the\enumeratenumber
\advance\count255 by -1 \advance\count255 by `a
\edef\enumeratemark{(\noexpand\char\the\count255 )}\else
\ifnum\@itemdepth=3
\edef\enumeratemark{\noexpand\romannumeral\the\enumeratenumber.}\else
\ifnum\@itemdepth=4
\count255=\the\enumeratenumber
\advance\count255 by -1 \advance\count255 by `A
\edef\enumeratemark{\noexpand\char\the\count255 .}\else
\edef\enumeratemark{\the\enumeratenumber.}\fi\fi\fi\fi
\edef\@currentlabel{\enumeratemark}% needed?
\llap{\enumeratemark\enspace}\ignorespaces}}
\def\endenumerate{\smallbreak\smallbreak\endgroup\par}
% itemize
\newcount\@itemdepth
\@itemdepth=0
\def\labelitemi{$\bullet$}
\def\labelitemii{$-$}
\def\labelitemiii{$\star$}
\def\labelitemiv{$\circ$}
\def\itemize{\par\begingroup
\ifnum\@itemdepth>3
\message{Too deeply nested.}%
\fi
\advance\@itemdepth by 1
\advance\leftskip\parindent
\smallbreak
\def\item{\smallbreak\noindent
\llap{\csname labelitem\romannumeral
\the\@itemdepth\endcsname\enspace}%
\ignorespaces}}
\def\enditemize{\smallbreak\smallbreak\endgroup\noindent}
\atcatcodebeforeplainsection
% end of file