6

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?

  • 3
    You should perhaps say which are the "modern fonts" you are using. – Ulrike Fischer Jan 4 at 22:49
  • 3
    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 4 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 4 at 23:07
  • 1
    pdflatex only has 256 characters? – vy32 Jan 4 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 5 at 9:47
20

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.

| improve this answer | |
  • Woah. Apparently the Mac character picker gives me a VARIATION SELECTOR-15 whether I wanted one or not. – vy32 Jan 4 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 5 at 0: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 6 at 9:37
20

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.

| improve this answer | |
  • 1
    That's actually not too horrible. Though, there really should be a package that pre-defines all the obvious mappings from Unicode to AMSMath! – leftaroundabout Jan 6 at 14:47
  • 1
    @leftaroundabout That’s unicode-math, sort of? – Davislor Jan 6 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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