[XeTeX] Special characters: how to handle cleanly

Joseph Wright joseph.wright at morningstar2.co.uk
Mon May 26 09:53:14 CEST 2008


Will Robertson wrote:
> On 25/05/2008, at 4:28 AM, Joseph Wright wrote:
> 
>> I'm trying to work out how to handle a small set of special characters
>> cleanly.  Consider the following:
>>
>> \documentclass{article}
>> % Need something clever here!
>> \begin{document}
>>  Some text $°Åμ$ °Åμ
>> \end{document}
>>
>> If I compile with xelatex, only "Some text" shows up.
> 
> Hi Joseph,
> 
> Good question. There aren't many macro packages that yet explicitly 
> support XeTeX (or rather, accommodating plain unicode input). Maths 
> right now is a bit of a funny situation; if it's possible, it'd be best 
> if siunitx doesn't place those characters into running maths mode.
> 
> The good news for you is that you don't need to worry about things too 
> much. As you say, without any packages loaded means things don't display 
> correctly in XeTeX, but the same is true in LaTeX as well: you need to 
> load a font that will be able to display them.
> 
> So whether fontspec is loaded, or a font is loaded via any other method, 
> things kind of just work:
> 
> \documentclass{article}
> \begin{document}
> \font\1="Times"\1
> 10\,µm
> \end{document}
> 
> If you want to ensure that these glyphs are actually available in the 
> font, you might want to make them active and check for them:
> 
> \documentclass{article}
> \begin{document}
> \makeatletter
> \font\1="Times"\1
> \catcode`\µ=13
> \def\check at glyph@else#1{%
>   \@tempcnta=\XeTeXcharglyph #1\relax
>   \ifnum\@tempcnta>0
>     \XeTeXglyph\@tempcnta
>     \expandafter\@gobble
>   \else
>     \expandafter\@firstofone
>   \fi}
> \defµ{\check at glyph@else{`\µ}{\ERROR}}
> 10\,µm
> \end{document}
> 
> But I'd be reasonably confident that all roman fonts should contain 
> those glyphs.
> 
> Hope this helps,
> Will

Hello Will,

Thanks for that: very informative about how things work.  I'm hoping 
that somewhere there is a method to achieve what inputenc does with, for 
example, latin1.  There, the characters are made active and defined 
without needing to actually include the characters themselves in the 
input, by using the appropriate codes.  The problems for me is that I 
don't know how to use \catcode or \lccode with UTF codes (or indeed 
where to find such information).  In your example, you use explicit 
characters, which works fine in UTF8 but not is ASCII :-(. My editor 
isn't UTF8, and as my normal engine isn't xetex I'm not keen on making a 
file that is hard for me to compile!

Joseph Wright


More information about the XeTeX mailing list