[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex d6890e8 04/36: Improve caption and label inserti
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex d6890e8 04/36: Improve caption and label insertion in style/subcaption.el |
Date: |
Thu, 22 Dec 2016 13:08:10 +0000 (UTC) |
branch: externals/auctex
commit d6890e8c7d2fd925855e30d861887b0cf417dbb2
Author: Arash Esbati <address@hidden>
Commit: Arash Esbati <address@hidden>
Improve caption and label insertion in style/subcaption.el
* style/subcaption.el (LaTeX-arg-subcaption-subcaption): Delete
unused prompt argument. Ask for short caption acc. to the value
of `LaTeX-short-caption-prompt-length'. Fill the inserted
sub-caption before using `LaTeX-label' to insert the label.
(LaTeX-arg-subcaption-subcaptionbox): Delete unused prompt
argument. Ask for short caption acc. to the value of
`LaTeX-short-caption-prompt-length'. Use `LaTeX-label' to insert
the label. Use `TeX-argument-insert' instead of conditional
insert.
("subcaption"): Append package environments to `LaTeX-label-alist'.
("subcaption"): Do not fontify the last argument of
\subcaptionbox. Fontification happens within
\begin...\end{tabular} or \includegraphics.
---
style/subcaption.el | 102 +++++++++++++++++++++++++++++++--------------------
1 file changed, 63 insertions(+), 39 deletions(-)
diff --git a/style/subcaption.el b/style/subcaption.el
index 6205366..7a116c2 100644
--- a/style/subcaption.el
+++ b/style/subcaption.el
@@ -36,50 +36,67 @@
"Key=value options for subcaption package. This key takes the
same values as \"labelformat\" from caption package.")
-(defun LaTeX-arg-subcaption-subcaption (optional &optional star prompt)
- "Query for the arguments of \\subcaption incl. a label and
-insert them. If STAR is non-nil, then do not query for the lof entry
-and \\label and insert only a caption."
- (let ((lof (unless star
- (TeX-read-string
- (TeX-argument-prompt t prompt "List entry"))))
- (caption (TeX-read-string
- (TeX-argument-prompt optional prompt "Sub-caption"))))
- (LaTeX-indent-line)
- (when (and lof (not (string-equal lof "")))
- (insert LaTeX-optop lof LaTeX-optcl))
+(defun LaTeX-arg-subcaption-subcaption (optional &optional star)
+ "Query for the arguments of \"\\subcaption\" incl. a label and insert them.
+If STAR is non-nil, then do not query for a \\label and a short
+caption, insert only a caption."
+ (let* (;; \subcaption needs an environment, "minipage" will be
+ ;; popular. If so, check next higher environment to find out
+ ;; where we are
+ (currenv (if (string= (LaTeX-current-environment) "minipage")
+ (LaTeX-current-environment 2)
+ (LaTeX-current-environment)))
+ (caption (TeX-read-string
+ (TeX-argument-prompt optional nil "Sub-caption")))
+ (short-caption
+ (when (and (not star)
+ (>= (length caption) LaTeX-short-caption-prompt-length))
+ (TeX-read-string
+ (TeX-argument-prompt t nil "Short caption")))))
+ (indent-according-to-mode)
+ (when (and short-caption (not (string= short-caption "")))
+ (insert LaTeX-optop short-caption LaTeX-optcl))
(insert TeX-grop caption TeX-grcl)
+ ;; Fill the \subcaption paragraph before inserting the \label:
+ (LaTeX-fill-paragraph)
(unless star
(LaTeX-newline)
- (LaTeX-indent-line)
- (TeX-insert-macro "label"))))
-
-(defun LaTeX-arg-subcaption-subcaptionbox (optional &optional star prompt)
- "Query for the arguments of \\subcaptionbox incl. a label and
-insert them. If STAR is non-nil, then do not query for a \\label and
-insert only a caption."
- (let ((caption (TeX-read-string
- (TeX-argument-prompt optional prompt "Sub-caption"))))
- (LaTeX-indent-line)
+ (indent-according-to-mode)
+ (LaTeX-label currenv 'environment))))
+
+(defun LaTeX-arg-subcaption-subcaptionbox (optional &optional star)
+ "Query for the arguments of \"\\subcaptionbox\" incl. a label and insert
them.
+If STAR is non-nil, then do not query for a \\label and a short
+caption, insert only a caption."
+ (let* ((currenv (LaTeX-current-environment))
+ (caption (TeX-read-string
+ (TeX-argument-prompt optional nil "Sub-caption")))
+ (short-caption
+ (when (and (not star)
+ (>= (length caption) LaTeX-short-caption-prompt-length))
+ (TeX-read-string
+ (TeX-argument-prompt t nil "Short Sub-caption")))))
+ (indent-according-to-mode)
+ (when (and short-caption (not (string= short-caption "")))
+ (insert LaTeX-optop short-caption LaTeX-optcl))
(insert TeX-grop caption)
- (unless star (TeX-insert-macro "label"))
+ (unless star (LaTeX-label currenv 'environment))
(insert TeX-grcl))
- (let* ((width (completing-read (TeX-argument-prompt t prompt "Width")
+ (let* ((TeX-arg-opening-brace "[")
+ (TeX-arg-closing-brace "]")
+ (width (completing-read (TeX-argument-prompt t nil "Width")
(mapcar (lambda (elt) (concat TeX-esc (car
elt)))
(LaTeX-length-list))))
- (inpos (when (and width (not (string-equal width "")))
- (completing-read (TeX-argument-prompt t prompt "Inner
position")
- '("c" "l" "r" "s")))))
- (cond (;; 2 optional args
- (and width (not (string-equal width ""))
- inpos (not (string-equal inpos "")))
- (insert (format "[%s][%s]" width 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)))))
+ (inpos (if (and width (not (string-equal width "")))
+ (completing-read (TeX-argument-prompt t nil "Inner
position")
+ '("c" "l" "r" "s"))
+ "")))
+ (TeX-argument-insert width t)
+ (TeX-argument-insert inpos t))
+ ;; Fill the paragraph before inserting {}. We use this function
+ ;; since we add \subcaption to `paragraph-start' in the style hook
+ ;; below.
+ (LaTeX-fill-paragraph))
(TeX-add-style-hook
"subcaption"
@@ -96,7 +113,7 @@ insert only a caption."
;; Basic commands
'("subcaption" (LaTeX-arg-subcaption-subcaption))
'("subcaption*" (LaTeX-arg-subcaption-subcaption t))
- '("subcaptionbox" ["List entry"] (LaTeX-arg-subcaption-subcaptionbox) t)
+ '("subcaptionbox" (LaTeX-arg-subcaption-subcaptionbox) t)
'("subcaptionbox*" (LaTeX-arg-subcaption-subcaptionbox t) t)
'("subref" TeX-arg-ref)
;; \subref* is only available with hyperref.sty loaded, we don't
@@ -124,11 +141,18 @@ insert only a caption."
(TeX-argument-prompt nil nil "Type")
'("figure" "table"))))
+ ;; Everything starting with \subcaption should get its own line
+ (LaTeX-paragraph-commands-add-locally "subcaption")
+
;; The subfigure & subtable environments
(LaTeX-add-environments
'("subfigure" LaTeX-env-minipage)
'("subtable" LaTeX-env-minipage))
+ ;; Append them to `LaTeX-label-alist':
+ (add-to-list 'LaTeX-label-alist '("subfigure" . LaTeX-figure-label) t)
+ (add-to-list 'LaTeX-label-alist '("subtable" . LaTeX-table-label) t)
+
;; Introduce env's to RefTeX if loaded
(when (fboundp 'reftex-add-label-environments)
(reftex-add-label-environments
@@ -139,7 +163,7 @@ insert only a caption."
(when (and (featurep 'font-latex)
(eq TeX-install-font-lock 'font-latex-setup))
(font-latex-add-keywords '(("subcaption" "*[{")
- ("subcaptionbox" "*[{[[{")
+ ("subcaptionbox" "*[{[[")
("phantomcaption" "")
("phantomsubcaption" ""))
'textual)
- [elpa] externals/auctex updated (1b5875c -> 2e7ca50), Tassilo Horn, 2016/12/22
- [elpa] externals/auctex b59075b 06/36: Do not insert a new line if \label is omitted, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex cb6bc11 07/36: Add support for style/bicaption.el to style/caption.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex c5d1d02 13/36: Append entry to `LaTeX-label-alist' for new "verbatim" floats, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex c265fc9 02/36: Add new style/FiraMono.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 2f75f51 17/36: Add support for LaTeX core command \textsubscript, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 6ec185e 16/36: Do not spell-check arguments of \LTXtable, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 94db238 05/36: Improve caption and label insertion in style/caption.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex eb748ea 18/36: Fix query for defined colors in style/ntheorem.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 8a14439 11/36: Add style file for subfiles package., Tassilo Horn, 2016/12/22
- [elpa] externals/auctex d6890e8 04/36: Improve caption and label insertion in style/subcaption.el,
Tassilo Horn <=
- [elpa] externals/auctex 42dd1f1 22/36: Support RefTeX with `reftex-add-index-macros' in style/splitidx.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 945035c 24/36: Append tabular[xy] to `LaTeX-item-list', Tassilo Horn, 2016/12/22
- [elpa] externals/auctex e4aba95 21/36: Support RefTeX with `reftex-add-label-environments' in style/mathtools.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex f04e5f7 09/36: Add style file for amsfonts package, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex c4cb166 33/36: Add style/ directory to TeX-style-path for tests, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 25e4f33 03/36: Add new style/FiraSans.el, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex c073d3e 12/36: Insert \label inside the mandatory argument of \caption, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 0d26aba 01/36: Suggest to display warnings when there are no errors in error overview, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 6a31d4e 14/36: Support new floats defined with newfloat package, Tassilo Horn, 2016/12/22
- [elpa] externals/auctex 29ae5fb 15/36: Add \LTXtable to list of file-loading commands, Tassilo Horn, 2016/12/22