summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/thaienum/thaienum.pre.tex
blob: 0445f765981fa1ff09fc2ddc73c684e2996f2378 (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
%% thaienum.tex
%% Copyright 2017 Abhabongse Janthong
%
% 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 of this work is Abhabongse Janthong.
% This work consists of all files in the repository, including
% thaienum.sty and thaienum[.pre].tex.
%
% This file provides the basic howto usages of the package 'thaienum'.
%
\documentclass[11pt]{ltxguide}

%%------------------------------------------------------------------
%%  Load utility package
%%------------------------------------------------------------------
\usepackage{etoolbox}

%%------------------------------------------------------------------
%%  Set up Thai language and default font selection
%%------------------------------------------------------------------
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage[varqu,varl]{inconsolata}
\usepackage[thai,thaiindentfirst]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[sans,sflaksaman,rmnorasi]{fonts-tlwg}

\renewcommand{\baselinestretch}{1.5}
\renewrobustcmd{\englishrmdefault}{LinuxLibertineT-TLF}
\renewrobustcmd{\englishsfdefault}{LinuxBiolinumT-TLF}
\renewrobustcmd{\englishttdefault}{zi4}

\renewrobustcmd{\thaittdefault}{zi4}
\renewrobustcmd{\ttfamily}{%
    \fontencoding{\latinencoding}%
    \fontfamily{\ttdefault}%
    \selectfont}

%%------------------------------------------------------------------
%% Load package to be documented
%%------------------------------------------------------------------
\usepackage{enumitem}
\usepackage{thaienum}
\setlist[enumerate,1]{%
    topsep=1pc,partopsep=0pc,parsep=0pc,itemsep=1pc,listparindent=2pc,%
    itemindent=0pc}

%%------------------------------------------------------------------
%%  Set default titlesec
%%  There is a bug when loading 'titlesec' so here is the quick hack. https://tex.stackexchange.com/questions/299969/titlesec-loss-of-section-numbering-with-the-new-update-2016-03-15
%%------------------------------------------------------------------
\usepackage[sf,bf]{titlesec}
\makeatletter
\patchcmd{\ttlh@hang}{\parindent\z@}{\parindent\z@\leavevmode}{}{}
\patchcmd{\ttlh@hang}{\noindent}{}{}{}
\makeatother
\usepackage{multicol}

%%------------------------------------------------------------------
%%  Setup color choices
%%------------------------------------------------------------------
\usepackage[dvipsnames,svgnames,table,fixpdftex,hyperref]{xcolor}
\definecolor{DarkGray}{gray}{0.25}
\definecolor{Gray}{gray}{0.5}
\definecolor{LightGray}{gray}{0.65}
\definecolor{VeryLightGray}{gray}{0.9}
\definecolor{GrayBG}{gray}{0.9}
\definecolor{LightGrayBG}{gray}{0.935}
\definecolor{VeryLightGrayBG}{gray}{0.97}

% Color settings for mdframed
\definecolor{ShadeColor}{gray}{0.935}
\definecolor{BorderColor}{gray}{0.785}

%%------------------------------------------------------------------
%%  Code listings package and settings
%%------------------------------------------------------------------
\RequirePackage{listings}
\lstset{%
    % Basic Settings
    basicstyle=\small\ttfamily,%
    captionpos=b,%
    % Margins and Background
    xleftmargin=0pc,%
    xrightmargin=0pc,%
    rulesep=2pc,%
    frame=trbl,%
    framesep=0.5pc,%
    framextopmargin=0pc,%
    framexbottommargin=0pc,%
    framexleftmargin=0.125pc,%
    framexrightmargin=0pc,%
    backgroundcolor=\color{ShadeColor},%
    rulecolor=\color{BorderColor},%
    % Spacing and Horizontal Flow
    showspaces=false,%
    showstringspaces=false,%
    showtabs=false,%
    tabsize=2,%
    breaklines=true,%
    columns=fullflexible,%
    keepspaces=true,%
    % Vertical Flow
    aboveskip=\bigskipamount,%
    belowskip=\bigskipamount,%
    lineskip=0.0001pt,
    % Line Numbers
    stepnumber=1,%
    numbers=left,%
    numbersep=1.25pc,%
    numberstyle=\ttfamily\color{Gray},%
    % Special Keyword Format
    stringstyle=\color{red},%
    commentstyle=\color{ForestGreen!90},%
    keywordstyle=\color{MidnightBlue!80},%
    keywordstyle={[2]\color{teal!80}},%
    extendedchars=true}

\lstdefinelanguage{LaTeX}{%
    language=[LaTeX]{TeX},%
    sensitive=true}

%%------------------------------------------------------------------
%%  Setup constant lengths for parts of document.
%%------------------------------------------------------------------
\addtolength{\topmargin}{-3pc}
\addtolength{\textwidth}{6pc}
\addtolength{\oddsidemargin}{-2pc}
\addtolength{\textheight}{7pc}
\setlength{\parindent}{2pc}
\setlength{\parskip}{0pc}

%%------------------------------------------------------------------
%%  Document information
%%------------------------------------------------------------------
\title{แพ็กเกจ \textlatin{\texttt{thaienum}}}
\author{อาภาพงศ์ จันทร์ทอง}

\date{เวอร์ชัน 0.2\\30 เมษายน 2017}

\begin{document}
\maketitle

\section{กล่าวนำ}

โดยปกติแล้ว หากผู้ใช้งาน \textlatin{\textrm\LaTeX} ต้องการที่จะเขียนลำดับรายการโดยที่สามารถกำหนดชนิดของหัวรายการในรูปแบบต่าง ๆ มักจะเรียกใช้งานแพ็กเกจ \texttt{enumitem} เพราะเป็นแพ็กเกจที่มีความยืดหยุ่นสูง เช่น สามารถกำหนดให้ตั้งหัวรายการด้วยเลขโรมันได้ เช่น

\smallskip
\renewcommand{\baselinestretch}{0.1}
\begin{lstlisting}[language=LaTeX,escapechar={â},basicstyle=\ttfamily,lineskip={0.05pc}]
\begin{enumerate}[label={\Roman*.}]
    \item  â{\textthai{\small รายการที่หนึ่ง}}â
    \item  â{\textthai{\small รายการที่สอง}}â
    \item  â{\textthai{\small รายการที่สาม}}â
    \item  â{\textthai{\small รายการที่สี่}}â
\end{enumerate}
\end{lstlisting}
\renewcommand{\baselinestretch}{1.5}

\begin{enumerate}[topsep=0pc,itemsep=0pc,label={\latintext\rmfamily\Roman*.}]
    \item รายการที่หนึ่ง
    \item รายการที่สอง
    \item รายการที่สาม
    \item รายการที่สี่
\end{enumerate}

\medskip
แต่ก็มีผู้ใช้งาน \textlatin{\textrm\LaTeX} กลุ่มหนึ่ง โดยเฉพาะผู้ใช้งานภาษาไทยมักประสบปัญหาที่ไม่สามารถตั้งหัวรายการเป็นเลขไทย (เช่น ๑ ๒ ๓ ๔ \ldots) หรืออักษรภาษาไทย (ก ข ค ง \ldots) ได้โดยอัตโนมัติ ก่อให้เกิดความไม่สะดวกในการใช้งาน \textlatin{\textrm\LaTeX} กับภาษาไทยเป็นอย่างยิ่ง

แพ็กเกจ \textlatin{\texttt{thaienum}} สำหรับ \textlatin{\textrm\LaTeX} จึงถูกสร้างขึ้นมาเพื่อตอบโจทย์ดังกล่าว โดยใช้ควบคู่กับแพ็กเกจหลักอย่าง \texttt{enumitem} นั่นเอง


\section{วิธีใช้งานเบื้องต้น}

\subsection{ก่อนเริ่มใช้งาน}

ก่อนที่ผู้ใช้งานจะนำเข้าแพ็กเกจ \texttt{thaienum} นีเพื่อใช้งาน ผู้นั้นจำเป็นต้องเรียกนำเข้าแพ็กเกจทั้งสิ้น 2 แพ็กเกจก่อนดังต่อไปนี้
\begin{enumerate}[topsep=0.25pc,itemsep=0pc,label={\thainum*.}]
    \item  แพ็กเกจ \texttt{babel} และต้องนำเข้าการใช้งานภาษาไทยด้วย
    \item  แพ็กเกจ \texttt{enumitem}
\end{enumerate}

\begin{lstlisting}[language=LaTeX]
\usepackage[thai]{babel}
\usepackage{enumitem}
\usepackage{thaienum}
\end{lstlisting}

\subsection{การเลือกใช้งาน}

เมื่อผู้ใช้งานต้องการจะเขียนรายการใหม่ สามารถสร้าง \texttt{environment} ประะภท \texttt{enumerate} โดยกำหนดค่า \texttt{parameter} ชื่อ \texttt{label} ให้มีหัวรายการตามที่ต้องการได้ โดยสามารถกำหนดค่าต่อไปนี้

\begin{enumerate}[topsep=0.25pc,itemsep=0pc,label={\thainum*.}]
    \item  \texttt{thainum} สำหรับการนับโดยใช้เลขไทย ๑ ๒ ๓ ๔ ๕ \ldots
    \item  \label{it:loalph} \texttt{thaialph} สำหรับการนับโดยใช้พยัญชนะไทย ก ข ค ง จ \ldots
    \item  \label{it:hialph} \texttt{thaiAlph} สำหรับการนับโดยใช้พยัญชนะไทย ก ข ฃ ค ฅ \ldots\, โดยไม่ข้าม ฃ ฅ และ ฆ
\end{enumerate}

\medskip
อย่างไรก็ดี สำหรับหัวรายการประเภทที่ \ref{it:loalph} และ \ref{it:hialph} นั้น มีจำนวนพยัญชนะจำกัด จึงไม่สามารถใช้ในกรณีที่รายการมีความยาวเกิน 41 และ 44 รายการได้ตามลำดับ แพ็กเกจนี้จึงมีอนุญาตให้กำหนดค่าได้อีกสองประเภทเพิ่มเติม ได้แก่

\begin{enumerate}[topsep=0.25pc,itemsep=0pc,start=4,label={\thainum*.}]
    \item  \texttt{thaimultialph} ซึ่งคล้ายกับ \texttt{thaialph} แต่ว่าถัดจาก ฮ.นกฮูก นั้นรายการถัดไปจะนับใหม่เป็น กก กข กค กง กจ \ldots\, ไปเรื่อย ๆ
    \item  \texttt{thaimultiAlph} ซึ่งคล้ายกับ \texttt{thaiAlph} แต่ว่าถัดจาก ฮ.นกฮูก นั้นรายการถัดไปจะนับใหม่เป็น กก กข กฃ กค กฅ \ldots\, ไปเรื่อย ๆ
\end{enumerate}

\newpage
\subsubsection{ตัวอย่างการใช้งานกับเลขไทย}

เราสามารถใช้เลขไทยกับรายการได้ดังนี้

\smallskip
\renewcommand{\baselinestretch}{0.1}
\begin{lstlisting}[language=LaTeX,escapechar={â},basicstyle=\ttfamily,lineskip={0.05pc}]
\begin{enumerate}[label={\thainum*.}]
    \item  â{\textthai{\small รายการที่หนึ่ง}}â
    \item  â{\textthai{\small รายการที่สอง}}â
    \item  â{\textthai{\small รายการที่สาม}}â
    \item  â{\textthai{\small รายการที่สี่}}â
\end{enumerate}
\end{lstlisting}
\renewcommand{\baselinestretch}{1.5}

\begin{enumerate}[topsep=0pc,itemsep=0pc,label={\thainum*.}]
    \item  รายการที่หนึ่ง
    \item  รายการที่สอง
    \item  รายการที่สาม
    \item  รายการที่สี่
\end{enumerate}

\subsubsection{ตัวอย่างการใช้งานกับอักษรไทย}

เราสามารถใช้อักษรไทยกับรายการได้ดังนี้

\smallskip
\renewcommand{\baselinestretch}{0.1}
\begin{lstlisting}[language=LaTeX,escapechar={â},basicstyle=\ttfamily,lineskip={0.05pc}]
\begin{enumerate}[label={\thaialph*.}]
    \item  â{\textthai{\small รายการที่หนึ่ง}}â
    \item  â{\textthai{\small รายการที่สอง}}â
    \item  â{\textthai{\small รายการที่สาม}}â
    \item  â{\textthai{\small รายการที่สี่}}â
\end{enumerate}
\end{lstlisting}
\renewcommand{\baselinestretch}{1.5}

\begin{enumerate}[topsep=0pc,itemsep=0pc,label={\thaialph*.}]
    \item  รายการที่หนึ่ง
    \item  รายการที่สอง
    \item  รายการที่สาม
    \item  รายการที่สี่
\end{enumerate}

\newpage
\subsubsection{ตัวอย่างการใช้งานกับอักษรไทยในรายการที่ยาว}

หากเราตั้งค่าให้ \lstinline[language=LaTeX]!label={\thaialph.}! กับรายการที่ยาวเกิน 41 รายการ เราจะพบปัญหาดังนี้ (โปรดดู \texttt{source code} เพื่อความชัดเจนที่มากขึ้น)
\begin{center}
    \color{red}\texttt{thaienum.tex:315: LaTeX Error: Counter too large. [ {\textbackslash}item ]}
\end{center}

\begin{multicols}{4}
    \scriptsize
    \begin{enumerate}[listparindent=0pc,topsep=0pc,itemsep=0pc,label={\thaialph*.}]
        \item  รายการที่หนึ่ง
        \item  รายการที่สอง
        \item  รายการที่สาม
        \item  รายการที่สี่
        \item  รายการที่ห้า
        \item  รายการที่หก
        \item  รายการที่เจ็ด
        \item  รายการที่แปด
        \item  รายการที่เก้า
        \item  รายการที่สิบ
        \item  รายการที่สิบเอ็ด
        \item  รายการที่สิบสอง
        \item  รายการที่สิบสาม
        \item  รายการที่สิบสี่
        \item  รายการที่สิบห้า
        \item  รายการที่สิบหก
        \item  รายการที่สิบเจ็ด
        \item  รายการที่สิบแปด
        \item  รายการที่สิบเก้า
        \item  รายการที่ยี่สิบ
        \item  รายการที่ยี่สิบเอ็ด
        \item  รายการที่ยี่สิบสอง
        \item  รายการที่ยี่สิบสาม
        \item  รายการที่ยี่สิบสี่
        \item  รายการที่ยี่สิบห้า
        \item  รายการที่ยี่สิบหก
        \item  รายการที่ยี่สิบเจ็ด
        \item  รายการที่ยี่สิบแปด
        \item  รายการที่ยี่สิบเก้า
        \item  รายการที่สามสิบ
        \item  รายการที่สามสิบเอ็ด
        \item  รายการที่สามสิบสอง
        \item  รายการที่สามสิบสาม
        \item  รายการที่สามสิบสี่
        \item  รายการที่สามสิบห้า
        \item  รายการที่สามสิบหก
        \item  รายการที่สามสิบเจ็ด
        \item  รายการที่สามสิบแปด
        \item  รายการที่สามสิบเก้า
        \item  รายการที่สี่สิบ
        \item  รายการที่สี่สิบเอ็ด
        \item[.]  รายการที่สี่สิบสอง
        % To replicate error, replace the line above with the line below.
        % \item  รายการที่สี่สิบสอง
    \end{enumerate}
\end{multicols}

\medskip
แต่หากเราตั้งค่าให้ \lstinline[language=LaTeX]!label={\thaimultialph.}! กับรายการที่ยาวเกิน 41 รายการ เราจะได้ผลลัพธ์ดังนี้

\begin{multicols}{4}
    \scriptsize
    \begin{enumerate}[listparindent=0pc,topsep=0pc,itemsep=0pc,label={\thaimultialph*.}]
        \item  รายการที่หนึ่ง
        \item  รายการที่สอง
        \item  รายการที่สาม
        \item  รายการที่สี่
        \item  รายการที่ห้า
        \item  รายการที่หก
        \item  รายการที่เจ็ด
        \item  รายการที่แปด
        \item  รายการที่เก้า
        \item  รายการที่สิบ
        \item  รายการที่สิบเอ็ด
        \item  รายการที่สิบสอง
        \item  รายการที่สิบสาม
        \item  รายการที่สิบสี่
        \item  รายการที่สิบห้า
        \item  รายการที่สิบหก
        \item  รายการที่สิบเจ็ด
        \item  รายการที่สิบแปด
        \item  รายการที่สิบเก้า
        \item  รายการที่ยี่สิบ
        \item  รายการที่ยี่สิบเอ็ด
        \item  รายการที่ยี่สิบสอง
        \item  รายการที่ยี่สิบสาม
        \item  รายการที่ยี่สิบสี่
        \item  รายการที่ยี่สิบห้า
        \item  รายการที่ยี่สิบหก
        \item  รายการที่ยี่สิบเจ็ด
        \item  รายการที่ยี่สิบแปด
        \item  รายการที่ยี่สิบเก้า
        \item  รายการที่สามสิบ
        \item  รายการที่สามสิบเอ็ด
        \item  รายการที่สามสิบสอง
        \item  รายการที่สามสิบสาม
        \item  รายการที่สามสิบสี่
        \item  รายการที่สามสิบห้า
        \item  รายการที่สามสิบหก
        \item  รายการที่สามสิบเจ็ด
        \item  รายการที่สามสิบแปด
        \item  รายการที่สามสิบเก้า
        \item  รายการที่สี่สิบ
        \item  รายการที่สี่สิบเอ็ด
        \item  รายการที่สี่สิบสอง
        \item  รายการที่สี่สิบสาม
        \item  รายการที่สี่สิบสี่
        \item  รายการที่สี่สิบห้า
        \item  รายการที่สี่สิบหก
        \item  รายการที่สี่สิบเจ็ด
        \item  รายการที่สี่สิบแปด
        \item  รายการที่สี่สิบเก้า
        \item  รายการที่ห้าสิบ
    \end{enumerate}
\end{multicols}

\section{ขอขอบคุณ}

ขอขอบคุณแพ็กเกจ \texttt{moreenum} สำหรับความคิดริเริ่มและแนวทางที่จะสร้างแพ็กเกจนี้ขึ้นมา และขอขอบคุณแพ็กเกจ \texttt{babel-thai} สำหรับการสนับสนุนภาษาไทยใน \textlatin{\textrm\LaTeX} เรื่อยมา


\end{document}