如何在 KOMA-script 中实现文档范围的标题大小写大写?

如何在 KOMA-script 中实现文档范围的标题大小写大写?

我想在 KOMA-script-typeset 标题页和章节标题中使用标题大小写。

当然可以

\documentclass[version=last]{scrreprt} % it's 3.32
\usepackage{titlecaps}

\title{\titlecap{The Beginning of the document}}

\begin{document}
    \maketitle
    \tableofcontents
    \section{\titlecap{My title with caps}}
\end{document}          

不过,我想说一些惯用的话,比如说,

\setkomafont{disposition}{\rmfamily\MakeTitleCase}

如何实现标题大小写自动化?

答案1

您可以修补\chapterlinesformat,,,也许:\chapterlineswithprefixformat\sectionlinesformat\sectioncatchphraseformat\minisec

\usepackage{titlecaps}
\usepackage{xpatch}

\newcommand*\MakeTitleCase[1]{\titlecap{#1}}

\xpatchcmd\chapterlinesformat{#3}{\MakeTitleCase{#3}}{}{\clfpatchfailed}
\xpatchcmd\chapterlineswithprefixformat{#3}{\MakeTitleCase{#3}}{}{\clwpfpatchfailed}
\xpatchcmd\sectionlinesformat{#4}{\MakeTitleCase{#4}}{}{\slfpatchfailed}
\xpatchcmd\sectioncatchphraseformat{#4}{\MakeTitleCase{#4}}{}{\scpfpatchfailed}
\xpatchcmd\minisec{#1}{\MakeTitleCase{#1}}{}{\mspatchfailed}

对于标题,您可以使用

\newcommand*\originaltitle{}
\let\originaltitle\title
\renewcommand\title[1]{\originaltitle{\MakeTitleCase{#1}}}

\newcommand*\originaladdchaptertocentry{}
\let\originaladdchaptertocentry\addchaptertocentry
\renewcommand*\addchaptertocentry[2]{\originaladdchaptertocentry{#1}{\MakeTitleCase{#2}}}

\MakeTitleCase目录中仅使用章节条目。

如果目录中的所有条目都应使用\MakeTitleCase

\newcommand*\originaladdtocentrydefault{}
\let\originaladdtocentrydefault\addtocentrydefault
\renewcommand*\addtocentrydefault[3]{\originaladdtocentrydefault{#1}{#2}{\MakeTitleCase{#3}}}

例子:

\documentclass[version=last]{scrreprt} % it's 3.32
\usepackage{titlecaps}
\usepackage{xpatch}

\newcommand*\MakeTitleCase[1]{\titlecap{#1}}

\xpatchcmd\chapterlinesformat{#3}{\MakeTitleCase{#3}}{}{\clfpatchfailed}
\xpatchcmd\chapterlineswithprefixformat{#3}{\MakeTitleCase{#3}}{}{\clwpfpatchfailed}
\xpatchcmd\sectionlinesformat{#4}{\MakeTitleCase{#4}}{}{\slfpatchfailed}
\xpatchcmd\sectioncatchphraseformat{#4}{\MakeTitleCase{#4}}{}{\scpfpatchfailed}
\xpatchcmd\minisec{#1}{\MakeTitleCase{#1}}{}{\mspatchfailed}

\newcommand*\originaltitle{}
\let\originaltitle\title
\renewcommand\title[1]{\originaltitle{\MakeTitleCase{#1}}}


\newcommand*\originaladdtocentrydefault{}
\let\originaladdtocentrydefault\addtocentrydefault
\renewcommand*\addtocentrydefault[3]{\originaladdtocentrydefault{#1}{#2}{\MakeTitleCase{#3}}}

\title{The Beginning of the document}
\author{Author}
\begin{document}
\maketitle
\tableofcontents
\chapter{A chapter with caps}
\section{A section with caps}
\minisec{A minisec with caps}
\paragraph{A paragraph with caps}
Example text ...
\end{document}

在此处输入图片描述

相关内容