Initial Commit
[packages] / xemacs-packages / auctex / style / mathtools.el
1 ;;; mathtools.el --- Style hook for the LaTeX package `mathtools'.
2
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
4
5 ;; Author: Mads Jensen <mje@inducks.org>
6 ;; Created: 2011-02-13
7 ;; Keywords: tex
8
9 ;; This file is part of AUCTeX.
10
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 ;; 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;  This file adds support for `mathtools.sty'
29
30 ;;; Comments:
31
32 ;;; This package serves as a wrapper for amsmath, adding more features
33 ;;; and fixing a few bugs in amsmath.  The mathstyle argument for many
34 ;;; of the macros is discussed at
35 ;;; <http://www.tug.org/TUGboat/Articles/tb22-4/tb72perlS.pdf>
36
37 ;;; Code:
38
39 ;; amsmath options which can be passed directly to mathtools are
40 ;; appended in the style hook below
41 (defvar LaTeX-mathtools-package-options
42   '("fixamsmath" "donotfixamsmathbugs" "allowspaces" "disallowspaces")
43   "Package options for the mathtools package.")
44
45 (defvar LaTeX-mathtools-key-val-options
46   '(("showonlyrefs")
47     ("mathic" ("true" "false"))
48     ("showmanualtags" ("true" "false"))
49     ("firstline-afterskip")
50     ("lastline-preskip")
51     ("multlined-pos" ("c" "b" "t"))
52     ("multlined-width")
53     ("centercolon" ("true" "false"))
54     ("prescript-sub-format")
55     ("prescript-sup-format")
56     ("prescript-arg-format"))
57   "Options for the \\mathtoolsset command")
58
59 (TeX-add-style-hook
60  "mathtools"
61  (lambda ()
62
63    ;; mathtools requires amsmath, as some bugs in amsmath are fixed
64    (TeX-run-style-hooks "amsmath")
65
66    (dolist (elt LaTeX-amsmath-package-options)
67      (add-to-list 'LaTeX-mathtools-package-options elt))
68
69    (LaTeX-add-environments
70     '("lgathered" ["Vertical position (t or b)"])
71     '("rgathered" ["Vertical position (t or b)"])
72     '("multlined" LaTeX-mathtools-env-multlined)
73     '("matrix*" LaTeX-mathtools-env-matrix-starred)
74     '("pmatrix*" LaTeX-mathtools-env-matrix-starred)
75     '("bmatrix*" LaTeX-mathtools-env-matrix-starred)
76     '("Bmatrix*" LaTeX-mathtools-env-matrix-starred)
77     '("vmatrix*" LaTeX-mathtools-env-matrix-starred)
78     '("Vmatrix*" LaTeX-mathtools-env-matrix-starred)
79     '("spreadlines" LaTeX-mathtools-env-spreadlines)
80     "dcases" "dcases*")
81
82    (TeX-add-symbols
83     '("mathtoolsset" (TeX-arg-key-val LaTeX-mathtools-key-val))
84     '("mathclap" 1)
85     '("mathllap" ["Mathstyle"] t)
86     '("mathrlap" ["Mathstyle"] t)
87     '("mathclap" ["Mathstyle"] t)
88     '("mathmakebox" [TeX-arg-size] [ TeX-arg-size ] 1)
89     '("clap" 1)
90     '("mathmbox" 1)
91     '("cramped" 1)
92     '("crampedllap" [ "Mathstye" ] t)
93     '("crampedrlap" [ "Mathstyle" ] t)
94     '("crampedclap" [ "Mathstyle" ] t)
95     '("smashoperator" [ "Position (l, r or lr (default)" ] 2)
96     ;; 3.1.4 Adjusting the limits of operators
97     ;; explicit argument encapsulation does not seem to be required
98     '("adjustlimits" 4)
99     ;; 3.2 Controlling tags
100     '("newtagform" "Name" ["Inner format"] "Left" "Right")
101     '("renewtagform" "Name" ["Inner format"] "Left" "Right")
102     '("usetagform" "Name")
103     '("xleftrightarrow" ["Below"] "Above")
104     '("xLeftarrow" ["Below"] "Above")
105     '("xRightarrow" ["Below"] "Above")
106     '("xLeftrightarrow" ["Below"] "Above")
107     '("xhookleftarrow" ["Below"] "Above")
108     '("xhookrightarrow" ["Below"] "Above")
109     '("xmapsto" ["Below"] "Above")
110     '("xrightharpoondown" ["Below"] "Above")
111     '("xrightharpoonup" ["Below"] "Above")
112     '("xleftharpoondown" ["Below"] "Above")
113     '("xleftharpoonup" ["Below"] "Above")
114     '("xrightleftharpoons" ["Below"] "Above")
115     '("xleftrightharpoons" ["Below"] "Above")
116     '("underbracket" [ "Rule thickness" ] [ "Bracket height" ] t)
117     '("overbracket" [ "Rule thickness" ] [ "Bracket height" ] t)
118     '("underbrace" 1)
119     '("overbrace" 1)
120     '("LaTeXunderbrace" 1)
121     '("LaTeXoverbrace" 1)
122     ;; 3.4.2
123     '("shoveleft"  [ TeX-arg-size ] 1)
124     '("shoveright" [ TeX-arg-size ] 1)
125     ;; don't understand t, but intertext in amsmath.el uses it
126     '("shortintertext" t)
127     '("DeclarePairedDelimeter" TeX-arg-macro "Left delimeter" "Right delimeter")
128     ;; 3.4.4
129     '("MoveEqLeft" [ "Number" ])
130     '("ArrowBetweenLines" [ TeX-arg-macro ] )
131     '("ArrowBetweenLines*" [ TeX-arg-macro ] )
132     ;; colon operators
133     "vcentcolon" "ordinarycolon" "coloneqq" "Coloneqq"
134     "coloneq" "Coloneq" "eqqcolon" "Eqqcolon" "eqcolon"
135     "Eqcolon" "colonapprox" "Colonapprox" "colonsim" "Colonsim"
136     ;; 3.7.1
137     "lparen" "rparen"
138     ;; left sub/superscripts
139     '("prescript" "Below" "Above" t)
140     ;; Declaring math sizes; this command doesn't seem so relevant, but
141     ;; for completion, it's included
142     '("DeclareMathSizes" 4)
143     ;; Gathered envionments
144     '("newgather" "Name" "Pre-line" "Post-line" "After")
145     '("renewgather" "Name" "Pre-line" "Post-line" "After")
146     ;; Split fractions
147     '("splitfrac" 2)
148     '("splitdfrac" 2))
149
150    (setq LaTeX-item-list
151          (append '(("multlined"    . LaTeX-item-equation)
152                    ("lgathered" . LaTeX-item-equation)
153                    ("rgathered" . LaTeX-item-equation)
154                    ("spreadlines" . LaTeX-item-equation)
155                    ("matrix*" .  LaTeX-item-equation)
156                    ("pmatrix*" .  LaTeX-item-equation)
157                    ("bmatrix*" .  LaTeX-item-equation)
158                    ("Bmatrix*" .  LaTeX-item-equation)
159                    ("vmatrix*" .  LaTeX-item-equation)
160                    ("Vmatrix*" .  LaTeX-item-equation)
161                    ("dcases"    . LaTeX-item-equation)
162                    ("dcases*"    . LaTeX-item-equation))
163                  LaTeX-item-list))
164
165    (setq LaTeX-label-alist
166          (append '(("lgathered"    . LaTeX-amsmath-label)
167                    ("rgathered"   . LaTeX-amsmath-label)
168                    ("multlined"    . LaTeX-amsmath-label)
169                    LaTeX-label-alist))))
170  LaTeX-dialect)
171
172 (defun LaTeX-mathtools-env-matrix-starred (env)
173   (let ((where (read-string "(optional) Vertical placement of columns: ")))
174     (if (string= where "")
175         (setq where "")
176       (setq where (concat "[" where "]")))
177     (LaTeX-insert-environment env where)))
178
179 (defun LaTeX-mathtools-env-spreadlines (env)
180   (let ((spread (read-string "Spacing between lines: ")))
181     (LaTeX-insert-environment env (concat TeX-grop spread TeX-grcl))
182     (newline-and-indent)))
183
184 ;; FIXME: there are probably more subtle ways to support more than one
185 ;; optional argument; please change if this is the case
186 (defun LaTeX-mathtools-env-multlined (env)
187   (let ((pos (read-string "(optional) Position: "))
188         (width (read-string "(optional) Width: "))
189         (extra ""))
190     (if (not (string= pos ""))
191         (setq pos (concat LaTeX-optop pos LaTeX-optcl))
192       (setq pos ""))
193     (if (not (string= width ""))
194         (setq width (concat LaTeX-optop width LaTeX-optcl))
195       (setq width ""))
196     (setq extra (concat pos width))
197     (LaTeX-insert-environment env extra)
198     (newline-and-indent)))
199
200 ;;; mathtools.el ends here.