### LaTeX users online

In total there are 8 users online :: 0 registered, 0 hidden and 8 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 8 guests

### LaTeX Friends

Sponsored by DANTE e.V.: The German speaking TeX Users Group

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

### LaTeX Forum: Text Formatting

Add tags Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
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
loukote

Posts: 3
Joined: Tue Feb 3rd, 2009

I think there is a better way to set captions optically apart from the normal text.
Code: Select all  •  Open in online LaTeX editor
\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¹
LaTeX Community Moderator

¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses

localghost
Site Moderator

Posts: 9218
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

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.
Keta

Posts: 63
Joined: Tue Nov 25th, 2008

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  •  Open in online LaTeX editor
\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}
phi

Posts: 577
Joined: Tue Oct 21st, 2008

That was awesome phi, love it! I won't use it right now, but I'll save this thread as reference for the future. Thanks!
Keta

Posts: 63
Joined: Tue Nov 25th, 2008

An alternative solution:

Code: Select all  •  Open in online LaTeX editor
\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

sommerfee

Posts: 495
Joined: Mon Apr 9th, 2007

sommerfee wrote:An alternative solution:
...
Regards,
Axel

Axel, this is not an alternative solution. This is THE solution. Thanks a lot.
Ondra
loukote

Posts: 3
Joined: Tue Feb 3rd, 2009