# Using non-ASCII characters in packages

What is the best way to use non-ASCII (say, Cyrillic) characters in a .sty file?

If it's used in a LaTeX file that uses \inputenc[utf8]{inputenc}, than one can just use utf8 encoding in the .sty file and everything's fine. Or the other way round: one can add \RequirePackage[utf8]{inputenc} to the .sty file. But in any case, the author of .tex file has to use the encoding used in .sty file.

Is there a way to specify encoding in the .sty file, so it may be used in a .tex file in any encoding?

(Recipe that is also compatible with XeLaTeX would be especially nice.)

-
I have the same problem with files with the Norwegian characters ø, æ, and å. –  Andrew Stacey Aug 20 '10 at 15:07

Edited (my original answer was quite confusing): The babel package has this problem, because it needs to translate "Table of contents", and so on into other languages, in a way that doesn't force a particular encoding on the document author. The way babel deals with Cyrillic (which can be used in with multiple input encodings) without forcing an a choice, is to use encoding-dependent commands (\cyrr, \cyre, etc).

-
It works, thanks. But it makes .sty file quite unreadable (and un-editable)... Is there some tool to convert strings between such commands and unicode, btw? –  Grigory M Aug 20 '10 at 16:16
I don't know of any such tool. –  Lev Bishop Aug 20 '10 at 19:17

It's generally not a good idea to use non-ascii characters in LaTeX packages, since TeX doesn't have much understanding of input encodings, but inputenc itself provides a command to specify the encoding:

\inputencoding{encoding name}

It may perform what you need, but the better idea would be to use standard LaTeX control sequences for such characters. (Of course, this isn't always convenient, hence your question.)

For XeLaTeX packages, it's a different story, because XeTeX can handle different input encodings natively. For this, you can use the \XeTeXinputencoding primitive.

-
Adding "\inputencoding" in .sty file doesn't work for me. –  Grigory M Aug 20 '10 at 15:57
Could you please provide MWE? –  Grigory M Aug 20 '10 at 16:13
I suspect you need to put \inputencoding inside the macro that uses the non-ascii text. –  Will Robertson Aug 21 '10 at 1:56
did you try it? I did — and it also doesn't work –  Grigory M Aug 21 '10 at 10:21
Okay, sorry for the wild goose chase. –  Will Robertson Aug 22 '10 at 23:30