File: ltcaption.el

package info (click to toggle)
auctex 13.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,440 kB
  • sloc: lisp: 53,963; makefile: 835; sh: 112; perl: 91
file content (120 lines) | stat: -rw-r--r-- 4,483 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
;;; ltcaption.el --- AUCTeX style for `ltcaption.sty' version v1.4c  -*- lexical-binding: t; -*-

;; Copyright (C) 2022 Free Software Foundation, Inc.

;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
;; Created: 2022-05-04
;; Keywords: tex

;; This file is part of AUCTeX.

;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Commentary:

;; This file adds support for `ltcaption.sty' version v1.4c from
;; 2021/01/08.  `ltcaption.sty' is part of TeXLive.

;; This style tracks ltcaption.sty which doesn't load longtable.sty
;; and emits an error when longtable package is missing.  The same
;; happens here when longtable.el isn't loaded yet where
;; `LaTeX-item-longtable' is undefined.  The remedy is to load
;; longtable before ltcaption.  The caption package loads ltcaption
;; automatically if longtable is loaded.

;;; Code:

(require 'tex)
(require 'latex)

;; Silence the compiler:
(declare-function font-latex-add-keywords
                  "font-latex" (keywords class))
(declare-function LaTeX-item-longtable
                  "longtable" (&optional suppress))

(defun LaTeX-env-longtable* (environment)
  "Insert a longtable* ENVIRONMENT with a starred caption."
  (let ((pos (and LaTeX-default-position ; `LaTeX-default-position'
                                        ; can be nil, i.e. no prompt
                  (completing-read (TeX-argument-prompt t nil "Position")
                                   '("l" "r" "c")
                                   nil nil LaTeX-default-position)))
        (fmt (TeX-read-string
              (if (string= LaTeX-default-format "")
                  "Format: "
                (format "Format (default %s): " LaTeX-default-format))
              nil nil
              (if (string= LaTeX-default-format "")
                  nil
                LaTeX-default-format)))
        (caption (TeX-read-string
                  (TeX-argument-prompt nil nil "Starred caption"))))
    (setq LaTeX-default-position pos
          LaTeX-default-format   fmt)
    (LaTeX-insert-environment environment
                              (concat
                               (unless (zerop (length pos))
                                 (concat LaTeX-optop pos LaTeX-optcl))
                               (concat TeX-grop fmt TeX-grcl)))
    ;; top caption -- do nothing if user skips caption
    (unless (zerop (length caption))
      ;; insert '\caption*{text} \\':
      (insert TeX-esc "caption*" TeX-grop caption TeX-grcl " \\\\")
      ;; fill the caption
      (when auto-fill-function (LaTeX-fill-paragraph))
      ;; Insert a new line and indent
      (LaTeX-newline)
      (indent-according-to-mode))
    ;; Insert suitable number of &'s, suppress line break
    (LaTeX-item-longtable t)))

(TeX-add-style-hook
 "ltcaption"
 (lambda ()

   (TeX-add-symbols
    "LTcapmarginsfalse"
    "LTcaptype")

   ;; These parameters are set with \setlength
   (LaTeX-add-lengths
    "LTcapskip" "LTcapleft" "LTcapright")

   (LaTeX-add-environments
    '("longtable*" LaTeX-env-longtable*))

   ;; Use the enhanced table formatting.  Append to
   ;; `LaTeX-indent-environment-list' in order not to override custom
   ;; settings.
   (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                '("longtable*" LaTeX-indent-tabular) t)

   ;; Append 'longtable*' to `LaTeX-item-list' with `LaTeX-item-longtable':
   (add-to-list 'LaTeX-item-list '("longtable*" . LaTeX-item-longtable) t)

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("LTcapmarginsfalse" ""))
                              'function)))
 TeX-dialect)

(defvar LaTeX-ltcaption-package-options nil
  "Package options for the ltcaption package.")

;;; ltcaption.el ends here