summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/titleps.el
blob: 8de8b1d3d78295239e54a322410b55d8108510cb (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
;;; titleps.el --- AUCTeX style for `titleps.sty' (v1.1.1)  -*- lexical-binding: t; -*-

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

;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
;; Created: 2016-06-22
;; 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 `titleps.sty' (v1.1.1) from 2016/03/15.
;; `titleps.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-titleps-section-command-list
  '("part"
    "chapter"
    "section"
    "subsection"
    "subsubsection"
    "paragraph"
    "subparagraph")
  "List of sectioning commands available in \"titleps.sty\".")

(defun LaTeX-titleps-section-command-list ()
  "Remove \"chapter\" from variable
`LaTeX-titleps-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-titleps-section-command-list)
    (remove "chapter" LaTeX-titleps-section-command-list)))

(defvar LaTeX-titleps-newpagestyle-regexp
  '("\\\\newpagestyle[ \t\n\r%]*{\\([^}]+\\)}" 1 LaTeX-auto-pagestyle)
  "Match the argument of \"\\newpagestyle\" from titleps.sty.")

(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)

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

   ;; Add titleps to the parser.
   (TeX-auto-add-regexp LaTeX-titleps-newpagestyle-regexp)

   ;; Add \<section>title's
   (dolist (sec (LaTeX-titleps-section-command-list))
     (TeX-add-symbols `(,(concat sec "title") 0)))

   (TeX-add-symbols
    ;; 2. Defining Page Styles
    '("newpagestyle"
      (TeX-arg-eval
       (lambda ()
         (let ((ps (TeX-read-string
                    (TeX-argument-prompt nil nil "Page style"))))
           (LaTeX-add-pagestyles ps)
           (format "%s" ps))))
      (TeX-arg-conditional (y-or-n-p "With optional global style? ")
                           ( [ t ] nil)
                           ( t )))

    '("renewpagestyle" TeX-arg-pagestyle
      (TeX-arg-conditional (y-or-n-p "With optional global style? ")
                           ( [ t ] nil)
                           ( t )))

    '("sethead"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 3 ] nil nil nil)
                           ( 3 )))

    '("setfoot"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 3 ] nil nil nil)
                           ( 3 )))

    '("sethead*" 3)
    '("setfoot*" 3)

    '("settitlemarks"
      (TeX-arg-eval mapconcat #'identity
                    (TeX-completing-read-multiple
                     (TeX-argument-prompt nil nil "Level names")
                     (LaTeX-titleps-section-command-list))
                    ","))

    '("settitlemarks"
      (TeX-arg-eval mapconcat #'identity
                    (TeX-completing-read-multiple
                     (TeX-argument-prompt nil nil "Level names")
                     (LaTeX-titleps-section-command-list))
                    ","))

    '("headrule" 0)
    '("setheadrule" "Thickness")

    '("footrule" 0)
    '("setfootrule" "Thickness")

    '("makeheadrule" 0)
    '("makefootrule" 0)

    ;; 3. On \markboth and \markleft
    '("setmarkboth" t)
    '("resetmarkboth" 0)

    ;; 4. Headline/footline width
    '("widenhead"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 2 ] nil nil)
                           ( 2 )))

    '("widenhead*" 2)

    '("TitlepsPatchSection"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titleps-section-command-list)))

    '("TitlepsPatchSection*"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titleps-section-command-list)))

    ;; 5. Marks
    '("bottitlemarks"     0)
    '("toptitlemarks"     0)
    '("firsttitlemarks"   0)
    '("nexttoptitlemarks" 0)
    '("outertitlemarks"   0)
    '("innertitlemarks"   0)

    '("newtitlemark" (TeX-arg-macro "Command name"))
    '("newtitlemark*" (TeX-arg-counter "Variable name"))

    '("pretitlemark"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titleps-section-command-list))
      "Text")

    '("pretitlemark*"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Sectioning command")
                    (LaTeX-titleps-section-command-list))
      "Text")

    '("ifsamemark"
      (TeX-arg-macro "Marks group: \\")
      (TeX-arg-macro "Command: \\")
      2)

    ;; 6. Running heads with floats
    '("setfloathead"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 3 ] nil nil nil nil [ nil ] )
                           ( 4 [ nil ] )))

    '("setfloatfoot"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 3 ] nil nil nil nil [ nil ] )
                           ( 4 [ nil ] )))

    '("setfloathead*" 4 [ nil ] )
    '("setfloatfoot*" 4 [ nil ] )

    '("nextfloathead"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 3 ] nil nil nil nil [ nil ] )
                           ( 4 [ nil ] )))

    '("nextfloatfoot"
      (TeX-arg-conditional (y-or-n-p "With optional even pages? ")
                           ( [ 3 ] nil nil nil nil [ nil ] )
                           ( 4 [ nil ] )))

    '("nextfloathead*" 4 [ nil ] )
    '("nextfloatfoot*" 4 [ nil ] )

    ;; 7. Extra marks: I'm not clear how the marks commands work;
    ;; until then, I ignore them
    )

   ;; Don't increase indent at \ifsamemark:
   (add-to-list 'LaTeX-indent-begin-exceptions-list "ifsamemark" t)
   (LaTeX-indent-commands-regexp-make)

   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("newpagestyle"         "{[{")
                                ("renewpagestyle"       "{[{")
                                ("settitlemarks"        "*{")
                                ("widenhead"            "*[[{{")
                                ("TitlepsPatchSection"  "*{")
                                ("newtitlemark"         "*{")
                                ("pretitlemark"         "*{{")
                                ("nextfloathead"        "*[[[{{{{[")
                                ("nextfloatfoot"        "*[[[{{{{["))
                              'function)))
 TeX-dialect)

(defvar LaTeX-titleps-package-options
  '(;; 4. Headline/footline width
    "nopatches"

    ;; 5. Marks
    "outermarks" "innermarks" "topmarks" "botmarks"

    ;; 6. Running heads with floats
    "psfloats"

    ;; 7. Extra marks
    "extramarks")
  "Package options for the titleps package.")

;;; titleps.el ends here