Changes

Jump to navigation Jump to search
Actualization, better structure
< [[Fonts]] >
The [http://unicode.org/ Unicode] effort clearly shows that 256 characters cannot possibly contain the world's languages. However (with the exception of modern variants like [[Omega]] and [[XeTeX]]), TeX is an old system, and will only deal with 256 characters per font. Similarly, many "legacy" file encodings on current operating systems will attempt to shoehorn a set of characters into eight bytes.==Introduction==
As a resultThe [http://unicode.org/ Unicode] effort clearly shows that 256 characters cannot possibly contain the world's languages. However, traditional TeX is an old system, you need to make a choice which input encoding ('''regime''') or and will only deal with 256 characters per font/output encoding . Similarly, "legacy" file encodings on current operating systems ('''encoding'''e.g. Latin-1, Mac Roman, Windows 1252, ISO-8859-#) you useattempt to shoehorn a set of characters into eight bytes. ==Encodings==
As a result, working with [[pdfTeX]] (MkII) you need to make a choice which input encoding ('''regime''') or font/output encoding ('''encoding''') you use.  Modern TeX variants, from [[Omega]] over [[XeTeX]] to [[LuaTeX]], dropped that limitation and work with full Unicode character sets, in fonts as well as in your source documents. ==Font Encodings== LaTeX users will probably know them under the name '''fontenc''' (<code>\usepackage[T1]{fontenc}</code> for example).  As TeX can only handle 256 characters at once, it is important to choose the encoding which covers all the characters of your language, otherwise the hyphenation won't won’t work for words with composite characters and most probably you won't won’t be able to simply extract text from the resulted PDFs.
To enable ec encoding in [[Latin Modern]] for example, you can type:
Some good choices for encodings are:
=== in pdfTeX (MkII) ===
* '''texnansi''' for Western European languages with only a small subset of additional accented characters (includes many other important glyphs)
* '''ec''' for European languages with many accented characters
http://fun.contextgarden.net/encodingtable/enctable.rb?ec,texnansi,8r,8a
=== in XeTeX & luaTeX (MkII) === 
* '''uc''' standing for Unicode (the only font encoding supported by [[XeTeX]])
* ('''texnansi''' as the very last resort in [[XeTeX]] - where there are no proper fonts available apart from the old ones)
{{todo|I hope that the content of this section will soon move to a page on its own with more comprehensive overview of different encodings.}}=== in LuaTeX (MkIV) ===
you can normally forget about font encodings.
=== A note about the ec encoding ===
 
Ec encoding is also known under the names '''cork''' or '''T1''' (<code>\usepackage[T1]{fontenc}</code> in LaTeX). Its old version was '''dc''' (should not be used any more). Some of the glyph names in ec are old and deprecated, '''tex256''' uses the same set of glyphs, but the glyph names are compatible with Adobe, see also [ftp://tug.ctan.org/pub/tex-archive/info/fontname/tex256.enc tex256.enc] and [http://partners.adobe.com/public/developer/en/opentype/aglfn13.txt Adobe Glyph List].
</texcode>
At the time of writing this article, only '''il2''' and '''ec''' are were being supported, but support for other encodings can be added.
See also:
* [http://source.contextgarden.net/tex/context/base/enco-pfr.tex enco-pfr.tex] and all pdfr-*.tex files
== Input Regimes == (Also known as "input encodings", but in ConTeXt "encoding" refers to fonts, while input is handled by a "regime".) If you write ConTeXt source documents and use more than 7-bit ASCII, you must decide on the encoding of your file. That’s a matter of your text editor.The best choice is normally UTF-8, but if you insist to use an outdated editor that can’t handle Unicode properly or if you’re forced to use legacy code, you have to choose the proper 8-bit encoding, see below. ===Available Regimes===
<table style="border:1px solid #DDDDDD">
<tr style="background-color:#DDDDDD"><th>ConTeXt name(s)</th><th>Official name(s)</th><th>Remarks</th></tr>
* [http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/] for Windows
You enable such a regime with <cmd>enableregime</cmd><code>[some]</code>, preferably in your [[Project_structure|environment file]]. ===Typesetting in UTF-8===
Use <texcodecmd>\enableregime</cmd><code>[utf]</texcodecode> in order to be able to typeset in unicode Unicode under ConTeXtMkII. (This is '''not ''' necessary under mkIVin MkIV, as it is enabled by default using LuaTeX.)
Unfortunately you must save your UTF-8 encoded files '''withoutBOM''' BOM (byte order mark), because ConTeXt (or pdfTeX) doesn't ignore that but typesets the characters. This is correct behaviour since UTF-8 doesn't doesn’t have a BOM according to the Unicode standard, even if it’s use is widespread.
===Using non-ASCII characters===
As a TeX/LaTeX user you were probably told to use the accents in the following way (the example is taken from the TeXbook, page 24):
named R.~J. Drofnats.
</texcode>
The galaxy name will be shown as<context>\"O\"o\c c</context>.
In ConTeXt, please <b>'''try to avoid</b> ''' using this backslashed character composition, if possible (there are several good reasons for it - hyphenation, etc.).
You have two alternatives:
====Type the characters as you do in any other text editor====
<texcode>
\enableregime[utf] % or any other supported regime
galaxy called Ööç
</texcode>
 
Once you figure out what regime you need, you can simply type the characters as you do in any text editor
(See above for the list of available regimes - some more will probably be added in the near future. If you don't find the one you would like to use, please ask on the mailing list)
With [[LuaTeX]] engine ([[Mark IV]]) all utf8 characters from your font may be used directly. Typing some characters may require some keyboard setting or may not be possible at all. In this case try to copy/paste them from this [[Symbols/utf8|list of selected utf8 characters]] or use your OS’s character table or a program like [http://live.gnome.org/Gucharmap Gucharmap] for example.
====Use glyph names====If you don't have the letter on your keyboard (, if you are too lazy to look it up in a table, if your editor font doesn’t show it or if you want some strange letters not supported by the regime /font/editor/OS you use, for example greek or cyrillic), you can access the glyphs by their names:
<texcode>
Once upon a time, in a distant
</texcode>
====How do I know which glyph name to use?====
* use <cmd>showcharacters</cmd>
* [http://partners.adobe.com/public/developer/en/opentype/aglfn13.txt Adobe glyph list]
</context>
==How does it workswork?==
'''Robert Ermers''' and '''[[User:adam|Adam]]''' provided a helpful explanation of how characters are constructed in LaTeX and ConTeXt (in some discussion on the mailing list):
* in most fonts: show the character on the a given numerical position, which means that there is one character <context>\"{a}</context>.
* in some other fonts <code>\"{a}</code> means: combine <code>"¨</code> with <code>a</code> and make an <context>\"{a}</context>. This means that <code>"¨</code> is combined with the character on the numerical position of <code>a</code>. TeX does this very well and thus construes very acceptable diacritical signs like <code>\"{q}</code>, <code>\d{o}</code>, <code>\v{o}</code>, which do not exist in regular fonts.
If you have a font which contains <context>\"{q}</context>(<code>\"{q}</code>), <context>\d{o}</context>(<code>\d{o}</code>) or some other special characters, you may instruct TeX not to create the character, but rather to show the contents of a given numerical position in that font. That's what the <code>.enc </code> and <code>.fd </code> files under LaTeX are for.
That's That’s also the reason why there are, or used to be, special fonts for Polish an Czech and other languages: they contain predefined characters in one single numerical position, e.g. <code>\v{s}</code> and <code>\v{c}</code> that TeX does not have to create anew from two signsglyphs.
===In ConTeXt===
the combination <code>\"{a}</code> means one thing: <code>\adiaeresis</code> (see [[source:enco-acc.tex|enco-acc]]). This <code>\adiaeresis</code> can mean one of two things, depending on the font encoding:
* Numerical position, or
* The fallback case (defined in [[source:enco-def.tex|enco-def]]), where a diaeresis/umlaut is placed atop an <context>a</context> glyph. Hyphenation implications as Hans described.
The interesting/helpful thing about ConTeXt is that internally, that glyph is given a consistent name, no matter how it is input or output. So, if you type <code>ä</code> in your given input regime, and that encoding is properly set, that numerical <code>ä</code> (e.g., character <code>#228</code> in the windows regime) is mapped to <code>\adiaeresis</code>.
Wanna know what happens in '''UTF-8'''? Here's Here’s a 'simplified' explanation: 
In a UTF-8 bytestream, that character <context>\"{a}</context> is signified by two bytes:
<code>0xC3</code>, <code>0xA4</code>. That first byte triggers a conversion of both bytes into two
different bytes, the actual Unicode number, <code>0x00 0xE4</code> (or: <code>0, 228</code>). ConTeXt then looks into internal hashes set up (in this case, the [[source:unic-000.tex|unic-000]] vector), looks at the 228<sup>th</sup> element, and sees that it's <code>\adiaeresis</code>. Things then proceed as normal. <tt>:) </tt>
(It's It’s also interesting to note that for PostScript and TrueType fonts, that number -> name -> number (glyph) mapping happens yet again in the driver. But all that is outside of TeX proper, so to say any more would be confusing.)
==External links==

Navigation menu