Text Formattingmath text in caption in sf font - how to do it?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
loukote
Posts: 3
Joined: Tue Feb 03, 2009 11:52 pm

math text in caption in sf font - how to do it?

Post by loukote »

Hi all.

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

Recommended reading 2024:

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

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

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

math text in caption in sf font - how to do it?

Post by localghost »

I think there is a better way to set captions optically apart from the normal text.

Code: Select all

\usepackage[font=small,labelfont=bf]{caption}
This looks nice and wouldn't cause any issues with math expressions in captions.


Best regards and welcome to the board
Thorsten¹
Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Re: math text in caption in sf font - how to do it?

Post by Keta »

I've been willing to use sans-serifs captions for long time, well more than willing to use, kind of willing to know how to do it. If I recall correctly, I read somewhere that once math fonts are declared they're fixed for the rest of the document. I don't know it for sure, but I'm sure there are people in here who can tell us easily if this is correct or not.

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.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

math text in caption in sf font - how to do it?

Post by phi »

It is possible, but very involved, to change the family automatically according to the text font family.
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}
Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Re: math text in caption in sf font - how to do it?

Post by Keta »

That was awesome phi, love it! :D :D I won't use it right now, but I'll save this thread as reference for the future. Thanks! :D
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

math text in caption in sf font - how to do it?

Post by sommerfee »

An alternative solution:

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}
Regards,
Axel
loukote
Posts: 3
Joined: Tue Feb 03, 2009 11:52 pm

math text in caption in sf font - how to do it?

Post by loukote »

sommerfee wrote:An alternative solution:
...
Regards,
Axel
Axel, this is not an alternative solution. This is THE solution. Thanks a lot.
Ondra
Post Reply