I want to put the following phrase into a book.
Khabarovsk (Russian: Хабаровск) is located 30 kilometers (19 mi) from the Chinese border.
The source is NOT UTF-8 and I don't have the option to make it UTF-8. I want to enter the Russian characters in a robust way that will not be distorted when the file is transferred between different people, and so I am limited to ASCII.
I have entered this:
Khabarovsk (Russian: \char"0425 \char"0430 \char"0431 \char"0430 \char"0440 \char"043E \char"0432 \char"0441 \char"043A ) is located 30 kilometers (19 mi) from the Chinese border.
This works in XeLaTeX (which is what I am using). Is this really the best way to enter these Unicode character code-points into LaTeX source?
Is there a standard way to specify a Unicode character that will work across all versions of LaTeX? If not, any comments on why there is no such standard notation for this? I am just trying to understand where all this is going.
Let me expand upon the excellent answer given by David Carlisle below. The caret notation would be like this:
Khabarovsk (Russian: ^^^^0425^^^^0430^^^^0431^^^^0430^^^^0440^^^^043e^^^^0432^^^^0441^^^^043a) is located 30 kilometers (19 mi) from the Chinese border.
This is superior for a number of reasons:
- The \char form 'eats' a space after the command (the way TeX normally does) and that means that if you want a space, you have to do something special, like put an extra slash-space (standard TeX command behavior). The caret notation is exactly like a character: put a space between them and that space works like a space between characters.
- This conversion is done at the initial parsing level, which means these characters can be used for anything in TeX, including spelling of commands. They simply represent characters in the input stream for any purpose.
- David implied that the \char notation might be picking a code point in a font. I suppose most fonts use Unicode so this might or might not be a problem, but in any case using the caret notation allows the character to be processed by all the following logic exactly as if you typed the character into the source file.
- The notation is slightly more compact: 8 characters instead of 10.
Only note: the hex digits MUST use lower case letters. I don't know for sure, but I assume this only works on XeTeX and variants of that.
See further discussion at blog post on Adding Unicode Characters to LaTeX documents