3

I wanted to have Bold math in title but not in TOC and I chose Bernard's solution with titlesec which the document was already heavily using. It worked except for two problems:

--I was unable to make it work for Chapter as \titleformat*{\chapter}{\bfseries\boldmath} causes an error.

--The size of section titles has now shrunk to, I believe, tinyand adding \big causes an error.

(An hour ago, I had a third one but that was because I can't read!)

I think the issue is complicated by all the reference machinery I have. So, here it is in a 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}
  • A general solution is \makeatletter \g@addto@macro\bfseries{\boldmath} \makeatother which causes \bfseries to also do \boldmath – Andrew Swann Nov 16 '18 at 16:55
  • Generally you should ask on only one question at a time. Your posting contains several. – Andrew Swann Nov 16 '18 at 16:57
  • @AndrewSwann I will try your first suggestion a bit later but entering \boldsymbolby hand caused an error. Also, I think that all three issues are strongly related. – schremmer Nov 16 '18 at 17:16
2

The main problem is that \titleformat* cannot be applied to \chapter. You can instead patch \@makechapterhead and \@makeschapterhead, actually the aliases to them defined by titlesec. Also, you need to state the font size for \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}

enter image description here

| improve this answer | |
  • It works. Of course. (But why does the titlesec doc give big instead of Large???) Thanks. – schremmer Nov 17 '18 at 3:32
  • @schremmer I'm not sure what big you're referring to. – egreg Nov 17 '18 at 9:07
  • Sorry about that, I was just grumbling because the titlesec doc says on page 2: ""big small medium tiny Set the the size of titles." and I felt like an idiot as I should have known better. :-) – schremmer Nov 18 '18 at 15:31
1

To amplify a little on my comment, just adding

\makeatletter
\g@addto@macro\bfseries{\boldmath}
\makeatother

to your code does not produce errors and makes mathematics bold whenever you request the text to be bold:

Sample output

(Full document code below.)

Of course it should be used with care, as one needs to decide what should be done if the mathematics already contains individual \mathbf symbols, but your own attempt has a similar caveat.

As I said in my comment the sizing issues etc. are separate problems.

\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}
| improve this answer | |
  • Re size. I agree of course but the size issue came about only as I was trying to solve the math boldface issue. Unfortunately I have to push LaTeX way beyond the usual and I am programming impaired to begin with. – schremmer Nov 18 '18 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.