%%
%% This is file `thaispec.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% thaispec.dtx  (with options: `thaispec.sty,package')
%% 
%%  thaispec.dtx
%%  Copyright 2019 Ratthaprom_Promkam
%% 
%%  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 Ratthaprom_Promkam.
%% 
%%  This work consists of the files thaispec.dtx and thaispec.ins and the derived file thaispec.sty.
%% 
%% \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         \~}
%% By default the package set \texttt{thaifont} to \texttt{TH Sarabun New},
%% while set \texttt{mainfont}, \texttt{sansfont} and \texttt{monofont} to \TeX\ Gyre fonts.
%% In case \TeX\ Gyre font family is not system wide installed, the package should be loaded
%% with the following option:
%% \begin{minted}[frame=single]{LaTeX}
%% \usepackage[texgyrefont = false]{thaispec}
%% \end{minted}
%%\begin{lstlisting}[style=tex,numbers=left]
%%\documentclass{article}
%%\usepackage{thaispec}
%%\begin{document}
%%\section{Thai ภาษาไทย}
%%Thai charaters can be input directly like this ทดสอบการพิมพ์ภาษาไทยในเอกสาร \XeLaTeX\
%%
%%\end{lstlisting}
%%\begin{lstlisting}[style=tex,numbers=left]
%%\documentclass{article}
%%\usepackage[math,
%%thaifont = Tahoma,
%%texgyrefont = false,
%%sloppy = false]{thaispec}
%%\begin{document}
%%\section{Math ภาษาไทย}
%%Thai charaters can be input directly like this ทดสอบการพิมพ์ภาษาไทยในเอกสาร $ax^2+bx+c=0$
%%
%%\end{lstlisting}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{thaispec}[2019/07/03 version 0.4 thaispec]

\RequirePackage{kvoptions}
\RequirePackage[no-math]{fontspec}
\RequirePackage[Latin, Thai]{ucharclasses}
\RequirePackage{setspace}
\RequirePackage{polyglossia}
\RequirePackage[calc]{datetime2}
\RequirePackage{xstring}
\RequirePackage{afterpackage}
\RequirePackage{xpatch}

\SetupKeyvalOptions{
family=THL,
prefix=THL@
}

\DeclareStringOption[TH Sarabun New]{thaifont}[TH Sarabun New]

\DeclareVoidOption{math}{%
\RequirePackage{mathtools}
\RequirePackage{amssymb}
\RequirePackage{amsthm}
\RequirePackage{mathspec}
}

\DeclareVoidOption{thainum}{\renewcommand{\thesection}{\thainum{section}}}

\DeclareBoolOption[true]{sloppy}
\DeclareBoolOption[true]{thaispacing}
\DeclareBoolOption[true]{thaicaption}
\DeclareBoolOption[false]{beamerthmcount}

\DeclareStringOption[default]{thmcount}[default]

\ProcessKeyvalOptions{THL}


\XeTeXlinebreaklocale "th"
\XeTeXlinebreakskip = 0pt plus 0pt
\ifTHL@sloppy
\sloppy
\fi
\defaultfontfeatures{Mapping=tex-text}


\newfontfamily{\thaifont}[Scale=MatchUppercase,Mapping=tex-text]{\THL@thaifont}

\newenvironment{thailang}
{\thaifont}
{}

\setTransitionTo{Thai}{\begin{thailang}}
\setTransitionFrom{Thai}{\end{thailang}}

\setdefaultlanguage{english}
\setotherlanguage{thai}
\ifTHL@thaicaption
\AtBeginDocument\captionsthai
\fi

\def\thaialph#1{\expandafter\thalph\csname c@#1\endcsname}
\def\thalph#1{%
    \ifcase#1\or ก\or ข\or ค\or ง\or จ\or ฉ\or ช\or ซ\or
    ฌ\or ญ\or ฎ\or ฏ\or ฐ\or ฑ\or ฒ\or ณ\or ด\or ต\or ถ\or ท\or ธ\or น\or
    บ\or ป\or ผ\or ฝ\or พ\or ฟ\or ภ\or ม\or ย\or ร\or ฤ\or ล\or ฦ\or ว\or
    ศ\or ษ\or ส\or ห\or ฬ\or อ\else ฮ\else\xpg@ill@value{#1}{thalph}\fi}
\def\thainum#1{\expandafter\thainumber\csname c@#1\endcsname}
\def\thainumber#1{%
    \thaidigits{\number#1}%
}
\def\thaidigits#1{\expandafter\thdigits #1@ }
\def\thdigits#1{%
    \ifx @#1% then terminate
    \else
    \ifx0#1๐\else\ifx1#1๑\else\ifx2#1๒\else\ifx3#1๓\else\ifx4#1๔\else\ifx5#1๕\else\ifx6#1๖\else\ifx7#1๗\else\ifx8#1๘\else\ifx9#1๙\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\thdigits
    \fi
}

\DTMsavenow{now}
\newcommand{\dtdow}{\IfStrEqCase{\DTMfetchdow{now}}{{0}{วันจันทร์}
{1}{วันอังคาร}
{2}{วันพุธ}
{3}{วันพฤหัสบดี}
{4}{วันศุกร์}
{5}{วันเสาร์}
{6}{วันอาทิตย์}
}}

