LaTeX/Special Characters

From testwiki
Jump to navigation Jump to search

Template:LaTeX/Top


Template:Info

In this chapter we will tackle matters related to input encoding, typesetting diacritics and special characters.

In the following document, we will refer to special characters for all symbols other than the lowercase letters a–z, uppercase letters A-Z, figures 0–9, and English punctuation marks.

Some languages usually need a dedicated input system to ease document writing. This is the case for Arabic, Chinese, Japanese, Korean and others. This specific matter will be tackled in Internationalization.

The rules for producing characters with diacritical marks, such as accents, differ somewhat depending whether you are in text mode, math mode, or the tabbing environment.

Input encoding

TeX uses ASCII by default. But 128 characters is not enough to support non-English languages. TeX has its own way of doing that with commands for every diacritical marking (see Escaped codes). But if we want accents and other special characters to appear directly in the source file, we have to tell TeX that we want to use a different encoding.

There are several encodings available to LaTeX:

  • ASCII: the default. Only bare English characters are supported in the source file.
  • ISO-8859-1 (a.k.a., Latin 1): 8-bits encoding. It supports most characters for Latin languages, but that's it.
  • UTF-8: a Unicode multi-byte encoding. Supports the complete Unicode specification.
  • Others...

In the following we will assume that you want to use UTF-8.

There are some important steps to specify encoding.

  • Make sure your text editor decodes the file in UTF-8.
  • Make sure it saves your file in UTF-8. Most text editors do not make the distinction, but some do, such as Notepad++.
  • If you are working in a terminal, make sure it is set to support UTF-8 input and output. Some old Unix terminals may not support UTF-8. PuTTY is not set to use UTF-8 by default, you have to configure it.
  • Tell LaTeX that the source file is UTF-8 encoded.

Template:LaTeX/Usage

Template:LaTeX/Package [1] package tells LaTeX what the text encoding format of your .tex files is.

Template:Warning

The inputenc package allows the user to change the encoding within the document as well — by means of the command Template:LaTeX/LaTeX.

Template:LaTeX/Usage

Extending the support

The LaTeX support of UTF-8 is fairly specific: it includes only a limited range of Unicode input characters. It only defines those symbols that are known to be available with the current font encoding. You might encounter a situation where using UTF-8 might result in error:

! Package inputenc Error: Unicode char \u8:ũ not set up for use with LaTeX.

This is due to the utf8 definition not necessarily having a mapping of all the character glyphs you are able to enter on your keyboard. Such characters include, for example:

ŷ Ŷ ũ Ũ ẽ Ẽ ĩ Ĩ

In such case, you may try to use the Template:LaTeX/Parameter option to define more character combinations. Template:LaTeX/Parameter is not officially supported, but can be viable in some cases. However, it might break up compatibility with some packages like Template:LaTeX/Package.

Another possiblity is to stick with Template:LaTeX/Parameter and to define the characters yourself. This is easy: Template:LaTeX/Usage where Template:LaTeX/Parameter is the unicode codepoint of the desired character. Template:LaTeX/Parameter is what to print when the character matching the codepoint is met. You may find codepoints on this site. Codepoints are easy to find on the web. Example: Template:LaTeX/Usage Now inputting ŷ will effectively print ŷ.

Escaped codes

In addition to direct UTF-8 input, LaTeX supports the composition of special characters as well. This is convenient if your keyboard lacks some desired accents and other diacritics.

The following accents may be placed on letters. Although "o" letter is used in most of the examples, the accents may be placed on any letter. Accents may even be placed above a "missing" letter; for example, Template:LaTeX/LaTeX produces a tilde over a blank space.

The following commands may be used only in paragraph (default) or LR (left-right) mode.

