1 ;;; longtable.el --- AUCTeX style for `longtable.sty'.
3 ;; Copyright (C) 2013--2017 Free Software Foundation, Inc.
5 ;; Maintainer: auctex-devel@gnu.org
6 ;; Author: Mosè Giordano <mose@gnu.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 `longtable.sty'.
32 (defvar LaTeX-longtable-skipping-regexp
33 (regexp-opt '("[l]" "[r]" "[c]" ""))
34 "Regexp matching between \\begin{longtable} and column specification.
35 For longtable environments only.")
37 (defun LaTeX-item-longtable (&optional suppress)
38 "Insert line break macro on the last line and suitable number of &'s.
39 For longtable environments. If SUPPRESS is non-nil, do not
40 insert line break macro."
45 (TeX-insert-macro "\\")))
46 (LaTeX-insert-ampersands
47 LaTeX-longtable-skipping-regexp #'LaTeX-array-count-columns))
49 (defun LaTeX-env-longtable (environment)
50 "Insert a longtable-like ENVIRONMENT with caption and label."
51 (let* ((pos (completing-read (TeX-argument-prompt t nil "Position")
52 '(("l") ("r") ("c"))))
53 (fmt (TeX-read-string "Format: " LaTeX-default-format))
54 (caption (TeX-read-string "Caption: "))
55 (short-caption (when (>= (length caption) LaTeX-short-caption-prompt-length)
56 (TeX-read-string "(Optional) Short caption: "))))
57 (setq LaTeX-default-format fmt)
58 (LaTeX-insert-environment environment
60 (unless (zerop (length pos))
61 (concat LaTeX-optop pos LaTeX-optcl))
62 (concat TeX-grop fmt TeX-grcl)))
63 ;; top caption -- do nothing if user skips caption
64 (unless (zerop (length caption))
65 ;; insert `\caption[short-caption]{caption':
66 (insert TeX-esc "caption")
67 (when (and short-caption (not (string= short-caption "")))
68 (insert LaTeX-optop short-caption LaTeX-optcl))
69 (insert TeX-grop caption)
70 ;; ask for a label and insert it
71 (LaTeX-label environment 'environment)
72 ;; the longtable `\caption' is equivalent to a
73 ;; `\multicolumn', so it needs a `\\' at the
74 ;; end of the line. Prior to that, add } to
76 (insert TeX-grcl "\\\\")
78 (LaTeX-fill-paragraph)
79 ;; Insert a new line and indent
81 (indent-according-to-mode))
82 ;; Insert suitable number of &'s, suppress line break
83 (LaTeX-item-longtable t)))
88 (LaTeX-add-environments
89 '("longtable" LaTeX-env-longtable))
92 ;; Commands to end table rows
100 ;; These parameters are set with \setlength
102 "LTleft" "LTright" "LTpre" "LTpost" "LTcapwidth")
104 ;; This parameter is set with \setcounter
105 (LaTeX-add-counters "LTchunksize")
107 ;; Use the enhanced table formatting. Append to
108 ;; `LaTeX-indent-environment-list' in order not to override custom settings.
109 (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
110 '("longtable" LaTeX-indent-tabular) t)
112 ;; Append longtable to `LaTeX-label-alist', in order not to override possible
114 (add-to-list 'LaTeX-label-alist '("longtable" . LaTeX-table-label) t)
116 ;; Append longtable to `LaTeX-item-list' with `LaTeX-item-longtable'
117 (add-to-list 'LaTeX-item-list '("longtable" . LaTeX-item-longtable) t)
120 (when (and (featurep 'font-latex)
121 (eq TeX-install-font-lock 'font-latex-setup))
122 ;; Actually, `\caption*{}' macro takes only one mandatory
123 ;; argument, not an optional one, the following is a workaround
124 ;; to fontify correctly also the standard `\caption[]{}' macro.
125 (font-latex-add-keywords '(("caption" "*[{"))
129 ;; `longtable.sty' has two options "errorshow" and "pausing", both for
130 ;; debugging purposes. We ignore them both in order to make package
131 ;; loading faster in a buffer.
132 (defvar LaTeX-longtable-package-options nil
133 "Package options for the longtable package.")
135 ;; longtable.el ends here