\newcommand{\dtmonth}{\IfStrEqCase{\DTMfetchmonth{now}}{{1}{มกราคม}
{2}{กุมภาพันธ์}
{3}{มีนาคม}
{4}{เมษายน}
{5}{พฤษภาคม}
{6}{มิถุนายน}
{7}{กรกฎาคม}
{8}{สิงหาคม}
{9}{กันยายน}
{10}{ตุลาคม}
{11}{พฤศจิกายน}
{12}{ธันวาคม}
}}

\newcounter{yearbd}
\setcounter{yearbd}{\DTMfetchyear{now}}
\addtocounter{yearbd}{543}
\AtBeginDocument{
\def\Today{\dtdow\ \DTMfetchday{now}\ \dtmonth\ พ.ศ. \theyearbd}
\def\today{\DTMfetchday{now}\ \dtmonth\ พ.ศ. \theyearbd}
}

\@ifclassloaded{beamer}
{
\let\theorem\relax
\let\c@theorem\relax
\let\lemma\relax
\let\corollary\relax
\let\definition\relax
\let\example\relax
\let\note\relax

\ifTHL@beamerthmcount
    \setbeamertemplate{theorems}[numbered]
\fi

}
{%
\ifTHL@thaispacing
\onehalfspacing
\fi
}

\@ifclassloaded{article}
{
\renewcommand{\THL@thmcount}{section}
}
{}

\@ifclassloaded{book}
{
\renewcommand{\THL@thmcount}{chapter}
}
{}

\@ifclassloaded{report}
{
\renewcommand{\THL@thmcount}{chapter}
}
{}

\@ifpackageloaded{amsthm}
{%
\IfStrEqCase{\THL@thmcount}{%
{default}{%
\newtheorem{theorem}{ทฤษฎีบท}
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{บทนิยาม}
\newtheorem{undefinedterm}[theorem]{อนิยาม}
\newtheorem{axiom}[theorem]{สัจพจน์}
\newtheorem{example}[theorem]{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem*{remark}{หมายเหตุ}
\newtheorem*{note}{บันทึก}
}%
{no}{%
\newtheorem*{theorem}{ทฤษฎีบท}
\newtheorem*{lemma}{บทตั้ง}
\newtheorem*{corollary}{บทแทรก}
\newtheorem*{proposition}{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem*{definition}{บทนิยาม}
\newtheorem*{undefinedterm}{อนิยาม}
\newtheorem*{axiom}{สัจพจน์}
\newtheorem*{example}{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem*{remark}{หมายเหตุ}
\newtheorem*{note}{บันทึก}
}%
{full}{%
\newtheorem{theorem}{ทฤษฎีบท}
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{บทนิยาม}
\newtheorem{undefinedterm}[theorem]{อนิยาม}
\newtheorem{axiom}[theorem]{สัจพจน์}
\newtheorem{example}[theorem]{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem{remark}{หมายเหตุ}
\newtheorem{note}{บันทึก}
}%
{section}{%
\newtheorem{theorem}{ทฤษฎีบท}[section]
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{บทนิยาม}
\newtheorem{undefinedterm}[theorem]{อนิยาม}
\newtheorem{axiom}[theorem]{สัจพจน์}
\newtheorem{example}[theorem]{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem*{remark}{หมายเหตุ}
\newtheorem*{note}{บันทึก}
}%
{chapter}{%
\newtheorem{theorem}{ทฤษฎีบท}[chapter]
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{บทนิยาม}
\newtheorem{undefinedterm}[theorem]{อนิยาม}
\newtheorem{axiom}[theorem]{สัจพจน์}
\newtheorem{example}[theorem]{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem*{remark}{หมายเหตุ}
\newtheorem*{note}{บันทึก}
}%
{kind}{%
\newtheorem{theorem}{ทฤษฎีบท}
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}{บทนิยาม}
\newtheorem{undefinedterm}[definition]{อนิยาม}
\newtheorem{axiom}[definition]{สัจพจน์}
\newtheorem{example}{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem{remark}{หมายเหตุ}
\newtheorem{note}{บันทึก}
}%
{kind-section}{%
\newtheorem{theorem}{ทฤษฎีบท}[section]
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}{บทนิยาม}[section]
\newtheorem{undefinedterm}[definition]{อนิยาม}
\newtheorem{axiom}[definition]{สัจพจน์}
\newtheorem{example}{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem{remark}{หมายเหตุ}[section]
\newtheorem{note}{บันทึก}[section]
}%
{kind-chapter}{%
\newtheorem{theorem}{ทฤษฎีบท}[chapter]
\newtheorem{lemma}[theorem]{บทตั้ง}
\newtheorem{corollary}[theorem]{บทแทรก}
\newtheorem{proposition}[theorem]{ทฤษฎีบทประกอบ}
\theoremstyle{definition}
\newtheorem{definition}{บทนิยาม}[chapter]
\newtheorem{undefinedterm}[definition]{อนิยาม}
\newtheorem{axiom}[definition]{สัจพจน์}
\newtheorem{example}{ตัวอย่าง}
\theoremstyle{remark}
\newtheorem{remark}{หมายเหตุ}[chapter]
\newtheorem{note}{บันทึก}[chapter]
}%
}%
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
}
{}

\endinput
%%
%% End of file `thaispec.sty'.
