summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/iitem/iitem.dtx
blob: 2e1b4e5b5ecd68244b2abf61bcae68444327250a (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
% \iffalse meta-comment 
% 
% Copyright (C) 2013 by Ben Vitecek
% 
% This file 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 2008-05-04 or later. 
% 
% \fi
%
% \iffalse 
%<*driver> 
\documentclass{ltxdoc} 
\usepackage{iitem} 
\usepackage[ngerman,english]{babel}
\usepackage[T1]{fontenc}
\usepackage[applemac]{inputenc}
\usepackage{paralist, xcolor, listings,ragged2e} 
\usepackage{lmodern} 
\usepackage{microtype}
\usepackage[colorlinks=true, linkcolor=blue!70!black]{hyperref} 

\lstset{%
basicstyle=\small\sffamily,
language=[LaTeX]TeX,   
breaklines=true,
frame=single,
%framexleftmargin=8mm, 
framexrightmargin=0mm, 
%xleftmargin=0mm,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
backgroundcolor=\color{green!5},
texcsstyle=*\color{blue},
rulecolor=\color{red},
morekeywords={\iitem, \iiitem, \ivtem},
keywordstyle=\color[rgb]{0,0,1},                    % keywords
commentstyle=\color[rgb]{1,0,0},    % comments
stringstyle=\color[rgb]{0.627,0.926,0.941},  % strings
columns=fullflexible ,
literate={\{ }{\textcolor{green!70!black}{\{}}1
{\}}{\textcolor{green!70!black}{\}}}1
{\%}{\textcolor{green!5}{}}1     
{]}{\textcolor{black}{]}}1     
{\ }{\textcolor{blue}{\ }}1     
}%


\EnableCrossrefs 
\CodelineIndex 
\RecordChanges 

\makeatletter 
\g@addto@macro\@marginparreset{\Huge\RaggedLeft\vspace{-0.5ex}} \makeatother


\begin{document}
\DocInput{iitem.dtx} 
\end{document} 
%</driver> 
% \fi
%
%
% \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} {2013/01/19} {Initial version}
%
%
%
% \GetFileInfo{iitem.sty}
%
%\DoNotIndex {\begin{tikzpicture},\end{tikzpicture}}
%\DoNotIndex {\verb, \DeclareRobustCommandx}
%\DoNotIndex {=\verb}
%\DoNotIndex {\verb||}
%\DoNotIndex {\draw,\fill,\DeclareRobustCommand, \colorlet,\shade}
%\DoNotIndex {\xspace,\begin,\end}
%
%
%
%
%\title{Package \textsf{iitem}\thanks{This document corresponds to \textsf{iitem}~\fileversion, dated~\filedate.}}
%\author{Ben Vitecek \\ \texttt{b.vitecek@gmx.at}} 
%\maketitle
%
%
% \begin{abstract}
% It was always a bit annoying to write \lstinline|\begin{itemize}| inside \lstinline|\begin{itemize}| to go a step deeper. Using this package you can just write \lstinline|\iitem|, \lstinline|\iiitem| and \lstinline|\ivtem|. Of course you can also use \verb|description|, \verb|enumerate|, etc. {\color{red}But\marginpar{!!!} they are not usable in \verb|\footnote{}|, \verb|\marginpar{}| (I think they are named ``fragile'') etc. commands!}
% \end{abstract}
%
% \tableofcontents
%
% \section{Interesting Part}
% \lstset{deletekeywords={iitem}}
% First of all, include this package via: 
%\begin{lstlisting}
%\usepackage{iitem}\end{lstlisting}
%
% \lstset{morekeywords={iitem}}
%
% This package offers three new commands: \lstinline|\iitem|, \lstinline|\iiitem| and \lstinline|\ivtem|. \bigskip
%
%\noindent Instead of writing ~
%\begin{minipage}{0.24\textwidth}
% \begin{lstlisting}
%\begin{itemize}
% \item 1 
%  \begin{itemize} 
%  \item 2 
%  \end{itemize}
%\end{itemize}\end{lstlisting}
%\end{minipage}\quad
%you can just write ~
%\begin{minipage}{0.22\textwidth}
% \begin{lstlisting}
%\begin{itemize}
%\item 1 
%\iitem 2 
%\end{itemize}\end{lstlisting}
%\end{minipage}
%
% But there \emph{has to be} an \verb|\item| at the beginning of the list (it's the default behavior of  lists). And they \emph{don't} work in \verb|\footnote{}| etc.
%\bigskip
%
%Of course it also works with \verb|enumerate|, \verb|description|, and several others (e.g. compactitem, \dots{} from \verb|paralist|). \bigskip 
%
%\begin{minipage}{0.49\textwidth}
%\begin{lstlisting} 
%\begin{enumerate}
% \item First
% \iitem Second
% \iitem Second two  
% \iiitem Third
% \iiitem Third two
% \iitem Second three
% \iiitem Third
% \ivtem Fourth
% \ivtem Fourth four
% \iitem Second four
% \ivtem Fourth
% \end{enumerate}\end{lstlisting}

