TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to change the font in XeLaTeX when I enter a new Unicode block with a certain Script (e.g. Devanagari for Hindi languages). The ucharclasses package seems to do exactly that.

However, when I leave the place where the different script is used and go back to what I had before (e.g. latin script) I loose the formatting (e.g. boldface) and the font size.

To illustrate, try this:


\setmainfont[Mapping=tex-text]{Liberation Serif}
\setsansfont[Mapping=tex-text]{Liberation Sans}
\setmonofont[Mapping=tex-text]{Liberation Mono}

\section{A latin script section}
Some latin script
\section{Devanagari: ताजा धनिया के साथ अनायास and so on}
A mixture \textbf{ of normal text and ताजा धनिया के साथ अनायास Devanagari script} in bold
\section{Some more latin script}
Some latin script

The output looks like this:

Script changes

The \setTransitionTo correctly picks up the Devanagari script and changes the font to Siddhanta. However, when I come back to latin script, the boldface is gone and the fontsize is increased. The table of contents line shows the same problem.

N.B. \setTransitionsFor{...}{...}{...} is what the documentation describes as \setTransitions. The doc seems to be wrong.

share|improve this question
I don't know if this will solve your problem (and can't test right now, hence not an answer), but you should not use {\bf text}. Use \textbf{text} instead. For reasons as to why, see the l2tabu package. – Roelof Spijker Oct 21 '11 at 16:01
@whlt3 Thanks for your advice. I've changed the question to use \textbf but that doesn't help. I also added some text to the section title to show the same problem appearing in the table of contents. – kongo09 Oct 21 '11 at 16:07
up vote 5 down vote accepted

You can try something like this (I used the ^^-notation because I don't have an utf8-editor here):


\newfontfamily\hindifont{Arial Unicode MS}

\begin{document} \tableofcontents \section{A latin script section} Some latin script

\section{Devanagari: ^^^^0908 ^^^^0909 and so on} A mixture \textbf{ of normal text and ^^^^0908 ^^^^0909 Devanagari script} in bold
\section{Some more latin script} Some latin script

share|improve this answer
I bow my head and am deeply impressed. Works like a charm! – kongo09 Oct 21 '11 at 16:55
Would you please add some explanation as to what you did here, for us who are font impaired? – Yiannis Lazarides Oct 21 '11 at 17:14
@Yiannis: I simply stored the description of the actual font before switching to \hindifont and then called this font when quiting the devanangari block. – Ulrike Fischer Oct 21 '11 at 17:20
@UlrikeFischer Thanks. – Yiannis Lazarides Oct 21 '11 at 17:36
I think this actually doesn't work for mixtures of scripts, where you go from latin to script1 then to script2 and then back to latin. This can happen in Japanese, for example, that can go from kanji to katagana to hiragana and even latin script. – kongo09 Oct 21 '11 at 20:49

I think it's easy:

  \XeTeXinterchartoks 255 \csname#1Class\endcsname{\relax}}

This is what we do in xeCJK. Note that we must reset the \XeTeXinterchartoks to make the group balance. It is a place that ucharclasses is not very well implemented.

Hmm, spaces between scripts are necessary here. It's very boring to define all transitions for all scripts in the document, if there are many.

share|improve this answer
Thanks a lot for your insight and help. – kongo09 Oct 24 '11 at 8:44
Can you explain how your solution works? What does \ResetTransitionTo do? Is it better than a simple \setTransitionsFor{Devanagari}{\begingroup\sethindifont}{\endgroup}? – Olivier Cailloux Feb 9 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.