3

Possible Duplicate:
Font substitution with XeLaTeX

I am using a text font that unfortunately does not have accents for the letter e, which I need. But I have found a very similar font, and have created a simple \newcommand that I can use to switch font when I need the accent. But naturally, the the old unaccented letter e doesn't match the accented one exactly, so I would like to switch all of the unaccented letter e's in my document to the new font as well, but I would rather not have to use a macro to do this, naturally. [Why don't I just use the new font? Ah, well, the new e looks acceptable with the old font, but the rest of the font is not acceptable.]

Is this possible? What I was hoping for was something like using mathspec "ranges", which allow me to redefine an individual math character's font, but for non-math characters.

I am using lyx, xetex, mathspec, et. al.

[update] well, I should have tried a little harder I guess. I found an answer soon after, by borrowing from an answer I think was built for another purpose, but that works here: Font substitution with XeLaTeX. It's a bit deep in the works, and I never would have figured it out on my own I am sure, but anyway, back to work...sorry to trouble...

\newfontfamily{\JapSubstFont}{newfont}

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\JapSubst

\XeTeXcharclass"0065=\JapSubst % "0065 is unicode for the letter e

\XeTeXinterchartoks 0 \JapSubst = {\begingroup\JapSubstFont}
\XeTeXinterchartoks 255 \JapSubst = {\begingroup\JapSubstFont}
\XeTeXinterchartoks \JapSubst 0 = {\endgroup}
\XeTeXinterchartoks \JapSubst 255 = {\endgroup}

[upupdate] I know the question is closed, and that I am not sure I should give any more answer, but lest anyone else stumble here and would like to add a small postscript to the effect that the above changes the letter for ALL fonts, and that one has to add statements like

\newfontfamily\fontone{myfontnameone}
\newfontfamily\fonttwo{myfontnametwo}
\providecommand{\enablefontone}{\XeTeXinterchartokenstate=1  \fontone  }
\providecommand{\enablefonttwo}{\XeTeXinterchartokenstate=0  \fonttwo  }

to turn the feature on or off, respectively, for specific fonts.

[up3date] Again, lest someone stumble...I found the latter method didn't quite work as I wanted (e.g. as the substitution also got applied to my sans-serif and typewriter fonts, which now had substitute e's instead of their proper e's). To test for the appropriate font directly is more apt:

\makeatletter % necessary to enable f@...

% will test if current font is the badfont
\newcommand{\iffont}[3]{\ifthenelse{\equal{\f@family}{#1}}{#2}{#3}}

\newfontfamily{\JapSubstFont}{goodfontname}

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\JapSubst

\XeTeXcharclass"0065=\JapSubst
\XeTeXcharclass"00E9=\JapSubst

% function test for transition into JapSubstFont,
% from either
% class 0 (default, i.e. inside word) tokens  
\XeTeXinterchartoks 0 \JapSubst = {\begingroup 
\iffont{badfontname}{\JapSubstFont %if correct, substitute
}{           %else do nothing
}}
% or class 255 (text or word boundary)
\XeTeXinterchartoks 255 \JapSubst = {\begingroup
\iffont{badfontname}{\JapSubstFont}{
}}
%and then back out from JapSubst into class 0 or 255
\XeTeXinterchartoks \JapSubst 0 = {\endgroup}
\XeTeXinterchartoks \JapSubst 255 = {\endgroup}

\makeatother %necessary to turn off private functions f@...

marked as duplicate by lockstep, Werner, egreg, user11232, diabonas May 7 '12 at 22:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.