TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

This is a partial re-asking of my question Can I change the font and colour of a letter permanently?. The answers there focussed on the colour aspect of what I wanted. I also want to be able to change the actual font used for a character.

What's the right way to reassign a character to a particular glyph from a particular font?

As a possible (albeit slightly manic) example, suppose I wanted (in maths mode) to use C just for the set of complex numbers. So typing C should produce ℂ. I also want to be able to shift the glyphs around, so maybe typing d should produce δ.

Will's answer to my original question began with:

In regular latex you can choose different fonts for different symbols

but didn't tell me exactly how to do that!

share|improve this question
up vote 12 down vote accepted

The first argument is the token (control sequences are valid here) you're defining. The second is the class, \mathord, \mathbin, \mathop, \mathrel, \mathopen, \mathclose, \mathpunct, and 7 for variable (there's probably some \mathfoo for variable, but I don't know what it is). The third is the font family. The fourth is the position within that family.

As would be expected, this particular case eventually expands to a \mathcode `C="0.43. I don't really know what the missing hex digit (the family) is. \mathcode is one of those mysterious (to me) primitives.

I believe the basic format is: \mathcode `x="cfpp where x is any literal character, c is the class (0 = ordinary through 7 = variable), f is the family, and pp is the position within that family. cfpp is a hexadecimal value, of course.

It occurs to me that you might want to use 7 instead of \mathord to get a letter in the variable class. I'm not sure. Hopefully someone else can express an opinion on the matter.

share|improve this answer
That's probably enough for me to work out the rest, but if you happen to know a link to an explanation of what the fields mean (or can put it in yourself), that'd be much appreciated! – Loop Space Sep 10 '10 at 10:01
Sorry, this isn't my greatest answer ever. Hopefully someone will come give a better answer. – TH. Sep 10 '10 at 10:14

Just an example to get you started; see texdoc fntguide for the complete documentation.


This doesn't have a proper user interface in unicode-math yet, since it's a somewhat obscure feature to have. But I'll definitely keep it mind when I do my next round of updates.

share|improve this answer
As a matter of fact, this question came out of trying to hack unicode-math to allow me to do exactly that. Then further reading of unicode-math led me to realise that every time I call 'setmathfont', I set up a whole new font - even for just one character! So better to set up the fonts at the start and then just use them each time. But that needs the reassignment code. – Loop Space Sep 10 '10 at 12:42
I agree that it sounds a little obscure at first, but the more I think about it the more ways I can think to use it! Just imagine giving a seminar on cryptography where the lecturer wants to show how different letters occur in text. On one frame, everything's black. On the next, all the letter 'e's appear in green. Though, having read your last blog post, I think that you have more important things to do right now than implement this! – Loop Space Sep 12 '10 at 13:22
Changing the colour is one thing, and I agree, but remapping C to \mathfrak{C} is less convincing :) It certainly makes the source much less portable. – Will Robertson Sep 12 '10 at 22:36
Agreed, and that's not actually what I want to do. All I really want to do is shift a character to boldface (for vectors). So if 'bf' were on the same level at 'up' and 'it' in your unicode-math package, then I'd be happy. By the way, I've now gotten a working system with the colours and all that. If you want to see what it looks like, take a look at the latest lecture (beamer or trans versions) at math.ntnu.no/~stacey/Teaching/TMA4145h2010/lectures.html I think maybe it's a bit garish, but I'm still experimenting with what looks best. – Loop Space Sep 14 '10 at 19:40

Even though there already is an accepted answer, I wanted to chip in one thought. The only "shifting" that comes to mind would require XeTeX, a font which has everything packed in (latin, greek, etc.), and knowing how much to "shift". Ie.

\count0=0 \advance\count0 by \XeTeXcharglyph`A
\advance\count0 by 500% Or how much it is to shift until the wanted version
\XeTeXglyph\count0% Out comes the shifted glyph

Of course, all this would need to be macro'd somehow. I'm sorry I don't know macroing well enough to be of help here, but hopefully the basic idea could provide some food for thought.

share|improve this answer

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.