LaTeX forum ⇒ 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, ...)
loukote
Posts: 3
Joined: Tue Feb 03, 2009 11:52 pm

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

Postby loukote » Wed Feb 04, 2009 12:01 am

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Wed Feb 04, 2009 7:38 pm

I think there is a better way to set captions optically apart from the normal text.
  1. \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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

Link:
BBcode:
HTML:
Hide post links
Show post links

Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Postby Keta » Thu Feb 05, 2009 2:21 am

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

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

Postby phi » Thu Feb 05, 2009 2:15 pm

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:
  1. \documentclass{article}
  2.  
  3. \DeclareMathVersion{sans}
  4. \SetSymbolFont{operators}{sans}{OT1}{cmss}{m}{n}
  5. \SetSymbolFont{letters}{sans}{OT1}{cmss}{m}{sl}
  6. \SetMathAlphabet\mathbf{sans}{OT1}{cmss}{bx}{n}
  7. \SetMathAlphabet\mathsf{sans}{OT1}{cmss}{m}{n}
  8. \SetMathAlphabet\mathit{sans}{OT1}{cmss}{m}{sl}
  9.  
  10. \DeclareMathVersion{sansbright}
  11. \SetSymbolFont{operators}{sansbright}{OT1}{cmbr}{m}{n}
  12. \SetSymbolFont{letters}{sansbright}{OML}{cmbrm}{m}{it}
  13. \SetSymbolFont{symbols}{sansbright}{OMS}{cmbrs}{m}{n}
  14. \SetMathAlphabet\mathbf{sansbright}{OT1}{cmbr}{bx}{n}
  15. \SetMathAlphabet\mathsf{sansbright}{OT1}{cmbr}{m}{n}
  16. \SetMathAlphabet\mathit{sansbright}{OT1}{cmbr}{m}{it}
  17. \SetMathAlphabet\mathtt{sansbright}{OT1}{cmtl}{m}{n}
  18.  
  19. \begin{document}
  20. \tableofcontents
  21. \section{\sffamily\mathversion{sans}abc $a^2 + b^2 = c^2 \sum \prod \int$}
  22. \section{\sffamily\mathversion{sansbright}abc $a^2 + b^2 = c^2 \sum \prod \int$}
  23. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

Keta
Posts: 63
Joined: Tue Nov 25, 2008 1:00 pm

Postby Keta » Thu Feb 05, 2009 5:22 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
sommerfee
Posts: 495
Joined: Mon Apr 09, 2007 4:20 pm
Contact:

Postby sommerfee » Sat Feb 07, 2009 2:33 pm

An alternative solution:

  1. \documentclass{article}
  2. \usepackage{caption,sansmath}
  3. \DeclareCaptionFont{sansmath}{\sansmath}
  4. \captionsetup{textfont={sf,sansmath}}
  5.  
  6. \begin{document}
  7. \begin{figure}
  8. \caption{Some text and a formular: $E = mc^2$}
  9. \end{figure}
  10. \end{document}


Regards,
Axel

Link:
BBcode:
HTML:
Hide post links
Show post links

loukote
Posts: 3
Joined: Tue Feb 03, 2009 11:52 pm

Postby loukote » Sat Feb 07, 2009 7:07 pm

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

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

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests