From f6b0b42506502f19eb3717c9a1c18c68f1b18467 Mon Sep 17 00:00:00 2001 From: ywxy12138 <176694876+ywxy12138@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:57:54 +0800 Subject: [PATCH] Preserve algorithm emphasis when loading ulem --- buaathesis.cls | 4 ++-- tests/README.md | 11 ++++++++++ tests/algorithm-emphasis.tex | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/README.md create mode 100644 tests/algorithm-emphasis.tex diff --git a/buaathesis.cls b/buaathesis.cls index 3e3bdba..f92e439 100644 --- a/buaathesis.cls +++ b/buaathesis.cls @@ -563,8 +563,8 @@ The LaTeX template for thesis of BUAA] \oldappendix\rmrelation } -% 下划线 -\RequirePackage{ulem} +% 保留显式下划线命令,同时避免将强调文字(如 algorithm2e 的条件)改为下划线 +\RequirePackage[normalem]{ulem} % 设置行距 \RequirePackage{setspace} diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..06625f4 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,11 @@ +# 算法强调样式回归样例 + +在仓库根目录执行: + +```sh +xelatex -halt-on-error tests/algorithm-emphasis.tex +``` + +依赖与论文模板相同,另需安装 `algorithm2e` 宏包。 +样例检查 `\emph` 是否仍选择斜体;若被 `ulem` 改成下划线,编译将报错。 +生成的 PDF 中,`while` 和 `if` 的条件应为斜体且没有下划线,末尾三个显式下划线仍应显示。 diff --git a/tests/algorithm-emphasis.tex b/tests/algorithm-emphasis.tex new file mode 100644 index 0000000..2e084a2 --- /dev/null +++ b/tests/algorithm-emphasis.tex @@ -0,0 +1,41 @@ +% 使用 xelatex -halt-on-error tests/algorithm-emphasis.tex 编译。 +\documentclass[master,openright,twoside,color,AutoFakeBold=true]{buaathesis} +\usepackage[ruled]{algorithm2e} + +\begin{document} +% ulem 不应接管强调命令;算法条件也使用这一命令。 +\makeatletter +\emph{% + \edef\actualshape{\f@shape}% + \def\expectedshape{it}% + \ifx\actualshape\expectedshape\else + \PackageError{algorithm-emphasis}{Emphasis no longer selects italic text}{}% + \fi + Ordinary emphasis% +} +\makeatother + +\begin{algorithm}[H] + \SetAlgoLined + \KwData{this text} + \KwResult{how to write an algorithm} + initialization\; + \While{not at end of this document}{ + read current\; + \eIf{understand}{ + go to next section\; + current section becomes this one\; + }{ + go back to the beginning of current section\; + } + } + \caption{Algorithm emphasis regression} +\end{algorithm} + +% 显式下划线及封面使用的辅助命令仍须可用。 +\uline{Explicit underline} + +\ulinecvrtc{Student ID} + +\ulinecvcbc{School} +\end{document}