"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/amsmath.el" (18 Oct 2020, 9213 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "amsmath.el": 12.2_vs_12.3.

    1 ;;; amsmath.el --- Style hook for the AMS-LaTeX amsmath package.
    2 
    3 ;; Copyright (C) 2002, 2005-2007, 2012-2014, 2017-2020
    4 ;;      Free Software Foundation, Inc.
    5 ;; FIXME: What about the copyright for <= 2001?
    6 
    7 ;; Author: Carsten Dominik <dominik@strw.leidenuniv.nl>
    8 ;; Maintainer: auctex-devel@gnu.org
    9 
   10 ;; This file is part of AUCTeX.
   11 
   12 ;; AUCTeX is free software; you can redistribute it and/or modify it
   13 ;; under the terms of the GNU General Public License as published by
   14 ;; the Free Software Foundation; either version 3, or (at your option)
   15 ;; any later version.
   16 
   17 ;; AUCTeX is distributed in the hope that it will be useful, but
   18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
   19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20 ;; General Public License for more details.
   21 
   22 ;; You should have received a copy of the GNU General Public License
   23 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
   24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   25 ;; 02110-1301, USA.
   26 
   27 ;;; Commentary:
   28 
   29 ;; This will also load the amstext, amsbsy and amsopn style files.
   30 
   31 ;;; Code:
   32 
   33 ;; Fontification
   34 (declare-function font-latex-add-keywords
   35           "font-latex"
   36           (keywords class))
   37 
   38 (TeX-add-style-hook
   39  "amsmath"
   40  (lambda ()
   41    (LaTeX-add-environments
   42     '("align"      LaTeX-env-label)
   43     '("gather"     LaTeX-env-label)
   44     '("flalign"    LaTeX-env-label)
   45     '("multline"   LaTeX-env-label)
   46     '("alignat"    LaTeX-amsmath-env-alignat)
   47     '("alignat*"   LaTeX-amsmath-env-alignat)
   48     '("xalignat"   LaTeX-amsmath-env-alignat)
   49     '("xalignat*"  LaTeX-amsmath-env-alignat)
   50     '("xxalignat"  LaTeX-amsmath-env-alignat)
   51     '("aligned"    ["Vertical position (t or b)"])
   52     '("gathered"   ["Vertical position (t or b)"])
   53     '("alignedat"  LaTeX-amsmath-env-alignedat)
   54     "align*" "gather*" "flalign*" "multline*" "equation*"
   55     "split"
   56     "cases"
   57     "matrix" "smallmatrix" "pmatrix" "bmatrix" "Bmatrix" "vmatrix" "Vmatrix"
   58     "subequations"
   59     '("subarray" "Alignment"))
   60 
   61    (TeX-add-symbols
   62     '("eqref" TeX-arg-ref)
   63     '("numberwithin" TeX-arg-counter "Section level")
   64     '("raisetag" "Dimension")
   65     '("shoveright" t) '("shoveleft" t)
   66     '("intertext" t)
   67     '("hdotsfor" ["Stretch"] "Number of columns to cover")
   68     '("xleftarrow" ["Below"] "Above")
   69     '("xrightarrow" ["Below"] "Above")
   70     '("overset" "Above symbol" "Symbol")
   71     '("underset" "Below symbol" "Symbol")
   72     '("overunderset" "Above symbol" "Below symbol" "Symbol")
   73     '("dfrac" 2)
   74     '("tfrac" 2)
   75     '("binom" 2)
   76     '("dbinom" 2)
   77     '("tbinom" 2)
   78     '("genfrac" "Left delimiter" "Right delimiter" "Thickness"
   79       "Mathstyle" 2)
   80     '("cfrac" ["position (l or r)"] 2)
   81     '("smash" ["where (t or b)"] t)
   82     '("sideset" "Left" "Right")
   83     '("tag" "(Tag)")
   84     '("tag*" "Tag")
   85     '("displaybreak" ["Weight (0..4)"])
   86     '("allowdisplaybreaks" ["Weight (1..4)"])
   87     '("substack" t)
   88     '("leftroot" "Push root index left by")
   89     '("uproot" "Push root index upward by")
   90     '("boxed" t)
   91     '("mspace" t)
   92     '("mod" t)
   93     '("pmod" t)
   94     '("pod" t)
   95     '("overleftrightarrow" t)
   96     '("underleftarrow" t)
   97     '("underrightarrow" t)
   98     '("underleftrightarrow" t)
   99     '("dddot" t)
  100     '("ddddot" t)
  101     "bmod" "notag"
  102     "dots" "dotsb" "dotsc" "dotsi" "dotsm" "dotso" "nobreakdash"
  103     '("lvert" TeX-arg-insert-right-brace-maybe)
  104     '("lVert" TeX-arg-insert-right-brace-maybe)
  105     "rvert" "rVert"
  106     "iint" "iiint" "iiiint" "idotsint")
  107 
  108    (setq LaTeX-item-list
  109      (append '(("split"    . LaTeX-item-equation)
  110            ("multline" . LaTeX-item-equation)
  111            ("multline*" . LaTeX-item-equation)
  112            ("gather"   . LaTeX-item-equation)
  113            ("gather*"  . LaTeX-item-equation)
  114            ("gathered" . LaTeX-item-equation)
  115            ("align"    . LaTeX-item-equation)
  116            ("align*"   . LaTeX-item-equation)
  117            ("aligned"  . LaTeX-item-equation)
  118            ("alignat"  . LaTeX-item-equation-alignat)
  119            ("alignat*" . LaTeX-item-equation-alignat)
  120            ("xalignat"  . LaTeX-item-equation-alignat)
  121            ("xalignat*" . LaTeX-item-equation-alignat)
  122            ("xxalignat" . LaTeX-item-equation-alignat)
  123            ("alignedat" . LaTeX-item-equation-alignat)
  124            ("flalign"  . LaTeX-item-equation)
  125            ("flalign*" . LaTeX-item-equation)
  126            ("matrix" .  LaTeX-item-equation)
  127            ("pmatrix" .  LaTeX-item-equation)
  128            ("bmatrix" .  LaTeX-item-equation)
  129            ("Bmatrix" .  LaTeX-item-equation)
  130            ("vmatrix" .  LaTeX-item-equation)
  131            ("Vmatrix" .  LaTeX-item-equation)
  132            ("subarray" . LaTeX-item-equation)
  133            ("cases"    . LaTeX-item-equation))
  134          LaTeX-item-list))
  135 
  136    ;; When `LaTeX-amsmath-label' is nil, use value of LaTeX-equation-label:
  137    (unless LaTeX-amsmath-label
  138      (setq LaTeX-amsmath-label LaTeX-equation-label))
  139 
  140    (setq LaTeX-label-alist
  141      ;; Append amsmath environments to `LaTeX-label-alist', in order not to
  142      ;; override possible custome values.
  143      (append LaTeX-label-alist
  144          '(("align"      . LaTeX-amsmath-label)
  145            ("alignat"    . LaTeX-amsmath-label)
  146            ("xalignat"   . LaTeX-amsmath-label)
  147            ("multline"   . LaTeX-amsmath-label)
  148            ("flalign"    . LaTeX-amsmath-label)
  149            ("gather"     . LaTeX-amsmath-label))))
  150 
  151    (set (make-local-variable 'TeX-braces-association)
  152     (append '(("\\lvert" . "\\rvert")
  153           ("\\lVert" . "\\rVert"))
  154         TeX-braces-association))
  155    (set (make-local-variable 'TeX-left-right-braces)
  156     (append '(("\\lvert") ("\\rvert") ("\\lVert") ("\\rVert"))
  157         TeX-left-right-braces))
  158 
  159    ;; amsmath includes amstext, amsbsy, & amsopn.
  160    ;; So we run their hooks, too.
  161    (TeX-run-style-hooks "amstext" "amsbsy" "amsopn")
  162 
  163    ;; RefTeX support: Tell RefTeX about amsmath environments.
  164    (when (fboundp 'reftex-add-to-label-alist)
  165      (reftex-add-to-label-alist '(AMSTeX)))
  166 
  167    ;; Add \eqref to `reftex-ref-style-alist' and associate it to `e'
  168    (when (and (boundp 'reftex-ref-style-alist)
  169           ;; check if Emacs is already equipped with this
  170           (not (assoc "AMSmath" reftex-ref-style-alist)))
  171      ;; Append it to a local version in order to avoid a clash with
  172      ;; user settings
  173      (add-to-list (make-local-variable 'reftex-ref-style-alist)
  174           '("AMSmath" "amsmath" (("\\eqref" ?e)))
  175           t))
  176 
  177    ;; Activate `AMSmath' when `LaTeX-reftex-ref-style-auto-activate'
  178    ;; is non-nil
  179    (and LaTeX-reftex-ref-style-auto-activate
  180     (fboundp 'reftex-ref-style-activate)
  181     (reftex-ref-style-activate "AMSmath"))
  182 
  183    (when (and (featurep 'font-latex)
  184           (eq TeX-install-font-lock 'font-latex-setup))
  185      (font-latex-add-keywords '(("boxed" "{"))
  186                   'math-command)))
  187  LaTeX-dialect)
  188 
  189 (defun LaTeX-amsmath-env-alignat (env)
  190   "Insert ENV with column number specifications.
  191 Insert suitable number of ampersands also if possible."
  192   (let ((ncols (TeX-read-string "Number of columns: ")))
  193     (LaTeX-insert-environment env (concat TeX-grop ncols TeX-grcl))
  194     (LaTeX-item-equation-alignat t)))
  195 
  196 (defun LaTeX-amsmath-env-alignedat (env)
  197   "Insert ENV with position and column number specifications.
  198 Insert suitable number of ampersands also if possible."
  199   (let ((where (TeX-read-string "(Optional) Vertical position (t or b): "))
  200     (ncols (TeX-read-string "Number of columns: ")))
  201     (unless (string= where "")
  202       (setq where (concat LaTeX-optop where LaTeX-optcl)))
  203     (LaTeX-insert-environment env (concat where TeX-grop ncols TeX-grcl))
  204     (LaTeX-item-equation-alignat t)))
  205 
  206 (defun LaTeX-item-equation (&optional suppress)
  207   "Insert contents to terminate a line in multi-line equations environment.
  208 Put line break macro on the last line.  If the current environment
  209 wants \\label, insert it also.
  210 
  211 If SUPPRESS is non-nil, do not insert line break macro."
  212   (unless suppress
  213     (end-of-line 0)
  214     (just-one-space)
  215     (TeX-insert-macro "\\")
  216     (forward-line 1)
  217     (indent-according-to-mode))
  218   (let ((env (LaTeX-current-environment)))
  219     (when (and (assoc env LaTeX-label-alist)
  220            (LaTeX-label env 'environment))
  221       (LaTeX-newline)
  222       (indent-according-to-mode))))
  223 
  224 (defun LaTeX-item-equation-alignat (&optional suppress)
  225   "Insert contents to terminate a line in multi-line equations environment.
  226 Put line break macro on the last line.  Next, if the current
  227 environment wants \\label, insert it also.  And insert suitable number
  228 of ampersands if possible.
  229 
  230 If SUPPRESS is non-nil, do not insert line break macro."
  231   (LaTeX-item-equation suppress)
  232   (LaTeX-insert-ampersands
  233    (concat "\\(?:"
  234        (regexp-quote LaTeX-optop) "[tb]" (regexp-quote LaTeX-optcl)
  235        "\\)?")
  236    'LaTeX-amsmath-alignat-number-of-ampersands))
  237 
  238 (defun LaTeX-amsmath-alignat-number-of-ampersands (start end)
  239   "Return the number of ampersands to insert.
  240 The number is 2N-1 where N is the number taken from the text between
  241 START and END."
  242   (let ((num (string-to-number (buffer-substring-no-properties start end))))
  243     (if (integerp num) (+ num num -1))))
  244 
  245 (defvar LaTeX-amsmath-package-options '("intlimits" "nointlimits"
  246                     "sumlimits" "nosumlimits"
  247                     "namelimits" "nonamelimits"
  248                     "leqno" "reqno" "centertags"
  249                     "tbtags" "cmex10" "fleqn" "?"
  250                     "alignedleftspaceyes"
  251                     "alignedleftspaceno"
  252                     "alignedleftspaceyesifneg")
  253   "Package options for the amsmath package.")
  254 
  255 ;;; amsmath.el ends here.