7

I understand that LaTeX has horrible Unicode support, and if I want Unicode I should be using XeTeX. And I have read Entering Unicode characters in LaTeX but it doesn't seem to do what I want.

What I want to do is to just enter Unicode characters like ↔︎ and ↕︎ into my text. I'm not using Computer Modern Roman, I'm using modern fonts that have full Unicode support. So I want the output to be ↔︎ and ↕︎ in the chosen font.

I get this error message:

! Package ucs Error: Unknown Unicode character 65038 = U+FE0E,
(ucs)                possibly declared in uni-254.def.
(ucs)                Type H to see if it is available with options.

See the ucs package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.881 will call this the ↔︎
                                direction, or a 0º rotation.
?

And I include the packages like so:

\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}

What magic LaTeX incantations do I include?

vy32
  • 4,780
  • 4
    You should perhaps say which are the "modern fonts" you are using. – Ulrike Fischer Jan 04 '20 at 22:49
  • 4
    If you're using ucs, then you're with legacy pdflatex and there is *no* font that has “full Unicode support”. Please, make a minimal example starting from \documentclass up to \end{document}. – egreg Jan 04 '20 at 22:51
  • 4
    you are using pdftex so no font has more than 256 characters, so can not possibly be "a modern font with Unicode support" however you do not need ucs package or utf8x option simply \DeclareUniocdeCharacter{2194}{\leftrightarrow} – David Carlisle Jan 04 '20 at 23:07
  • 1
    pdflatex only has 256 characters? – vy32 Jan 04 '20 at 23:55
  • 1
    @vy32 each font only has 256 (in fact all the default cm fonts, and all the math fonts you are using for \leftrightarrow etc only have 127.) – David Carlisle Jan 05 '20 at 09:47
  • Package unicode-math defines thousands of symbols (compile under xelatex or lualatex). Depends how many you need. `\documentclass{article} \usepackage{unicode-math} \setmathfont{XITS Math} \begin{document} $A \leftrightarrow B $

    $X \updownarrow Y $ \end{document}` You can also use any of the unicode math fonts that way, too.

    – Cicada Jan 05 '20 at 11:15
  • Downvote for your start. – Martin Schröder Jan 05 '20 at 14:05
  • Thanks. UNICODE just keeps getting more and more complete. If it gets loops, it will be Turing-complete! – vy32 Jan 06 '20 at 13:04
  • "I understand that LaTeX has horrible Unicode support, and if I want Unicode I should be using XeTeX." Just want to note that you get the terminology terribly wrong (you didn't really understand it). Plain TeX/LaTeX/Context are TeX formats, PDFTeX/XeTeX/LuaTeX are TeX engines. What is bad at Unicode support is PDFTeX (although LaTeX can define ways to draw Unicode characters in the engine to alleviate the problem a bit), not LaTeX (XeLaTeX should support Unicode well) – user202729 Dec 28 '21 at 04:43

2 Answers2

21

Actually, LaTeX has a pretty good Unicode support (better yet since the October 2019 update). You just need to define the character you want to type:

\documentclass{article}
\DeclareUnicodeCharacter{2194}{\ensuremath{\leftrightarrow}}
\DeclareUnicodeCharacter{2195}{\ensuremath{\updownarrow}}
\begin{document}
How can I type ↔ and ↕ in \LaTeX?
\end{document}

Note that you have a (spurious, I think) caracter U+FE0E (VARIATION SELECTOR-15) after each ↔ and ↕ character.

  • Woah. Apparently the Mac character picker gives me a VARIATION SELECTOR-15 whether I wanted one or not. – vy32 Jan 04 '20 at 23:54
  • 1
    @vy32 Computers trying to be clever ;-) You can just delete that character or you can define it to be a noop with \DeclareUnicodeCharacter{FE0E}{}. – Phelype Oleinik Jan 05 '20 at 00:01
  • 2
    @vy32: VS15 means "render as text" vs. VS16 which means "render as emoji". I am assuming that in the absence of a VS, the default would either be text or context-dependent (and that LaTeX would use text in that case), so it is redundant but "not technically wrong" for macOS to insert it. – Jörg W Mittag Jan 06 '20 at 09:37
19

I would recommend the newunicodechar package for this:

\usepackage{newunicodechar}
\newunicodechar{↔}{\ensuremath{\leftrightarrow}}
\newunicodechar{↕︎}{\ensuremath{\updownarrow}}

You could also write ^^^^2194 for .

This package has the advantage of working in PDFLaTeX, LuaLaTeX and XeLaTeX, whereas \DeclareUnicodeCharacter is part of inputenc and only works with legacy 8-bit font encodings.

Davislor
  • 44,045