Skip to content

Instantly share code, notes, and snippets.

@rangsimanketkaew
Last active May 6, 2022 13:31
Show Gist options
  • Select an option

  • Save rangsimanketkaew/e13bdaeef42d45f59aa3bb5c9cafb347 to your computer and use it in GitHub Desktop.

Select an option

Save rangsimanketkaew/e13bdaeef42d45f59aa3bb5c9cafb347 to your computer and use it in GitHub Desktop.
LaTeX source for a tufte-book supporting Thai and English, modified by Rangsiman Ketkaew
% LaTeX source for a tufte-book modified by Rangsiman Ketkaew
% Multiple languages support: Thai and English
\documentclass[fullbook,nohyper,nobib,justified,titlepage]{tufte-book}
\usepackage{nameref}
\ifxetex
\newcommand{\textls}[2][5]{%
\begingroup\addfontfeatures{LetterSpace=#1}#2\endgroup
}
\renewcommand{\allcapsspacing}[1]{\textls[15]{#1}}
\renewcommand{\smallcapsspacing}[1]{\textls[10]{#1}}
\renewcommand{\allcaps}[1]{\textls[15]{\MakeTextUppercase{#1}}}
\renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{#1}}}
\renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{#1}}}
\fi
%----------------------------------------------------
%%% Option 1. Font for Thai %%%
\usepackage[utf8]{inputenc}
\usepackage{xltxtra} % this will load the fontspec, metalogo, and realscripts packages
\XeTeXlinebreaklocale "th_TH"
\XeTeXlinebreakskip = 0pt plus 1pt
\defaultfontfeatures{Scale=1.23}
\setmainfont[
Renderer=Basic,
BoldFont={THSarabunNew_Bold.ttf},
ItalicFont={THSarabunNew_Italic.ttf},
BoldItalicFont={THSarabunNew_BoldItalic.ttf},
]{THSarabunNew.ttf}
% \setmainfont{TH Sarabun New}
%%% Option 2. Fonts for different languages %%%
% \usepackage{fontspec,xunicode}
% \defaultfontfeatures{Mapping=tex-text}
% \setmainfont[Renderer=Basic, Numbers=OldStyle, Scale = 1.0]{TeX Gyre Pagella}
% \setmathrm[Renderer=Basic, Scale=0.90]{TeX Gyre Pagella}
% \setsansfont[Renderer=Basic, Scale=0.90]{TeX Gyre Heros}
% \setmonofont[Renderer=Basic]{TeX Gyre Cursor}
% \newfontfamily{\thaifont}{TH Sarabun New}[Scale=MatchLowercase]
% \usepackage[Latin, Thai]{ucharclasses}
% \setTransitionTo{Thai}{\thaifont}
% \setTransitionFrom{Thai}{\normalfont}
% \XeTeXlinebreaklocale "th_TH"
% \XeTeXlinebreakskip = 0pt plus 1pt
% \defaultfontfeatures{Scale=1.23}
%----------------------------------------------------
% Adjust size of the body text
\AtBeginDocument{\fontsize{14}{16.2}\selectfont}
% Math & scientific packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{physics}
\usepackage{setspace}
\usepackage{csquotes}
\usepackage{enumitem}
\usepackage{hyphenat}
\usepackage{url}
% \usepackage[ % for text hyperlink
% colorlinks=true,
% linkcolor=blue,
% urlcolor=blue,
% citecolor=blue,
% anchorcolor=blue,
% filecolor=blue,
% pdfborder={0 0 0},
% breaklinks,
% ]{hyperref}
\usepackage{xargs}
% \renewcommandx{\cite}[3][1={0pt},2={}]{\sidenote[][#1]{\fullcite[#2]{#3}}}
\usepackage[
backend=bibtex,
% autocite=footnote,
sorting=none,
style=numeric,
natbib=true,
mincitenames=1,
doi=false,
url=false,
isbn=false,
backref=true
]{biblatex}
\addbibresource{references.bib}
%%
% For nicely typeset tabular material
\usepackage{booktabs}
% For graphics / images
\usepackage{graphicx}
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{graphics/}}
% The fancyvrb package lets us customize the formatting of verbatim
% environments. We use a slightly smaller font.
\usepackage{fancyvrb}
\fvset{fontsize=\normalsize}
%%
% Prints argument within hanging parentheses (i.e., parentheses that take
% up no horizontal space). Useful in tabular environments.
\newcommand{\hangp}[1]{\makebox[0pt][r]{(}#1\makebox[0pt][l]{)}}
%%
% Prints an asterisk that takes up no horizontal space.
% Useful in tabular environments.
\newcommand{\hangstar}{\makebox[0pt][l]{*}}
%%
% Prints a trailing space in a smart way.
\usepackage{xspace}
% Prints the month name (e.g., January) and the year (e.g., 2008)
\newcommand{\monthyear}{%
\ifcase\month\or January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or
December\fi\space\number\year
}
% Prints an epigraph and speaker in sans serif, all-caps type.
\newcommand{\openepigraph}[2]{%
%\sffamily\fontsize{14}{16}\selectfont
\begin{fullwidth}
\sffamily\large
\begin{doublespace}
\noindent\allcaps{#1}\\% epigraph
\noindent\allcaps{#2}% author
\end{doublespace}
\end{fullwidth}
}
% Inserts a blank page
\newcommand{\blankpage}{\newpage\hbox{}\thispagestyle{empty}\newpage}
\usepackage{units}
% Typesets the font size, leading, and measure in the form of 10/12x26 pc.
\newcommand{\measure}[3]{#1/#2$\times$\unit[#3]{pc}}
% Macros for typesetting the documentation
\newcommand{\hlred}[1]{\textcolor{Maroon}{#1}}% prints in red
\newcommand{\hangleft}[1]{\makebox[0pt][r]{#1}}
\newcommand{\hairsp}{\hspace{1pt}}% hair space
\newcommand{\hquad}{\hskip0.5em\relax}% half quad space
\newcommand{\TODO}{\textcolor{red}{\bf TODO!}\xspace}
\newcommand{\ie}{\textit{i.\hairsp{}e.}\xspace}
\newcommand{\eg}{\textit{e.\hairsp{}g.}\xspace}
\newcommand{\na}{\quad--}% used in tables for N/A cells
\providecommand{\XeLaTeX}{X\lower.5ex\hbox{\kern-0.15em\reflectbox{E}}\kern-0.1em\LaTeX}
\newcommand{\tXeLaTeX}{\XeLaTeX\index{XeLaTeX@\protect\XeLaTeX}}
% \index{\texttt{\textbackslash xyz}@\hangleft{\texttt{\textbackslash}}\texttt{xyz}}
\newcommand{\tuftebs}{\symbol{'134}}% a backslash in tt type in OT1/T1
\newcommand{\doccmdnoindex}[2][]{\texttt{\tuftebs#2}}% command name -- adds backslash automatically (and doesn't add cmd to the index)
\newcommand{\doccmddef}[2][]{%
\hlred{\texttt{\tuftebs#2}}\label{cmd:#2}%
\ifthenelse{\isempty{#1}}%
{% add the command to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2}}% command name
}%
{% add the command and package to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2} (\texttt{#1} package)}% command name
\index{#1 package@\texttt{#1} package}\index{packages!#1@\texttt{#1}}% package name
}%
}% command name -- adds backslash automatically
\newcommand{\doccmd}[2][]{%
\texttt{\tuftebs#2}%
\ifthenelse{\isempty{#1}}%
{% add the command to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2}}% command name
}%
{% add the command and package to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2} (\texttt{#1} package)}% command name
\index{#1 package@\texttt{#1} package}\index{packages!#1@\texttt{#1}}% package name
}%
}% command name -- adds backslash automatically
\newcommand{\docopt}[1]{\ensuremath{\langle}\textrm{\textit{#1}}\ensuremath{\rangle}}% optional command argument
\newcommand{\docarg}[1]{\textrm{\textit{#1}}}% (required) command argument
\newenvironment{docspec}{\begin{quotation}\ttfamily\parskip0pt\parindent0pt\ignorespaces}{\end{quotation}}% command specification environment
\newcommand{\docenv}[1]{\texttt{#1}\index{#1 environment@\texttt{#1} environment}\index{environments!#1@\texttt{#1}}}% environment name
\newcommand{\docenvdef}[1]{\hlred{\texttt{#1}}\label{env:#1}\index{#1 environment@\texttt{#1} environment}\index{environments!#1@\texttt{#1}}}% environment name
\newcommand{\docpkg}[1]{\texttt{#1}\index{#1 package@\texttt{#1} package}\index{packages!#1@\texttt{#1}}}% package name
\newcommand{\doccls}[1]{\texttt{#1}}% document class name
\newcommand{\docclsopt}[1]{\texttt{#1}\index{#1 class option@\texttt{#1} class option}\index{class options!#1@\texttt{#1}}}% document class option name
\newcommand{\docclsoptdef}[1]{\hlred{\texttt{#1}}\label{clsopt:#1}\index{#1 class option@\texttt{#1} class option}\index{class options!#1@\texttt{#1}}}% document class option name defined
\newcommand{\docmsg}[2]{\bigskip\begin{fullwidth}\noindent\ttfamily#1\end{fullwidth}\medskip\par\noindent#2}
\newcommand{\docfilehook}[2]{\texttt{#1}\index{file hooks!#2}\index{#1@\texttt{#1}}}
\newcommand{\doccounter}[1]{\texttt{#1}\index{#1 counter@\texttt{#1} counter}}
% Generates the index
\usepackage{imakeidx}
\makeindex
%---------------------------------
\makeatletter
\newcommand{\plainsubtitle}{}% plain-text-only subtitle
\newcommand{\subtitle}[1]{%
\gdef\@subtitle{#1}%
\renewcommand{\plainsubtitle}{#1}% use provided plain-text title
\ifthenelse{\isundefined{\hypersetup}}%
{}% hyperref is not loaded; do nothing
{\hypersetup{pdftitle={\plaintitle: \plainsubtitle{}}}}% set the PDF metadata title
}
\renewcommand{\maketitlepage}{%
\begingroup%
\setlength{\parindent}{0pt}
{\fontsize{24}{24}\selectfont\textit{\@author}\par} % author
\vspace{1.75in}{\fontsize{32}{54}\selectfont\@title\par} % title
\vspace{0.20in}{\fontsize{24}{28}\selectfont\noindent\plainsubtitle\par}
\vspace{0.5in}{\fontsize{14}{16}\selectfont\textsf{\smallcaps{\@date}}\par} % date
\vfill{\fontsize{14}{16}\selectfont\textit{\@publisher}\par}
\thispagestyle{empty}
\endgroup
}
\makeatother
%---------------------------------
\setlength{\parindent}{4em}
\setlength{\parskip}{1em}
% add numbers to chapters, sections, subsections
\setcounter{secnumdepth}{4}
\usepackage{xcolor}
\definecolor{g1}{HTML}{077358}
\definecolor{g2}{HTML}{00b096}
% set level of TOC
\setcounter{tocdepth}{3}
% line spacing
\usepackage{tocloft}
\renewcommand{\contentsname}{\bfseries\Huge สารบัญ}
\renewcommand\cftchapafterpnum{\vskip10pt}
\renewcommand\cftsecafterpnum{\vskip10pt}
\ifthenelse{\boolean{@tufte@toc}}{%
\titlecontents{part}%
[0em] % distance from left margin
{\vspace{0.3\baselineskip}\begin{fullwidth}\huge\rmfamily\itshape} % above (global formatting of entry)
{\hspace*{0em}\contentslabel{0em}\hspace*{0.5in}} % before w/label (label = ``2'')
{\hspace*{0em}\contentslabel{0em}Part~} % before w/o label
{\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
[\end{fullwidth}] % after
\titlecontents{chapter}%
[0em] % distance from left margin
{\vspace{.3\baselineskip}\begin{fullwidth}\huge\rmfamily\itshape} % above (global formatting of entry)
{\hspace*{0em}\contentslabel{2em}} % before w/label (label = ``2'')
{\hspace*{0em}} % before w/o label
{\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
[\end{fullwidth}] % after
\titlecontents{section}% FIXME
[0em] % distance from left margin
{\vspace{0\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
{\hspace*{2em}\contentslabel{2em}} % before w/label (label = ``2.6'')
{\hspace*{2em}} % before w/o label
{\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
[\end{fullwidth}] % after
\titlecontents{subsection}% FIXME
[0em] % distance from left margin
{\vspace{0\baselineskip}\begin{fullwidth}\Large\rmfamily\itshape} % above (global formatting of entry)
{\hspace*{4em}\contentslabel{4em}} % before w/label (label = ``2.6.1'')
{\hspace*{4em}} % before w/o label
{\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
[\end{fullwidth}] % after
\titlecontents{paragraph}% FIXME
[0em] % distance from left margin
{\vspace{0\baselineskip}\begin{fullwidth}\normalsize\rmfamily\itshape} % above (global formatting of entry)
{\hspace*{6em}\contentslabel{2em}} % before w/label (label = ``2.6.0.0.1'')
{\hspace*{6em}} % before w/o label
{\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
[\end{fullwidth}] % after
}{}
%---------------------------------
% part format
\titleclass{\part}{top}
\titleformat{\part}%
[hang]% shape MOSS: changed from [display] to [hang] to remove newline
{}% format applied to label+text
{\itshape\Huge Part~\thepart:}% label
{1em}% horizontal separation between label and title body
{\huge\rmfamily\itshape}% before the title body
% chapter format %(if you use tufte-book class)
\titleformat{\chapter}%
{\Huge\rmfamily\itshape\bfseries\color{red}}% format applied to label+text
{\llap{\colorbox{red}{\parbox{1.5cm}{\hfill\itshape\huge\color{white}\thechapter}}}}% label
{5pt}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
% section format
\titleformat{\section}%
{\normalfont\huge\itshape\color{g1}}% format applied to label+text
{\llap{\colorbox{g1}{\parbox{1.5cm}{\hfill\color{white}\thesection}}}}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
% subsection format
\titleformat{\subsection}%
{\normalfont\LARGE\itshape\color{g2}}% format applied to label+text
{\llap{\colorbox{g2}{\parbox{1.5cm}{\hfill\color{white}\thesubsection}}}}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment