TransWikia.com

Entering Unicode characters in LaTeX

TeX - LaTeX Asked on December 20, 2021

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?

11 Answers

As of 2020, Arthur Reutenauer says that XeTeX has “gone into maintenance mode,” and the future of TeX development is LuaTeX. I would therefore recommend using LuaTeX when you can, then XeTeX if you have to, and PDFTeX if it’s all that your publisher supports.

Now that LuaTeX supports complex scripts, the main XeTeX feature I use that LuaTeX does not have (as of July 2020) is interchar tokens. There are, on the other hand, many LuaTeX features that XeTeX does not have. I use microtype font expansion in nearly every document I create.

If you’re asking what syntax to use to enter Unicode characters, you can use the syntax ^^^^abcd for U+ABCD, char"ABCD, symbol{"ABCD}, or any of the macros defined by the LaTeX kernel or unicode-math.

Answered by Davislor on December 20, 2021

If you are looking for unicode characters defined in a standard font, you can do: Use either XeLaTeX or LuaLaTeX.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{fontspec}
begin{document}
Print some leaves: {fontspec{Symbola} %the font name
                                      symbol{"1F343}} %unicode symbol code                  
end{document}

enter image description here

Answered by Schroeder on December 20, 2021

In case anyone is not satisfied with any of the answers: I just had the same problem and came up with my own little solution. I didn't want to dig into another distribution but stay with pdflatex. So I created a textfield in inkscape, put the character in, cropped it, and saved as pdf. You can include the pdf in your document like this:

includegraphics[width=1em]{symbol.pdf}

Answered by Moritz H. on December 20, 2021

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 :-(

Answered by vonbrand on December 20, 2021

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

Answered by raphink on December 20, 2021

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.

Answered by Olivier on December 20, 2021

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

Answered by Becheru Petru-Ioan on December 20, 2021

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}

Answered by Roberto Bonvallet on December 20, 2021

"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:

DeclareRobustCommanddash{%
  unskipnobreakthinspacetextemdashallowbreakthinspaceignorespaces}

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

Answered by Will Robertson on December 20, 2021

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.

Answered by ChrisN on December 20, 2021

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).

Another Unicode package for LaTeX has a new name (formerly unicode; now ucs). For a list of Unicode packages, see https://ctan.org/topic/unicode .

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

Answered by TimB on December 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP