\@ssect 的不兼容用法

\@ssect 的不兼容用法

为了定制章节和部分标题的布局,通常建议按以下方式进行:

\renewcommand{\chapter}{\@startsection{chapter}{0}{\z@}{-2em}{6pt}{\normalfont\LARGE\bfseries}}

我的代码必须在安装了不同 TeX 的机器上运行,特别是在安装了 KOMA-Script v. 3.11 的机器上,所以这似乎是唯一的方法(在后来的版本中引入了更好的 KOMA-Script 特定选项,用于重新定义章节布局等)。

但是,在最近的一次更新之后,我在其他机器上收到以下警告:

incompatible usage of \@ssect detected. You've used the KOMA-Script implementation of \@ssect from within a non compatible caller, that does not \scr@s@ct@@nn@m@ locally.

该问题似乎源于使用未编号的章节(包括目录标题和词汇表标题)。

另一个问题是将短章节标题与星号结合使用

MWE 如下:

\documentclass[%
final,% include images
twoside=semi
%]{scrartcl}
]{scrreprt}

%Layout redefinition of chapter, section, subsection and paragraph:
\makeatletter
\renewcommand{\chapter}{\@startsection{chapter}{0}{\z@}{-2em}{6pt}{\normalfont\LARGE\bfseries}}
\renewcommand{\section}{\@startsection{section}{1}{\z@}{-1.5em}{6pt}{\normalfont\Large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{1}{\z@}{-1.2em}{6pt}{\normalfont\large\bfseries}}
\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}{-2.25ex \@plus -1ex \@minus -0.2ex}{0.5ex \@plus 0.2ex}{\normalfont\normalsize\bfseries\itshape}}
\makeatother

\begin{document}

%the first warning komes here (tableofcontents is defined as chapter*, which makes problems)
\tableofcontents

%Here everything is ok:
\chapter[First chapter - short title]{First chapter - long title - here is everything ok}
Some text

%The second warning is issued here:
\section*{First Section - long title - asterisk poses a problem}
Some further text

%Here there are two problems:
% - asterisk issues a warning
% - content of [..] is not recognized as the shot subsection title
\subsection*[First subsection - short title]{First subsection - long title - asterisk poses a problem}
Some more text

\end{document}

是否有可能重新定义各个部分,使一切按照预期进行?

答案1

这种不兼容性是由 Koma-Script 在 3.15 版中引入的。从此版本开始,Koma-Script 使用\scr@startsection代替\@startsection。因此,消除警告的最简单方法是使用\scr@startsection代替并为旧版 Koma-Script\@startsection提供 的映射。这是通过\scr@startsection

\makeatletter
\@ifpackagelater{scrbase}{2014/12/12}{% for newer versions: do nothing:
    %
}{% for older versions: use \@startsection instead of \scr@startsection:
    \def\scr@startsection{\@startsection}%
}%
\makeatother

布局定制命令现在可以使用\scr@startsection宏:

\makeatletter
% redefinition of sectioning commands using either \scr@startsection
% or \@startsection (depending on the Koma-Script version)
\renewcommand{\chapter}{\scr@startsection{chapter}{0}{\z@}{-2em}{6pt}{\normalfont\LARGE\bfseries}}
\renewcommand{\section}{\scr@startsection{section}{1}{\z@}{-1.5em}{6pt}{\normalfont\Large\bfseries}}
\renewcommand{\subsection}{\scr@startsection{subsection}{1}{\z@}{-1.2em}{6pt}{\normalfont\large\bfseries}}
\renewcommand{\paragraph}{\scr@startsection{paragraph}{4}{\z@}{-2.25ex \@plus -1ex \@minus -0.2ex}{0.5ex \@plus 0.2ex}{\normalfont\normalsize\bfseries\itshape}}
\makeatother

如上所示,也可以使用不同 Koma-Script 版本之间的差异,以便使用最新的 Koma-Script 功能,而\RedeclareSectionCommand不会失去与旧安装的兼容性。

相关内容