Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How do I enter Unicode characters in LaTeX? What packages do I need to install and what escape sequence do I type to specify Unicode characters in an ASCII source file?

share|improve this question

migrated from stackoverflow.com Nov 12 '11 at 18:53

This question came from our site for professional and enthusiast programmers.

6  
is there a reason you can't encode the source file in UTF8? –  bene Oct 20 '08 at 21:05
2  
@bene, even with that: inputenc with UTF-8 is more of a hack (and a very long sequence of translations between byte sequences and correspondig LaTeX commands). It's not pretty. –  Јοеу Jan 26 '11 at 1:14
4  
Why is everyone recommending XeTeX and not LuaTeX? –  Canageek Nov 12 '11 at 22:50
2  
Yeah, LuaTeX FTW! –  ℝaphink Aug 30 '12 at 22:04
    
If you're a Mac user, you might be interested in this answer, which describes how I made a custom keyboard layout full of math symbols, greek letters, and so on. –  John Wickerson Apr 22 '13 at 20:47
show 2 more comments

8 Answers

up vote 35 down vote accepted

Have you considered using XeTeX? This is an adaptation of TeX that adds Unicode support, and is included in the latest TeX Live and MiKTeX distributions. This Wikipedia article gives a good introduction.

share|improve this answer
1  
Not only Unicode support (that was partially available as an ugly hack-job before) but proper modern font support as well. Very nice, but a pain to get working, at least here :-) –  Јοеу Jul 25 '11 at 12:48
5  
Can you post a minimal example of using xetex that illustrates what you mean? At minimum, it seems you need to set the default font to something that covers the range of characters you want -- otherwise, characters not covered are simply (and silently!) ignored. –  ShreevatsaR Jan 16 '12 at 5:54
1  
Unlike the other answers, this doesn't seem to answer the question. –  András Salamon Feb 27 '13 at 19:35
add comment

"Unicode" in this context could mean either in the input or in the output. I assume you're looking to insert something like "©" into your source and have it do something meaningful.

For full support for unicode input and unicode fonts, take a look at XeTeX; it's easy to get started — just select an appropriate font and the unicode characters in your input are directly typeset as unicode glyphs in the output. Switching engines is not always a possibility, however, and sometimes you'll want to stick with pdfTeX for its other useful features.

The best that regular LaTeX (i.e., based from pdfTeX in a modern distribution) can do is recognise UTF-8 sequences in the text and expand macros based on what it sees. Load the inputenc package to select the UTF-8 input encoding:

\usepackage[utf8]{inputenc}

Note that the resulting input file must not have a byte-order mark (BOM) at the beginning, or else it won't compile. (You can also use the [utf8x] option which has more extensive coverage but is not as well supported. I don't have any experience using this option.)

To define behaviour for unicode characters, use the \DeclareUnicodeCharacter command that is then defined. Here's an example for binding the control sequence \dash to the input character "—"; i.e., a literal em-dash, U+2014, in the source:

\DeclareUnicodeCharacter{2014}{\dash}

\dash can then be defined in the usual manner; I use:

\DeclareRobustCommand\dash{%
  \unskip\nobreak\thinspace\textemdash\allowbreak\thinspace\ignorespaces}

This defines a dash that has a small space on either side and will only allow a line break after it.

share|improve this answer
1  
\usepackage[utf8]{inputenc} worked for me, cheers –  Grzenio Mar 21 '09 at 15:50
1  
Doesn't work for me. \DeclareUnicodeCharacter has no effect, whether it's in or not, the \dash command works. OTOH, if \DeclareRobustCommand is missing, \dash doesn't work. And where does the Unicode character enter anyways? \DeclareRobustCommand uses \textemdash. (Of course this works in a way for the dash, but I tried to transfer it to another Unicode character, U+2318, the "twiddle" known from the Apple command key.) –  Jann Nov 19 '09 at 9:04
    
I suggest creating a minimal example and asking a new question. –  Will Robertson Nov 19 '09 at 13:24
    
Note though that in practice there seem to be no constraints against line breaks either before or after an (em-/en-)dash used for parenthetical purposes. See my now updated answer to this question about hyphens and dashes. –  Lover of Structure Jul 24 '12 at 19:42
    
@user14996 I'm fairly sure this is discussed in the TeXbook, and I have no problem consulting Knuth as an authority in this area. Happy to concede that most publications don't do it though — possibly due to the software they use. –  Will Robertson Jul 26 '12 at 3:03
show 3 more comments

This is a minimal example that finally worked for me without using XeTeX:

\documentclass{article}
\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}

\begin{document}
    The vorticity $ω$ is defined as $ω = ∇ × u$.
\end{document}
share|improve this answer
    
Thanks Roberto, this is a nice trick when you are bound to use no XeTeX. E.g. with texi2dvi which I used in R I did not know how to switch the engine. I had to reprogram my rendering functions if it wasn't for your hint here, mathletters did the trick, YAY! –  hans0l0 Nov 23 '12 at 18:44
    
Also works for pdflatex –  mangledorf Aug 27 '13 at 11:58
add comment

Try \char"hexcode like \char"2012 for the ‒ (figure-dash). This command works in XeLaTeX and probably other engines

share|improve this answer
1  
Welcome to Stack Overflow! This will only work in certain TeX engines, especially the unicode-capable ones (XeTeX, LuaTeX). Could you add to your answer in which engine your example worked? –  Paŭlo Ebermann Nov 12 '11 at 18:19
add comment

As of today, both XeTeX and LuaTeX will let you input unicode without complaining.

share|improve this answer
add comment

In order to use XeLaTeX (and even both pdflatex and xelatex on the same document), you can use the simple unixode package:

\documentclass{article}
\usepackage{unixode}

\begin{document}
    The vorticity $ω$ is defined as $ω = ∇ × u$.
\end{document}

You may then compile your document either with pdflatex or with xelatex.

Note: the package is in development; the aim is to support as many unicode equivalents as possible.

share|improve this answer
add comment

This question is really ambiguous, and I believe the answers are to the wrong interpretation. To have LaTeX handle Unicode is what is being answered, what I understand is being asked is how to enter such characters into the file. And that depends on the editor used... I've even copy&pasted some from Wikipedia pages into xemacs to go around that. The methods given in the Unicode FAQ clash with xemacs definitions or get interpreted at random by gnome-terminal :-(

share|improve this answer
add comment

Sorry, I'm not an expert on this, but hope I can at least provide some useful leads.

A lot of the early multi-lingual support for LaTeX predates the widespread adoption of Unicode, although it looks like there's been some consolidation around Unicode recently. So you might find something useful in specific language support packages, e.g. CJK LaTeX (for Chinese, Japanese and Korean).

It looks like one Unicode package for LaTeX is no longer supported, although it may still be the best thing out there.

You might also have a look at the excellent book The LaTeX Companion, which includes a section on multilingual text.

share|improve this answer
    
unicode.sty was renamed ucs.sty, and the old name was kept as an alias. ucs.sty acquired a new maintainer, and it was decided that the alias would be dropped. –  wasteofspace Aug 31 '12 at 8:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.