% Book layout and memoir styles.
% Copyright 2019, 2026 Adib Hasan. Part of BOOKbangla; LPPL 1.3c or later.

% Apply the book's trimmed layout only when it fits the selected stock.
% Smaller paper options retain memoir's own page and margin dimensions, so
% layout validation succeeds before authors can apply further adjustments.
\ifdim\stockwidth<\dimexpr6.8in+53.118pt\relax
\else
  \ifdim\stockheight<\dimexpr9.5in+79.136pt\relax
  \else
    \settrimmedsize{9.5in}{6.8in}{*}
    \settrims{79.136pt}{53.118pt}
    \settypeblocksize{7.8in}{5in}{*}
    \setlrmargins{*}{*}{1}
    \setulmargins{*}{*}{.7}
  \fi
\fi
% Allow room for the tested Bangla heading fonts, avoiding clipped headers.
\setheadfoot{18pt}{30pt}
\checkandfixthelayout
\linespread{1.15}
\setlength{\parskip}{4pt}
\setlength{\parindent}{0pt}
\interfootnotelinepenalty=1000
\allowdisplaybreaks

\definecolor{bookbanglaaccent}{RGB}{60,60,60}
\colorlet{bookbanglaboxframe}{black}
\colorlet{bookbanglaboxbackground}{white}

\renewcommand*\cftchapteraftersnum{.}

% Memoir retains \thetitle after \maketitle, unlike LaTeX's temporary \@title.
% A page can ship out while a bibliography entry is in English. Running heads
% and page numbers still belong to the book's language.
\newcommand*\bookbangla@runningtext[1]{%
  \foreignlanguage{\mainlanguagename}{#1}}
\makepagestyle{bookbangla}
\makeevenhead{bookbangla}{\bookbangla@runningtext{\thepage}}{}%
  {\bookbangla@runningtext{\itshape\thetitle}}
\makeoddhead{bookbangla}{\bookbangla@runningtext{\itshape\rightmark}}{}%
  {\bookbangla@runningtext{\thepage}}
\makeevenfoot{plain}{}{\bookbangla@runningtext{\thepage}}{}
\makeoddfoot{plain}{}{\bookbangla@runningtext{\thepage}}{}
\makepsmarks{bookbangla}{%
  \nouppercaseheads
  \createmark{section}{right}{shownumber}{}{\space}}
\pagestyle{bookbangla}

% Bangla has no small-cap case. Avoid lettrine's default small-cap request for
% the word following the initial, which otherwise produces font substitutions.
\renewcommand*\LettrineTextFont{\normalfont}

% This is an optional ornament, not a mandatory chapter-opening convention.
\newcommand\firstword[2]{%
  \lettrine[lraise=.25,nindent=0pt,findent=2pt]{#1}{#2}}
\endinput
