Well libertineotf declares which font to use for bold:
\setmainfont[Extension=.otf,
BoldFont=LinLibertine_RB,
....
And this can be a different font to the one found if you use only \setmainfont
.
You can add \XeTeXtracingfonts= 1
to your document to get some more informations in the log-file. And you can compile with xelatex --output-driver="xdvipdfxm -vv"
to see on the terminal which fonts are included.
A good guide on what factors to consider when mixing fonts is Thierry Bouche's Diversity in math fonts article in TUGboat, Volume 19 (1998), No. 2.
The most important aspect is to use the same font for text and math letters (as well as letter-like symbols as \partial
or \infty
). This has drawbacks as some letters will suffer from spacing problems, but compared to the other option (using totally different math letters), it's really a lesser evil. Of course, if this is not acceptable to you, then you should first choose the math font and then use the same font for text, but that limits your font choices dramatically.
Once you've assigned the text font to the math letters, the remaining choices you face is for the geometric symbols, the delimiters and the big operators (\sum
, \int
, \bigcup
etc.). The main consideration is color (how bold the symbols are) and the shape of the symbols (mainly the shape of sum or integral symbols, especially if you use them often). Compared to Libertine, XITS and Asana are a bit too bold (especially true for the sum symbol), Latin Modern is a bit too light (especially +
, \otimes
, etc.), and Cambria has a very huge \sum
symbol, huge \otimes
and \oplus
as well as very bold \bigcup
. Thus, which font will look better will depend on what type of math you're typing, and none will be perfect.
Here's a sample to show the results of this font mixing with Libertine. Notice the spacing problems around the f in f(r_k)
and \Sigma_c f(r)
due to the fact that's it's a text font we're using for math. I've not set all letter-like symbols to come from Libertine (only \infty
), so there's still room for improvement. (Note also the missing parenthesis in one of the formulas with Latin Modern Math.)
\documentclass{article}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{Linux Libertine O}
\newcommand{\setlibertinemath}{%
% use Libertine for the letters
\setmathfont[range=\mathit/{latin,Latin,num,Greek,greek}]{Linux Libertine O Italic}
\setmathfont[range=\mathup/{latin,Latin,num,Greek,greek}]{Linux Libertine O}
\setmathfont[range=\mathbfup/{latin,Latin,num,Greek,greek}]{Linux Libertine O Bold}
%\setmathfont[range={"2202}]{Linux Libertine O}% "02202 = \partial % doesn't work
\setmathfont[range={"221E}]{Linux Libertine O}% "0221E = \infty
% etc. (list should be completed depending on needs)
}
\newcommand{\sample}{%
When computing the sums $\sum_{k=0}^{+\infty}{f(r_k)}$ of $f$ the integral representation of $K_0(x)$ may be used.
\[
\eta(r)\frac{\partial f}{\partial r} + 2\Sigma_cf(r)
= \sum_{k=0}^{+\infty}{K_0\mathopen{}\left(\frac{\lvert r - r_k \rvert}{L}\right)}
= \int_{0}^{\infty}{e^{-\left(z+\frac{r^2}{4L^2\pi}\right)} \frac{dz}{2z}}.
\]
We then use
\[
\bigcup_{\lambda \in \Lambda}{U_\lambda} \cap \bigsqcup_{\delta > 0}{G_\delta} = \bigcap_{i \in I}{\mathbf{A}_i}
\quad \text{so that} \quad
u \otimes w \oplus v = 0.
\]
}
\pagestyle{empty}
\begin{document}
\section{Libertine + Latin Modern}
\setmathfont{Latin Modern Math}\setlibertinemath
\sample
\section{Libertine + Cambria}
\setmathfont{Cambria Math}\setlibertinemath
\sample
\section{Libertine + XITS}
\setmathfont{XITS Math}\setlibertinemath
\sample
\section{Libertine + Asana}
\setmathfont{Asana Math}\setlibertinemath
\sample
\end{document}
Best Answer
I don't get the error you claim, but some things go wrong, I believe because of how
libertine
interacts withmathspec
.One has to specify the classes for which Libertine is wanted, though, and this triggers the error about insufficient mathgroups. This can be cured with the method outlined in
http://tex.stackexchange.com/a/100428/4427
This version works, by directly calling the fonts by name.
I added a line to your formula, showing how
"
is necessary as explained in themathspec
manual.