强制 \bibname 全部大写

强制 \bibname 全部大写

我需要强制执行一个样式指南,要求所有章节和章节级别等效项的标题和目录条目全部大写。目前,我已经为大多数内容管理了这一点,但在参考书目方面遇到了问题。我知道我可以通过重新定义将参考书目名称预设为全部大写\bibname(类文件基于类report)。但是,我需要支持可能\bibname自己重新定义(或使用类似的东西babel)的用户,所以我想找到一种编程方式来强制将\bibname(无论它是什么)全部大写。不幸的是,我到目前为止的尝试都失败了。

我尝试用替换\bibliography命令来替换该命令,该替换首先重新命名\bibname,添加 ToC 条目,然后调用旧\bibliography命令,如该 MWE 中所示:

\documentclass{report}

\usepackage{hyperref} %must be supported, but not required

\makeatletter

\providecommand{\texorpdfstring}[2]{%
    #1%
}

\def\@chapter[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
        \refstepcounter{chapter}%
        \typeout{*** \@chapapp\space\thechapter\space ****}%
        \addtocontents{toc}{\protect\pagebreak[3]}%
        \def\@LastLevel{0}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter.}\space\texorpdfstring{\MakeUppercase{#1}}{#1}}%
    \else
        \addtocontents{toc}{\protect\pagebreak[3]}%
        \def\@LastLevel{0}%
        \addcontentsline{toc}{chapter}{\texorpdfstring{\MakeUppercase{#1}}{#1}}%
    \fi
    \chaptermark{#1}%
    \@makechapterhead{#2}%
}


\def\@makechapterhead#1{%
    \cleardoublepage
    \vspace*{0\p@}%
    {\parindent \z@ \raggedright \centering\normalfont\Large
        \ifnum \c@secnumdepth >\m@ne
            \bfseries \MakeUppercase{\chaptername}\ \thechapter
            \vskip -3pt
        \fi
        \interlinepenalty\@M
        \bfseries\texorpdfstring{\MakeUppercase{#1}}{#1}\par\nobreak
        \vskip 15\p@
    }%
}

\def\@makeschapterhead#1{%
    \cleardoublepage
    \vspace*{0\p@}%
    {\parindent \z@ \raggedright \centering\normalfont\Large
        \interlinepenalty\@M
%        \bfseries \texorpdfstring{\MakeUppercase{#1}}{#1}\par\nobreak
        \bfseries #1\par\nobreak
        \vskip 15\p@
    }%
}

%% Unnumbered bibliography
\let\oldbibliography\bibliography
\renewcommand\bibliography{%
  \addcontentsline{toc}{chapter}{\texorpdfstring{\MakeUppercase{\bibname}}{\bibname}}%
  \oldbibliography
}

%%%%%%%%%%%%%%%%%%%%%
% Page Style Definitions
%%%%%%%%%%%%%%%%%%%%%

\newcommand{\ps@bottom}{%
    \let\@mkboth\markboth % <-- This is the problematic line
    \renewcommand{\@oddhead}{}%
    \renewcommand{\@evenhead}{\@oddhead}
    \renewcommand{\@oddfoot}{\hfil\thepage\hfil}%
    \renewcommand{\@evenfoot}{\@oddfoot}
}

\pagestyle{bottom}

\makeatother

%%

\begin{document}
\tableofcontents

\chapter{Sample Chapter}

\cite{book-full}

\clearpage
\bibliographystyle{plain}
\bibliography{xampl}

\end{document}

关于我做错什么以及如何解决它,您有什么想法吗?

注意:MWE 已扩展为包含现有代码,该代码强制常规章节的首字母大写,以及自定义页面样式的略微简化版本,这似乎与迄今为止尝试的解决方案产生冲突。

编辑:我进行了一些额外的实验,进一步缩小了冲突代码的范围。我标记了似乎导致 @phelype-oleinik 给出的解决方案失败的行。不幸的是,那行是我接手维护这个类文件时继承的代码的一部分,所以我不知道它有多必要。如果您认为删除它是解决此冲突的答案,请指出为什么它可能不需要。

答案1

您可以按照\@makeschapterhead相同的方式操作\@makechapterhead并添加以下\texorpdfstring{\MakeUppercase{#1}}{#1}内容:

\documentclass{report}

\usepackage{hyperref} %must be supported, but not required

\makeatletter

\providecommand{\texorpdfstring}[2]{%
    #1%
}


\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname}%
     \@mkboth{\MakeUppercase\contentsname}%
             {\MakeUppercase\contentsname}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }

\def\@chapter[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
        \refstepcounter{chapter}%
        \typeout{*** \@chapapp\space\thechapter\space ****}%
        \addtocontents{toc}{\protect\pagebreak[3]}%
        \def\@LastLevel{0}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter.}\space\texorpdfstring{\MakeUppercase{#1}}{#1}}%
    \else
        \addtocontents{toc}{\protect\pagebreak[3]}%
        \def\@LastLevel{0}%
        \addcontentsline{toc}{chapter}{\texorpdfstring{\MakeUppercase{#1}}{#1}}%
    \fi
    \chaptermark{#1}%
    \@makechapterhead{#2}%
}


\def\@makechapterhead#1{%
    \cleardoublepage
    \vspace*{0\p@}%
    {\parindent \z@ \raggedright \centering\normalfont\Large
        \ifnum \c@secnumdepth >\m@ne
            \bfseries \MakeUppercase{\chaptername}\ \thechapter
            \vskip -3pt
        \fi
        \interlinepenalty\@M
        \bfseries\texorpdfstring{\MakeUppercase{#1}}{#1}\par\nobreak
        \vskip 15\p@
    }%
}

\def\@makeschapterhead#1{%
    \cleardoublepage
    \vspace*{0\p@}%
    {\parindent \z@ \raggedright \centering\normalfont\Large
        \interlinepenalty\@M
        \bfseries \texorpdfstring{\MakeUppercase{#1}}{#1}\par\nobreak
        \bfseries #1\par\nobreak
        \vskip 15\p@
    }%
}

%% Unnumbered bibliography
\let\oldbibliography\bibliography
\renewcommand\bibliography{%
  \addcontentsline{toc}{chapter}{\texorpdfstring{\MakeUppercase{\bibname}}{\bibname}}%
  \oldbibliography
}

%%%%%%%%%%%%%%%%%%%%%
% Page Style Definitions
%%%%%%%%%%%%%%%%%%%%%

\newcommand{\ps@bottom}{%
    \let\@mkboth\markboth % <-- This is the problematic line
    \renewcommand{\@oddhead}{}%
    \renewcommand{\@evenhead}{\@oddhead}
    \renewcommand{\@oddfoot}{\hfil\thepage\hfil}%
    \renewcommand{\@evenfoot}{\@oddfoot}
}

\pagestyle{bottom}

\makeatother

%%

\begin{document}
\tableofcontents

\chapter{Sample Chapter}

\cite{book-full}

\clearpage
\bibliographystyle{plain}
\bibliography{xampl}

\end{document}

您仍然需要手动\addcontentsline为参考书目发出一个,因为它是一个未编号的章节(如果您愿意,我评论了一个使其编号的选项)。

此外,由于 LaTeX 标准类的一个奇怪之处(为了与 LaTeX 2.09 兼容而保留。请参阅classes.dtx在第 3739 行左右或classes.pdf第 8.1.1 节——目录)。不同于\listoffigures和 等,其中包含:

\chapter*{\listfigurename}%
 \@mkboth{\MakeUppercase\listfigurename}%
         {\MakeUppercase\listfigurename}%

\tableofcontents宏包含:

\chapter*{\contentsname
 \@mkboth{\MakeUppercase\contentsname}%
         {\MakeUppercase\contentsname}}%

注意\@mkboth说明里面\chapter*第二种情况下的命令。这将传递(\@mkboth\let\markboth\MakeUppercase,本质上,执行\MakeUppercase{\markboth{sur}{prise!}}。我有精确的写作时遇到同样的问题这个班我发现的解决方案是制作\tableofcontents类似的代码\listoffigures

\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname}%
     \@mkboth{\MakeUppercase\contentsname}%
             {\MakeUppercase\contentsname}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }

我发现这个和另一个之间没有区别(除了它之前没有编译 :P)。而且正如文档中所说,这是为了兼容性...

相关内容