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.

Cross-post of http://latex-community.org/forum/viewtopic.php?f=48&t=24483 but since I get no answer there I'm hoping someone over here can help.

The Goal:
I want to use a custom font (Calluna and Calluna Sans by Exljbris) as main font for my document using fontspec, with eulervm as math font. Also, Calluna provides both OldStyle and Lining figures, of which I prefer the former in my main text, and the latter in mathmode. Furthermore, I'm a big fan of siunitx to format numbers with units. Finally I also use biblatex for typesetting my references.

The Problem:
eulervm comes with a set of numerals that just don't look very nice together with Calluna, especially when formatting numbers inline in the text. Also, the default setting to eulervm is to not use the Euler digits but the default roman digits. Apparently, these are not set by fontspec because in 'plain' math mode the Computer Modern digits are used and that looks even worse. To make matters worse, with or without the euler-digits option to eulervm, siunitx always uses the Euler numerals in math mode, and depending on the detect-all option also in text mode.

To correct these problems I use the mathspec package to set the digits in math mode to Calluna as well, while leaving the normal text alone. This solution works fine throughout the whole main text, including verbatim environments.

But then, enter references. Most of my references contain either an URL or a DOI (Digital Object Identifier), and these are handled in a verbatim style by biblatex. But as soon as I use the \setmathfont command, the numerals (and only the numerals) inside the biblatex-verbatim fields are changed to Calluna as well. However, the verbatim font (Latin Modern Mono) and Calluna are quite different, and don't mix very well. And unfortunately, the \setmonofont command does change the letters but not the numerals.

The Question
What is the best way to get the numerals consistent throughout the document? I prefer the Calluna numerals both in text and math mode, but the default mono font in verbatim mode. If it is possible to set the numerals in math mode without mathspec, using only fontspec, then I would prefer that since mathspec limits me to using XeTeX, while I would like to use LuaTeX.

The Code
Note that for compatibility I changed all references to Calluna in the code to fonts available by default on most computers.