LaTeX command Sample Description
Template:LaTeX/LaTeX ò grave accent
Template:LaTeX/LaTeX ó acute accent
Template:LaTeX/LaTeX ô circumflex
Template:LaTeX/LaTeX ö umlaut, trema or dieresis
Template:LaTeX/LaTeX ő long Hungarian umlaut (double acute)
Template:LaTeX/LaTeX õ tilde
Template:LaTeX/LaTeX ç cedilla
Template:LaTeX/LaTeX ą ogonek
Template:LaTeX/LaTeX ł barred l (l with stroke)
Template:LaTeX/LaTeX ō macron accent (a bar over the letter)
Template:LaTeX/LaTeX o bar under the letter
Template:LaTeX/LaTeX ȯ dot over the letter
Template:LaTeX/LaTeX dot under the letter
Template:LaTeX/LaTeX å ring over the letter (for å there is also the special command Template:LaTeX/LaTeX)
Template:LaTeX/LaTeX ŏ breve over the letter
Template:LaTeX/LaTeX š caron/háček ("v") over the letter
Template:LaTeX/LaTeX o͡o "tie" (inverted u) over the two letters
Template:LaTeX/LaTeX ø slashed o (o with stroke)
Template:LaTeX/LaTeX ı dotless i (i without tittle)

Older versions of LaTeX would not remove the dot on top of the i and j letters when adding a diacritic. To correct this, one had to use the dotless version of these letters, by typing Template:LaTeX/LaTeX and Template:LaTeX/LaTeX. For example:

However, current versions of LaTeX do not need this anymore (and may, in fact, crash with an error).

If a document is to be written completely in a language that requires particular diacritics several times, then using the right configuration allows those characters to be written directly in the document. For example, to achieve easier coding of umlauts, the babel package can be configured as Template:LaTeX/LaTeX. This provides the short hand Template:LaTeX/LaTeX for Template:LaTeX/LaTeX. This is very useful if one needs to use some text accents in a label, since no backslash will be accepted otherwise.

More information regarding language configuration can be found in the Internationalization section.

Less than < and greater than >

The two symbols '<' and '>' are actually ASCII characters, but you may have noticed that they will print '¡' and '¿' respectively. This is a font encoding issue. If you want them to print their real symbol, you will have to use another font encoding such as T1, loaded with the Template:LaTeX/Package package. See Fonts for more details on font encoding.

Alternatively, they can be printed with dedicated commands: Template:LaTeX/Usage

Euro currency symbol

When writing about money these days, you need the euro sign. The Template:LaTeX/Package package features a Template:LaTeX/LaTeX command which gives you the euro symbol as supplied by your current text font. Depending on your chosen font this may be quite far from the official symbol.

An official version of the euro symbol is provided by Template:LaTeX/Package. Load it in the preamble (optionally with the Template:LaTeX/Parameter option):

Template:LaTeX/Usage

then you can insert it with the Template:LaTeX/LaTeX command. Finally, if you want a euro symbol that matches with the current font style (e.g., bold, italics, etc.) you can use a different option:

Template:LaTeX/Usage

again you can insert the euro symbol with Template:LaTeX/LaTeX.

Alternatively, you can use the Template:LaTeX/Package package which also provides the official euro symbol. Template:LaTeX/Usage

Now that you have succeeded in printing a euro sign, you may want the '€' on your keyboard to actually print the euro sign as above. There is a simple method to do that. You must make sure you are using UTF-8 encoding along with a working Template:LaTeX/LaTeX or Template:LaTeX/LaTeXcommand.

Template:LaTeX/Usage

Complete example:

Template:LaTeX/Usage

Degree symbol for temperature and math

The easiest way to print temperature and angle values is to use the Template:LaTeX/LaTeX command from the Template:LaTeX/Package package, which works both in text and math mode: Template:LaTeX/Usage For more information, see the documentation of the Template:LaTeX/Package package.

A common mistake is to use the Template:LaTeX/LaTeX command. It will not print the correct character (though Template:LaTeX/LaTeX will). Use the Template:LaTeX/Package package instead, which provides a Template:LaTeX/LaTeX command.

Template:LaTeX/Usage

For temperature, you can use the same command or opt for the Template:LaTeX/Package package and write

Template:LaTeX/Usage

Some keyboard layouts feature the degree symbol, you can use it directly if you are using UTF-8 and Template:LaTeX/Package. For better results in terms of font quality, we recommend the use of an appropriate font, like Template:LaTeX/Package:

Template:LaTeX/Usage

Other symbols

LaTeX has many symbols at its disposal. The majority of them are within the mathematical domain, and later chapters will cover how to get access to them. For the more common text symbols, use the following commands:

