Text Formatting ⇒ math text in caption in sf font - how to do it?
math text in caption in sf font - how to do it?
I have captions in sf font. In some, there is some math text. But the math text renders the same way as all math texts in equations.
Is there a way to tell the math texts that are inside a caption to render in mathsf in an automatic way?
Thanks
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
math text in caption in sf font - how to do it?
Code: Select all
\usepackage[font=small,labelfont=bf]{caption}
Best regards and welcome to the board
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: math text in caption in sf font - how to do it?
If that's true, one solution could be to write code which first writes the caption to an external file, then processes that file with the desired options, and finally includes the output as a pdf or eps. Kind of how the examples where created in The LaTeX Companion book -- if I understood well the making process. I'm far from knowing how to do that, but there are real experts around here who might give us some useful hints.
math text in caption in sf font - how to do it?
It is easier to declare a new math version. Here is an example using the Computer Modern fonts. Note that you get a warning because the sans-serif font doesn't use the correct encoding. Thus it is better to use the CM-Bright fonts. The following code shows both possibilities:
Code: Select all
\documentclass{article}
\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{OT1}{cmss}{m}{n}
\SetSymbolFont{letters}{sans}{OT1}{cmss}{m}{sl}
\SetMathAlphabet\mathbf{sans}{OT1}{cmss}{bx}{n}
\SetMathAlphabet\mathsf{sans}{OT1}{cmss}{m}{n}
\SetMathAlphabet\mathit{sans}{OT1}{cmss}{m}{sl}
\DeclareMathVersion{sansbright}
\SetSymbolFont{operators}{sansbright}{OT1}{cmbr}{m}{n}
\SetSymbolFont{letters}{sansbright}{OML}{cmbrm}{m}{it}
\SetSymbolFont{symbols}{sansbright}{OMS}{cmbrs}{m}{n}
\SetMathAlphabet\mathbf{sansbright}{OT1}{cmbr}{bx}{n}
\SetMathAlphabet\mathsf{sansbright}{OT1}{cmbr}{m}{n}
\SetMathAlphabet\mathit{sansbright}{OT1}{cmbr}{m}{it}
\SetMathAlphabet\mathtt{sansbright}{OT1}{cmtl}{m}{n}
\begin{document}
\tableofcontents
\section{\sffamily\mathversion{sans}abc $a^2 + b^2 = c^2 \sum \prod \int$}
\section{\sffamily\mathversion{sansbright}abc $a^2 + b^2 = c^2 \sum \prod \int$}
\end{document}
Re: math text in caption in sf font - how to do it?



math text in caption in sf font - how to do it?
Code: Select all
\documentclass{article}
\usepackage{caption,sansmath}
\DeclareCaptionFont{sansmath}{\sansmath}
\captionsetup{textfont={sf,sansmath}}
\begin{document}
\begin{figure}
\caption{Some text and a formular: $E = mc^2$}
\end{figure}
\end{document}
Axel
math text in caption in sf font - how to do it?
Axel, this is not an alternative solution. This is THE solution. Thanks a lot.sommerfee wrote:An alternative solution:
...
Regards,
Axel
Ondra