我希望我的 LaTeX 文件包含 Unicode 字符。例如,我希望看到
x ⟶ β
在我的文本编辑器中,而不是
\exists x\ldotp x\longrightarrow\beta
另外,我想直接从键盘输入这些字符。例如,我想要
- 通过输入来获取“∃” altE,
- 通过输入得到“β” altb,然后
- 通过输入来获取“⟶” alt-->。
我正在运行 Mac OS X,我的键盘采用英式布局。
答案1
这里有两个独立的任务:让你的键盘产生各种 Unicode 符号,并让这些符号对 LaTeX 有意义。
1. 从键盘输入 Unicode 符号
如果您使用的是 Mac,请创建一个.keylayout
文件,将其放入~/Library/Keyboard Layouts
目录中,然后注销并重新登录。您的新键盘布局现在应该出现在“系统偏好设置”>“语言和文本”>“输入源”中。
但是如何创建这个键盘布局呢?我使用了一个编辑器(例如尤克里里),但最终还是手动做了不少调整。按键布局是用 XML 编写的,如下所示苹果的规格。我的键盘布局叫做MathUnicode.keylayout
,可以下载这里。它基于英国键盘布局。我通过保存为我的键盘布局提供了一个自定义图标MathUnicode.icns
(可以下载这里) 位于同一目录中。
我在下面列出了我的布局中的所有按键绑定。请注意,例如,alt-->(产生⟶
)表示“-->按住alt按键时键入”。还请注意,我通常避免标注shift按键(更喜欢P,shiftp等等),除非它使助记符更容易记住。
α(阿尔法)alta
β(贝塔)altb
γ(伽马)altg
Γ(伽马)altG
δ(德尔塔)altd
Δ(增量)altD
ε(埃普西隆)alte
ζ(泽塔)altz
η(埃塔)alth
θ(西塔)alto
Θ(西塔)altO
ι (丝)alti
κ(卡帕)altk
λ(拉姆达)altl
Λ(λ)altL
μ(亩)altm
ν(努)altn
ξ(十一)altx
Ξ(西)altX
π(圆周率)altp
π(Pi)altP
ρ (rho)altr
σ(西格玛)alts
Σ(西格玛)altS
τ(τ)altt
υ(upsilon)altu
φ(φ)(altf
φ(φ)altF
χ (卡)altc
ψ (磅/平方英寸)alty
Ψ(磅/平方英寸)altY
ω(欧米茄)altw
Ω(欧米茄)altW
ℂ(复数)altC
ℕ (自然数)altN
ℚ (有理数)altQ
ℝ(实数)altR
ℤ(整数)altZ
”(结束双引号)alt'
“ (开头双引号)alt`
¶ (段落)alt§
°(度)alt±
…(省略号)alt;
⌊ (左下括号)alt[
⌋ (右下括号)alt]
⌈(左上括号)altshift[
⌉(右上括号)altshift]
〈 (左尖括号)alt<
〉(右尖括号)alt>
⟦ (双左括号)alt|[
⟧ (双右括号)alt|]
↑(向上箭头)alt6
↓ (向下箭头)alt7
⇑(双向上箭头)altshift6
⇓(双向下箭头)altshift7
←(左箭头)alt<-
→ (向右箭头)alt->
↔(左右箭头)alt<->
⇐(双左箭头)alt<=
⇒(双右箭头)alt=>
⇔(双左右箭头)alt<=>
⟵(长左箭头)alt<--
⟶(长右箭头)alt-->
⟷ (长左右箭头)alt<-->
⟸(长双左箭头)alt<==
⟹(长双右箭头)alt==>
⟺ (长双左右箭头)alt<==>
↦ (映射到)alt|->
⤇(双重映射到)alt|=>
⟼ (长映射到)alt|-->
⟾ (长双精度映射到)alt|==>
⇀ (右鱼叉)alt--`
⇝(波浪右箭头)alt~>
¬ (逻辑非)alt~
∨ (逻辑或)alt\
∧ (逻辑连词)alt/\
∀ (全部)altA
∃(存在)altE
∄(不存在)alt/E
.(ldotp, 中的点∃x. p
)alt,
⊦(旋转栅门)alt|-
⊩(双闸)alt||-
⊧(模型)alt|=
⟂ (底部)alt _ |或alt| _
∅(空集)alt/0
∈(成员)alt:
∉(不是成员)alt/:
∪ (并集)altU
∩(交点)altI
⫛ (不相交)alt/I
⊂ (严格子集)alt(
⊃ (严格超集)alt)
⊆(子集或相等)alt _ (
⊇(超集或相等)alt _ )
∗(居中星号)alt*
÷ (除法)altshift/
×(次)alt8
|(酒吧)alt|
‖ (双线)alt||
∤ (不是杠)alt/|
◁ (左三角形)alt<|
▷ (直角三角形)alt|>
◇(钻石)alt<>
∘(圆圈)alt0
·(中心点)alt.
⊗(圈出次数)alt08
⊛(带圆圈的星号)alt0*
⊖ (带圆圈的减号)alt0-
⊕(带圆圈的加号)alt0+
⊘(带圆圈的斜线)alt0/
⊙(圆圈点)alt0.
≝(定义为相等)altshift=
≠(不等于)alt/=或alt=/
≡ (等价)alt==
≈(大约)alt~~
≤(小于或等于)alt _ <或alt< _
≥(大于或等于)alt _ >
∴ (因此)altT
∵ (因为)altB
∞(无穷大)alt9
∇(呪がそば)altV
²(平方)altshift2
³(立方)altshift3
√ (根)altv
我已经使用这个设置好几年了,并且非常满意。在编写数学电子邮件时,这个设置特别有用,因为没有 LaTeX。我发现的唯一问题是,在某些程序中,一些常用的键盘快捷键不再alt起作用。为了解决这个问题,我配置了键盘快捷键,cmdspace这样我就可以随时切换回我的默认英国布局。
2. 让 LaTeX 理解 Unicode 符号
注意:如果您希望在 LaTeX 源文件中使用 Unicode,最好使用 XeTeX。但我们假设您暂时想继续使用原始 LaTeX。
我将以下内容保存在文件中MathUnicode.sty
,并将该包包含MathUnicode
在我的所有 LaTeX 文件中(即,放入\usepackage{MathUnicode}
序言中)。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Created by John Wickerson, 07 Jan 2010.
% Updated 28 Mar 2010.
% For use with the MathUnicode keyboard layout.
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8x]{inputenc}
\RequirePackage{amssymb}
\RequirePackage{stmaryrd}
\DeclareUnicodeCharacter{183}{\cdot}
\DeclareUnicodeCharacter{915}{\ensuremath{\Gamma}}
\DeclareUnicodeCharacter{916}{\ensuremath{\Delta}}
\DeclareUnicodeCharacter{918}{\ensuremath{\Zeta}}
\DeclareUnicodeCharacter{920}{\ensuremath{\Theta}}
\DeclareUnicodeCharacter{923}{\ensuremath{\Lambda}}
\DeclareUnicodeCharacter{926}{\ensuremath{\Xi}}
\DeclareUnicodeCharacter{928}{\ensuremath{\Pi}}
\DeclareUnicodeCharacter{931}{\ensuremath{\Sigma}}
\DeclareUnicodeCharacter{933}{\ensuremath{\Upsilon}}
\DeclareUnicodeCharacter{934}{\ensuremath{\Phi}}
\DeclareUnicodeCharacter{935}{\ensuremath{\Chi}}
\DeclareUnicodeCharacter{936}{\ensuremath{\Psi}}
\DeclareUnicodeCharacter{937}{\ensuremath{\Omega}}
\DeclareUnicodeCharacter{945}{\ensuremath{\alpha}}
\DeclareUnicodeCharacter{946}{\ensuremath{\beta}}
\DeclareUnicodeCharacter{947}{\ensuremath{\gamma}}
\DeclareUnicodeCharacter{948}{\ensuremath{\delta}}
\DeclareUnicodeCharacter{949}{\ensuremath{\epsilon}}
\DeclareUnicodeCharacter{950}{\ensuremath{\zeta}}
\DeclareUnicodeCharacter{951}{\ensuremath{\eta}}
\DeclareUnicodeCharacter{952}{\ensuremath{\theta}}
\DeclareUnicodeCharacter{953}{\ensuremath{\iota}}
\DeclareUnicodeCharacter{954}{\ensuremath{\kappa}}
\DeclareUnicodeCharacter{955}{\ensuremath{\lambda}}
\DeclareUnicodeCharacter{956}{\ensuremath{\mu}}
\DeclareUnicodeCharacter{957}{\ensuremath{\nu}}
\DeclareUnicodeCharacter{958}{\ensuremath{\xi}}
\DeclareUnicodeCharacter{959}{\ensuremath{\omicron}}
\DeclareUnicodeCharacter{960}{\ensuremath{\pi}}
\DeclareUnicodeCharacter{961}{\ensuremath{\rho}}
\DeclareUnicodeCharacter{963}{\ensuremath{\sigma}}
\DeclareUnicodeCharacter{964}{\ensuremath{\tau}}
\DeclareUnicodeCharacter{965}{\ensuremath{\upsilon}}
\DeclareUnicodeCharacter{966}{\ensuremath{\phi}}
\DeclareUnicodeCharacter{967}{\ensuremath{\chi}}
\DeclareUnicodeCharacter{968}{\ensuremath{\psi}}
\DeclareUnicodeCharacter{969}{\ensuremath{\omega}}
\DeclareUnicodeCharacter{8214}{\parallel}
\DeclareUnicodeCharacter{8450}{\mathbb{C}}
\DeclareUnicodeCharacter{8470}{\mathbb{N}}
\DeclareUnicodeCharacter{8474}{\mathbb{Q}}
\DeclareUnicodeCharacter{8477}{\mathbb{R}}
\DeclareUnicodeCharacter{8484}{\mathbb{Z}}
\DeclareUnicodeCharacter{8614}{\mathbin{\mapsto}}
\DeclareUnicodeCharacter{8656}{\Leftarrow}
\DeclareUnicodeCharacter{8657}{\Uparrow}
\DeclareUnicodeCharacter{8658}{\Rightarrow}
\DeclareUnicodeCharacter{8659}{\Downarrow}
\DeclareUnicodeCharacter{8669}{\rightsquigarrow}
\newcommand{\eqdef}{\stackrel{{\scriptsize\rm def}}{=}}
\DeclareUnicodeCharacter{8797}{\eqdef}
\DeclareUnicodeCharacter{8870}{\vdash}
\DeclareUnicodeCharacter{8873}{\Vdash}
\DeclareUnicodeCharacter{8871}{\models}
\DeclareUnicodeCharacter{9121}{\lceil}
\DeclareUnicodeCharacter{9123}{\lfloor}
\DeclareUnicodeCharacter{9124}{\rceil}
\DeclareUnicodeCharacter{9126}{\rfloor}
\DeclareUnicodeCharacter{9655}{\triangleright}
\DeclareUnicodeCharacter{9665}{\triangleleft}
\DeclareUnicodeCharacter{9671}{\diamond}
\DeclareUnicodeCharacter{9675}{\circ}
\DeclareUnicodeCharacter{10178}{\bot}
\DeclareUnicodeCharacter{10214}{\llbracket} % needs stmaryrd
\DeclareUnicodeCharacter{10215}{\rrbracket} % needs stmaryrd
\DeclareUnicodeCharacter{10229}{\longleftarrow}
\DeclareUnicodeCharacter{10230}{\longrightarrow}
\DeclareUnicodeCharacter{10231}{\longleftrightarrow}
\DeclareUnicodeCharacter{10232}{\Longleftarrow}
\DeclareUnicodeCharacter{10233}{\Longrightarrow}
\DeclareUnicodeCharacter{10234}{\Longleftrightarrow}
\DeclareUnicodeCharacter{10236}{\longmapsto}
\DeclareUnicodeCharacter{10238}{\Longmapsto} % needs stmaryrd
\DeclareUnicodeCharacter{10503}{\Mapsto} % needs stmaryrd
\DeclareUnicodeCharacter{10971}{\mathrel{\not\hspace{-0.2em}\cap}}
\DeclareUnicodeCharacter{65294}{\ldotp}
\DeclareUnicodeCharacter{65372}{\mid}