%\end{minipage}\hfill%
%\begin{minipage}{0.49\textwidth}
% \begin{enumerate}
% \item First
% \iitem Second
% \iitem Second two  
% \iiitem Third
% \iiitem Third two
% \iitem Second three
% \iiitem Third
% \ivtem Fourth
% \ivtem Fourth two
%\iitem Second four
% \ivtem Fourth
% \end{enumerate}
%\end{minipage}\bigskip\bigskip 
%
%

%
% \section{What doesn't work}
% I am bad at explaining so here is an example:
%
%\begin{minipage}{0.49\textwidth}
%\begin{lstlisting} 
%\begin{enumerate}
% \item Using the ``normal'' item, 
% you can make paragraphs and the text 
%is still caught by the item.
% \iitem Using the new commands, this doesn't work anymore.
%If you make a paragraph, the text isn't caught anymore.
%\iiitem So it's the best, if you write a long sentence after an iitem, iiitem and ivtem  that you write the sentence in a long line.
% \end{enumerate}\end{lstlisting}

%\end{minipage}\hfill%
%\begin{minipage}{0.49\textwidth}
%\begin{enumerate}
% \item Using the ``normal'' item, 
% you can make paragraphs and the text 
%is still caught by the item.
% \iitem Using the new commands, this doesn't work anymore.
%If you make a paragraph, the text isn't caught anymore.
%\iiitem So it's the best, if you write a long sentence after an iitem, iiitem and ivtem  that you write the sentence in a long line.
%\end{enumerate}
%\end{minipage}\bigskip 

%
% \section{Any ideas?}
% Like I said before you cannot use them in \verb|\footnote{}| etc. 
% If anyone has the knowledge 	of how this  behavior can be changed, he or she might write an email to me (I don't have the knowledge to do it).
%


% \section{Code (in german)}
% In der ersten Zeile steht immer dasselbe: Was brauche ich, wie hei§t das Paket.
%    \begin{macrocode} 
\NeedsTeXFormat{LaTeX2e}[2011/06/27] 
\ProvidesPackage{iitem} 
[2013/03/31 v1.0 Go a step deeper in lists 
using the new commands ``iitem'', ``iiitem'' and ``ivtem''.] 
%    \end{macrocode} 

%\begin{macro}{\Pseudo@item}
% Unsere Befehle werden dadurch definiert, dass Umgebungen um ein \verb|\item| in der Mitte gebaut werden.
% Nun muss aber in jeder Liste ein \verb|\item| vorhanden sein.
% Um dieses Problem zu lšsen, definiere ich dieses \verb|\Pseudo@item|.
% Es ist eigentlich nichts anderes, als ein unsichtbares \verb|\item|.
%    \begin{macrocode} 
\def\Pseudo@item{{{%
  \@inmatherr\item
  \@ifnextchar [\@item{\@item[]}
 }}}
%    \end{macrocode} 
%\end{macro}

%\begin{macro}{iitemcounter}
%\begin{macro}{iiitemcounter}
%\begin{macro}{ivtemcounter}
% Damit die Nummerierung bei \verb|enumerate| richtig funktioniert, brauchen wir diese drei ZŠhler.
%    \begin{macrocode} 
\newcounter{iitemcounter}
\newcounter{iiitemcounter}
\newcounter{ivtemcounter}
%    \end{macrocode} 
%\end{macro}
%\end{macro}
%\end{macro}

%\begin{macro}{\item}
% Ich hoffe, ich mach keinen Blšdsinn \dots{}
% Zuerst sage ich ihm, dass \verb|\AltesItem| \verb|\item| ist.
% Dann definiere ich \verb|\item| um: Wir brauchen diese Konstruktion, damit die Nummerierung  funktioniert.
% Die ZŠhler werden auf Null gesetzt, wenn ein \verb|\item| auf der obersten Ebene geschrieben wird. 
%    \begin{macrocode} 
\let\AltesItem\item
\renewcommand{\item}{%
\if@nmbrlist%
 \ifnum%
  \@enumdepth=1%
  \setcounter{iitemcounter}{0}%
  \setcounter{iiitemcounter}{0}%
  \setcounter{ivtemcounter}{0}%
 \fi%
\fi%
\AltesItem}
%    \end{macrocode} 
%\end{macro}


% \begin{macro}{\iitem@line@command}
% Eigentlich habe ich ja keine Ahnung von \LaTeX{} Code und dem Programmieren damit.
%Aber zum GlŸck fand ich folgenden Code auf dieser Internetseite: \href{http://tex.stackexchange.com/questions/10426/def-taking-rest-of-the-line-as-argument}{http://tex.stackexchange.com/questions/10426/def-taking-rest-of-the-line-as-argument}.
% Ich habe den Code genommen, den Namen geŠndert und hier ist er:
%    \begin{macrocode} 
\newcommand*{\iitem@line@command}[2]{%
  \newcommand*{#1}{%
    \begingroup%
    \escapechar=`\\%
    \catcode\endlinechar=\active%
    \csname\string#1\endcsname%
  }%
  \begingroup%
  \escapechar=`\\%
  \lccode`\~=\endlinechar%
  \lowercase{%
    \expandafter\endgroup
    \expandafter\def\csname\string#1\endcsname##1~%
  }{\endgroup#2\space}%
}
%    \end{macrocode} 
%\end{macro}

% \begin{macro}{\iitem}
% Wir definieren \verb|\iitem|. 
% Als erstes setzen wir \verb|\partopsep0pt| damit die AbstŠnde nicht zu gro§ sind.
% Danach kommt die Umgebung: ich benutze das Makro \verb|\@currenvir|, dieses hat die Umgebung, die gerade aktiv, ist gespeichert (z.B.~itemize, enumerate, description, etc.).
% Wenn ich einfach \verb|\begin{\@currenvir}| hinschreiben wŸrde, wŸrde \LaTeX{} zuerst \verb|\begin{| ausfŸhren, dann auf \verb|\@currenvir| sto§en und versuchen, dieses als Umgebung zu aktivieren.
% Da dies aber nicht funktioniert, brauchen wir \verb|\exapndafter|: Mit dem Ersten, springen wir zum Zweiten, und mit diesem, sagen wir, dass \LaTeX{} \verb|\@currenvir| aktivieren soll, sprich \verb|\@currenvir| wird zu der gerade aktiven Umgebung.
% Dann kommt \verb|\begin{|. \LaTeX{} liest also z.B.~\verb|\begin{itemize}| statt \verb|\begin{\@currenvir}|
%
% Noch da? Als nŠchstes prŸfen wir, ob es eine Nummernliste ist, wenn ja, sagen wir das der merkwŸrdige \verb|\@listctr| Befehl auf \verb|\theiitemcounter| gesetzt wird, damit kommt die richtige Nummerierung zustande (hoffentlich).
% Danach schreiben wir \verb|\item| hin, schlie§en die Umgebung und erhšhen \verb|iitemcounter| um eins, und setzen \verb|iiitemcounter| auf 0.
%    \begin{macrocode}  
\iitem@line@command{\iitem}{\partopsep0pt%
 \expandafter\begin\expandafter{\@currenvir}%
  \if@nmbrlist\setcounter{\@listctr}{\theiitemcounter}\fi%
  \item #1%
 \expandafter\end\expandafter{\@currenvir}%
\stepcounter{iitemcounter}%
\setcounter{iiitemcounter}{0}\setcounter{ivtemcounter}{0}}
%    \end{macrocode} 
%\end{macro}


% \begin{macro}{\iiitem}
% Eigentlich dasselbe wie vorher.
% Nur kommt hier \verb|\Pseudo@item| ins Spiel.
% Wenn wir diesen Befehl nicht einfŸgen, meldet \LaTeX{} einen Fehler, da ein \verb|\item| fehlt (missing item). Der Rest ist mehr oder weniger derselbe.
%    \begin{macrocode} 
\iitem@line@command{\iiitem}{\partopsep0pt%
 \expandafter\begin\expandafter{\@currenvir}\Pseudo@item%
  \expandafter\begin\expandafter{\@currenvir}%
   \if@nmbrlist\setcounter{\@listctr}{\theiiitemcounter}\fi%
   \item #1 
  \expandafter\end\expandafter{\@currenvir}%
 \expandafter\end\expandafter{\@currenvir}%
\stepcounter{iiitemcounter}\setcounter{ivtemcounter}{0}}
%    \end{macrocode} 
%\end{macro}

% \begin{macro}{\ivtem}
% Selbe wie vorher.
%    \begin{macrocode} 
\iitem@line@command{\ivtem}{\partopsep0pt%
 \expandafter\begin\expandafter{\@currenvir}\Pseudo@item%
  \expandafter\begin\expandafter{\@currenvir}\Pseudo@item%
   \expandafter\begin\expandafter{\@currenvir}%
    \if@nmbrlist  \setcounter{\@listctr}{\theivtemcounter}\fi%
    \item #1%
   \expandafter\end\expandafter{\@currenvir}%
  \expandafter\end\expandafter{\@currenvir}%
 \expandafter\end\expandafter{\@currenvir}%
\stepcounter{ivtemcounter}}
%    \end{macrocode} 
%\end{macro}

% Well that's it. Happy \TeX ing. 




%\PrintChanges \PrintIndex