% 2026-01-09 cp  initial cut of shared preamble for NU physics deck
% 2026-01-09 pds tuned fonts, Thai line breaks, and baseline spacing
% 2026-01-09 cp adopted \thaifont{...} "second form" for robust Thai markup
% 2026-03-17 pds \XeTeXlinebreaklocale moved to \AtBeginDocument (safe for any class)
%                merged duplicate \fvset blocks
%                fixed typo: BVerbadim -> BVerbatim

% Fonts, languages, and packages are centralized here so the slide
% files stay as close as possible to "content only".

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{amsmath}
%\usepackage{amssymb}
\usepackage{tikz}
\usepackage{fancyvrb}
\usetikzlibrary{arrows.meta}

% Languages
\setmainlanguage{english}
\setotherlanguage{thai}

% Thai line breaking: important so Thai text doesn't overlap or break
% mid-cluster. These values come from pds' experience with book-length
% Thai documents.
% \AtBeginDocument ensures these XeTeX primitives fire after the document
% class (Beamer, article, book, etc.) has initialized its typesetting
% context. Placing them bare in the preamble is unreliable across classes.
\AtBeginDocument{%
  \XeTeXlinebreaklocale "th"
  \XeTeXlinebreakskip = 0pt plus 2.5pt
}

% Fonts
\newfontfamily\englishfont{TeX Gyre Pagella}[
  Ligatures=Rare,
  Scale=MatchLowercase
]

\newfontfamily\thaifont{THSarabunNew}[
  Path           = ./fonts/THSarabunNew/,
  Extension      = .ttf,
  Scale          = MatchUppercase,
  UprightFont    = THSarabunNew,
  BoldFont       = THSarabunNew Bold,
  ItalicFont     = THSarabunNew Italic,
  BoldItalicFont = THSarabunNew BoldItalic
]

% Code font: TeX Gyre Cursor slightly reduced. This is based on
% pds' observation that Cursor is visually a bit large relative
% to Thai; Scale=0.85 harmonizes them.
\setmonofont{TeX Gyre Cursor}[
  Ligatures=NoCommon,
  Scale=0.85
]

% Global text size tuning. 12/18 gives comfortable line spacing
% for mixed Thai and Latin, and plays well with header height.
\renewcommand{\normalsize}{\fontsize{12}{18}\selectfont}

% FancyVerbatim tuning. All code is in BVerbatim blocks, never inline
% \texttt, to avoid Beamer's fragile frame issues and catcode traps.
% allow \cmd{arg} escape inside BVerbatim blocks when needed.
% Note: escape literal backslashes inside code as \textbackslash{}
\fvset{
  fontsize=\small,
  commandchars=\\\{\}
}

% Beamer font usage
\setbeamerfont{normal text}{family=\englishfont}
\setbeamerfont{frametitle}{family=\englishfont}
\setbeamerfont{title}{family=\englishfont}

\mode<presentation>{
  \usetheme{default}
}

% for \textblock{}
\usepackage[absolute,overlay]{textpos}

