[XeTeX] font scope

Ross Moore ross at ics.mq.edu.au
Sun Nov 11 06:43:51 CET 2007

Hello Mike,

On 11/11/2007, at 2:50 PM, Mike Maxwell wrote:

> I guess I have a newbie question, about the scope of font commands.
> It's possible this is answered in the documentation, but I can't  
> figure
> out where I found it (specifically the documentation on
> \newfontinstance).  Senility, I guess.
> Anyway, here's the lines of code:
> %-----------------
> \usepackage{fontspec}
> \setmainfont{Charis SIL}
> \newfontinstance\DejaFont{DejaVu Sans}
> ...
> some text in Charis \DejaFont{∼} some more text
> %-----------------

You want:
   some text in Charis {\DejaFont ∼} some more text

> I was expecting the "some more text" to come out in the Charis  
> font, on
> the assumption that the scope of the \DejaFont command was the  
> material
> in the {}, i.e. only the tilde.  (BTW, the tilde is U+223C, which  
> is not
> really a tilde.)

You must have only ever read LaTeX documentation and not TeX itself.

{...}  are the delimiters in TeX, used for various purposes.
LaTeX uses them a lot for delimiting parameters to macros.
e.g. \textbf{...whatever...}

But this macro + parameter expands to something like:

   {\bfseries ...whatever...}

where now the \bfseries does the real work, but is delimited
by the '}' which follows, and which matches the preceding '}'.

Note that the bold-face doesn't appear in the output until the
\bfseries , and reverts to whatever was being used previously
after the '}' has been read.

That is, you could have typed:

...preceding stuff... { ... preceding whatever...
   \bfseries ...whatever ...} ...following stuff...

and only the  ...whatever... will use bold-face.

> Instead, the font change to the DejaVu Sans font remains until the  
> next
> overt font change.

Yes, because \DejaFont does not read a parameter, it just does the work.

That is, it is defined to work like \bfseries , not like \textbf .
It is a "declaration" (of which font to use), rather than a "function"
macro applied to a specific parameter (list of tokens).

> Obviously I'm not understanding the scope of this font change.  But in
> order to revert to the preceding font, I need to know what it is  
> (it is
> of course Charis in this example, but I can't count on that in  
> general).
>   What is the command to save the font, and then restore it?  Or  
> better,
> is there a way to do what I want to do, namely limit the scope of the
> font change to a specified string?

Sure. Keep \DejaFont as is is, and define a macro \textdj as follows:

      \DeclareRobustCommand{\textdj}[1]{\DejaFont #1}

then use:  \textdj{~} .

You could use any of  \newcommand , \newcommand* , or  \providecommand
  (and some other forms) instead of \DeclareRobustCommand .
I won't go into the technical distinctions that these entail.

> -- 
> 	Mike Maxwell
> 	maxwell at umiacs.umd.edu
> 	"For over a thousand years, the British Empire was the guardian
> 	 of good grammar and the English language.
> 	 Before the dark times.  Before the Americans."
> 	--Bob Kenobi (Ben Kenobi's younger brother)

Hope this helps,

	Ross Moore

Ross Moore                                         ross at maths.mq.edu.au
Mathematics Department                             office: E7A-419
Macquarie University                               tel: +61 +2 9850 8955
Sydney, Australia  2109                            fax: +61 +2 9850 8114

More information about the XeTeX mailing list