如何在 TeX 中输入 Unicode 字符?

如何在 TeX 中输入 Unicode 字符?

Л我需要在文本中写入一些 Unicode 字符(例如),而无需使用 XeTeX、LuaTeX 或inputenc使用 UTF-8 进行编码(请尽可能少地假设排版系统)。

我已经阅读了有关此问题的其他问题,但没有找到没有 XeTeX/LuaTeX/UTF-8/... 的答案(因此问题中明确使用了 TeX)。

编辑(因为对于评论来说它太长了,而且评论不提供代码标记):

Egreg 的答案与 TeXlive 2011 完美兼容(正如 egreg 的答案和 TeXlive 所预期的那样;为此 +1)。同样如预期的那样,使用“Old-TeX”(SWP5.5 @http://www.mackichan.com(最新版本)不起作用。此外,还需要安装西里尔左心室包并将代码更改为

\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T2A,T1]{fontenc}
\begin{document}
{\fontencoding{T2A}\selectfont\CYRL\cyra\CYRT\cyre\CYRK\CYRS}%
\end{document}

(那里必须在 之前有一个空行\documentclass,SE 不会显示它。)然后文档确实编译了,即使使用 SWP,但Л仍然没有显示。原因(由 Ulrike Fischer 发现)是“Old-TeX”无法生成所需的tfm字体文件(larm1000.mf)。当使用 TeXlive 生成​​它并将其复制到 SWP 时,它仍然没有被使用。

因此:使用当前版本的 SWP 是不可能的。:-(

尽管如此,这样做还是可能的:

\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T2A,T1]{fontenc}

\def\cylatex{%
%TCIMACRO{LaTeX}%
%BeginExpansion
{\fontencoding{T2A}\selectfont\CYRL\cyra\CYRT\cyre\CYRK\CYRS}%
%EndExpansion
}

\begin{document}

Text\cylatex{}Text

\end{document}

(那里必须again之前有一个空行\documentclass,但 SE 不会显示出来。

当使用现代 LaTeX 进行编译时,它会写入TextЛаТеКСText (我不确定是否КС适用于 X - 有没有使用西里尔符号的语言的人可以帮忙?),而当使用 SWP 进行编译时,它会写入TextLaTeXText(这比仅有 更好TextText)。

警告:当使用 SWP 打开并保存文档时,定义将更改为

\def\cylatex{LaTeX}

因此主文档可能永远不会被 SWP 保存(可以使用子文档并对其进行编辑)。

放置

\def\cylatex{%
%TCIMACRO
...
}

将导致 SWP 读取该{\fontencoding{T2A}\selectfont\CYRL\cyra\CYRT\cyre\CYRK\CYRS} 部分并再次创建错误而不是ЛаТеКСLaTeX

答案1

标准输出编码中的每个字符都有一个 LaTeX 内部字符表示 (LICR)。л 的 LICR 为\cyrl,该字符属于输出编码 T2A(西里尔文)。因此

\documentclass{article}
\usepackage[T2A,T1]{fontenc} % T1 can also be OT1
\usepackage[unicode=true,bookmarks=true]{hyperref}
\begin{document}
\section{{\fontencoding{T2A}\selectfont\cyrl} is the cyrillic letter ``ell''}

{\fontencoding{T2A}\selectfont\cyrl}l

\end{document}

就可以了。当然,你会想要定义一个更方便的命令来选择不同的输出编码。

相关内容