Skip to content

Commit

Permalink
fix: support the algorithm2e package
Browse files Browse the repository at this point in the history
  • Loading branch information
YDX-2147483647 authored and fky2015 committed Apr 15, 2024
1 parent 7760e33 commit 0f1b217
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bithesis-doc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,12 @@ \subsubsection{定理类环境}
(*\meta{证明过程}*)
\end{proof}
\end{bitsyntax}

一系列预定义的数学环境。具体含义见表~\ref{tab:theorem}。

其中提供了算法环境 |algo|,但模板也适配了
\href{https://www.overleaf.com/learn/latex/Algorithms}{Overleaf}
介绍的 |algorithm|+X 方式或 |algorithm2e| 方式,您引入相关宏包即可使用。只需注意这三种方法并不兼容,而且采用 |algorithm2e| 方式时,要加上选项 |algochapter| 才能按学校要求分章编号(例如 |\usepackage[ruled,algochapter]{algorithm2e}|)。
\end{function}

\begin{table}[]
Expand Down
19 changes: 16 additions & 3 deletions bithesis.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,16 @@
tabularFontSize .initial:n = {5},
arialFont .tl_set:N = \l_@@_misc_arial_font_path_tl,
autoref / algo .code:n = {
% 定义算法的 autoref
\tl_set:Nn \algorithmautorefname {#1}
% 定义算法标题
\AtBeginDocument{
% 定义算法标题
% 针对 algorithm 宏包
\tl_set:Nn \ALG@name {#1}
% 针对 algorithm2e 宏包
\tl_set:Nn \algorithmcfname {#1}

% 定义算法的 autoref
% algorithm2e 宏包会覆写它,所以我们必须AtBeginDocument时再修改
\tl_set:Nn \algorithmautorefname {#1}
}
},
autoref / algo .initial:n = {\g_@@_const_autoref_algo_tl},
Expand Down Expand Up @@ -1596,8 +1601,16 @@
\cs_gset:Npn \lstlistingname {\c_@@_label_code_tl}

% 算法变成「章节号-序号」
% 针对 algorithm 宏包
\cs_gset:Npn \thealgorithm
{\thechapter\g__bithesis_label_divide_char_tl\arabic{algorithm}}
% 针对 algorithm2e 宏包
% 为了减少修改,我们只适配按章编号(algochapter)的情况。
\@ifpackagewith{algorithm2e}{algochapter}{
% 名字中的“cf”是指其作者 Christophe Fiorio。
\cs_gset:Npn \thealgocf
{\thechapter\g__bithesis_label_divide_char_tl\arabic{algocf}}
}{}

% 默认的情况下,保留公式和上下文的一定间距。(会比 Word 稍宽一些)
\setlength{\abovedisplayskip}{\l_@@_style_math_above_display_skip_dim}
Expand Down

0 comments on commit 0f1b217

Please sign in to comment.