summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/autopuncitems/autopuncitems.tex
blob: 89552c0db5d488237082735bd2ede24ed668c5b3 (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
% Kale Ewasiuk (kalekje@gmail.com)
% 2022-04-16
% Copyright (C) 2021-2022 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
% PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
% OR OTHER DEALINGS IN THE SOFTWARE.


\documentclass[11pt,parskip=half]{scrartcl}
\setlength{\parindent}{0ex}
\newcommand{\llcmd}[1]{\leavevmode\llap{\texttt{\detokenize{#1}\ }}}
\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}}
\newcommand{\qcmd}[1]{``\cmd{#1}''}
\RequirePackage{url}
\RequirePackage{xcolor}
\RequirePackage{showexpl}
\lstset{explpreset={justification=\raggedright,pos=r,wide=true}}
\setlength\ResultBoxRule{0mm}
\lstset{
	language=[LaTeX]TeX,
	basicstyle=\ttfamily\small,
	commentstyle=\ttfamily\small\color{gray},
	frame=none,
	numbers=left,
	numberstyle=\ttfamily\small\color{gray},
	prebreak=\raisebox{0ex}[0ex][0ex]{\color{gray}\ensuremath{\hookleftarrow}},
	extendedchars=true,
	breaklines=true,
	tabsize=4,
}
\addtokomafont{title}{\raggedright}
\addtokomafont{author}{\raggedright}
\addtokomafont{date}{\raggedright}
\author{Kale Ewasiuk (\url{kalekje@gmail.com})}
\RequirePackage[yyyymmdd]{datetime}\renewcommand{\dateseparator}{--}
\date{\today}


\usepackage{autopuncitems}
\setlist{nosep}

\title{autopuncitems}


\begin{document}
\maketitle


\section{Introduction}
This package provides environments \cmd{AutoPuncItemize}, \cmd{AutoPuncItemizeO}, and \cmd{AutoPuncItemizeE} (beta)
to automatically punctuate the items.
By default, it adds the \cmd{autopunc (O|E)} options in the
\cmd{enumitem} environments \cmd{itemize}, \cmd{enumerate}, and \cmd{description}, to wrap the contents in these enviroments.
If you want to skip this (say if you were using the beamer class which
may be interefered with by enum item), pass the \cmd{noenumitem} option to this package. You can still use the environments with beamer, though.
It uses lua pattern matching to modify the environment's contents.



\section{Some commands}
\llcmd{\APomit}Used in an \cmd{\item} to signify that that item should not be automatically punctuated, and not be counted. Expands to nothing.\\
\llcmd{\APpass}Used in an \cmd{\item} to signify that that item should not be automatically punctuated, and but still counted. Expands to nothing.\\

\begin{addmargin}[0.8in]{0in}
\llcmd{\setAPeach{}{}{}}Set the default, second last, and last punctuation point in that order.\\
\llcmd{\setAPall{}}Set all punctuation points the same.\\
\llcmd{\setAPdef{}}Set the default punctuation point. \cmd{;} by default.\\
\llcmd{\setAPseclast{}}Set the second last punctuation point. \cmd{; and} by default.\\
\llcmd{\setAPlast{}}Set the second last punctuation point. \cmd{.} by default.\\

\llcmd{\enableAPautopassnest}Automatically put an \cmd{\APpass} on items that introduce a nested list. Default behaviour.\\
\llcmd{\disableAPautopassnest}Do not automatically put an \cmd{\APpass} on items that introduce a nested list.\\

\end{addmargin}

\section{Variants}
\llcmd{autopunc}Does not expand the contents of environment. Tutorial on next section shows this.\\
\llcmd{autopuncO}Expands the contents of environment once. Useful if \cmd{\item}'s are in a command \\
\llcmd{autopuncE}Fully expands the contents of environment first. This is in-progress and should not be used.\\


\section{Tutorial}
\subsection{Basic Use}

\begin{LTXexample}
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three
    \item four
\end{itemize}
\end{LTXexample}


\subsection{Demonstrating Pass}

\begin{LTXexample}
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three \APpass
    \item four
\end{itemize}
\end{LTXexample}

\begin{LTXexample}
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three \APpass
    \item four  \APpass
\end{itemize}
\end{LTXexample}


\subsection{Demonstrating Omit}

\begin{LTXexample}
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three \APomit
    \item four
\end{itemize}
\end{LTXexample}

\begin{LTXexample}
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three \APomit
    \item four  \APomit
\end{itemize}
\end{LTXexample}

\subsection{Nested}
You must use \cmd{autopunc} on each nested list if you want that sub-list to be automatically punctuated.
Note that by default, the item introducing (before) a sub-list will not be automatically punctuated.

\begin{LTXexample}
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three:
    \begin{enumerate}[autopunc]
        \item alpha:
        \begin{description}[autopunc]
            \item[hello] world
        \end{description}
        \item beta
        \item delta
    \end{enumerate}
    \item four
\end{itemize}
\end{LTXexample}


\subsubsection{If you forget to use APpass}
If you disable auto-pass nested lists, and don't use \cmd{\APpass}, here is what happens. Notice the extra ``; and'' below hello world and beta.
\begin{LTXexample}
\disableAPautopassnest
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three
    \begin{enumerate}[autopunc]
        \item alpha
        \begin{description}[autopunc]
            \item[hello] world
        \end{description}
        \item beta
    \end{enumerate}
    \item four
\end{itemize}
\end{LTXexample}

\begin{LTXexample}
\enableAPautopassnest
\begin{itemize}[autopunc]
    \item one
    \item two
    \item three
    \begin{enumerate}
        \item alpha
        \begin{description}[autopunc]
            \item[hello] world
        \end{description}
        \item beta
    \end{enumerate}
    \item four
\end{itemize}
\end{LTXexample}

\subsection{Expanding list contents}
\begin{LTXexample}
\def\listexample{
    \item one
    \item two
    \item three
    \item four
}
--will work fine (expand once)
\begin{itemize}[autopuncO]
    \listexample
\end{itemize}

--will throw error
  (author to fix this)
%\begin{itemize}[autopuncE]
%    \listexample
%\end{itemize}

--does not give desired result
  (no items found)
\begin{itemize}[autopunc]
    \listexample
\end{itemize}

\end{LTXexample}


\subsection{Using the environment}

The normal way to use the environment should be inside the first list, like so.

\begin{LTXexample}
\enableAPautopassnest % default settn
\begin{itemize}
\begin{AutoPuncItems}
    \item one
    \item two
    \item three
    \item four
\end{AutoPuncItems}
\end{itemize}
\end{LTXexample}

You may want to use the \cmd{AutoPuncItems} environment outside a list environment instead,
say perhaps if you're using the \cmd{beamer}.
Note that  nested lists are normally not punctuated, and since the first-level list is inside the environment, it's considered nested.
If you would like to disable the prevention of auto-punctuating all nested lists, use the \cmd{\disableAPprotectnest}.
Note that nested lists will cause an error to occur.

\begin{LTXexample}
\disableAPprotectnest
\begin{AutoPuncItems}
\begin{itemize}
    \item one
    \item two
    \item three
    \item four
\end{itemize}
\end{AutoPuncItems}
\end{LTXexample}





\end{document}