Command Sample Character
Template:LaTeX/LaTeX % %
Template:LaTeX/LaTeX $ $
Template:LaTeX/LaTeX { {
Template:LaTeX/LaTeX _ _
Template:LaTeX/LaTeX
Template:LaTeX/LaTeX n/a
Template:LaTeX/LaTeX n/a |
Template:LaTeX/LaTeX > >
Template:LaTeX/LaTeX n/a
Template:LaTeX/LaTeX n/a
Template:LaTeX/LaTeX n/a ¡
Template:LaTeX/LaTeX Xa a
Template:LaTeX/LaTeX n/a £
Template:LaTeX/LaTeX # #
Template:LaTeX/LaTeX & &
Template:LaTeX/LaTeX } }
Template:LaTeX/LaTeX § §
Template:LaTeX/LaTeX n/a
Template:LaTeX/LaTeX n/a \
Template:LaTeX/LaTeX < <
Template:LaTeX/LaTeX n/a
Template:LaTeX/LaTeX n/a ®
Template:LaTeX/LaTeX n/a ¿
Template:LaTeX/LaTeX n/a
Template:LaTeX/LaTeX n/a ©

Not mentioned in above table, tilde (~) is used in LaTeX code to produce non-breakable space. To get printed tilde sign, either write Template:LaTeX/LaTeX or Template:LaTeX/LaTeX. And a visible space can be created with Template:LaTeX/LaTeX.

For some more interesting symbols, the Postscript ZapfDingbats font is available thanks to the Template:LaTeX/Package package. Add the declaration to your preamble: Template:LaTeX/LaTeX. Next, the command Template:LaTeX/LaTeX, will print the specified symbol. Here is a table of the available symbols:

ZapfDingbats symbols.

In special environments

Math mode

Several of the above and some similar accents can also be produced in math mode. The following commands may be used only in math mode.

LaTeX command Sample Description Text-mode equivalence
Template:LaTeX/LaTeX o^ circumflex Template:LaTeX/LaTeX
Template:LaTeX/LaTeX oo^ wide version of Template:LaTeX/LaTeX over several letters
Template:LaTeX/LaTeX oˇ vee or check Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o~ tilde Template:LaTeX/LaTeX
Template:LaTeX/LaTeX oo~ wide version of Template:LaTeX/LaTeX over several letters
Template:LaTeX/LaTeX o´ acute accent Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o` grave accent Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o˙ dot over the letter Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o¨ two dots over the letter (umlaut in text-mode) Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o˘ breve Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o¯ macron Template:LaTeX/LaTeX
Template:LaTeX/LaTeX o vector (arrow) over the letter

When applying accents to letters Template:LaTeX/LaTeX and Template:LaTeX/LaTeX, you can use Template:LaTeX/LaTeX and Template:LaTeX/LaTeX to keep the dots from interfering with the accents:

LaTeX command Sample Description Sample with upper dot
Template:LaTeX/LaTeX ı^ circumflex on letter Template:LaTeX/LaTeX without upper dot i^
Template:LaTeX/LaTeX ȷ vector (arrow) on letter Template:LaTeX/LaTeX without upper dot j

Tabbing environment

Some of the accent marks used in running text have other uses in the tabbing environment. In that case they can be created with the following command:

Unicode keyboard input

Template:Wikipedia Some operating systems provide a keyboard combination to input any Unicode code point, the so-called unicode compose key.

Many X applications (*BSD and GNU/Linux) support the Ctrl+Shift+u combination. A "u" symbol should appear. Type the code point and press enter or space to actually print the character. Example:

<Ctrl+Shift+u> 20AC <space>

will print the euro character.

Desktop environments like GNOME and KDE may feature a customizable compose key for more memorizable sequences.

Xorg features advanced keyboard layouts with variants that let you enter a lot of characters easily with combination using the appropriate modifier, like Alt Gr. It highly depends on the selected layout+variant, so we suggest you to play a bit with your keyboard, preceding every key and dead key with the Alt Gr modifier.

In Windows, you can hold Alt and type a <codepoint> to get a desired character. For example,

<Alt> + 0252

will print the German letter ü.

Notes and References

Template:Reflist


Template:LaTeX/Bottom


sr:LaTeX/Посебни знакови

  1. For a detailed information on the package, see complete specifications written by the package's authors.