%% 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}