我想拥有标题中有粗体数学符号,但目录中没有我选择了 Bernard 的解决方案,titlesec
该文档已经大量使用了该解决方案。除了二问题:
——我无法让它为章节工作,因为\titleformat*{\chapter}{\bfseries\boldmath}
会导致错误。
--我认为,章节标题的大小现在已经缩小到,tiny
添加\big
会导致错误。
(一小时前,我又收到了第三个,但那是因为我看不懂!)
我认为这个问题因我拥有的所有参考机制而变得复杂。因此,这里是 MWE 中的内容。
\documentclass[11pt]{book}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amsbsy}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{fixmath}
\usepackage{titlesec}
\titleformat{\subsection}[runin]{\normalfont\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}
% \titleformat*{\chapter}{\bfseries\boldmath}%<<==BERNARD This causes an error
\titleformat*{\section}{\bfseries\boldmath}%<<==BERNARD This shrinks titles
\usepackage[detect-all]{siunitx}%<<<<<<<=======BERNARD
\usepackage[dotinlabels]{titletoc}
\titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
\newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
\titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
\newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%
\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs \hspace{10mm}
\usepackage{tcolorbox}%
\tcbuselibrary{%Begin load libraries for tcolorbox
xparse,%
}%End load libraries for tcolorbox
\usepackage{makeidx} %The \imakeindex does not work
\makeindex
\usepackage[hyperfootnotes=false]{hyperref}
%=============== Begin the Heiko Oberdiek ``quick and dirty hack'' which loads showidx
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
% Load package showidx
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
\@ifpackageloaded{multind}{%
\let\HyInd@org@wrindex\@wrindex
\def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
\def\HyInd@@wrindex#1#2|#3|#4\\{%
\ifx\\#3\\%
\HyInd@org@wrindex{#1}{#2|hyperpage}%
\else
\def\Hy@temp@A{#3}%
\ifx\Hy@temp@A\HyInd@ParenLeft
HyInd@org@wrindex{#1}{#2|#3hyperpage}%
\else
\HyInd@org@wrindex{#1}{#2|#3}%
\fi
\fi
}%
}{%
\def\@wrindex#1{\@@wrindex#1||\\}
\def\@@wrindex#1|#2|#3\\{%
\ifx\\#2\\%
\protected@write\@indexfile{}{%
\string\indexentry{#1|hyperpage}{\thepage}%
}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2hyperpage}{\thepage}%
}%
\else
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2}{\thepage}%
}%
\fi
\fi
\endgroup
\HyInd@showidx{#1}%
\@esphack
}%
}%
\fi
\makeatother
%=============== End the Heiko Oberdiek ``quick and dirty hack'' which loads showidx
\hypersetup{%begin colors
colorlinks,
linkcolor={red!50!black},
}%end colors
\usepackage{cleveref}% should be the last package
\Crefname{subsection}{Subsection}{Subsections}
\newcommand{\titleref}{\nameref}%displays TITLE of refered item
\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs
%========================== Begin math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
%========================== End math in Showindex
%========================== Begin Andrew code for ref to indexed words as edited Oct 27 at 17:24
\newcommand{\INDEX}[2][]{\phantomsection%
\if\relax\detokenize{#1}\relax\index{#2}\label{ind:#2}%
\else\index{#2}\label{ind:#1}\fi%
}%
%========================== End Andrew code for ref to indexed words as edited Oct 27 at 17:24
%===Begin DEX original
\newcommand{\DEX}[2][]{%
\if\relax\detokenize{#1}\relax\hyperref[ind:#2]{#2}%
% (\Cpageref{ind:#2})%
\else\hyperref[ind:#1]{#2}%
%(\Cpageref{ind:#1})%
\fi%
}%
%%===End DEX original
%============== Begin To make Cpageref work with INDEX
\newcommand{\PGX}[2][]{%
\if\relax\detokenize{#1}%
\relax%
% \hyperref[ind:#2]{#2}%
\Cpageref{ind:#2}%
\else%
% \hyperref[ind:#1]{#2}%
\Cpageref{ind:#1}%
\fi%
}%
%============== End To make Cpageref work with INDEX.
\begin{document}
\tableofcontents
\chapter{Chapter Title emboldens %
0 and $\infty$ but not $0$ nor $x_{0}$ nor $MathText$%
}%
\label{1-0-0}
\ChapterToc
Some text
with an indexed \textbf{word}\INDEX[]{word} and indexed math $\boldsymbol{x_{0}}$\INDEX[x0]{$x_{0}$}:
\section{Section Title emboldens %
0 and $\infty$ as well as $0$ and $x_{0}$ and $MathText$%
}%
\label{1-1-0}
A bit more text and finally:
\subsection{%
Subsection Title emboldens %
0 and $\infty$ %
but not $0$ nor $x_{0}$ nor $MathText$. %
However %
$\boldsymbol{MathText}$, %
$\boldsymbol{x_{0}}$ and %
$\bm{0}$ all work.%
}%
\label{1-2-1}
Plus just a tiny little bit of text%
with a referenced \DEX[word]{word} %
which was indexed in \Cref{1-0-0} \nameref{1-0-0} on \Cpageref{1-0-0}
\phantomsection%otherwise, clicking on index in toc gets to GNU
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}
答案1
主要问题是\titleformat*
不能应用于\chapter
。您可以改为修补\@makechapterhead
和\@makeschapterhead
,实际上是 定义的它们的别名titlesec
。此外,您需要说明 的字体大小\section
。
\documentclass[11pt]{book}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amsbsy}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{fixmath}
\usepackage{etoolbox}
\usepackage{titlesec}
\usepackage[dotinlabels]{titletoc}
\usepackage{tcolorbox}
\usepackage{makeidx} %The \imakeindex does not work
\usepackage[detect-all]{siunitx}
\usepackage[hyperfootnotes=false]{hyperref}
\makeatletter
\patchcmd{\ttl@save@mkchap}
{\huge\bfseries}
{\huge\bfseries\boldmath}
{}{\ddt}
\patchcmd{\ttl@save@mkchap}
{\Huge\bfseries}
{\Huge\bfseries\boldmath}
{}{}
\patchcmd{\ttl@save@mkschap}
{\Huge\bfseries}
{\Huge\bfseries\boldmath}
{}{}
\titleformat*{\section}{\Large\bfseries\boldmath}
\titleformat{\subsection}[runin]
{\normalfont\bfseries}
{\hspace{10mm}\arabic{subsection}.}
{1mm}
{}
\titlecontents{chapter}[6pc]
{\addvspace{1pc}\bfseries\boldmath\filright}
{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}
{}
{\hfill\contentspage}
[\addvspace{2pt}]
\newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
\titlecontents*{p-section}[0pt]
{\filright\small}
{}
{}
{, \thecontentspage}
[\xquad\textbullet\xquad]
[.]
\newcommand{\ChapterToc}{%
\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}%
}
\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs \hspace{10mm}
\tcbuselibrary{%Begin load libraries for tcolorbox
xparse,%
}%End load libraries for tcolorbox
\makeindex
%=============== Begin the Heiko Oberdiek ``quick and dirty hack'' which loads showidx
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
% Load package showidx
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
\@ifpackageloaded{multind}{%
\let\HyInd@org@wrindex\@wrindex
\def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
\def\HyInd@@wrindex#1#2|#3|#4\\{%
\ifx\\#3\\%
\HyInd@org@wrindex{#1}{#2|hyperpage}%
\else
\def\Hy@temp@A{#3}%
\ifx\Hy@temp@A\HyInd@ParenLeft
HyInd@org@wrindex{#1}{#2|#3hyperpage}%
\else
\HyInd@org@wrindex{#1}{#2|#3}%
\fi
\fi
}%
}{%
\def\@wrindex#1{\@@wrindex#1||\\}
\def\@@wrindex#1|#2|#3\\{%
\ifx\\#2\\%
\protected@write\@indexfile{}{%
\string\indexentry{#1|hyperpage}{\thepage}%
}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2hyperpage}{\thepage}%
}%
\else
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2}{\thepage}%
}%
\fi
\fi
\endgroup
\HyInd@showidx{#1}%
\@esphack
}%
}%
\fi
\makeatother
%=============== End the Heiko Oberdiek ``quick and dirty hack'' which loads showidx
\hypersetup{%begin colors
colorlinks,
linkcolor={red!50!black},
}%end colors
\usepackage{cleveref}% should be the last package
\Crefname{subsection}{Subsection}{Subsections}
\newcommand{\titleref}{\nameref}%displays TITLE of refered item
\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs
%========================== Begin math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
%========================== End math in Showindex
%========================== Begin Andrew code for ref to indexed words as edited Oct 27 at 17:24
\newcommand{\INDEX}[2][]{\phantomsection%
\if\relax\detokenize{#1}\relax\index{#2}\label{ind:#2}%
\else\index{#2}\label{ind:#1}\fi%
}%
%========================== End Andrew code for ref to indexed words as edited Oct 27 at 17:24
%===Begin DEX original
\newcommand{\DEX}[2][]{%
\if\relax\detokenize{#1}\relax\hyperref[ind:#2]{#2}%
% (\Cpageref{ind:#2})%
\else\hyperref[ind:#1]{#2}%
%(\Cpageref{ind:#1})%
\fi%
}%
%%===End DEX original
%============== Begin To make Cpageref work with INDEX
\newcommand{\PGX}[2][]{%
\if\relax\detokenize{#1}%
\relax%
% \hyperref[ind:#2]{#2}%
\Cpageref{ind:#2}%
\else%
% \hyperref[ind:#1]{#2}%
\Cpageref{ind:#1}%
\fi%
}%
%============== End To make Cpageref work with INDEX.
\begin{document}
\tableofcontents
\chapter{Chapter Title emboldens %
0 and $\infty$ but not $0$ nor $x_{0}$ nor $MathText$%
}%
\label{1-0-0}
\ChapterToc
Some text
with an indexed \textbf{word}\INDEX[]{word} and indexed math $\boldsymbol{x_{0}}$\INDEX[x0]{$x_{0}$}:
\section{Section Title emboldens %
0 and $\infty$ as well as $0$ and $x_{0}$ and $MathText$%
}%
\label{1-1-0}
A bit more text and finally:
\subsection{%
Subsection Title emboldens %
0 and $\infty$ %
but not $0$ nor $x_{0}$ nor $MathText$. %
However %
$\boldsymbol{MathText}$, %
$\boldsymbol{x_{0}}$ and %
$\bm{0}$ all work.%
}%
\label{1-2-1}
Plus just a tiny little bit of text%
with a referenced \DEX[word]{word} %
which was indexed in \Cref{1-0-0} \nameref{1-0-0} on \Cpageref{1-0-0}
\phantomsection%otherwise, clicking on index in toc gets to GNU
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}
答案2
为了进一步阐述我的评论,我补充一下
\makeatletter
\g@addto@macro\bfseries{\boldmath}
\makeatother
您的代码不会产生错误,并且在您要求文本加粗时使数学变为粗体:
(完整文档代码如下。)
当然,应该谨慎使用它,因为人们需要决定如果数学已经包含单个\mathbf
符号应该怎么做,但你自己的尝试也有类似的警告。
正如我在评论中所说,尺寸问题等是单独的问题。
\documentclass[11pt]{book}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amsbsy}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{fixmath}
\makeatletter
\g@addto@macro\bfseries{\boldmath}
\makeatother
\usepackage{titlesec}
\titleformat{\subsection}[runin]{\normalfont\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}
% \titleformat*{\chapter}{\bfseries\boldmath}%<<==BERNARD This causes an error
\titleformat*{\section}{\bfseries\boldmath}%<<==BERNARD This shrinks titles
\usepackage[detect-all]{siunitx}%<<<<<<<=======BERNARD
\usepackage[dotinlabels]{titletoc}
\titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
\newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
\titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
\newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%
\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs \hspace{10mm}
\usepackage{tcolorbox}%
\tcbuselibrary{%Begin load libraries for tcolorbox
xparse,%
}%End load libraries for tcolorbox
\usepackage{makeidx} %The \imakeindex does not work
\makeindex
\usepackage[hyperfootnotes=false]{hyperref}
%=============== Begin the Heiko Oberdiek ``quick and dirty hack'' which loads showidx
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
% Load package showidx
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
\@ifpackageloaded{multind}{%
\let\HyInd@org@wrindex\@wrindex
\def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
\def\HyInd@@wrindex#1#2|#3|#4\\{%
\ifx\\#3\\%
\HyInd@org@wrindex{#1}{#2|hyperpage}%
\else
\def\Hy@temp@A{#3}%
\ifx\Hy@temp@A\HyInd@ParenLeft
HyInd@org@wrindex{#1}{#2|#3hyperpage}%
\else
\HyInd@org@wrindex{#1}{#2|#3}%
\fi
\fi
}%
}{%
\def\@wrindex#1{\@@wrindex#1||\\}
\def\@@wrindex#1|#2|#3\\{%
\ifx\\#2\\%
\protected@write\@indexfile{}{%
\string\indexentry{#1|hyperpage}{\thepage}%
}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2hyperpage}{\thepage}%
}%
\else
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2}{\thepage}%
}%
\fi
\fi
\endgroup
\HyInd@showidx{#1}%
\@esphack
}%
}%
\fi
\makeatother
%=============== End the Heiko Oberdiek ``quick and dirty hack'' which loads showidx
\hypersetup{%begin colors
colorlinks,
linkcolor={red!50!black},
}%end colors
\usepackage{cleveref}% should be the last package
\Crefname{subsection}{Subsection}{Subsections}
\newcommand{\titleref}{\nameref}%displays TITLE of refered item
\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs
%========================== Begin math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
%========================== End math in Showindex
%========================== Begin Andrew code for ref to indexed words as edited Oct 27 at 17:24
\newcommand{\INDEX}[2][]{\phantomsection%
\if\relax\detokenize{#1}\relax\index{#2}\label{ind:#2}%
\else\index{#2}\label{ind:#1}\fi%
}%
%========================== End Andrew code for ref to indexed words as edited Oct 27 at 17:24
%===Begin DEX original
\newcommand{\DEX}[2][]{%
\if\relax\detokenize{#1}\relax\hyperref[ind:#2]{#2}%
% (\Cpageref{ind:#2})%
\else\hyperref[ind:#1]{#2}%
%(\Cpageref{ind:#1})%
\fi%
}%
%%===End DEX original
%============== Begin To make Cpageref work with INDEX
\newcommand{\PGX}[2][]{%
\if\relax\detokenize{#1}%
\relax%
% \hyperref[ind:#2]{#2}%
\Cpageref{ind:#2}%
\else%
% \hyperref[ind:#1]{#2}%
\Cpageref{ind:#1}%
\fi%
}%
%============== End To make Cpageref work with INDEX.
\begin{document}
\tableofcontents
\chapter{Chapter Title emboldens %
0 and $\infty$ but not $0$ nor $x_{0}$ nor $MathText$%
}%
\label{1-0-0}
\ChapterToc
Some text
with an indexed \textbf{word}\INDEX[]{word} and indexed math $\boldsymbol{x_{0}}$\INDEX[x0]{$x_{0}$}:
\section{Section Title emboldens %
0 and $\infty$ as well as $0$ and $x_{0}$ and $MathText$%
}%
\label{1-1-0}
A bit more text and finally:
\subsection{%
Subsection Title emboldens %
0 and $\infty$ %
but not $0$ nor $x_{0}$ nor $MathText$. %
However %
$\boldsymbol{MathText}$, %
$\boldsymbol{x_{0}}$ and %
$\bm{0}$ all work.%
}%
\label{1-2-1}
Plus just a tiny little bit of text%
with a referenced \DEX[word]{word} %
which was indexed in \Cref{1-0-0} \nameref{1-0-0} on \Cpageref{1-0-0}
\phantomsection%otherwise, clicking on index in toc gets to GNU
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}