4

I am trying to get text in font Calibri and math in font Cambria Math, so that it mimicks a mandatory Microsoft Word template that I am supposed to use.

I am a Mac user and copied the files Calibri.ttf and Cambria.ttc from Resources/DFonts in the Microsoft Word for Mac application package.

Here is a MWE:

\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{Calibri.ttf}
\usepackage{unicode-math}
\setmathfont{Cambria.ttc}
\begin{document}
Hello world! $x=y+z$
\end{document}

I get the following errors: (among others)

Package fontspec Warning: Font "Cambria" does not contain requested Script
"Math".
Package unicode-math Warning: The first font loaded by unicode-math must be an
OpenType Math font (with script=math).

How can I fix this?

5
  • 1
    Welcome to TeX.SE.
    – Mico
    Commented Feb 24 at 13:34
  • 1
    Please state whether you use LuaLaTeX or XeLaTeX to compile your document. (If you're undecided, I suggest employing LuaLaTeX.)
    – Mico
    Commented Feb 24 at 13:39
  • "that it mimicks a mandatory Microsoft Word template that I am supposed to use" Ireally like that. Commented Feb 24 at 13:47
  • 1
    I use LuLaTeX for this.
    – vdbuss
    Commented Feb 24 at 13:47
  • It appears that unicode-math cannot really read ttc files. I now extracted the ttf file for Cambria math from my ttc file using some free online tool, and specified the ttf file directly. Problem seems solved.
    – vdbuss
    Commented Feb 24 at 14:36

3 Answers 3

5

The cambria.ttc file is a font collection file (i.e. multiple fonts in the same file). When loading a font collection file by file name, the first font in the collection will be used, and in case of cambria.ttc this happens to be the regular text font. The math font is the second font in the collection. The fontspec package has FontIndex option to load the font at the given index in the font collection:

\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{Calibri.ttf}
\usepackage{unicode-math}
\setmathfont{Cambria.ttc}[FontIndex=1]
\begin{document}
Hello world! $x=y+z$
\end{document}
4
  • The problem is how one is supposed to know what's the index number…
    – egreg
    Commented Feb 25 at 23:00
  • The “easiest” way is to open the file in FontForge, but otherwise people are not supposed to be loading fonts using file names (Pretty much only TeX users do this, well and web fonts on the web, but there font collections are not even supported). Commented Feb 26 at 3:21
  • Maybe luaotfload could offer an option?
    – egreg
    Commented Feb 26 at 10:42
  • Now you mention it, FontConfig has fc-scan which gives information about font files, the output is a bit verbose but it can be used to get the face index of a given font in the collection. May be luaotfload-tool can do something similar, I believe the code for parsing font collections is already there to build the font names database. Commented Feb 27 at 0:57
4

Cambria is a text font, not a math font. You need to specify Cambria Math as the math font.

enter image description here

\documentclass[12pt]{article}

\usepackage{unicode-math} % 'unicode-math' loads 'fontspec' automatically
\setmainfont{Calibri}
\setmathfont{Cambria Math}[Scale=MatchLowercase]

\begin{document}
Hello world! $x=y+z$
\end{document}
6
  • I have to use font files since Calibri and Cambria are not system fonts on MacOS. Your example does not work on my system. Also, I understand Cambria Math is indeed contained in that ttc file?
    – vdbuss
    Commented Feb 24 at 13:51
  • @vdbuss There should be some location in the system, where you copy the ttf files to. Then it should be found by any application on the system including your LaTeX compiler. See superuser.com/questions/407446/location-of-core-fonts-on-osx Commented Feb 24 at 13:56
  • @MaestroGlanz that is not normally needed with lualatex. Xelatex is much more picky
    – daleif
    Commented Feb 24 at 14:32
  • 1
    @vdbuss - According to the log file, the files I used (I'm on a Mac system as well) are /Library/Fonts/Microsoft/Calibri.ttf and /Library/Fonts/Microsoft/Cambria Math.ttf. In case it matters, the file names have extension "ttf", not "ttc".
    – Mico
    Commented Feb 24 at 17:29
  • 1
    @Mico: See what I already wrote in my question, yes I did get the files from there, and also see my comment under my original question regarding ttc and ttf. Turns out that ttc is a collection of ttf files and unicode-math cannot handle ttc, it seems. I've solved my problem by extracting the Cambria Math ttf (which was bundled in the ttc file).
    – vdbuss
    Commented Feb 25 at 6:26
2

index

Per the comments:

Quick screen capture code adapted to fc-scan.

\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{multicol}




\ExplSyntaxOn

%===================
\keys_define:nn { alba }
{
 namelist .bool_set:N = \l_alba_namelist_bool,
 namelistcomma .bool_set:N = \l_alba_namelistcomma_bool,
 table    .bool_set:N = \l_alba_tabular_bool,
 list     .bool_set:N = \l_alba_list_bool,
 otfinfo  .bool_set:N = \l_alba_otfinfo_bool,
 reset    .bool_set:N = \l_alba_resetoff_bool,
} 




%===================
\cs_new_protected:Nn
     \proc_alba_resetoptions:
{ 
%\bool_set_false:N \l_alba_namelist_bool
%\bool_set_false:N \l_alba_tabular_bool
%\bool_set_false:N \l_alba_list_bool
%\bool_set_false:N \l_alba_otfinfo_bool
\termcapoptions[  % when true, does:
namelist=false,   % copyable fn list
namelistcomma=false,
table=false,      % better sampler fmt
list=false,       % list/multicols
otfinfo=false,    % font features
]
} % end proc --------------









%===================
\cs_new_protected:Npn
     \proc_alba_doterminal:nn #1#2
{  % 1 command, 2 result storage tl
\sys_get_shell:onN
     {
      #1
      }{
       \cctab_select:N
         \c_str_cctab
       \endlinechar=33  % !
    }

     #2
} % end proc --------------













\tl_new:N \l_alba_acmnd_tl





%===================
\cs_set_protected:Nn
     \proc_alba_screencapture:
{
%\tl_show:N \l_alba_command_tl
\tl_set:Ne 
  \l_alba_fullcommand_tl
     { \l_alba_command_tl
       \c_space_tl
       \l_alba_glyphs_tl
      } %albatross -b1 ??
%\tl_show:N \l_alba_fullcommand_tl
\proc_alba_doterminal:nn
  { \l_alba_fullcommand_tl }
  { \l_tmpa_tl }

%£\str_if_in:NnTF 
%£   \l_tmpa_tl 
%£   { No~fonts~with }
%£%% "NofontswithsupportfortheseUnicodecodepointswerefound."
%£{
%£\bool_set_false:N
%£  \l_alba_foundfonts_bool
%£}
%£{
%£\bool_set_true:N
%£  \l_alba_foundfonts_bool
%£}
%\sys_get_shell:onN
%     { 
%      \l_alba_fullcommand_tl
%      } 
%     {
%       \cctab_select:N
%         \c_str_cctab
%    }
%     \l_tmpa_tl
} % end proc --------------




%===================
\cs_set_protected:Nn 
     \proc_alba_printscreencapture: 
{
% show screen capture
\group_begin:
\ttfamily\small
\tl_use:N \l_tmpa_tl
\group_end:
} % end proc --------------


%===================
\cs_set_protected:Nn
     \proc_alba_createrecordset:
{
% convert to a set of fontnames
   \seq_set_split:NnV
     \l_tmpa_seq
     { ! } %
     \l_tmpa_tl
} % end proc --------------



%===================
\cs_set_protected:Nn
     \proc_alba_cleanrecordset:
{

\seq_clear:N
  \l_tmpb_seq
\seq_map_inline:Nn
  \l_tmpa_seq
{ % start map
\tl_set:Nn \l_tmpb_tl {##1}

\str_if_in:NnT \l_tmpb_tl 
   { fullname: }
{ % 1
\seq_put_right:No 
   \l_tmpb_seq
   {\l_tmpb_tl}
} % end T
\str_if_in:NnT \l_tmpb_tl
   { file: }
{ % 2
\seq_put_right:No
   \l_tmpb_seq
   {\l_tmpb_tl}
} % end T
\str_if_in:NnT \l_tmpb_tl
   { index: }
{ % 3
\seq_put_right:No 
   \l_tmpb_seq 
   {\l_tmpb_tl}
} % end T

} % end map
%\seq_show:N\l_tmpb_seq
} % end proc --------------















%===================
\cs_set_protected:Nn
     \proc_alba_printsampler:
{

  \proc_alba_printitems: 

} % end proc -------------







\tl_new:N \l_alba_listhead_tl






%===================
\cs_set_protected:Nn
     \proc_alba_printitems:
{
\seq_map_inline:Nn
  \l_tmpb_seq

{ % start map
\str_set:Nn \l_tmpa_str {##1}

       \l_tmpa_str

  \tex_par:D
 } % end map
}



%===================
\tl_new:N \l_alba_command_tl
\tl_new:N \l_alba_glyphs_tl
\tl_new:N \l_alba_fullcommand_tl
\seq_new:N \l_alba_master_seq





%===================
\NewDocumentCommand
  { \termcapoptions }
  { o }
 {
  \tl_if_novalue:nF{#1}
   {\keys_set:nn { alba } { #1 }}
} % end command



%===================
\NewDocumentCommand
  { \termcap } 
  { o m m } 
     % #2 term cmd + options
     % #3 cmd argument(s)
 {
  \tl_if_novalue:nF{#1}
   {\keys_set:nn { alba } { #1 }}
  \tl_set:Nn \l_alba_command_tl {#2}
  \tl_set:Nn \l_alba_glyphs_tl {#3}


  \proc_alba_screencapture:
  \proc_alba_createrecordset:
  \proc_alba_cleanrecordset:

  \proc_alba_printsampler:

} % end command



\cs_generate_variant:Nn
   \sys_get_shell:nnN
   { onN }
\cs_generate_variant:Nn
   \seq_set_split:NnV
   { NoV }
%\cs_generate_variant:Nn
%   \tl_set_eq:NN
%   { Ne }

\ExplSyntaxOff








\begin{document}
x


\termcap{fc-scan}
{/system/fonts/NotoSerifCJK-Regular.ttc}



\end{document}

Run with shell escape.


Added

tidy

Tidied-up-code version,

MWE

\documentclass{article}


\ExplSyntaxOn

%===================
\cs_new_protected:Npn
     \proc_fcsc_doterminal:nn #1#2
{  % 1 command, 2 result storage tl
\sys_get_shell:onN
     {
      #1
      }{
       \cctab_select:N
         \c_str_cctab
       \endlinechar=33  % !
    }

     #2
} % end proc --------------



\tl_new:N \l_fcsc_acmnd_tl

%===================
\cs_set_protected:Nn
     \proc_fcsc_screencapture:
{
%\tl_show:N \l_fcsc_command_tl
\tl_set:Ne 
  \l_fcsc_fullcommand_tl
     { \l_fcsc_command_tl
       \c_space_tl
       \l_fcsc_parms_tl
      } 
%
Running ~ \l_fcsc_command_tl
  \c_space_tl on~ \l_fcsc_parms_tl
  \tex_par:D
  \hrulefill
  \tex_par:D
%

\proc_fcsc_doterminal:nn
  { \l_fcsc_fullcommand_tl }
  { \l_tmpa_tl }


} % end proc --------------




%===================
\cs_set_protected:Nn 
     \proc_fcsc_printscreencapture: 
{
% show screen capture
\group_begin:
\ttfamily\small
\tl_use:N \l_tmpa_tl
\group_end:
} % end proc --------------


%===================
\cs_set_protected:Nn
     \proc_fcsc_createrecordset:
{
% convert to a set of records
   \seq_set_split:NnV
     \l_tmpa_seq
     { ! } %
     \l_tmpa_tl
} % end proc --------------



%===================
\cs_set_protected:Nn
     \proc_fcsc_cleanrecordset:
{

\seq_clear:N
  \l_tmpb_seq
\seq_map_inline:Nn
  \l_tmpa_seq
{ % start map
\tl_set:Nn \l_tmpb_tl {##1}

\str_if_in:NnT \l_tmpb_tl 
   { fullname: }
{ % 1
\seq_put_right:No 
   \l_tmpb_seq
   {\l_tmpb_tl}
} % end T
\str_if_in:NnT \l_tmpb_tl
   { file: }
{ % 2
\seq_put_right:No
   \l_tmpb_seq
   {\l_tmpb_tl}
} % end T
\str_if_in:NnT \l_tmpb_tl
   { index: }
{ % 3
\seq_put_right:No 
   \l_tmpb_seq 
   {\l_tmpb_tl}
} % end T

} % end map
%\seq_show:N\l_tmpb_seq
} % end proc --------------




%===================
\cs_set_protected:Nn
     \proc_fcsc_printsampler:
{
  \proc_fcsc_printitems: 
} % end proc -------------




%===================
\cs_set_protected:Nn
     \proc_fcsc_printitems:
{
\seq_map_inline:Nn
  \l_tmpb_seq

{ % start map
\str_set:Nn \l_tmpa_str {##1}

       \l_tmpa_str

  \tex_par:D
 } % end map
}



%===================
\tl_new:N \l_fcsc_command_tl
\tl_new:N \l_fcsc_parms_tl
\tl_new:N \l_fcsc_fullcommand_tl
\seq_new:N \l_fcsc_master_seq


%===================
\NewDocumentCommand
  { \termcap } 
  { m m } 
     % #1 term cmd + options
     % #2 cmd argument(s)
 {

  \tl_set:Nn \l_fcsc_command_tl {#1}
  \tl_set:Nn \l_fcsc_parms_tl {#2}

  \proc_fcsc_screencapture:
  \proc_fcsc_createrecordset:
  \proc_fcsc_cleanrecordset:

  \proc_fcsc_printsampler:

} % end command



\cs_generate_variant:Nn
   \sys_get_shell:nnN
   { onN }
\cs_generate_variant:Nn
   \seq_set_split:NnV
   { NoV }


\ExplSyntaxOff

\begin{document}

\termcap{fc-scan}
{/system/fonts/NotoSerifCJK-Regular.ttc}

\end{document}.

Run with shell escape.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.