如何让 LaTeX 理解 Unicode 字符 ↔︎ 和 ↕︎

如何让 LaTeX 理解 Unicode 字符 ↔︎ 和 ↕︎

我知道 LaTeX 对 Unicode 的支持很差,如果我想使用 Unicode,我应该使用 XeTeX。我读过在 LaTeX 中输入 Unicode 字符但它似乎没有实现我想要的效果。

我想要做的就是在文本中输入 Unicode 字符,例如 ↔︎ 和 ↕︎。我没有使用 Computer Modern Roman,而是使用具有完整 Unicode 支持的现代字体。因此,我希望输出结果为所选字体中的 ↔︎ 和 ↕︎。

我收到此错误信息:

! 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.
?

我把这些包包含进去了:

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

我应该包含哪些神奇的 LaTeX 咒语?

答案1

实际上,LaTeX 对 Unicode 的支持相当不错(自 2019 年 10 月更新以来,支持程度有所提高)。你只需要定义要输入的字符:

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

请注意,你有一个(我认为是虚假的)角色乌+FE0E(变体选择器-15)每个 ↔ 和 ↕ 字符之后。

答案2

我会推荐newunicodechar为此打包:

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

您也可以^^^^2194为写作

该包的优点是可以在 PDFLaTeX、LuaLaTeX 和 XeLaTeX 中工作,但\DeclareUnicodeCharacter它是传统 8 位字体编码的一部分inputenc并且仅适用于传统 8 位字体编码。

相关内容