1 ;;; titletoc.el --- AUCTeX style for `titletoc.sty' (v1.6)
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
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)
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.
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
29 ;; This file adds support for `titletoc.sty' (v1.6) from
30 ;; 2011/12/15. `titletoc.sty' is part of TeXLive.
34 (defvar LaTeX-titletoc-section-command-list
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.")
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)))
57 ;; Needed for auto-parsing.
60 ;; Setup for \contentsuse:
61 (TeX-auto-add-type "titletoc-contentsuse" "LaTeX")
63 (defvar LaTeX-titletoc-contentsuse-regexp
64 '("\\\\contentsuse{\\([^}]+\\)}"
65 1 LaTeX-auto-titletoc-contentsuse)
66 "Matches the argument of \\contentsuse from titletoc package.")
68 (defun LaTeX-titletoc-auto-prepare ()
69 "Clear `LaTeX-auto-titletoc-contentsuse' before parsing."
70 (setq LaTeX-auto-titletoc-contentsuse nil))
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))))
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)
88 ;; Add titletoc to the parser
89 (TeX-auto-add-regexp LaTeX-titletoc-contentsuse-regexp)
93 ;; \dottedcontents{<section>}[<left>]{<above-code>}
94 ;; {<label width>}{<leader width>}
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)
101 ;; \titlecontents{<section>}[<left>]{<above-code>}
102 ;; {<numbered-entry-format>}{<numberless-entry-format>}
103 ;; {<filler-page-format>}[<below-code>]
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? ")
113 ;; \titlecontents*{<section>}[<left>]{<above-code>}
114 ;; {<numbered-entry-format>}{<numberless-entry-format>}
115 ;; {<filler-page-format>}[<separator>]
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? ")
125 ;; \contentsmargin[<correction>]{<right>}
126 '("contentsmargin" [ "Correction" ] "Right margin")
128 '("thecontentslabel" 0)
130 '("thecontentspage" 0)
132 '("contentslabel" [ "Format" ] (TeX-arg-length "Space"))
134 '("contentspage" [ "Format" ])
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.
146 (let ((name (if (and (member "newfloat" (TeX-active-styles))
147 (LaTeX-newfloat-DeclareFloatingEnvironment-list))
149 (TeX-argument-prompt optional nil "Name of contents")
151 (LaTeX-newfloat-DeclareFloatingEnvironment-list)))
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))))
159 ;; 6.3. Partial TOC's
160 '("startcontents" [ "Name" ])
162 '("stopcontents" [ "Name" ])
164 '("resumecontents" [ "Name" ])
166 '("printcontents" [ "Name" ] "Prefix" "Start level" t)
168 ;; 6.4. Partial lists
169 '("startlist" [ "Name" ] "List")
171 '("stoplist" [ "Name" ] "List")
173 '("resumelist" [ "Name" ] "List")
175 '("printlist" [ "Name" ] "Prefix" t) )
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" "{{"))
189 (defvar LaTeX-titletoc-package-options
190 '("leftlabels" "rightlabels" "dotinlabels")
191 "Package options for the titletoc package.")
193 ;;; titletoc.el ends here