3

I think the font provided by the cochineal package is excellent, and I want to write documents using it, so I use the following in my preamble:

\usepackage[osf, p]{cochineal}
\usepackage[cochineal]{newtxmath}

However I dislike one particular change that was made in the math font, namely the way that italic f is changed. See the difference in the line \textit{f} versus $f$: the visual difference in regular italics and math mode letter 'f'

As far as I can tell this is one of three changes to the lowercase italic alphabet in math mode: the letters v and w are also changed to have better distinction from the greek letter nu.

My issue is that I strongly dislike this new letter f. I understand this may have been a stylistic choice by the designer but I much prefer the reclining, two-tailed f to this one.

I can force the math f to display as the regular italic one by writing \mathit{f} rather than just f, but this is obviously not very convenient.

How can I change the way that the lowercase letter f is displayed in math mode?


Here is a minimal document to reproduce this: (compiled with pdfTeX)

\documentclass{article}

\usepackage[osf, p]{cochineal}
\usepackage[cochineal]{newtxmath}

\begin{document}
Comparison: \textit{f} versus $f$.

Default: $f(x + y) = f(2x) + f(2y) - 1$.

Forced italic: $\mathit{f}(x + y) = \mathit{f}(2x) + \mathit{f}(2y) - 1$.
\end{document}

4 Answers 4

2

Declare a new math symbol font.

\documentclass{article}

\usepackage[osf, p]{cochineal}
\usepackage[cochineal]{newtxmath}

\DeclareSymbolFont{cochinealit}{\encodingdefault}{\familydefault}{m}{it}
\DeclareMathSymbol{f}{\mathalpha}{cochinealit}{`f}
\DeclareSymbolFontAlphabet{\mathit}{cochinealit}

\begin{document}

Comparison: \textit{f} versus $f$. Also $f^2$.

Default: $f(x + y) = f(2x) + f(2y) - 1$.

Forced italic: $\mathit{f}(x + y) = \mathit{f}(2x) + \mathit{f}(2y) - 1$.

Beware: $ff+f\/f$

Math roman: $\mathrm{f}$

\end{document}

There's a small catch, shown in the last line: you need something like f\/f if two consecutive f's appear in a formula.

enter image description here

2
  • This is very explanatory. I wonder if there is any way to automatically supress ligatures here?
    – AJF
    Commented Sep 4, 2019 at 23:19
  • @AJFarmar Not without much labor: the font needs to be duplicated to be loaded at a slightly (but unnoticeable) different size and its internal parameter be changed.
    – egreg
    Commented Sep 4, 2019 at 23:22
1

enter image description here

\documentclass{article}
\showoutput
\usepackage[osf, p]{cochineal}
\usepackage[cochineal]{newtxmath}
\sbox0{$\mathit{abc}$}


\mathcode`f=\numexpr\mathcode`f+"700\relax

\begin{document}


Comparison: \textit{f} versus $f$.

Default: $f(x + y) = f(2x) + f(2y) - 1$.

Forced italic: $\mathit{f}(x + y) = \mathit{f}(2x) + \mathit{f}(2y) - 1$.

Forced roman: $\mathrm{f}(x + y) = \mathrm{f}(2x) + \mathrm{f}(2y) - 1$.
\end{document}
2
  • Did you forget something?
    – egreg
    Commented Sep 4, 2019 at 22:07
  • @egreg there are lots of things I didn't mention, if that is what you mean. Commented Sep 4, 2019 at 22:17
1

The newest version of the newtxmath package supports two new options, cochf and cochrho which change the f in mathmode to the requested one, and of \rho to \rhoAlt.

\documentclass{article}

\usepackage[p,osf]{cochineal}
\usepackage[cochf,cochrho,cochineal]{newtxmath}

\begin{document}
\emph{elf} and $f\in F$ and $\rho\rhoAlt$

\emph{effective} and $ff\in F$

\end{document}

alt f and rho

0

One hacky way is to change the letter f to an active character, but only in math mode. This is described in this post on the TeX FAQ.

We do this by inserting this:

% Warning: there are serious issues with this; see below.
\begingroup
\lccode`~=`f
\lowercase{\endgroup
    \def~{\text{\textit{f}}}%
}%
\mathcode`f="8000

Put simply, this replace all occurences of the solitary letter f with \text{\textit{f}} in math mode.

So, here's a full example:

\documentclass{article}

\usepackage[osf, p]{cochineal}
\usepackage[cochineal]{newtxmath}


\begingroup
\lccode`~=`f
\lowercase{\endgroup
    \def~{\text{\textit{f}}}%
}%
\mathcode`f="8000

\begin{document}
Comparison: \textit{f} versus $f$.


Default: $f(x + y) = f(2x) + f(2y) - 1$.

Forced italic: $\mathit{f}(x + y) = \mathit{f}(2x) + \mathit{f}(2y) - 1$.
\end{document}

This produces the desired result:Result with catcode change

There are serious issues with this. In particular, \mathrm{f} displays strictly in italic, so for instance \liminf has a jarring italic f at the end.

For this reason, it may be preferable simply to define \newcommand\f{\mathit{f}} and simply write \f(x) instead of f(x).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .