%%
%% This is file `dtx-style.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bithesis.dtx  (with options: `dtx-style')
%% bithesis-doc-style.dtx 
%% bithesis-finale.dtx 
%% 
%%   Copyright (C) 2020–2026
%%   Net Pioneer Association of BIT and any individual authors listed in the documentation.
%% ------------------------------------------------------------------------------
%% 
%%     This work may be distributed and/or modified under the
%%     conditions of the LaTeX Project Public License, either
%%     version 1.3c of this license or (at your option) any later
%%     version. This version of this license is in
%%        https://www.latex-project.org/lppl/lppl-1-3c.txt
%%     and the latest version of this license is in
%%        https://www.latex-project.org/lppl.txt
%%     and version 1.3 or later is part of all distributions of
%%     LaTeX version 2020/11/27 or later.
%% 
%%     This work has the LPPL maintenance status `maintained'.
%% 
%%     The Current Maintainer of this work is Feng Kaiyu.
%% ------------------------------------------------------------------------------
%% 
\ProvidesPackage{dtx-style}
\RequirePackage{hypdoc}
\RequirePackage{ifthen}
\RequirePackage[quiet]{fontspec}
\RequirePackage{amsmath}
\RequirePackage{unicode-math}
\RequirePackage[UTF8,scheme=chinese,heading,sub3section]{ctex}
\RequirePackage[
  top=2.5cm, bottom=2.5cm,
  left=5cm, right=2cm,
  headsep=3mm]{geometry}
\RequirePackage{graphicx}
\RequirePackage{multirow}
\RequirePackage{wrapfig}
\RequirePackage{hologo}
\RequirePackage{array,longtable,booktabs}
\RequirePackage{listings}
\RequirePackage{fancyhdr}
\RequirePackage[dvipsnames,table,xcdraw]{xcolor}
\RequirePackage{awesomebox}
\RequirePackage{dirtree}
\RequirePackage{metalogo}
\RequirePackage[tightLists=false]{markdown}
\RequirePackage{caption}
\RequirePackage{tikz}
\usetikzlibrary{positioning}
\RequirePackage{framed}
\RequirePackage{menukeys}
\RequirePackage{float}
\RequirePackage{subfig}

 % 设置列表无间隔
\usepackage{enumitem}
\setlist{nosep}

\markdownSetup{
  renderers = {
    link = {\href{#2}{#1}},
  }
}

\hypersetup{
  pdflang     = zh-CN,
  pdftitle    = {BIThesis：北京理工大学学位论文及报告模板},
  pdfauthor   = {冯开宇},
  pdfsubject  = {北京理工大学学位论文及报告模板使用说明},
  pdfkeywords = {论文模板; 北京理工大学; 使用说明},
  pdfdisplaydoctitle = true
}%

\renewcommand{\subsectionautorefname}{小节}
\renewcommand{\subsubsectionautorefname}{小节}
\renewcommand{\sectionautorefname}{节}
\renewcommand{\chapterautorefname}{章}

\newcommand{\BIThesisLaTeX}{{\BIThesis}北京理工大学学位论文及报告{\LaTeX}模板}
\newcommand{\BIThesisMacroPackage}{{\BIThesis}宏包}
\newcommand{\BIThesisWiki}{{\BIThesis}在线文档}
\newcommand{\BIThesisScaffold}{{\BIThesis}模板}
\newcommand{\BIThesisRelease}{{\BIThesis}模板}
\newcommand{\LPPL}{{\href{https://www.latex-project.org/lppl/lppl-1-3c.txt}{\LaTeX{} Project Public License (1.3.c)}}}
\newcommand{\versionold}{v2.0 BirthdayCake}
\newcommand{\version}{v3 Summer Time}

\ExplSyntaxOn

\AtBeginEnvironment { bitsyntax } {
  \cs_set:Npn \lparen { \textup { ( } }
  \cs_set:Npn \rparen { \textup { ) } }
  \char_set_catcode_active:N |
  \char_set_catcode_active:N <
  \char_set_catcode_active:N (
  \char_set_active_eq:NN | \orbar
  \char_set_active_eq:NN < \syntaxopt@aux
  \char_set_active_eq:NN ( \defaultval@aux
}

\NewDocumentCommand \BIThesisTemplates {m} {
  \str_case:nn {#1} {
    {UT}{本科生毕业论文模板（undergraduate-thesis）}
    {UTE}{本科生全英文专业毕业论文模板（undergraduate-thesis-en）}
    {GT}{研究生学位论文模板（graduate-thesis）}
    {LR}{简易实验报告模板（lab-report）}
    {PT}{本科生毕业设计外文翻译模板（paper-translation）}
    {PS}{北理工主题的 Beamer 模板（presentation-slide）}
    {UP}{本科生毕业设计开题报告（undergraduate-proposal，已废弃）}
    {RR}{本科生读书报告模板（reading-report）}
  }
}

\def\breakablethinspace{\hskip 0.16667em\relax}

\DeclareDocumentCommand\kvopt{mm}
  {\texttt{#1\breakablethinspace=\breakablethinspace#2}}

\ExplSyntaxOff

\ctexset{
  today=big,
  abstractname=简介,
}

\pagestyle{fancy}

\ctexset{section={
  format={\raggedright \bfseries \zihao{-3}},
  name = {第,章}
  }
}

\ctexset{subsection={
  format = {\bfseries \raggedright \zihao{4}}
  }
}

\ifthenelse{\equal{\@nameuse{g__ctex_fontset_tl}}{mac}}{
  \setmainfont{Palatino}
  \setsansfont[Scale=MatchLowercase]{Helvetica}
  \setmonofont[Scale=MatchLowercase]{Menlo}
  \xeCJKsetwidth{‘’“”}{1em}
}{
  \setmainfont[
    Extension      = .otf,
    UprightFont    = *-regular,
    BoldFont       = *-bold,
    ItalicFont     = *-italic,
    BoldItalicFont = *-bolditalic,
  ]{texgyrepagella}
  \setsansfont[
    Extension      = .otf,
    UprightFont    = *-regular,
    BoldFont       = *-bold,
    ItalicFont     = *-italic,
    BoldItalicFont = *-bolditalic,
  ]{texgyreheros}
  \setmonofont[
    Extension      = .otf,
    UprightFont    = *-regular,
    BoldFont       = *-bold,
    ItalicFont     = *-italic,
    BoldItalicFont = *-bolditalic,
    Scale          = MatchLowercase,
    Ligatures      = CommonOff,
  ]{texgyrecursor}
}
\unimathsetup{
  math-style=ISO,
  bold-style=ISO,
}
\IfFontExistsTF{XITSMath-Regular.otf}{
  \setmathfont[
    Extension    = .otf,
    BoldFont     = XITSMath-Bold,
    StylisticSet = 8,
  ]{XITSMath-Regular}
  \setmathfont[range={cal,bfcal},StylisticSet=1]{XITSMath-Regular.otf}
}{
  \setmathfont[
    Extension    = .otf,
    BoldFont     = *bold,
    StylisticSet = 8,
  ]{xits-math}
  \setmathfont[range={cal,bfcal},StylisticSet=1]{xits-math.otf}
}

\colorlet{bit@macro}{blue!60!black}
\colorlet{bit@env}{blue!70!black}
\colorlet{bit@option}{purple}
\patchcmd{\PrintMacroName}{\MacroFont}{\MacroFont\bfseries\color{bit@macro}}{}{}
\patchcmd{\PrintDescribeMacro}{\MacroFont}{\MacroFont\bfseries\color{bit@macro}}{}{}
\patchcmd{\PrintDescribeEnv}{\MacroFont}{\MacroFont\bfseries\color{bit@env}}{}{}
\patchcmd{\PrintEnvName}{\MacroFont}{\MacroFont\bfseries\color{bit@env}}{}{}

\def\DescribeOption{%
  \leavevmode\@bsphack\begingroup\MakePrivateLetters%
  \Describe@Option}
\def\Describe@Option#1{\endgroup
  \marginpar{\raggedleft\PrintDescribeOption{#1}}%
  \bit@special@index{option}{#1}\@esphack\ignorespaces}
\def\PrintDescribeOption#1{\strut \MacroFont\bfseries\sffamily\color{bit@option} #1\ }
\def\bit@special@index#1#2{\@bsphack
  \begingroup
    \HD@target
    \let\HDorg@encapchar\encapchar
    \edef\encapchar usage{%
      \HDorg@encapchar hdclindex{\the\c@HD@hypercount}{usage}%
    }%
    \index{#2\actualchar{\string\ttfamily\space#2}
           (#1)\encapchar usage}%
    \index{#1:\levelchar#2\actualchar
           {\string\ttfamily\space#2}\encapchar usage}%
  \endgroup
  \@esphack}

\lstdefinestyle{lstStyleBase}{%
   basicstyle=\small\ttfamily,
   aboveskip=\medskipamount,
   belowskip=\medskipamount,
   lineskip=0pt,
   boxpos=c,
   showlines=false,
   extendedchars=true,
   escapeinside  = {(*}{*)},
   upquote=true,
   tabsize=2,
   showtabs=false,
   showspaces=false,
   showstringspaces=false,
   numbers=none,
   linewidth=\linewidth,
   xleftmargin=4pt,
   xrightmargin=0pt,
   resetmargins=false,
   breaklines=true,
   breakatwhitespace=false,
   breakindent=0pt,
   breakautoindent=true,
   columns=flexible,
   keepspaces=true,
   gobble=0,
   framesep=3pt,
   rulesep=1pt,
   framerule=1pt,
   backgroundcolor=\color{gray!5},
   stringstyle=\color{green!40!black!100},
   keywordstyle=\bfseries\color{blue!50!black},
   commentstyle=\slshape\color{black!60}}

\lstdefinestyle{lstStyleShell}{%
   style=lstStyleBase,
   frame=l,
   rulecolor=\color{purple},
   language=bash,
}

\lstdefinestyle{lstStyleLaTeX}{%
   style=lstStyleBase,
   frame=l,
   rulecolor=\color{violet},
   language=[LaTeX]TeX,
   emphstyle=[1]\color{teal},
}

\lstdefinestyle{lstStyleSyntax}{%
   style=lstStyleBase,
   frame=l,
   rulecolor=\color{violet},
   language=[LaTeX]TeX,
   emphstyle=[1]\color{teal},
}

\lstnewenvironment{latex}[1][]{\lstset{style=lstStyleLaTeX, #1}}{}
\lstnewenvironment{shell}[1][]{\lstset{style=lstStyleShell, #1}}{}
\lstnewenvironment{bitsyntax}[1][]{\lstset{style=lstStyleSyntax, #1}}{}

\def\orbar{\textup{\textbar}}
\def\syntaxopt#1{\textit{#1}}
\def\defaultval#1{\textbf{\textup{#1}}}
\def\syntaxopt@aux#1>{\syntaxopt{#1}}
\def\defaultval@aux#1){\defaultval{#1}}

\setlist{nosep}

\DeclareDocumentCommand{\option}{m}{\textsf{#1}}
\DeclareDocumentCommand{\env}{m}{\texttt{#1}}
\newcommand{\myentry}[1]{%
  \marginpar{\raggedleft\color{purple}\bfseries\strut #1}}
\newenvironment{note}[1][Note]
  {{\color{magenta} \bfseries #1} \itshape}
  {}

\DeclareDocumentCommand{\githubuser}{m}{\href{https://github.com/#1}{@#1}}

  % 设置 caption 与 figure 之间的距离
\setlength{\abovecaptionskip}{11pt}
\setlength{\belowcaptionskip}{9pt}

  % 设置图片的 caption 格式
\renewcommand{\thefigure}{\thesection-\arabic{figure}}
\captionsetup[figure]{font=small,labelsep=space}

  % 设置表格的 caption 与 table 之间的垂直距离
\captionsetup[table]{skip=2pt}

  % 设置表格的 caption 格式
\renewcommand{\thetable}{\thesection-\arabic{table}}
\captionsetup[table]{font=small,labelsep=space}

  % 定义 BIThesis \LaTeX 风格的 Logo
\usepackage{relsize}
\makeatletter
\def\matex@ssize{\smaller\scshape}
\DeclareRobustCommand{\BIThesis}{
  \texorpdfstring{\mbox{
      \kern-0.5em{B}\kern-0.05em
      {I}\kern-0.05em
      {T}\kern-0.1em
      \raisebox{-0.38ex}{\matex@ssize {H}}\kern-0.1em
      {\matex@ssize {E}}\kern-0.05em
      \raisebox{-0.38ex}{\matex@ssize {S}}\kern-0.05em
      {\matex@ssize {I}}\kern-0.05em
      \raisebox{-0.35ex}{\matex@ssize {S}}\kern-0.5em
      \kern 1ex
     }}{BIThesis}
}

%% from \pkg{ctxdoc}
\newlist{optdesc}{description}{3}
%% 设置间距为 \marginparsep，与 l3doc 一致
\setlist[optdesc]{%
  font=\mdseries\small\ttfamily,align=right,listparindent=\parindent,
  labelsep=\marginparsep,labelindent=-\marginparsep,leftmargin=0pt}

\makeatother

\endinput
%%
%% End of file `dtx-style.sty'.
