summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/titletoc.el
blob: c0ac512198c1fad1027567ff637e1772be07871c (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
;;; titletoc.el --- AUCTeX style for `titletoc.sty' (v1.6)  -*- lexical-binding: t; -*-

;; Copyright (C) 2016, 2018, 2020 Free Software Foundation, Inc.

;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
;; Created: 2015-09-19
;; 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 `titletoc.sty' (v1.6) from
;; 2011/12/15.  `titletoc.sty' is part of TeXLive.

;;; Code:

(require 'tex)
(require 'latex)

;; Silence the compiler:
(declare-function font-latex-add-keywords
                  "font-latex"
                  (keywords class))

(defvar LaTeX-titletoc-section-command-list
  '("part"
    "chapter"
    "section"
    "subsection"
    "subsubsection"
    "paragraph"
    "subparagraph"
    "figure"
    "table")
  "List of sectioning commands available in \"titletoc.sty\".
Other environments producing a \"Table of ENVIRONMENT\" (figure,
table) are also available in this variable.")

(defun LaTeX-titletoc-section-command-list ()
  "Remove \"chapter\" from variable
`LaTeX-titletoc-section-command-list' and return the remainder.
Removal is based on the return value of function
`LaTeX-largest-level'."
  (if (< (LaTeX-largest-level) 2)
      (symbol-value 'LaTeX-titletoc-section-command-list)
    (remove "chapter" LaTeX-titletoc-section-command-list)))

;; Setup for \contentsuse:
(TeX-auto-add-type "titletoc-contentsuse" "LaTeX")

(defvar LaTeX-titletoc-contentsuse-regexp
  '("\\\\contentsuse{\\([^}]+\\)}"
    1 LaTeX-auto-titletoc-contentsuse)
  "Matches the argument of \\contentsuse from titletoc package.")

(defun LaTeX-titletoc-auto-prepare ()
  "Clear `LaTeX-auto-titletoc-contentsuse' before parsing."
  (setq LaTeX-auto-titletoc-contentsuse nil))

(defun LaTeX-titletoc-auto-cleanup ()
  "Move parsed arguments of \"\\contentsuse\" to the variable
`LaTeX-titletoc-section-command-list'."
  (when (LaTeX-titletoc-contentsuse-list)
    (make-local-variable 'LaTeX-titletoc-section-command-list)
    (dolist (content (mapcar #'car (LaTeX-titletoc-contentsuse-list)))
      (add-to-list 'LaTeX-titletoc-section-command-list content))))

(add-hook 'TeX-auto-prepare-hook #'LaTeX-titletoc-auto-prepare t)
(add-hook 'TeX-auto-cleanup-hook #'LaTeX-titletoc-auto-cleanup t)
(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)

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

   ;; Add titletoc to the parser
   (TeX-auto-add-regexp LaTeX-titletoc-contentsuse-regexp)

   (TeX-add-symbols
    ;; Basic macros
    ;; \dottedcontents{<section>}[<left>]{<above-code>}
    ;;                {<label width>}{<leader width>}
    '("dottedcontents"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titletoc-section-command-list))
      [ TeX-arg-length "Left margin" ] 3)

    ;; \titlecontents{<section>}[<left>]{<above-code>}
    ;;               {<numbered-entry-format>}{<numberless-entry-format>}
    ;;               {<filler-page-format>}[<below-code>]
    '("titlecontents"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titletoc-section-command-list))
      [ TeX-arg-length "Left margin" ]
      (TeX-arg-conditional (y-or-n-p "With optional below code argument? ")
                           (4 [nil])
                           (4)))

    ;; \titlecontents*{<section>}[<left>]{<above-code>}
    ;;                {<numbered-entry-format>}{<numberless-entry-format>}
    ;;                {<filler-page-format>}[<separator>]
    '("titlecontents*"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titletoc-section-command-list))
      [ TeX-arg-length "Left margin" ]
      (TeX-arg-conditional (y-or-n-p "With optional separator argument? ")
                           (4 [nil])
                           (4)))

    ;; \contentsmargin[<correction>]{<right>}
    '("contentsmargin" [ "Correction" ] "Right margin")

    '("thecontentslabel" 0)

    '("thecontentspage" 0)

    '("contentslabel" [ "Format" ] (TeX-arg-length "Space"))

    '("contentspage" [ "Format" ])

    '("contentspush" t)

    ;; Check if newfloat.el is loaded and any new environment is
    ;; defined with it.  titletoc.sty can also be used to customize
    ;; new environments defined with newfloat.sty.  As a prerequisite,
    ;; the environments must be introduced to titletoc.sty with
    ;; \contentuse{ENV} and then can be used as argument to \titlecontents.
    '("contentsuse"
      (TeX-arg-eval
       (lambda ()
         (let ((name (if (and (member "newfloat" (TeX-active-styles))
                              (LaTeX-newfloat-DeclareFloatingEnvironment-list))
                         (completing-read
                          (TeX-argument-prompt nil nil "Name of contents")
                          (mapcar #'car
                                  (LaTeX-newfloat-DeclareFloatingEnvironment-list)))
                       (TeX-read-string
                        (TeX-argument-prompt nil nil "Name of contents")))))
           (make-local-variable 'LaTeX-titletoc-section-command-list)
           (add-to-list 'LaTeX-titletoc-section-command-list name)
           (format "%s" name))))
      "File extension")

    ;; 6.3. Partial TOC's
    '("startcontents" [ "Name" ])

    '("stopcontents" [ "Name" ])

    '("resumecontents" [ "Name" ])

    '("printcontents" [ "Name" ] "Prefix" "Start level" t)

    ;; 6.4. Partial lists
    '("startlist" [ "Name" ] "List")

    '("stoplist" [ "Name" ] "List")

    '("resumelist" [ "Name" ] "List")

    '("printlist" [ "Name" ] "Prefix" t) )

   ;; Fontification: We only add macros which are used at top level;
   ;; most of macros definded above are intended to be used in
   ;; arguments of \dottedcontents or \titlecontents
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("dottedcontents"  "{[{{{")
                                ("titlecontents"   "*{[{{{[[[")
                                ("contentsmargin"  "[{")
                                ("contentsuse"     "{{"))
                              'function)) )
 TeX-dialect)

(defvar LaTeX-titletoc-package-options
  '("leftlabels" "rightlabels" "dotinlabels")
  "Package options for the titletoc package.")

;;; titletoc.el ends here