\begin{filecontents}{test.bib}
@Article{Hay2011,
  Title                    = {Can humans force a return to a `Cretaceous' climate?},
  Author                   = {William W. Hay},
  Journaltitle             = {Sedimentary Geology},
  Year                     = {2011},
  Doi                      = {10.1016/j.sedgeo.2010.04.015},
  ISSN                     = {0037-0738},
  Language                 = {english},
  Note                     = {Causes of oxic - anoxic changes in Cretaceous marine environments and their implications for Earth systems },
  Number                   = {1-2},
  Pages                    = {5--26},
  Volume                   = {235},

  Journal                  = {Sedimentary Geology },
  Keywords                 = {Cretaceous},
}
\end{filecontents}
\documentclass{scrartcl}

\usepackage{amsfonts}
\usepackage[
        euler-digits    
    ]{eulervm}

\usepackage{siunitx}
\sisetup{
    detect-all,
    }

\usepackage{mathspec}
\setmainfont[Ligatures={Common,TeX},Numbers={OldStyle,Proportional}]{Times New Roman}
\setsansfont[Ligatures={Common,TeX},Numbers={Lining,Proportional}]{Arial}
\setmathfont(Digits,Latin,Greek)[Arabic=Regular,Uppercase=Plain,Lowercase=Plain,Numbers={Lining,Monospaced}]{Times New Roman}% According to the manual this sets the digits to the regular arabics, while leaving the latin and greek letters untouched, which is intented, I want eulervm for maths letters.
\setmonofont[Ligatures={NoRequired,NoCommon,NoContextual},Numbers={Lining,Monospaced}]{Courier New}

\usepackage[
    style=authoryear-comp,
    doi=true,
    url=true,
    sorting=nyvt,
    backend=biber,
    ]{biblatex}
\usepackage[hidelinks]{hyperref}
\addglobalbib{test.bib}
\begin{document}

\section{Verify sans font}
The following line shows the normal verb command is unaffected:

{\scshape DOI:}\ \verb|10.1016/j.sedgeo.2010.04.015|

This is a sentence to test the various fonts for digits with or without \verb|\sisetup{detect-all}| or \verb|\setmathfont|. 1234567890, \(1234567890\), \SI{1234567890}{\metre}, \(\SI{1234567890}{\metre}\),\\ \num{1234567890}, \(\num{1234567890}\).

\begin{verbatim}
This is a test of numerals in the verbatim environment: 1234567890
\end{verbatim}

\textcite{Hay2011} shows the problem with the DOI, I included this one because it has an ugly mixture of letters and digits, showing the problem to its full extent.
\printbibliography
\end{document}
share|improve this question

1 Answer 1

up vote 5 down vote accepted

Here's a workaround with fontspec only. The trick is to define a new math symbol font for the lining figures.

I wouldn't use detect-all: numbers in \SI or \num should always be typeset in math mode (hence with lining figures).

\begin{filecontents}{test.bib}
@Article{Hay2011,
  Title                    = {Can humans force a return to a `Cretaceous' climate?},
  Author                   = {William W. Hay},
  Journaltitle             = {Sedimentary Geology},
  Year                     = {2011},
  Doi                      = {10.1016/j.sedgeo.2010.04.015},
  ISSN                     = {0037-0738},
  Language                 = {english},
  Note                     = {Causes of oxic - anoxic changes in Cretaceous marine environments and their implications for Earth systems },
  Number                   = {1-2},
  Pages                    = {5--26},
  Volume                   = {235},

  Journal                  = {Sedimentary Geology },
  Keywords                 = {Cretaceous},
}
\end{filecontents}

\documentclass{scrartcl}

\usepackage{amsfonts}
\usepackage{eulervm}

\usepackage{siunitx}
\sisetup{
%  detect-all,
  math-rm=\mathlining,
}

\usepackage[no-math]{fontspec}
\setmainfont[Ligatures={Common,TeX},Numbers={OldStyle,Proportional}]{TeX Gyre Termes}
\newfontfamily{\liningmain}[Ligatures={Common,TeX},Numbers=Lining]{TeX Gyre Termes}
\setsansfont[Ligatures={Common,TeX},Numbers={Lining,Proportional}]{TeX Gyre Heros}
\setmonofont[Ligatures={NoRequired,NoCommon,NoContextual},Numbers={Lining,Monospaced}]{TeX Gyre Cursor}

% A trick for extracting the family information
% which works independently of the chosen font
\begingroup
  \def\getfamily#1#2#3#4#5{#4}
  \edef\x{\endgroup
  \def\noexpand\liningdefault{\expandafter\expandafter\expandafter
    \getfamily\csname liningmain \endcsname}}\x

\DeclareSymbolFont{liningmath}{\encodingdefault}{\liningdefault}{m}{n}
\DeclareSymbolFontAlphabet{\mathlining}{liningmath}
\Umathcode`0="7 \symliningmath `0
\Umathcode`1="7 \symliningmath `1
\Umathcode`2="7 \symliningmath `2
\Umathcode`3="7 \symliningmath `3
\Umathcode`4="7 \symliningmath `4
\Umathcode`5="7 \symliningmath `5
\Umathcode`6="7 \symliningmath `6
\Umathcode`7="7 \symliningmath `7
\Umathcode`8="7 \symliningmath `8
\Umathcode`9="7 \symliningmath `9

\usepackage[
    style=authoryear-comp,
    doi=true,
    url=true,
    sorting=nyvt,
    backend=biber,
    ]{biblatex}
\usepackage[hidelinks]{hyperref}
\addglobalbib{test.bib}
\begin{document}

\section{Verify sans font}
The following line shows the normal verb command is unaffected:

DOI: \verb|10.1016/j.sedgeo.2010.04.015|

URL: \url{10.1016/j.sedgeo.2010.04.015}

This is a sentence to test the various fonts for digits with or without 
\verb|\sisetup{detect-all}| or \verb|\setmathfont|.\\
No math: 1234567890,\\
Math:  \(1234567890\),\\
\verb|\SI| in text: \SI{1234567890}{\metre},\\
\verb|\SI| in math: \(\SI{1234567890}{\metre}\),\\
\verb|\num| in text: \num{1234567890},\\
\verb|\num| in math: \(\num{1234567890}\).

A test of math: $X=12$.

\begin{verbatim}
This is a test of numerals in the verbatim environment: 1234567890
\end{verbatim}

\textcite{Hay2011} shows the problem with the DOI, I included this one because it has an ugly mixture of letters and digits, showing the problem to its full extent.
\printbibliography
\end{document}

enter image description here

share|improve this answer
    
I'm afraid your solution does not produce lining numbers with the Calluna font. When I copy your entire example it works fine, and produces the same document as you've shown, but when I change references to TeX Gyre Termes to Calluna both in normal math mode as well as in siunitx commands the numbers are changed to OldStyle. In my original document Lining numbers work just fine. –  hugovdberg Mar 2 at 15:33
    
If you would like to try it with the Calluna font, the regular font is available for free on various websites, including myfonts.com. I noticed that when I use the 'Latin Modern' font instead of TeX Gyre your solution also works fine, so I'm wondering if it has something to do with the fact that these fonts are included with texlive, while Calluna is installed manually. –  hugovdberg Mar 2 at 15:43
1  
@hugovdberg Sorry, but I'm not going to register just to download a free font. –  egreg Mar 2 at 16:38
    
This is a bit odd, I did try some other Open Type fonts outside the texmf tree, and they worked so I once more switched to Calluna and now it works fine. I even copied your solution once more and, to my knowledge, made the exact same changes as before, and it still works. –  hugovdberg Mar 2 at 17:46
    
Ok, I think I've found the root of the problem, because it occurred to me again, the problem is your solution works fine using any font (including Calluna) and xetex, but not using Calluna and luatex, then it produces old style numerals in mathmode as well. Do you have an idea where this would come from and how to fix it? –  hugovdberg Mar 12 at 18:25

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.