LaTeX forum ⇒ XeTeXSelecting a different font for numbers in main font

Information and discussion about XeTeX, an alternative for pdfTeX based on e-Tex
tafi
Posts: 42
Joined: Sat May 07, 2011 12:01 am

Selecting a different font for numbers in main font

Postby tafi » Wed Jun 06, 2012 2:48 pm

I'm writing a thesis using XeLaTeX, and have so far specified my fonts using the mathspec package.

I like the look of Adobe's Arno Pro and am using that as the main font. For maths I've been using Mastic (which is like STIX but with a couple of usefull modifications). Some might think it's a weird combo but I think it works.

My main problem is to do with numbers. Using different sets of numbers for maths and text looks very bad. I would really prefer to use the Mastic or STIX or XITS numbers throughout the document, but I can't find a command to change the numbers range of the mainfont.

What I need is a command like:

  1. \setmainfont(Digits){Mastic}


But of course no such command exists. Does anyone know of an alternative way to change the mainfont numbers?
Last edited by cgnieder on Mon Oct 22, 2012 11:56 am, edited 1 time in total.
Reason: added code markup

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Postby CrazyHorse » Wed Jun 06, 2012 2:52 pm

did you read the mathspec documentation?

tafi
Posts: 42
Joined: Sat May 07, 2011 12:01 am

Postby tafi » Thu Jun 07, 2012 1:50 am

Um, yes I have, several times. Have you?

If you did you'd probably already know that mathspec does not provide the command for setting the main text font, it is fontspec which does this.

Mathspec provides commands to allow the setting of digits, latin and greek in maths fonts. I currently have the following commands to set my maths font(s)

  1. \setmathfont(Digits){Font1}
  2. \setmathfont(Latin){Font2}
  3. \stemathfont(Greek){Font3}


However, when you set the main font there is no (Digits) option provided by fontspec so the commands

  1. \setmainfont(Latin){TextFont}
  2. \setmainfont(Digits){Font1}


are not possible (at least not for me). Unless I am missing something which is not obvious from the documentation.

That is why I have posed the question, and I will gratefully accept constructive comments on whether or not a solution exists.
Last edited by Stefan Kottwitz on Thu Jun 07, 2012 8:46 am, edited 1 time in total.
Reason: code marked

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Postby CrazyHorse » Thu Jun 07, 2012 8:55 am

ok, a misunderstanding. I thought you want it the other way round: using in math the text digits

tafi
Posts: 42
Joined: Sat May 07, 2011 12:01 am

Postby tafi » Sat Jun 09, 2012 2:52 am

I see,

Yes the best solution I have so far is to share the digits from the mainfont (Arno) with the maths latin and greek of Mastic with the following commands:

  1. \setmainfont[Mapping=tex-text]{Arno Pro}
  2. \setmathsfont(Digits)[Numbers={Lining,Proportional}]{Arno Pro}
  3. \setmathsfont(Latin)[Scale=MatchLowercase]{Mastic}
  4. \setmathsfont(Greek)[Scale=MatchLowercase]{Mastic}


However, the Arno Pro digits really don't look quite like professional mathematics, so I really would prefer it to be the other way around (to keep Matic's digits and then use them in the mainfont)

tafi
Posts: 42
Joined: Sat May 07, 2011 12:01 am

Postby tafi » Mon Oct 22, 2012 1:34 am

The best workaround I have found so far is to use "character tokens" as described in a tex.stackexchange thread:

http://tex.stackexchange.com/questions/10248/font-selection-in-xetex-for-specific-characters

Thus the font definition part of my preamble now looks like this:

  1. \setmainfont[Mapping=tex-text]{Arno Pro}
  2.  
  3. \XeTeXinterchartokenstate=1
  4. \chardef\CharNormal=0
  5. \chardef\CharBound=255
  6. \newXeTeXintercharclass\CharNumbers
  7. \XeTeXcharclass`0=\CharNumbers
  8. \XeTeXcharclass`1=\CharNumbers
  9. \XeTeXcharclass`2=\CharNumbers
  10. \XeTeXcharclass`3=\CharNumbers
  11. \XeTeXcharclass`4=\CharNumbers
  12. \XeTeXcharclass`5=\CharNumbers
  13. \XeTeXcharclass`6=\CharNumbers
  14. \XeTeXcharclass`7=\CharNumbers
  15. \XeTeXcharclass`8=\CharNumbers
  16. \XeTeXcharclass`9=\CharNumbers
  17. \newtoks\TokSetfont
  18. \TokSetfont={\begingroup\fontspec{Mastic}}
  19. \XeTeXinterchartoks\CharNormal\CharNumbers=\TokSetfont
  20. \XeTeXinterchartoks\CharBound\CharNumbers=\TokSetfont
  21. \XeTeXinterchartoks\CharNumbers\CharNormal={\endgroup}
  22. \XeTeXinterchartoks\CharNumbers\CharBound={\endgroup}
  23.  
  24. \setmathsfont(Digits)[Numbers={Lining,Proportional}]{Mastic}
  25. \setmathsfont(Latin)[Scale=MatchLowercase]{Mastic}
  26. \setmathsfont(Greek)[Scale=MatchLowercase]{Mastic}


I don't understand the inner workings of this solution, so I have no idea if this can be simplified. However, it does give the desired result. It certainly is a drain on resources in compilation (tens of times slower than without it).

I would love to know if there are any easier (and more resource efficient) ways of achieving the same thing using a package or some package options.


Return to “XeTeX”

Who is online

Users browsing this forum: No registered users and 3 guests