AUCTeX Sync -- New Style Files
[packages] / xemacs-packages / auctex / style / titletoc.el
1 ;;; titletoc.el --- AUCTeX style for `titletoc.sty' (v1.6)
2
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Created: 2015-09-19
8 ;; Keywords: tex
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 file adds support for `titletoc.sty' (v1.6) from
30 ;; 2011/12/15.  `titletoc.sty' is part of TeXLive.
31
32 ;;; Code:
33
34 (defvar LaTeX-titletoc-section-command-list
35   '("part"
36     "chapter"
37     "section"
38     "subsection"
39     "subsubsection"
40     "paragraph"
41     "subparagraph"
42     "figure"
43     "table")
44   "List of sectioning commands available in \"titletoc.sty\".
45 Other environments producing a \"Table of ENVIRONMENT\" (figure,
46 table) are also available in this variable.")
47
48 (defun LaTeX-titletoc-section-command-list ()
49   "Remove \"chapter\" from variable
50 `LaTeX-titletoc-section-command-list' and return the remainder.
51 Removal is based on the return value of function
52 `LaTeX-largest-level'."
53   (if (< (LaTeX-largest-level) 2)
54       (symbol-value 'LaTeX-titletoc-section-command-list)
55     (remove "chapter" LaTeX-titletoc-section-command-list)))
56
57 ;; Needed for auto-parsing.
58 (require 'tex)
59
60 ;; Setup for \contentsuse:
61 (TeX-auto-add-type "titletoc-contentsuse" "LaTeX")
62
63 (defvar LaTeX-titletoc-contentsuse-regexp
64   '("\\\\contentsuse{\\([^}]+\\)}"
65     1 LaTeX-auto-titletoc-contentsuse)
66   "Matches the argument of \\contentsuse from titletoc package.")
67
68 (defun LaTeX-titletoc-auto-prepare ()
69   "Clear `LaTeX-auto-titletoc-contentsuse' before parsing."
70   (setq LaTeX-auto-titletoc-contentsuse nil))
71
72 (defun LaTeX-titletoc-auto-cleanup ()
73   "Move parsed arguments of \"\\contentsuse\" to the variable
74 `LaTeX-titletoc-section-command-list'."
75   (when (LaTeX-titletoc-contentsuse-list)
76     (make-local-variable 'LaTeX-titletoc-section-command-list)
77     (dolist (content (mapcar #'car (LaTeX-titletoc-contentsuse-list)))
78       (add-to-list 'LaTeX-titletoc-section-command-list content))))
79
80 (add-hook 'TeX-auto-prepare-hook #'LaTeX-titletoc-auto-prepare t)
81 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-titletoc-auto-cleanup t)
82 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
83
84 (TeX-add-style-hook
85  "titletoc"
86  (lambda ()
87
88    ;; Add titletoc to the parser
89    (TeX-auto-add-regexp LaTeX-titletoc-contentsuse-regexp)
90
91    (TeX-add-symbols
92     ;; Basic macros
93     ;; \dottedcontents{<section>}[<left>]{<above-code>}
94     ;;                {<label width>}{<leader width>}
95     '("dottedcontents"
96       (TeX-arg-eval completing-read
97                      (TeX-argument-prompt optional nil "Sectioning command")
98                      (LaTeX-titletoc-section-command-list))
99       [ TeX-arg-length "Left margin" ] 3)
100
101     ;; \titlecontents{<section>}[<left>]{<above-code>}
102     ;;               {<numbered-entry-format>}{<numberless-entry-format>}
103     ;;               {<filler-page-format>}[<below-code>]
104     '("titlecontents"
105       (TeX-arg-eval completing-read
106                      (TeX-argument-prompt optional nil "Sectioning command")
107                      (LaTeX-titletoc-section-command-list))
108       [ TeX-arg-length "Left margin" ]
109       (TeX-arg-conditional (y-or-n-p "With optional below code argument? ")
110                            (4 [nil])
111                          (4)))
112
113     ;; \titlecontents*{<section>}[<left>]{<above-code>}
114     ;;                {<numbered-entry-format>}{<numberless-entry-format>}
115     ;;                {<filler-page-format>}[<separator>]
116     '("titlecontents*"
117       (TeX-arg-eval completing-read
118                      (TeX-argument-prompt optional nil "Sectioning command")
119                      (LaTeX-titletoc-section-command-list))
120       [ TeX-arg-length "Left margin" ]
121       (TeX-arg-conditional (y-or-n-p "With optional separator argument? ")
122                            (4 [nil])
123                          (4)))
124
125     ;; \contentsmargin[<correction>]{<right>}
126     '("contentsmargin" [ "Correction" ] "Right margin")
127
128     '("thecontentslabel" 0)
129
130     '("thecontentspage" 0)
131
132     '("contentslabel" [ "Format" ] (TeX-arg-length "Space"))
133
134     '("contentspage" [ "Format" ])
135
136     '("contentspush" t)
137
138     ;; Check if newfloat.el is loaded and any new environment is
139     ;; defined with it.  titletoc.sty can also be used to customize
140     ;; new environments defined with newfloat.sty.  As a prerequisite,
141     ;; the environments must be introduced to titletoc.sty with
142     ;; \contentuse{ENV} and then can be used as argument to \titlecontents.
143     '("contentsuse"
144       (TeX-arg-eval
145        (lambda ()
146          (let ((name (if (and (member "newfloat" (TeX-active-styles))
147                               (LaTeX-newfloat-DeclareFloatingEnvironment-list))
148                          (completing-read
149                           (TeX-argument-prompt optional nil "Name of contents")
150                           (mapcar #'car
151                                   (LaTeX-newfloat-DeclareFloatingEnvironment-list)))
152                        (TeX-read-string
153                         (TeX-argument-prompt optional nil "Name of contents")))))
154            (make-local-variable 'LaTeX-titletoc-section-command-list)
155            (add-to-list 'LaTeX-titletoc-section-command-list name)
156            (format "%s" name))))
157       "File extension")
158
159     ;; 6.3. Partial TOC's
160     '("startcontents" [ "Name" ])
161
162     '("stopcontents" [ "Name" ])
163
164     '("resumecontents" [ "Name" ])
165
166     '("printcontents" [ "Name" ] "Prefix" "Start level" t)
167
168     ;; 6.4. Partial lists
169     '("startlist" [ "Name" ] "List")
170
171     '("stoplist" [ "Name" ] "List")
172
173     '("resumelist" [ "Name" ] "List")
174
175     '("printlist" [ "Name" ] "Prefix" t) )
176
177    ;; Fontification: We only add macros which are used at top level;
178    ;; most of macros definded above are intended to be used in
179    ;; arguments of \dottedcontents or \titlecontents
180    (when (and (featurep 'font-latex)
181               (eq TeX-install-font-lock 'font-latex-setup))
182      (font-latex-add-keywords '(("dottedcontents"  "{[{{{")
183                                 ("titlecontents"   "*{[{{{[[[")
184                                 ("contentsmargin"  "[{")
185                                 ("contentsuse"     "{{"))
186                               'function)) )
187  LaTeX-dialect)
188
189 (defvar LaTeX-titletoc-package-options
190   '("leftlabels" "rightlabels" "dotinlabels")
191   "Package options for the titletoc package.")
192
193 ;;; titletoc.el ends here