forked from wenweili/Modulform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myarrows.sty
83 lines (78 loc) · 3.56 KB
/
myarrows.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% Copyright 2018 李文威 (Wen-Wei Li).
% Permission is granted to copy, distribute and/or modify this
% document under the terms of the Creative Commons
% Attribution 4.0 International (CC BY 4.0)
% http://creativecommons.org/licenses/by/4.0/
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myarrows}[2018/02/20 Package for extendable arrows]
\RequirePackage{amsmath}
\RequirePackage{tikz-cd}
% 以下用 tikz 定义可伸缩箭头, 不用 amsmath 和 extarrows 的版本以免 unicode-math 产生问题. 代码借自 Antal Spector-Zabusky
% 重定义 \xrightarrow[below]{above}
\makeatletter
\newbox\xratbelow
\newbox\xratabove
\renewcommand{\xrightarrow}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [->, baseline=-.75ex]
\draw (0,0) -- node[below=-2pt] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
% 重定义 \xlefttarrow[below]{above}
\renewcommand{\xleftarrow}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [<-, baseline=-.75ex]
\draw (0,0) -- node[below] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
% 重定义 \xleftrightarrow[below]{above}
\renewcommand{\xleftrightarrow}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [<->, baseline=-.75ex]
\draw (0,0) -- node[below] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
% 重定义 \xhookrightarrow[below]{above}, 使用 tikz-cd 的 hookrightarrow
\renewcommand{\xhookrightarrow}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [baseline=-.75ex]
\draw (0,0) edge[commutative diagrams/hookrightarrow] node[below] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
% 重定义 \xhooklefttarrow[below]{above}, 使用 tikz-cd 的 hookleftarrow
\renewcommand{\xhookleftarrow}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [baseline=-.75ex]
\draw (0,0) edge[commutative diagrams/hookleftarrow] node[below] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
% 重定义 \xmapsto[below]{above}, 使用 tikz-cd 的 mapsto
\renewcommand{\xmapsto}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [baseline=-.75ex]
\draw (0,0) edge[commutative diagrams/mapsto] node[below] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
% 定义 \xlongequal[below]{above}, 使用 tikz-cd 的等号
\newcommand{\xlongequal}[2][]{%
\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
\mathrel{\tikz [baseline=-.75ex]
\draw (0,0) edge[commutative diagrams/equal] node[below] {\box\xratbelow}
node[above] {\box\xratabove}
(\xratlen,0) ;}}
\makeatother
\endinput