Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the cleanest way to redefine math-mode font commands such as \mathrm and \mathit?

I would like everything else to be unaffected; for example, perhaps I enjoy working with mathptmx and I want to keep its \mathnormal, but I want to change \mathrm and mathit to use a different font.

\documentclass{article}
\usepackage{mathptmx}


\begin{document}

Some text.

Some formula: \(abc = de/f \quad[\mathrm{var}, \mathit{val}]\)

\(\mathnormal{abc = de/f}\)

var, \textit{val}

\(\mathrm{var}, \mathit{val}\)

% Bitstream Charter
{\fontfamily{bch}\fontseries{m}\fontshape{n}\selectfont  var,
 \fontfamily{bch}\fontseries{m}\fontshape{it}\selectfont val}

% Linux Biolinum
{\fontfamily{LinuxBiolinumT-OsF}\fontseries{m}\fontshape{n}\selectfont  var,
 \fontfamily{LinuxBiolinumT-OsF}\fontseries{m}\fontshape{it}\selectfont val}

% Linux Libertine
{\fontfamily{LinuxLibertineT-OsF}\fontseries{m}\fontshape{n}\selectfont  var,
 \fontfamily{LinuxLibertineT-OsF}\fontseries{m}\fontshape{it}\selectfont val}

\end{document}
share|improve this question
    
Using Charter for \mathrm when the main font is Times is a typographic nonsense. –  egreg Dec 14 '13 at 15:39
    
@egreg I'm not sure I feel that strongly about it :-) but sometimes a bit of variety serves illustrative purposes, to give examples for the question. –  Lover of Structure Dec 14 '13 at 15:50
    
@egreg (bch is way better than some of the other choices that'd look outrageous in math mode.) –  Lover of Structure Dec 14 '13 at 15:58

1 Answer 1

up vote 4 down vote accepted

Just redefine the macros \mathrm and \mathit to use a different font: the interface is

\DeclareMathAlphabet{<encoding>}{<family>}{<series>}{<shape>}

You can also supplement the font for a different math version: say also

\SetMathAlphabet{bold}{<encoding>}{<family>}{<series>}{<shape>}

for defining the font to be used in a \boldmath (or \mathversion{bold}) context.

An example follows. But beware that using Charter for \mathrm and \mathit is a typographical nonsense. Here's the visual proof of my claim.

\documentclass{article}
\usepackage{mathptmx}
\DeclareMathAlphabet{\mathrm}{OT1}{bch}{m}{n}
\DeclareMathAlphabet{\mathit}{OT1}{bch}{m}{it}

\begin{document}

Some text.

Some formula: \(abc = de/f \quad[\mathrm{var}, \mathit{val}]\)

Some formula: \(\mathit{abc}=\mathit{de}/\mathit{f}\)

\end{document}

enter image description here

Instead of \DeclareMathAlphabet one can define a substitute that won't eat up math families:

 \usepackage{amsmath}
 \newcommand{\mathcharter}[1][\encodingdefault]{%
   \text{\usefont{#1}{bch}{m}{n}#2}%
 }

and use it as

\mathcharter{abc}

or even

\mathcharter[T1]{l'Hôpital}
share|improve this answer
    
What function does the OT1 serve? (I know it's about the "encoding", but practically what does that mean here? Somewhere in the preamble I have the line \usepackage[T3,T1]{fontenc}, with T3 included for tipa. Are there alternatives to OT1?) –  Lover of Structure Dec 14 '13 at 15:47
1  
@LoverofStructure Not really; with \mathrm you should only use ASCII characters. –  egreg Dec 14 '13 at 15:51
1  
@LoverofStructure No, OT1 is predefined. –  egreg Dec 14 '13 at 15:58
1  
@LoverofStructure Using \fontfamily doesn't work in math mode. –  egreg Dec 14 '13 at 16:59
1  
@LoverofStructure The math families are allocated only when expressly requested in a math formula for the first time. –  egreg Dec 23 '13 at 17:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.