Text FormattingFormat of math mode in titles

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
nanobot
Posts: 4
Joined: Tue Apr 28, 2009 10:18 pm

Format of math mode in titles

Post by nanobot »

I need to use math mode in chapter and section headings. e.g.:
\chapter{Quadratic: $x^2$}
\section{The properties of $\mathrm{A_B}$}

Unfortunately these math commands are typeset with the normal font weight rather than bold, as titles should be. The result looks incongruous. For these simple examples I could cheat and use \mathbf{}, but my real application uses a complicated macro to generate the math for insertion. How do I get latex to format the math in a manner more consistent with the other title text?

Thanks,

-AM

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Format of math mode in titles

Post by localghost »

Include the amsmath package to get bold output of math expressions.

Code: Select all

\chapter[Quadratic: $x^2$]{Quadratic: $\boldsymbol{x^2}$}
\section[The properties of $\text{A_B}$]{The properties of $\boldsymbol{\text{A_B}}$}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The short form is necessary not to let the math expression appear bold in the ToC.


Best regards and welcome to the board
Thorsten¹
nanobot
Posts: 4
Joined: Tue Apr 28, 2009 10:18 pm

Re: Format of math mode in titles

Post by nanobot »

Thanks for your reply. I see a couple of problems though:
1) This isn't that much better that adding \mathbf{} to everything, which is what I'm trying to avoid.
2) $\text{A_B}$ doesn't work, but $\text{A}_\text{B}$ does. In fact it works really well -- \text{} takes the font/weight of the surrounding text, so you don't need the \boldsymbol at all. This is great for situations where I'm just trying to take advantage of super/subscripts for text. Unfortunately, I want more than that (I oversimplified my example).

But this gives me some ideas... I'll be back
nanobot
Posts: 4
Joined: Tue Apr 28, 2009 10:18 pm

Re: Format of math mode in titles

Post by nanobot »

OK, the following macro will simultaneously embolded (?) text and math
\newcommand{\allbold}[1]{\textbf{$\boldsymbol{#1}$}}

So it will work on macros like the following that contain both
\newcommand{\mac}{\ensuremath{\bar{\text{A}}^{2}}}

Now, the real question is how do you avoid this altogether? I don't really want to add \allbold to all my titles. How does \text{} work that it knows about and mimics the font settings immediately outside the math environment? Is it possible to make the math environment itself behave the same way, at least on macros?

I'll stop rambling now. This works well enough. Thanks for your help.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Format of math mode in titles

Post by phi »

A q'n'd solution would be to overwrite \bfseries such that it switches to the bold math version:

Code: Select all

Code, edit and compile here:
\documentclass{report}
\makeatletter
\DeclareRobustCommand*{\bfseries}{%
\not@math@alphabet\bfseries\mathbf
\fontseries\bfdefault\selectfont
\boldmath
}
\makeatother
\begin{document}
\tableofcontents
\chapter{Quadratic: $x^2$}
\section{The properties of $A_B$}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Then you get bold math whenever the surrounding text is in boldface. For document classes that allow customization of heading and ToC fonts (like scrreprt or memoir), better solutions exist.
nanobot
Posts: 4
Joined: Tue Apr 28, 2009 10:18 pm

Re: Format of math mode in titles

Post by nanobot »

Wow. That works like a charm. Thanks very much.

You mention that there are better solutions. What makes this worse? Are there situations in which I should not use it?

Thanks again.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Format of math mode in titles

Post by phi »

At the moment I see no technical problems, but overwriting kernel commands like \bfseries can always lead to some unexpected behavior. If you are only interested in changing the headings, then you might use the titlesec package or one of the classes I mentioned. But if you really want bold math in all bold contexts (e.g. also within \textbf), then my solution should be fine.
Now_its_me
Posts: 1
Joined: Thu Jan 28, 2021 1:06 am

Format of math mode in titles

Post by Now_its_me »

Hello, I had a similar issue and the Robust Command works great. However, I have an additional complication. I am working on the same thing but with combined math symbols. For instance I have
\newcommand\tado{%
\mathrel{\ooalign{\hss$\curlyvee$\hss\cr%
\kern .35ex \raise .8ex\hbox{\scalebox{.5}{$\mathbf{\times}$}}}}}

The problem I am having is that while it looks fine in bold in the Chapter and section titles and whatnot, the overlaid symbol appears in a different location when not bolded than when bolded. Now I could make two versions of the symbol such that they match up properly and define something like\boldtado. I was wondering if there was a way to change the \makeatletter
\DeclareRobustCommand*{\bfseries}{%
\not@math@alphabet\bfseries\mathbf
\fontseries\bfdefault\selectfont
\boldmath
}
\makeatother
or make a new Robust Command such that if I have \tado in the heading then it will automatically choose an alternate \boldtadothat is defined identically with the exception of having different \kern and \raise values.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Format of math mode in titles

Post by Ijon Tichy »

I would suggest to either use localghost's solution with the optional argument or to use a class or package, that allows to change the font of titles, so that you can add the \boldmath to the font setting of the title but not the ToC entry or page header, e.g.

Code: Select all

Code, edit and compile here:
\documentclass[twoside]{scrreprt}
\usepackage{blindtext}
\addtokomafont{disposition}{\boldmath}% use bold math in titles
\pagestyle{headings}
\begin{document}
\tableofcontents
\chapter{Quadratic: $x^2$}
\section{The properties of $A_B$}
\Blindtext[10]
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
BTW: There is a \texttimes, that can be uses in text mode instead of switching to math mode. With old LaTeX kernels you need to load package textcomp. Up-to-date LaTeX kernels have build in \texttimes. See the fntguide (section 7 in the current release) for more information about such text symbol commands.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
rogesh
Posts: 1
Joined: Fri Apr 23, 2021 12:51 pm

Format of math mode in titles

Post by rogesh »

Yes, right now I see no specialized issues, yet overwriting portion orders like \bfseries can generally prompt some sudden conduct. Assuming you are just keen on changing the headings, you may utilize the titles bundle or one of the classes I referenced. In any case, in the event that you truly need striking math in every intense setting (for example additionally inside \textbf), at that point my answer ought to be fine.
Post Reply