1 ;;; mathtools.el --- Style hook for the LaTeX package `mathtools'.
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Mads Jensen <mje@inducks.org>
9 ;; This file is part of AUCTeX.
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)
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.
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
28 ;; This file adds support for `mathtools.sty'
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>
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.")
45 (defvar LaTeX-mathtools-key-val-options
47 ("mathic" ("true" "false"))
48 ("showmanualtags" ("true" "false"))
49 ("firstline-afterskip")
51 ("multlined-pos" ("c" "b" "t"))
53 ("centercolon" ("true" "false"))
54 ("prescript-sub-format")
55 ("prescript-sup-format")
56 ("prescript-arg-format"))
57 "Options for the \\mathtoolsset command")
63 ;; mathtools requires amsmath, as some bugs in amsmath are fixed
64 (TeX-run-style-hooks "amsmath")
66 (dolist (elt LaTeX-amsmath-package-options)
67 (add-to-list 'LaTeX-mathtools-package-options elt))
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)
83 '("mathtoolsset" (TeX-arg-key-val LaTeX-mathtools-key-val))
85 '("mathllap" ["Mathstyle"] t)
86 '("mathrlap" ["Mathstyle"] t)
87 '("mathclap" ["Mathstyle"] t)
88 '("mathmakebox" [TeX-arg-size] [ TeX-arg-size ] 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
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)
120 '("LaTeXunderbrace" 1)
121 '("LaTeXoverbrace" 1)
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")
129 '("MoveEqLeft" [ "Number" ])
130 '("ArrowBetweenLines" [ TeX-arg-macro ] )
131 '("ArrowBetweenLines*" [ TeX-arg-macro ] )
133 "vcentcolon" "ordinarycolon" "coloneqq" "Coloneqq"
134 "coloneq" "Coloneq" "eqqcolon" "Eqqcolon" "eqcolon"
135 "Eqcolon" "colonapprox" "Colonapprox" "colonsim" "Colonsim"
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")
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))
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))))
172 (defun LaTeX-mathtools-env-matrix-starred (env)
173 (let ((where (read-string "(optional) Vertical placement of columns: ")))
174 (if (string= where "")
176 (setq where (concat "[" where "]")))
177 (LaTeX-insert-environment env where)))
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)))
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: "))
190 (if (not (string= pos ""))
191 (setq pos (concat LaTeX-optop pos LaTeX-optcl))
193 (if (not (string= width ""))
194 (setq width (concat LaTeX-optop width LaTeX-optcl))
196 (setq extra (concat pos width))
197 (LaTeX-insert-environment env extra)
198 (newline-and-indent)))
200 ;;; mathtools.el ends here.