>From 05c1daf6d4f347ad5f22e752c994a80540bff803 Mon Sep 17 00:00:00 2001
From: Arash Esbati
Date: Sat, 22 Aug 2015 11:29:27 +0200
Subject: [PATCH 2/5] Add support for \captionbox[*].
* style/caption.el ("caption"): Add support for undocumented
macros `\captionbox[*]'.
(LaTeX-arg-caption-captionbox): New function.
---
ChangeLog | 4 ++++
style/caption.el | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index c60975e..4a4812e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2015-08-22 Arash Esbati
+ * style/caption.el ("caption"): Add support for undocumented
+ macros `\captionbox[*]'.
+ (LaTeX-arg-caption-captionbox): New function.
+
* style/array.el ("array"): Add fontification for
`\newcolumntype'.
diff --git a/style/caption.el b/style/caption.el
index 0ec6c29..3ceb2c6 100644
--- a/style/caption.el
+++ b/style/caption.el
@@ -190,6 +190,59 @@ suffix of the command."
format name))
(TeX-argument-insert name optional)))
+;; Support for an undocumented feature of caption.sty:
+;; `\captionbox' sets the width of the caption equal to the width of
+;; the contents (a feature provided e.g. by `threeparttable.sty').
+;; The starred version typesets the caption without label and without
+;; entry to the list of figures or tables.
+
+;; The first mandatory argument {} contains the caption text
+;; and the label. For now, we check if `LaTeX-label-function' is eq
+;; to `reftex-label' and run it, otherwise run
+;; `TeX-read-label'. (Thanks to M. Giordano for implementing this
+;; function!)
+
+;; Syntax:
+;; \captionbox[]{}[][]{}
+;; \captionbox*{}[][]{}
+
+(defun LaTeX-arg-caption-captionbox (optional &optional star prompt)
+ "Query for the arguments of `\\captionbox' incl. a label and
+insert them. If the STAR is t, then do not query for a `\\label'
+and insert only a caption."
+ (let* ((caption (TeX-read-string (TeX-argument-prompt optional prompt "Caption")))
+ (label (unless star (if (and (boundp 'LaTeX-label-function)
+ LaTeX-label-function
+ (fboundp LaTeX-label-function)
+ (eq LaTeX-label-function 'reftex-label))
+ (funcall LaTeX-label-function nil t)
+ (TeX-read-label optional "Label" t))))
+ (width (completing-read (TeX-argument-prompt t prompt "Width")
+ (mapcar (lambda(elt) (concat TeX-esc (car elt)))
+ (LaTeX-length-list))))
+ (inpos (completing-read (TeX-argument-prompt t prompt "Inner position")
+ '("c" "l" "r" "s")))
+ (heading (if star
+ (format "%s" caption)
+ (format "%s\\label{%s}" caption label))))
+ (LaTeX-indent-line)
+ (TeX-argument-insert heading optional)
+ (cond (;; 2 optional args
+ (and width (not (string-equal width ""))
+ inpos (not (string-equal inpos "")))
+ (insert (format "[%s][%s]" width inpos)))
+ (;; 1st empty opt. arg, 2nd opt. arg
+ (and (string-equal width "")
+ inpos (not (string-equal inpos "")))
+ (insert (format "[][%s]" inpos)))
+ (;; 1st opt. arg, 2nd empty opt. arg
+ (and width (not (string-equal width ""))
+ (string-equal inpos ""))
+ (insert (format "[%s]" width)))
+ (t ; Do nothing if both empty
+ (ignore)))
+ (LaTeX-fill-paragraph)))
+
(TeX-add-style-hook
"caption"
(lambda ()
@@ -240,6 +293,10 @@ suffix of the command."
(TeX-arg-eval completing-read (TeX-argument-prompt nil nil "Float type")
LaTeX-caption-supported-float-types))
+ '("captionbox" ["List entry"] (LaTeX-arg-caption-captionbox) t)
+
+ '("captionbox*" (LaTeX-arg-caption-captionbox t) t)
+
'("ContinuedFloat" 0)
'("DeclareCaptionFont"
@@ -286,7 +343,8 @@ suffix of the command."
(eq TeX-install-font-lock 'font-latex-setup))
(font-latex-add-keywords '(("caption" "*[{")
("captionlistentry" "[{")
- ("captionof" "*[{"))
+ ("captionof" "*[{")
+ ("captionbox" "*[{[[{"))
'textual)
(font-latex-add-keywords '(("captionsetup" "*[{")
("clearcaptionsetup" "*[{")
--
2.5.0