I just ran into another issue, I like to use gill sans very much but the number 1, lower case L and upper case I are almost indistinguisable. On the other hand I like Helvetica numbers. Is there a way to use Gill Sans for all non-numeric characters and Helvetica only for numbers [0 9] ?
[Tex/LaTex] Font selection in XeTeX for specific characters
fontsxetex
Related Solutions
Another way to enter the characters is to enter them directly with the \XeTeXglyph
macro or use their Unicode character code using the \char
macro.
For example, the heart symbol is Unicode 2665 so you can enter that using:
\char"2665
It's also possible to use the font specific glyph index number. For a font like the C64 font, which doesn't have a huge character inventory, this might be easiest. The following document creates a full font table for the C64 Pro Mono font (the upper bound was found by trial and error, but you could use FontForge to find the total number of glyphs as well).
% !TEX TS-program = xelatex
\documentclass[12pt]{article}
\usepackage{pgffor}
\usepackage{fontspec}
\newfontfamily\csixtyfour{C64 Pro Mono}
\DeclareTextFontCommand{\textcom}{\csixtyfour}
\begin{document}
\parindent=0pt
\foreach \x in {4,...,312}
{\x\thinspace\textcom{\XeTeXglyph\x} }
\end{document}
The code in my answer to TeX accents do not seem to work with fontspec and xe/lua/latex gives the idea, but for the dot above some additional code is needed.
\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Minion Pro} % a font without Latin Ext. Additional
\usepackage{newunicodechar}
\UndeclareUTFcomposite[\UTFencname]{x0101}{\=}{a}
\UndeclareUTFcomposite[\UTFencname]{x1E43}{\d}{m}
\UndeclareUTFcomposite[\UTFencname]{x1E45}{\.}{n}
\makeatletter
\let\d\relax
\DeclareRobustCommand{\d}[1]
{\hmode@bgroup
\o@lign{\relax#1\crcr\hidewidth\ltx@sh@ft{-1ex}.\hidewidth}\egroup
}
\let\.\relax
\DeclareRobustCommand{\.}[1]
{\hmode@bgroup\vbox{% \o@lign has \vtop
\lineskiplimit\z@
\baselineskip\z@skip
\lineskip.25ex
\ialign {##\crcr\hidewidth.\hidewidth\crcr#1\crcr}}\egroup
}
\makeatother
\newunicodechar{ā}{\={a}}
\newunicodechar{ṃ}{\d{m}}
\newunicodechar{ṅ}{{\.n}}
\begin{document}
German Umlaute:
\begin{itemize}
\item Unicode characters: ä ö ü Ä Ö Ü
\item by \LaTeX command: \"a \"o \"u \"A \"O \"U
\end{itemize}
a with macron above:
\begin{itemize}
\item by function: ā
\item by \LaTeX: {\=a}
\end{itemize}
m with dot underneath:
\begin{itemize}
\item by function: ṃ
\item by \LaTeX: \d{m}
\end{itemize}
n with dot above:
\begin{itemize}
\item by function: ṅ
\item by \LaTeX: \.n
\end{itemize}
\end{document}
Best Answer
Yes, you can. But I only know a tricky method --- to use
\XeTeXinterchartoks
and related commands. There have been some packages, for examplexeCJK
anducharclasses
, that use this mechanism for multilingual support. (I wrote a few code forxeCJK
.) For more information, you can read XeTeX's reference.Set
\XeTeXinterchartokenstate=1
to enable the mechanism.There are already some predefined char classes. 0 for normal westen alphabets and symbols, 1 for CJK ideographs, 4095 for boundary (255 in older versions of XeTeX), etc. And you can use
\newXeTeXintercharclass
to allocate a new class.Use
\XeTeXcharclass
to set the numbers to the new character class, and use\XeTeXinterchartoks
to do the trick.Full example:
BTW, this does not affect math fonts.
Note Code has been updated to reflect changes in XeTeX (but not actually reflected in the documentation.) If this code fails, remove the test for XeTeX version and just use
\chardef\CharBound=4095
. (There was one version of the kernel that did not have\e@alloc@intercharclass@top
defined, but the class was still 4095.)