AUCTeX Sync -- New Style Files
[packages] / xemacs-packages / auctex / style / floatrow.el
1 ;;; floatrow.el --- AUCTeX style for `floatrow.sty' (v0.3b)
2
3 ;; Copyright (C) 2017 Free Software Foundation, Inc.
4
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Created: 2016-11-11
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 `floatrow.sty' (v0.3b) from 2009/08/02.
30 ;; `floatrow.sty' is part of TeXLive.
31 ;;
32 ;; `floatrow.sty' is a powerful package and the documentation long.
33 ;; It is expected that this style is not feature complete.  One
34 ;; deliberate decision is that this style does not offer any package
35 ;; options: Please use the command `\floatsetup' to set the options
36 ;; you want.
37 ;;
38 ;; This style also alters the way AUCTeX inserts the environments
39 ;; "table" and "figure" (cf.  function `LaTeX-floatrow-env-init').  If
40 ;; you want the original behavior, try `C-c C-e rawfigure' or `C-c C-e
41 ;; rawtable' which include the environments incl.  the macro \RawFloats
42 ;; at the beginning of the environment (cf.  function
43 ;; `LaTeX-floatrow-env-figure-raw').
44 ;;
45 ;; Another deliberate decision is the implementation of commands like
46 ;; `\ffigbox' and `\ttabbox': When invoked with `C-c C-m ffigbox RET',
47 ;; the final result will look like this with cursor being at *:
48 ;;
49 ;;   \ffigbox{*}{%
50 ;;     \caption{query for a caption}%
51 ;;     \label{prefix:is-chosen-acc-to-current-environment}%
52 ;;   }
53 ;;
54 ;; This gives users the freedom to insert any command where point is.
55 ;; The mandatory arguments are not part of the fontification as
56 ;; commands like `\includegraphics' or `tabular' environments have their
57 ;; own fontification.
58
59 ;;; Code:
60
61 ;; Needed for compiling `pushnew':
62 (eval-when-compile (require 'cl))
63
64 ;; Needed for auto-parsing.
65 (require 'tex)
66
67 (defvar LaTeX-floatrow-key-val-options
68   '(;; 3.1.1 Float Style
69     ("style" ("plain" "plaintop" "Plaintop"
70               "ruled" "Ruled"
71               "boxed" "Boxed" "BOXED"
72               "shadowbox" "Shadowbox" "SHADOWBOX"
73               "doublebox" "Doublebox" "DOUBLEBOX"
74               "wshadowbox" "Wshadowbox" "WSHADOWBOX"))
75     ;; 3.1.2 Font Settings
76     ("font" ("scriptsize" "footnotesize" "small" "normalsize" "large"
77              "Large" "normalfont" "up" "it" "sl" "sc" "md" "bf"
78              "rm" "sf" "tt"))
79     ("footfont" ("scriptsize" "footnotesize" "small" "normalsize" "large"
80                  "Large" "normalfont" "up" "it" "sl" "sc" "md" "bf"
81                  "rm" "sf" "tt"))
82     ;; 3.1.3 Position of Caption
83     ("capposition" ("top" "TOP" "bottom" "beside"))
84     ;; 3.1.4 Position of Beside Caption
85     ("capbesideposition" ("left" "right" "inside" "outside"
86                           "top" "bottom" "center"))
87     ;; 3.1.5 Defining The Width of Beside Caption
88     ("capbesidewidth" ("none" "sidefil"))
89     ;; 3.1.6 Defining Width of Object
90     ("floatwidth" ("\\hsize" "\\textwidth" "\\columnwidth" "\\linewidth"))
91     ;; 3.1.7 Other Settings for Beside Captions
92     ("capbesideframe" ("yes" "no"))
93     ;; 3.1.8 Defining Float Foot Position (Legends and Footnotes)
94     ("footposition" ("default" "caption" "bottom"))
95     ;; 3.1.9 Vertical Alignment of Float Elements
96     ("heightadjust" ("all" "caption" "object" "none" "nocaption" "noobject"))
97     ("valign" ("t" "c" "b" "s"))
98     ;; 3.1.10 Facing Layout
99     ("facing" ("yes" "no"))
100     ;; 3.1.11 Object Settings
101     ("objectset" ("justified" "centering" "raggedright" "RaggedRight" "raggedleft"))
102     ;; 3.1.12 Defining Float Margins
103     ("margins" ("centering" "raggedright" "raggedleft"
104                 "hangright" "hanginside" "hangoutside"))
105     ;; 3.1.13 Defining Float Separators
106     ("floatrowsep" ("columnsep" "quad" "qquad" "hfil" "hfill" "none"))
107     ("capbesidesep" ("columnsep" "quad" "qquad" "hfil" "hfill" "none"))
108     ;; 3.1.14 Defining Float Rules/Skips
109     ("precode" ("none" "thickrule" "rule" "lowrule" "captionskip"))
110     ("rowprecode" ("none" "thickrule" "rule" "lowrule" "captionskip"))
111     ("midcode" ("none" "thickrule" "rule" "lowrule" "captionskip"))
112     ("postcode" ("none" "thickrule" "rule" "lowrule" "captionskip"))
113     ("rowpostcode" ("none" "thickrule" "rule" "lowrule" "captionskip"))
114     ;; 3.1.15 Defining Float Frames
115     ("framestyle" ("fbox" "colorbox" "FRcolorbox" "corners"
116                    "doublebox" "shadowbox" "wshadowbox"))
117     ("frameset")
118     ("framearound" ("none" "object" "all" "row" "none"))
119     ("framefit" ("yes" "no"))
120     ("rowfill" ("yes" "no"))
121     ;; 3.1.16 Settings for Colored Frames
122     ("colorframeset")
123     ("colorframecorners")
124     ;; 3.1.17 Defining Float Skips
125     ("captionskip")
126     ("footskip")
127     ;; 3.1.18 Defining Float Footnote Rule's Style
128     ("footnoterule" ("normal" "limited" "fullsize" "none"))
129     ;; 3.1.19 Managing Floats with [H] Placement Option
130     ("doublefloataswide" ("yes" "no"))
131     ("floatHaslist" ("yes" "no"))
132     ;; 7.2.1 Additions in The floatrow Package to longtable package
133     ("LTcapwidth" ("table" "contents")))
134   "Key=value options for floatrow macros and environments.")
135
136 (defvar LaTeX-floatrow-key-val-options-local nil
137   "Buffer-local key=value options for floatrow macros and environments.")
138 (make-variable-buffer-local 'LaTeX-floatrow-key-val-options-local)
139
140 (defvar LaTeX-floatrow-supported-float-types
141   '("figure" "table"                              ; Standard LaTeX
142     "widefigure" "widetable" "widefloat"          ; Standard figure* & table*
143     "wrapfigure" "wraptable" "wrapfloat"          ; wrapfig.sty
144     "rotfigure"  "rottable"  "rotfloat"           ; rotating.sty
145     "widerotfigure" "widerottable" "widerotfloat" ; for 2-col & wide
146     "figurerow"  "tablerow"  "floatrow"           ; inside floatrow env's
147     "capbesidefigure" "capbesidetable"            ; floats with beside captions
148     "capbesidefloat"
149     "longtable"                                   ; longtable.sty
150     "subfigure" "subtable" "sub")                 ; subcaption.sty
151   "List of float types supported by floatrow.sty.")
152
153 ;; Setup for \newfloatcommand
154 (TeX-auto-add-type "floatrow-newfloatcommand" "LaTeX")
155
156 (defvar LaTeX-floatrow-newfloatcommand-regexp
157   '("\\\\newfloatcommand{\\([^}]+\\)}" 1 LaTeX-auto-floatrow-newfloatcommand)
158   "Matches the arguments of \"\\newfloatcommand\" from floatrow.sty.")
159
160 ;; Setup for various \Declare* macros:
161 (TeX-auto-add-type "floatrow-DeclareNewOption" "LaTeX")
162
163 (defvar LaTeX-floatrow-DeclareNewOption-regexp
164   `(,(concat
165       "\\\\Declare"
166       "\\("
167       (mapconcat #'identity
168                  '("FloatStyle"         ; 3.6.1 Float Style Option (style=)
169                    "FloatFont"          ; 3.6.2 Float Font Option (font=)
170                    "FloatVCode"         ; 3.6.3 Option for Float Rules/Skips (precode= etc.)
171                    "ColorBox"           ; 3.6.4 Settings for Colored Frame (colorframeset=)
172                    "CBoxCorners"        ;       colorframecorners=
173                    "ObjectSet"          ; 3.6.5 Object Justification Option (objectset=)
174                    "MarginSet"          ; 3.6.6 Option for Float Box Alignment/Settings (margins=)
175                    "FloatSeparators"    ; 3.6.7 Float Separators Options (floatrowsep=, capbesidesep=)
176                    "FloatFootnoterule") ; 3.6.8 Option for Footnote Rule's Style (footnoterule=)
177                  "\\|")
178       "\\)"
179       "{\\([^}]+\\)}")
180     (0 1 2) LaTeX-auto-floatrow-DeclareNewOption)
181   "Matches the arguments of \"\\Declare*\" from floatrow.sty.")
182
183 ;; Setup for \newseparated(label|ref):
184 (TeX-auto-add-type "floatrow-newseparatedlabel-ref" "LaTeX")
185
186 (defvar LaTeX-floatrow-newseparatedlabel-ref-regexp
187   `(,(concat
188       "\\\\newseparated"
189       "\\(label\\|ref\\)"
190       "{?"
191       "\\\\"
192       "\\([a-zA-Z]+\\)"
193       "}?")
194     (2 1) LaTeX-auto-floatrow-newseparatedlabel-ref)
195   "Matches the arguments \"\\newseparated(label|ref)\" command from floatrow.sty.")
196
197 ;; Setup for \DeclareNewFloatType:
198 (TeX-auto-add-type "floatrow-DeclareNewFloatType" "LaTeX")
199
200 (defvar LaTeX-floatrow-DeclareNewFloatType-regexp
201   '("\\\\DeclareNewFloatType{\\([^}]+\\)}"
202     1 LaTeX-auto-floatrow-DeclareNewFloatType)
203   "Matches the argument of \"\\DeclareNewFloatType\" command from floatrow.sty.")
204
205 ;; Plug them into the machinery.
206 (defun LaTeX-floatrow-auto-prepare ()
207   "Clear various \"LaTeX-floatrow\" variables before parsing."
208   (setq LaTeX-auto-floatrow-newfloatcommand       nil
209         LaTeX-auto-floatrow-DeclareNewOption      nil
210         LaTeX-auto-floatrow-newseparatedlabel-ref nil
211         LaTeX-auto-floatrow-DeclareNewFloatType   nil))
212
213 (defun LaTeX-floatrow-auto-cleanup ()
214   "Process parsed results from floatrow package."
215   ;; Replace initially the way fig & tab env's are inserted:
216   (LaTeX-floatrow-env-init)
217   ;;
218   ;; Process new key=val options:
219   (when (LaTeX-floatrow-DeclareNewOption-list)
220     (LaTeX-floatrow-update-key-val-options))
221   ;;
222   ;; Process new float commands like \ffigbox:
223   (when (LaTeX-floatrow-newfloatcommand-list)
224     (dolist (cmd (mapcar #'car (LaTeX-floatrow-newfloatcommand-list)))
225       (TeX-add-symbols `(,cmd LaTeX-floatrow-arg-floatbox))
226       (when (and (featurep 'font-latex)
227                  (eq TeX-install-font-lock 'font-latex-setup))
228         (font-latex-add-keywords `((,cmd "[[["))
229                                  'textual))))
230   ;;
231   ;; Process new label/ref commands:
232   (when (LaTeX-floatrow-newseparatedlabel-ref-list)
233     (let (floatrow-run-reftex-compile-vars)
234       (dolist (elt (LaTeX-floatrow-newseparatedlabel-ref-list))
235         (let ((cmd (car elt))
236               (type (cadr elt)))
237           (if (string= type "ref")
238               ;; More fun w/ referencing macros:
239               (TeX-add-symbols `(,cmd TeX-arg-ref))
240             ;; Less fun w/ label defining macros.  Add cmd to
241             ;; TeX-symbol-list:
242             (TeX-add-symbols `(,cmd TeX-arg-define-label))
243             ;; For AUCTeX, parse the argument of the new macro and add
244             ;; it to `LaTeX-auto-label':
245             (TeX-auto-add-regexp
246              `(,(concat "\\\\" cmd "{\\([^\n\r%\\{}]+\\)}") 1 LaTeX-auto-label))
247             ;; For RefTeX, append cmd to `reftex-label-regexps and set
248             ;; floatrow-run-reftex-compile-vars to t:
249             (when (and (boundp 'reftex-label-regexps)
250                        (fboundp 'reftex-compile-variables)
251                        (not (string-match
252                              cmd
253                              (mapconcat #'identity reftex-label-regexps "|"))))
254               (add-to-list (make-local-variable 'reftex-label-regexps)
255                            (concat "\\\\" cmd "{\\(?1:[^}]*\\)}") t)
256               (setq floatrow-run-reftex-compile-vars t)))
257           ;; Fontify macros as reference:
258           (when (and (featurep 'font-latex)
259                      (eq TeX-install-font-lock 'font-latex-setup))
260             (font-latex-add-keywords `((,cmd "{"))
261                                      'reference))))
262       ;; Run `reftex-compile-variables' if needed only once:
263       (when floatrow-run-reftex-compile-vars
264         (reftex-compile-variables))))
265   ;;
266   ;; Process new floattypes:
267   (when (LaTeX-floatrow-DeclareNewFloatType-list)
268     (LaTeX-floatrow-arg-declare-new-floattype nil t))
269   ;;
270   ;; Add elements from `LaTeX-floatrow-supported-float-types' to
271   ;; `LaTeX-caption-supported-float-types':
272   (when (boundp 'LaTeX-caption-supported-float-types)
273     (make-local-variable 'LaTeX-caption-supported-float-types)
274     (dolist (float LaTeX-floatrow-supported-float-types)
275       (add-to-list 'LaTeX-caption-supported-float-types float t))) )
276
277 (add-hook 'TeX-auto-prepare-hook #'LaTeX-floatrow-auto-prepare t)
278 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-floatrow-auto-cleanup t)
279 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
280
281 (defun LaTeX-floatrow-update-key-val-options ()
282   "Update buffer-local key-val options before offering for completion."
283   (let ((vcode-keys '("precode" "rowprecode" "midcode" "postcode" "rowpostcode"))
284         (sep-keys '("floatrowsep" "capbesidesep")))
285     (dolist (keyvals (LaTeX-floatrow-DeclareNewOption-list))
286       (let* ((key (cond ((string= (nth 1 keyvals) "FloatStyle")
287                          "style")
288                         ((string= (nth 1 keyvals) "FloatFont")
289                          "font")
290                         ((string= (nth 1 keyvals) "FloatVCode")
291                          "precode")
292                         ((string= (nth 1 keyvals) "ColorBox")
293                          "colorframeset")
294                         ((string= (nth 1 keyvals) "CBoxCorners")
295                          "colorframecorners")
296                         ((string= (nth 1 keyvals) "ObjectSet")
297                          "objectset")
298                         ((string= (nth 1 keyvals) "MarginSet")
299                          "margins")
300                         ((string= (nth 1 keyvals) "FloatSeparators")
301                          "floatrowsep")
302                         ((string= (nth 1 keyvals) "FloatFootnoterule")
303                          "footnoterule")
304                         (t nil)))
305              (val (nth 2 keyvals))
306              (val-match (cadr (assoc key LaTeX-floatrow-key-val-options-local)))
307              (temp (copy-alist LaTeX-floatrow-key-val-options-local))
308              (opts (cond ((string= key "precode")
309                           (dolist (x vcode-keys)
310                             (setq temp (assq-delete-all (car (assoc x temp)) temp)))
311                           temp)
312                          ((string= key "floatrowsep")
313                           (setq temp (dolist (x sep-keys)
314                                        (assq-delete-all (car (assoc x temp)) temp)))
315                           temp)
316                          (t
317                           (assq-delete-all (car (assoc key temp)) temp)))))
318         (cond ((string= key "precode")
319                (dolist (x vcode-keys)
320                  (pushnew (list x (TeX-delete-duplicate-strings (append (list val) val-match)))
321                           opts :test #'equal)))
322               ((string= key "floatrowsep")
323                (dolist (x sep-keys)
324                  (pushnew (list x (TeX-delete-duplicate-strings (append (list val) val-match)))
325                           opts :test #'equal)))
326               (t
327                (pushnew (list key (TeX-delete-duplicate-strings (append (list val) val-match)))
328                         opts :test #'equal)))
329         (setq LaTeX-floatrow-key-val-options-local (copy-alist opts))))))
330
331 (defun LaTeX-floatrow-arg-floatbox (optional)
332   "Query and insert arguments of float box commands from floatrow.sty.
333 If OPTIONAL is non-nil, indicate optional argument during query."
334   ;; Query for the optional arguments; ask for "vertpos" only if
335   ;; "height" is given.  let-bind `TeX-arg-*-brace' for
336   ;; `TeX-argument-insert':
337   (let* ((TeX-arg-opening-brace "[")
338          (TeX-arg-closing-brace "]")
339          (width (completing-read
340                  (TeX-argument-prompt t nil "Width")
341                  (mapcar (lambda (x) (concat TeX-esc (car x)))
342                          (LaTeX-length-list))))
343          (height (completing-read
344                   (TeX-argument-prompt t nil "Height")
345                  (mapcar (lambda (x) (concat TeX-esc (car x)))
346                          (LaTeX-length-list))))
347          (vertpos (if (string= height "")
348                       ""
349                     (completing-read
350                      (TeX-argument-prompt t nil "Vertical alignment")
351                      '("t" "c" "b" "s")))))
352     (TeX-argument-insert width t)
353     ;; Insert an extra pair of brackets if only `height' is given,
354     ;; otherwise it will become `width'
355     (when (and (string= width "")
356                height (not (string= height "")))
357       (insert "[]"))
358     (TeX-argument-insert height t)
359     (TeX-argument-insert vertpos t))
360   ;; Now query for the (short-)caption.  Also check for the
361   ;; float-type; if we're inside (sub)?floatrow*?, then check for the
362   ;; next outer environment:
363   (let* ((currenv (if (string-match "floatrow\\*?\\_>" (LaTeX-current-environment))
364                       (LaTeX-current-environment 2)
365                     (LaTeX-current-environment)))
366          (caption (TeX-read-string
367                    (TeX-argument-prompt optional nil "Caption")))
368          (short-caption
369           (when (>= (length caption) LaTeX-short-caption-prompt-length)
370             (TeX-read-string
371              (TeX-argument-prompt t nil "Short caption")))))
372     (indent-according-to-mode)
373     ;; The final result will look like this with * being point:
374     ;;   \ffigbox{*}{%
375     ;;     \caption{text}%
376     ;;     \label{fig:foo}%
377     ;;   }
378     (insert TeX-grop)
379     (save-excursion
380       ;; We are inside the 1. mandatory arg: Save the pos & insert `}{':
381       (insert TeX-grcl TeX-grop)
382       (if (and caption (not (string= caption "")))
383           (progn
384             ;; If caption, move to EOL, delete any spaces and hide the line end
385             (end-of-line)
386             (delete-horizontal-space)
387             (insert "%")
388             ;; Add a newline and the caption
389             (newline-and-indent)
390             (insert (LaTeX-compose-caption-macro caption short-caption))
391             ;; If we have a caption, then we probably also want a
392             ;; label.  Hide EOL end and proceed to enter a label
393             (insert "%")
394             (newline-and-indent)
395             (when (LaTeX-label currenv 'environment)
396               ;; Move point to end of line and hide EOL
397               (end-of-line)
398               (delete-horizontal-space)
399               (insert "%")
400               (newline-and-indent))
401             ;; Now close the group
402             (insert TeX-grcl)
403             (indent-according-to-mode)
404             (end-of-line))
405         ;; Otherwise, only insert a }
406         (insert TeX-grcl)))))
407
408 (defun LaTeX-floatrow-env-init ()
409   "Replace AUCTeX entries in the variable `LaTeX-environment-list'.
410 After loading the style hook floatrow.el, delete the entries for
411 figure*? and table*? from variable `LaTeX-environment-list' and
412 replace them with the ones offered by the style.  Original
413 entries are available under \"rawfigure*?\" and \"rawtable*?\"."
414   (LaTeX-environment-list)
415   (dolist (env '("figure" "figure*" "table" "table*"))
416           (setq LaTeX-environment-list
417                 (assq-delete-all (car (assoc env LaTeX-environment-list))
418                                  LaTeX-environment-list))
419           (LaTeX-add-environments `(,env LaTeX-floatrow-env-figure)
420                                   `(,(concat "raw" env) LaTeX-floatrow-env-figure-raw))))
421
422 (defun LaTeX-floatrow-env-figure (environment)
423   "Create floating ENVIRONMENT suitable for floatrow macros."
424   (let ((float (and LaTeX-float
425                     (TeX-read-string
426                      (TeX-argument-prompt t nil "Float position")
427                      LaTeX-float))))
428     (LaTeX-insert-environment environment
429                               (unless (zerop (length float))
430                                 (concat LaTeX-optop float LaTeX-optcl)))))
431
432 (defun LaTeX-floatrow-env-figure-raw (env)
433   "Create raw floating ENV with floatrow.sty.
434 Also insert the macro \"\\RawFloats\" when finished with user
435 queries."
436   (let ((environment (TeX-replace-regexp-in-string "raw" "" env)))
437     (LaTeX-env-figure environment)
438     (save-excursion
439       ;; `LaTeX-find-matching-begin' will not work for us as we don't
440       ;; know how user answers queries from AUCTeX, hence we search
441       ;; back for `environment':
442       (re-search-backward (concat "\\\\begin{" environment "}") nil t)
443       (end-of-line)
444       (LaTeX-newline)
445       (indent-according-to-mode)
446       (insert TeX-esc "RawFloats"))))
447
448 (defun LaTeX-floatrow-arg-declare-new-options (optional prompt key)
449   "Query and insert user-defined values to keys provided by floatrow.sty.
450 If OPTIONAL is non-nil, ask for an optional argument and insert
451 it in square brackets.  PROMPT replaces the standard one.  KEY is
452 a string and corresponds to first parsed element in
453 `LaTeX-floatrow-DeclareNewOption-regexp'."
454   (let ((val (TeX-read-string
455               (TeX-argument-prompt optional prompt "New value option"))))
456     (LaTeX-add-floatrow-DeclareNewOptions
457      (list (concat TeX-esc "Declare" key TeX-grop val TeX-grcl)
458            key val))
459     (LaTeX-floatrow-update-key-val-options)
460     (TeX-argument-insert val optional)
461     (TeX-argument-insert
462      (TeX-read-key-val optional LaTeX-floatrow-key-val-options-local) optional)))
463
464 (defun LaTeX-floatrow-arg-newseparatedlabel/ref (optional type)
465   "Query and insert user defined label and reference macros from floatrow.sty.
466 If OPTIONAL is non-nil, insert the argument in brackets.  TYPE is
467 the string \"label\" or \"ref\"."
468   (let ((cmd (TeX-read-string
469               (if (string= type "label")
470                   (TeX-argument-prompt optional nil "Label command: \\" t)
471                 (TeX-argument-prompt optional nil "Reference command: \\" t)))))
472     (LaTeX-add-floatrow-newseparatedlabel-refs (list cmd type))
473     (if (string= type "label")
474         (TeX-add-symbols `(,cmd TeX-arg-define-label))
475       (TeX-add-symbols `(,cmd TeX-arg-ref)))
476     (TeX-argument-insert cmd optional TeX-esc)))
477
478 (defun LaTeX-floatrow-arg-declare-new-floattype (optional &optional cleanup)
479   "Query and insert the first argument of \"DeclareNewFloatType\" macro from floatrow.sty.
480 If OPTIONAL is non-nil, insert the argument in brackets.  If
481 CLEANUP in non-nil, skip the query and insert process as we are
482 inside the function `LaTeX-floatrow-auto-cleanup' and process
483 only the parsed items."
484   (let ((type (if cleanup
485                   (mapcar #'car (LaTeX-floatrow-DeclareNewFloatType-list))
486                 (list (TeX-read-string
487                        (TeX-argument-prompt optional nil "Environment type"))))))
488     ;; If not inside `LaTeX-floatrow-auto-cleanup', add user input to
489     ;; list of new floats and insert it
490     (unless cleanup
491       (LaTeX-add-floatrow-DeclareNewFloatTypes (car type))
492       (TeX-argument-insert (car type) optional))
493     ;; Make the next variables buffer local
494     (make-local-variable 'LaTeX-floatrow-supported-float-types)
495     (when (boundp 'LaTeX-caption-supported-float-types)
496       (make-local-variable 'LaTeX-caption-supported-float-types))
497     ;; Process new float type(s): a) add type to list of known
498     ;; environments incl. "raw" version b) add different flavors of
499     ;; type to `LaTeX-floatrow-supported-float-types' c) check if
500     ;; `LaTeX-caption-supported-float-types' is bound and add
501     ;; different flavors of type to it as well
502     (dolist (elt type)
503       (LaTeX-add-environments `(,elt LaTeX-floatrow-env-figure)
504                               `(,(concat "raw" elt) LaTeX-floatrow-env-figure-raw))
505       (add-to-list 'LaTeX-floatrow-supported-float-types elt t)
506       (add-to-list 'LaTeX-floatrow-supported-float-types (concat "wide" elt) t)
507       (add-to-list 'LaTeX-floatrow-supported-float-types (concat elt "row") t)
508       (add-to-list 'LaTeX-floatrow-supported-float-types (concat "capbeside" elt) t)
509       (when (boundp 'LaTeX-caption-supported-float-types)
510         (add-to-list 'LaTeX-caption-supported-float-types elt t)
511         (add-to-list 'LaTeX-caption-supported-float-types (concat "wide" elt) t)
512         (add-to-list 'LaTeX-caption-supported-float-types (concat elt "row") t)
513         (add-to-list 'LaTeX-caption-supported-float-types (concat "capbeside" elt) t)))))
514
515 (TeX-add-style-hook
516  "floatrow"
517  (lambda ()
518
519    ;; Add floatrow to the parser
520    (TeX-auto-add-regexp LaTeX-floatrow-DeclareNewOption-regexp)
521    (TeX-auto-add-regexp LaTeX-floatrow-newfloatcommand-regexp)
522    (TeX-auto-add-regexp LaTeX-floatrow-newseparatedlabel-ref-regexp)
523    (TeX-auto-add-regexp LaTeX-floatrow-DeclareNewFloatType-regexp)
524
525    ;; Activate the buffer-local version of key-vals
526    (setq LaTeX-floatrow-key-val-options-local
527          (copy-alist LaTeX-floatrow-key-val-options))
528
529    ;; Add pre-defined float commands:
530    (LaTeX-add-floatrow-newfloatcommands
531     "ffigbox" "fcapside" "ttabbox")
532
533    ;; Macros
534    (TeX-add-symbols
535     ;; 2.1 The \floatbox Macro
536     ;; \floatbox[<preamble>]{<captype>}[<width>][<height>][<vert pos>]{<caption>}{<object>}
537     '("floatbox"
538       [ TeX-arg-eval completing-read
539                      (TeX-argument-prompt optional nil "Preamble")
540                      '("\\capbeside" "\\nocapbeside" "\\captop") ]
541       (TeX-arg-eval completing-read
542                     (TeX-argument-prompt optional nil "Float type")
543                     LaTeX-floatrow-supported-float-types)
544       LaTeX-floatrow-arg-floatbox)
545
546     ;; 2.2 Creation of Personal Commands for Float Boxes
547     '("newfloatcommand"
548       (TeX-arg-eval
549        (lambda ()
550          (let ((cmd (TeX-read-string
551                      (TeX-argument-prompt optional nil "Command"))))
552            (LaTeX-add-floatrow-newfloatcommands cmd)
553            (TeX-add-symbols
554             `(,cmd LaTeX-floatrow-arg-floatbox))
555            (format "%s" cmd))))
556       (TeX-arg-eval completing-read
557                     (TeX-argument-prompt optional nil "Float type")
558                     '("figure" "table"))
559       [ 2 ])
560
561     '("renewfloatcommand"
562       (TeX-arg-eval completing-read
563                     (TeX-argument-prompt optional nil "Command")
564                     (LaTeX-floatrow-newfloatcommand-list))
565       (TeX-arg-eval completing-read
566                     (TeX-argument-prompt optional nil "Float type")
567                     '("figure" "table"))
568       [ 2 ])
569
570
571     ;; 2.2.2 Predefined Float Box Commands
572     '("ffigbox"
573       LaTeX-floatrow-arg-floatbox)
574
575     '("ttabbox"
576       LaTeX-floatrow-arg-floatbox)
577
578     '("fcapside"
579       LaTeX-floatrow-arg-floatbox)
580
581     ;; 2.3.1 Mixed Row
582     '("CenterFloatBoxes" 0)
583     '("TopFloatBoxes" 0)
584     '("BottomFloatBoxes" 0)
585     '("PlainFloatBoxes" 0)
586     '("buildFBBOX" 2)
587
588     ;; 3 Float Layout Settings
589     '("floatsetup"
590       [ TeX-arg-eval completing-read
591                      (TeX-argument-prompt optional nil "Float type")
592                      LaTeX-floatrow-supported-float-types ]
593       (TeX-arg-key-val LaTeX-floatrow-key-val-options-local))
594
595     ;; 3.2 Settings for Current Float Environment
596     '("thisfloatsetup"
597       (TeX-arg-key-val LaTeX-floatrow-key-val-options-local))
598
599     ;; 3.3 Clearing of Settings for Current Float Type
600     '("clearfloatsetup"
601       (TeX-arg-eval completing-read
602                      (TeX-argument-prompt optional nil "Float type")
603                      LaTeX-floatrow-supported-float-types))
604
605     ;; 3.4 Temporary Clearing of All Float Settings
606     '("killfloatstyle" 0)
607
608     ;; 3.6.1 Float Style Option (style=)
609     '("DeclareFloatStyle"
610       (LaTeX-floatrow-arg-declare-new-options "New style option"
611                                               "FloatStyle"))
612
613     ;; 3.6.2 Float Font Option (font=)
614     '("DeclareFloatFont"
615       (LaTeX-floatrow-arg-declare-new-options "New font option"
616                                               "FloatFont"))
617
618     ;; 3.6.3 Option for Float Rules/Skips (precode= etc.)
619     '("DeclareFloatVCode"
620       (LaTeX-floatrow-arg-declare-new-options "New rules/skip option"
621                                               "FloatVCode"))
622
623     ;; 3.6.4 Settings for Colored Frame (colorframeset=)
624     '("DeclareColorBox"
625       (LaTeX-floatrow-arg-declare-new-options "New colored frame option"
626                                               "ColorBox"))
627
628     ;; (colorframecorners=)
629     '("DeclareCBoxCorners"
630       (LaTeX-floatrow-arg-declare-new-options "New colored corner option"
631                                               "CBoxCorners"))
632
633     ;; 3.6.5 Object Justification Option (objectset=)
634     '("DeclareObjectSet"
635       (LaTeX-floatrow-arg-declare-new-options "New object justification"
636                                               "ObjectSet"))
637
638     ;; 3.6.6 Option for Float Box Alignment/Settings (margins=)
639     '("DeclareMarginSet"
640       (LaTeX-floatrow-arg-declare-new-options "New alignment option"
641                                               "MarginSet"))
642
643     '("setfloatmargins" 2)
644     '("setfloatmargins*" 2)
645     '("floatfacing" 2)
646     '("floatfacing*" 2)
647     '("floatboxmargins" 2)
648     '("floatrowmargins" 2)
649     '("floatcapbesidemargins" 2)
650
651     ;; 3.6.7 Float Separators Options (floatrowsep=, capbesidesep=)
652     '("DeclareFloatSeparators"
653       (LaTeX-floatrow-arg-declare-new-options "New separator option"
654                                               "FloatSeparators"))
655
656     ;; 3.6.8 Option for Footnote Rule's Style (footnoterule=)
657     '("DeclareFloatFootnoterule"
658       (LaTeX-floatrow-arg-declare-new-options "New footnote rule option"
659                                               "FloatFootnoterule"))
660
661     ;; 4 Creation of New Float Types
662     '("DeclareNewFloatType"
663       (LaTeX-floatrow-arg-declare-new-floattype)
664       (TeX-arg-key-val (("placement" ("tbp" "t" "b" "p"))
665                         ("name")
666                         ("fileext")
667                         ("within" ("chapter" "section" "subsection"))
668                         ("relatedcapstyle" ("yes" "no")))))
669
670     ;; 6.2 Support of The Label-Sublabel References
671     '("newseparatedlabel"
672       (LaTeX-floatrow-arg-newseparatedlabel/ref "label") 2)
673
674     '("newseparatedref"
675       (LaTeX-floatrow-arg-newseparatedlabel/ref "ref") t)
676
677     '("makelabelseparator" t) ) ;; terminate TeX-add-symbols
678
679    ;; Environments
680    (LaTeX-add-environments
681     ;; 2.3 Building Float Row
682     '("floatrow" [ "Number of beside floats" ])
683
684     ;; 6.1 Managing of Float Parts With the subfloatrow Environment
685     '("subfloatrow"  [ "Number of beside floats" ])
686     '("subfloatrow*" [ "Number of beside floats" ]))
687
688    ;; 2.1.1 Float Box Width Equals to The Width of Object Contents
689    (LaTeX-add-lengths "FBwidth" "FBheight" "Xhsize")
690
691    ;; Fontification
692    (when (and (featurep 'font-latex)
693               (eq TeX-install-font-lock 'font-latex-setup))
694      (font-latex-add-keywords '(("floatbox"  "[{[[[")
695                                 ("ffigbox"   "[[[")
696                                 ("ttabbox"   "[[[")
697                                 ("fcapside"  "[[["))
698                               'textual)
699      (font-latex-add-keywords '(("newfloatcommand"           "{{[[")
700                                 ("renewfloatcommand"         "{{[[")
701                                 ("buildFBBOX"                "{{")
702                                 ("floatsetup"                "[{")
703                                 ("thisfloatsetup"            "{")
704                                 ("clearfloatsetup"           "{")
705                                 ("killfloatstyle"            "")
706                                 ("DeclareFloatStyle"         "{{")
707                                 ("DeclareFloatFont"          "{{")
708                                 ("DeclareFloatVCode"         "{{")
709                                 ("DeclareColorBox"           "{{")
710                                 ("DeclareCBoxCorners"        "{{")
711                                 ("DeclareObjectSet"          "{{")
712                                 ("DeclareMarginSet"          "{{")
713                                 ("DeclareFloatSeparators"    "{{")
714                                 ("DeclareFloatFootnoterule"  "{{")
715                                 ("newseparatedlabel"         "{{{")
716                                 ("newseparatedref"           "{{")
717                                 ("makelabelseparator"        "{")
718                                 ("DeclareNewFloatType"       "{{")
719                                 ("RawFloats"                 ""))
720                               'function)))
721  LaTeX-dialect)
722
723 (defvar LaTeX-floatrow-package-options nil
724   "Prompt for package options for the floatrow package.")
725
726 ;;; floatrow.el ends here