Fonts & Character SetsSpecifications for Math Numerals

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Specifications for Math Numerals

Post by hugovdberg »

I use mathspec to change the numerals from eulervm to the numerals from my text font, which do blend quite nicely. I have to this because I also use siunitx, and no matter what setting I use, in math mode it will use the euler numerals even if I don't set the euler-digits option. Unfortunately, with the \setmathfont also the digits within the DOI identifiers in my bibliography are changed, and thus look really ugly. I tried using and explicit \setmonofont, that does change the letters and symbols, but still not the digits, whether I set the mono-spaced font before the math font or after it. Also note I only set the FreeMono as mono-spaced font for extra contrast to see what changed, I think it's rather ugly and definitely prefer a font better fitting with the rest of the text.

Below are the files "test2.tex", and "test2.bib" (sorry, "test.tex" was already actively in use ;) ) I also attached the corresponding output on my system.

Code: Select all

\documentclass{scrartcl}
\usepackage{amsfonts}
\usepackage{eulervm}

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

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

\usepackage[
  style=authoryear-comp,
  doi=true,
  url=true,
  sorting=nyvt,
  backend=biber,
]{biblatex}
\usepackage[hidelinks]{hyperref}
\addglobalbib{test2.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|

The following 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}\).

\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}

Code: Select all

@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},

  __markedentry            = {[hugo:1]},
  Journal                  = {Sedimentary Geology },
  Keywords                 = {Cretaceous},
  Owner                    = {hugo},
  Timestamp                = {2014.02.21}
}
Attachments
test2.pdf
(22.2 KiB) Downloaded 562 times
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Re: Specifications for Math Numerals

Post by hugovdberg »

A small update on the issue, for now I just set my monofont to Calluna, since in the current document I don't need listings or verbatim environments. However, if someone could point me in the right direction where to find the declarations that specify the typesetting of the DOI I would be very grateful.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Re: Specifications for Math Numerals

Post by hugovdberg »

Since apparently nobody over here can help me I decided to cross-post it to TeX.sx, see my question over there: http://tex.stackexchange.com/questions/ ... references
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Specifications for Math Numerals

Post by hugovdberg »

Thanks to egreg at TeX.se this problem has been solved, the code below is his solution to the problem.

Code: Select all

\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}
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Specifications for Math Numerals

Post by hugovdberg »

Another update of this topic, since it later turned out this didn't solve the problem entirely. This solution works as it stands with TeX Gyre since that has lining figures as its default numerals (so named characters one, two, three, etc. for those familiar with OpenType fonts' internals), but Calluna, and the more regularly available EB Garamond have OldStyle figures by default. These are not loaded correctly without adding the option Renderer=Basic to the \liningmain font specification, but then the font is loaded correctly only about half the time, randomly changing between compilation runs. At the moment we suspect this is caused by a bug in luaotfload, so an issue has been opened at their GitHub, hopefully a fix will be available any time soon.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
Post Reply