11

I am using the fourier font in a LaTeX document, but instead of the \rightarrow that fourier provides, I need the Computer Modern right arrow.

For example, I need

enter image description here

instead of:

enter image description here

I have tried using \DeclareMathSymbol to no avail and am totally stuck -- any help would be much appreciated!

1 Answers1

12

Quite easy, once you know how to do it. ;-)

\documentclass{article}
\usepackage{fourier}
\usepackage{amsmath}

% load the CM symbol font
\DeclareSymbolFont{arrows}{OMS}{cmsy}{m}{n}
% change the arrows to be taken from the CM symbol font
\DeclareMathSymbol{\leftrightarrow}{\mathrel}{arrows}{"24}
\DeclareMathSymbol{\leftarrow}{\mathrel}{arrows}{"20}
   \let\gets=\leftarrow
\DeclareMathSymbol{\rightarrow}{\mathrel}{arrows}{"21}
   \let\to=\rightarrow
\DeclareMathSymbol{\mapstochar}{\mathrel}{arrows}{"37}
% the bar for making longer arrows
\DeclareMathSymbol{\relbardash}{\mathbin}{arrows}{"00}
\DeclareRobustCommand\relbar{%
  \mathrel{\smash\relbardash}% \smash, because - has the same height as +
}

\begin{document}
$X\to Y\gets Z$

$X\longrightarrow Y\longleftarrow Z$

$x\mapsto f(x)$

$X\xrightarrow{aaaaaaaaa}Y$
\end{document}

enter image description here


How to find this solution? Here's a method.

We know that we need a new math symbol font to which assigning the arrows we want to modify. So I looked into fontmath.ltx, the file where the standard assignment are found. There I found the line

\DeclareSymbolFont{symbols}{OMS}{cmsy}{m}{n}

and assigned a new name to the symbol font (I chose arrows). Then I looked for \rightarrow, \leftarrow and \mapstochar, which are the basic ingredients for the needed arrow and copied the respective lines by changing symbols into arrows. I also put the two \let instruction to make sure that the aliases \to and \gets point to the redefined symbols.

Less easy is the question about \longrightarrow and \longleftarrow. They are built by pasting together a minus sign and an arrow:

\DeclareRobustCommand{\longrightarrow}{\relbar\joinrel\rightarrow}
\DeclareRobustCommand{\longlefttarrow}{\leftarrow\joinrel\relbar}

We need to change also \relbar, because \joinrel is just a negative spacing. Now, in fontmath.ltx we find

\DeclareRobustCommand\relbar{%
  \mathrel{\smash-}% \smash, because -has the same height as +
}

and we find a problem. This definition uses the minus sign, but we don't want to change the minus sign coming from the Fourier fonts. So I found the line for -:

\DeclareMathSymbol{-}{\mathbin}{symbols}{"00}

and defined a new symbol with the same properties; finally, I redeclared \relbar to use it instead of the minus sign:

% the bar for making longer arrows
\DeclareMathSymbol{\relbardash}{\mathbin}{arrows}{"00}
\DeclareRobustCommand\relbar{%
  \mathrel{\smash\relbardash}% \smash, because - has the same height as +
}

Doing the same with other symbol fonts can be done similarly, by looking at the style files where the correspondence of symbols with triples “math type+math font+slot” is defined.

egreg
  • 1,121,712
  • How did you find out that the \rightarrow was in slot 21 (and so on for the other symbols)? Is there an easy way of doing this? Thanks! – Andrew Bate Oct 04 '13 at 17:08
  • @AndrewBate Just find on your computer the file fontmath.ltx; I just copied from there changing symbols into arrows in order to assign the symbols to the new math font just declared. – egreg Oct 04 '13 at 17:23
  • amsmath has its own definition of \relbar which is not robust and uses \mathpalette. It also has its definition of \longrightarrow etc... so your code reverts this to the non-amsmath status, I don't know if or where this could show up concretely under certain circumstances. –  Oct 04 '13 at 17:55
  • @jfbu The \relbar redefinition by amsmath is just to make the construction compatible with the tricks amsmath does when doing \qopname; since I don't use the minus sign, nothing bad should happen. And I don't redefine \longrightarrow nor \longleftarrow. – egreg Oct 04 '13 at 17:59
  • @jfbu Actually, the amsmath definition uses directly \mathpalette\mathsm@sh, which is what \smash expands to when used in math mode. It would be probably slightly more efficient to use \mathpalette\mathsm@sh also here, but less direct for the beginner. – egreg Oct 04 '13 at 19:09
  • I do not understand why \newmcodes@ resets the mathcode of std@minus before assigning the - in operator names to be from the operator font. The \mathcode for - has anyhow a scope restricted to the \mathop in \qopname. Does amsmath want to allow \relbar in operator names??? Anyhow, this particular thing later broke unicode, and has been patched in lualatex-math in particular. –  Oct 04 '13 at 19:38
  • and thanks for the explanations before that (I forgot). Sorry about \longrightarrow I did a mix between your code and your later explanations. –  Oct 04 '13 at 19:41
  • @jfbu I don't know why \std@minus is reset; I can think to some situations where - is made math active. – egreg Oct 04 '13 at 19:47
  • The \std@minus is defined (a priori, once and for all) at begin document with a \mathchardef using the then \mathcode of -. I do not understand why it should be redefined, whatever suffering one may have inflicted to - later on. And especially why this should be in \newmcodes@. –  Oct 04 '13 at 19:53