-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoleftright.sty
85 lines (69 loc) · 2.03 KB
/
autoleftright.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
84
%% autoleftright --- Automatically prepends
%% \left and \right delimiter calls to parenthesis,
%% brackets, and other symbols in math mode.
%% Copyright (C) 2020 by Shervin Sahba
%% E-mail: shervin@tuta.io
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{autoleftright}[2020/05/07 v1.0 Automatically prepends left and right calls to parenthesis and brackets in math mode.]
\@ifpackageloaded{amsmath}{}{\RequirePackage{amsmath}}
%% OLD DELIMITERS
\let\oldlangle\langle
\let\oldrangle\rangle
\let\oldlceil\lceil
\let\oldrceil\rceil
\let\oldlfloor\lfloor
\let\oldrfloor\rfloor
% TODO: Need to preserve normal parenthesis and brackets.
% For now, these options are close to normal height.
\def\lp{\texttt{\big(}}
\def\rp{\texttt{\big)}}
\def\lb{\texttt{\big[}}
\def\rb{\texttt{\big]}}
\def\setautolrangle{
\xdef\langle{\left \oldlangle}
\xdef\rangle{\right\oldrangle}
}
\def\setautolrceil{
\xdef\lceil{\left \oldlceil}
\xdef\rceil{\right\oldrceil}
}
\def\setautolrfloor{
\xdef\lfloor{\left \oldlfloor}
\xdef\rfloor{\right\oldrfloor}
}
\def\setautolrpb{
\def\resetMathstrut@{ %% compare with amsmath.sty
% resetMathstrut builds a box around math mode tex, like \strut does for text mode. We redefine resetMathstrut to permit modification of character-based delimiters
\begingroup
\setbox\z@\hbox{} %% create a horizontal box, z@
\edef\@tempa{ %% match height/depth of math box to z@
\ht\Mathstrutbox@\the\ht\z@\relax
\dp\Mathstrutbox@\the\dp\z@\relax
}
\expandafter\endgroup\@tempa
}
% set char delimeters to active mathcode, allowing them to be defined.
\mathcode`(="8000
\mathcode`)="8000
\mathcode`[="8000
\mathcode`]="8000
% TODO work on | delimiters, alternating left and right
}
\def\autoleftright{
\setautolrfloor
\setautolrceil
\setautolrangle
\setautolrpb
}
\begingroup
\catcode`(\active
\catcode`)\active
\xdef({\left \string(}
\xdef){\right\string)}
\endgroup
\begingroup
\catcode`[\active
\catcode`]\active
\xdef[{\left \string[}
\xdef]{\right\string]}
\endgroup