"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/bicaption.el" (18 Oct 2020, 8051 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "bicaption.el": 12.2_vs_12.3.

    1 ;;; bicaption.el --- AUCTeX style for `bicaption.sty' (v1.1-158)
    2 
    3 ;; Copyright (C) 2016--2020 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 `bicaption.sty' (v1.1-158) from
   30 ;; 2016/03/27.  `bicaption.sty' is part of TeXLive.
   31 
   32 ;; If things do not work or when in doubt, press `C-c C-n'.  Comments
   33 ;; for improvement are welcome.
   34 
   35 ;;; Code:
   36 
   37 ;; Needed for compiling `LaTeX-check-insert-macro-default-style':
   38 (require 'latex)
   39 
   40 ;; Silence the compiler:
   41 (declare-function font-latex-add-keywords
   42           "font-latex"
   43           (keywords class))
   44 
   45 (declare-function LaTeX-babel-active-languages "babel" ())
   46 (declare-function LaTeX-polyglossia-active-languages "polyglossia" ())
   47 
   48 (defvar LaTeX-caption-supported-float-types)
   49 (defvar LaTeX-caption-key-val-options)
   50 
   51 (defvar LaTeX-bicaption-key-val-options
   52   '(("bi-lang" ("first" "second" "both"))
   53     ("bi-singlelinecheck" ("false" "no" "off" "0" "true" "yes" "on" "1"))
   54     ("bi-slc" ("false" "no" "off" "0" "true" "yes" "on" "1"))
   55     ("bi-swap" ("false" "no" "off" "0" "true" "yes" "on" "1"))
   56     ("listtype+"))
   57   "Key=value options for bicaption macros.")
   58 
   59 (defun LaTeX-arg-bicaption-bicaption (optional &optional prompt star cap-box label-inside)
   60   "Query for the arguments of \"\\bicaption\" incl. a label and insert them.
   61 PROMPT replaces the standard one.  If STAR is non-nil, then do
   62 not query for a \\label and short captions, insert only captions.
   63 If CAP-BOX is non-nil, also query and include optional arguments
   64 for the box command.  If LABEL-INSIDE is non-nil, insert \\label
   65 inside the first mandatory argument, otherwise after all
   66 arguments."
   67   ;; \bicaption   [<list entry #1>]{<heading #1>}[<list entry #2>]{<heading #2>}
   68   ;; \bicaptionbox[<list entry #1>]{<heading #1>}[<list entry #2>]{<heading #2>}
   69   ;;              [<width>][<inner-pos>]{<contents>}
   70   (let* (;; \bisubcaption needs an environment, "minipage" will be
   71      ;; popular.  If so, check next higher environment to find out
   72      ;; where we are
   73      (currenv (if (string= (LaTeX-current-environment) "minipage")
   74               (LaTeX-current-environment 2)
   75             (LaTeX-current-environment)))
   76      (captionI (TeX-read-string
   77             (TeX-argument-prompt
   78              optional (when prompt
   79                 (concat "1. " prompt "bicaption"))
   80              "1. bicaption")))
   81      (short-captionI
   82       (when (and (not star)
   83              (>= (length captionI) LaTeX-short-caption-prompt-length))
   84         (TeX-read-string
   85          (TeX-argument-prompt t (when prompt
   86                       (concat "Short 1. " prompt "bicaption"))
   87                   "Short 1. bicaption"))))
   88      (captionII (TeX-read-string
   89              (TeX-argument-prompt
   90               optional (when prompt
   91                  (concat "2. " prompt "bicaption"))
   92               "2. bicaption")))
   93      (short-captionII
   94       (when (and (not star)
   95              (>= (length captionII) LaTeX-short-caption-prompt-length))
   96         (TeX-read-string
   97          (TeX-argument-prompt t (when prompt
   98                       (concat "Short 2. " prompt "bicaption"))
   99                   "Short 2. bicaption")))))
  100     (indent-according-to-mode)
  101     ;; Insert short & regular 1. caption
  102     (when (and short-captionI (not (string= short-captionI "")))
  103       (insert LaTeX-optop short-captionI LaTeX-optcl))
  104     (insert TeX-grop captionI)
  105     ;; For \bi(sub)?captionbox, the label must be inserted here
  106     (when (and label-inside (not star))
  107       (LaTeX-label currenv 'environment))
  108     (insert TeX-grcl)
  109     (LaTeX-fill-paragraph)
  110     (LaTeX-newline)
  111     (indent-according-to-mode)
  112     ;; Insert short & regular 2. caption
  113     (when (and short-captionII (not (string= short-captionII "")))
  114       (insert LaTeX-optop short-captionII LaTeX-optcl))
  115     (insert TeX-grop captionII TeX-grcl)
  116     ;; Insert width & pos in case of captionbox macros:
  117     (when cap-box
  118       (let* ((TeX-arg-opening-brace "[")
  119          (TeX-arg-closing-brace "]")
  120          (last-optional-rejected nil)
  121          (width (LaTeX-check-insert-macro-default-style
  122              (completing-read (TeX-argument-prompt t nil "Width")
  123                       (mapcar (lambda (elt) (concat TeX-esc (car elt)))
  124                           (LaTeX-length-list)))))
  125          (last-optional-rejected (or (not width)
  126                      (and width (string= width ""))))
  127          (inpos (LaTeX-check-insert-macro-default-style
  128              (if (and width (not (string-equal width "")))
  129              (completing-read (TeX-argument-prompt t nil "Inner position")
  130                       '("c" "l" "r" "s"))
  131                ""))))
  132     (and width (TeX-argument-insert width t))
  133     (and inpos (TeX-argument-insert inpos t))))
  134     (LaTeX-fill-paragraph)
  135     ;; Insert label -- a new line is inserted only if label is there:
  136     (when (and (not label-inside) (not star)
  137            (save-excursion (LaTeX-label currenv 'environment)))
  138       (LaTeX-newline)
  139       (indent-according-to-mode)
  140       (end-of-line))))
  141 
  142 (defun LaTeX-arg-bicaption-captionsetup (optional)
  143   "Query for 2 arguments for \"\\captionsetup\" with bicaption.sty loaded.
  144 When OPTIONAL is non-nil, include both as optional arguments in
  145 square brackets."
  146   (let* ((flttype (completing-read (TeX-argument-prompt optional nil "Float type")
  147                   LaTeX-caption-supported-float-types))
  148      (biflt (if (and (not (or (string= flttype "bi")
  149                   (string= flttype "bi-first")
  150                   (string= flttype "bi-second")))
  151              flttype (not (string= flttype "")))
  152             (completing-read (TeX-argument-prompt optional nil "Bicaption type")
  153                      '("bi" "bi-first" "bi-second"))
  154           "")))
  155     (TeX-argument-insert flttype optional)
  156     (TeX-argument-insert biflt optional)))
  157 
  158 (TeX-add-style-hook
  159  "bicaption"
  160  (lambda ()
  161 
  162    ;; Load caption.el:
  163    (TeX-run-style-hooks "caption")
  164 
  165    ;; Macros
  166    (TeX-add-symbols
  167     '("bicaption"        (LaTeX-arg-bicaption-bicaption))
  168     '("bicaption*"       (LaTeX-arg-bicaption-bicaption  nil    t))
  169     '("bicaptionbox"     (LaTeX-arg-bicaption-bicaption  nil   nil  t   t) t)
  170     '("bicaptionbox*"    (LaTeX-arg-bicaption-bicaption  nil    t   t)     t)
  171     '("bisubcaption"     (LaTeX-arg-bicaption-bicaption "sub-"))
  172     '("bisubcaption*"    (LaTeX-arg-bicaption-bicaption "sub-"  t))
  173     '("bisubcaptionbox"  (LaTeX-arg-bicaption-bicaption "sub-" nil  t   t) t)
  174     '("bisubcaptionbox*" (LaTeX-arg-bicaption-bicaption "sub-"  t   t   t) t))
  175 
  176    ;; \bi(sub)?caption(box)? macros should get their own lines
  177    (LaTeX-paragraph-commands-add-locally '("bicaption"    "bicaptionbox"
  178                        "bisubcaption" "bisubcaptionbox"))
  179 
  180    ;; Fontification
  181    (when (and (featurep 'font-latex)
  182           (eq TeX-install-font-lock 'font-latex-setup))
  183      (font-latex-add-keywords '(("bicaption"       "*[{[{")
  184                 ("bicaptionbox"    "*[{[{[[")
  185                 ("bisubcaption"    "*[{[{")
  186                 ("bisubcaptionbox" "*[{[{[["))
  187                   'textual)))
  188  LaTeX-dialect)
  189 
  190 (defun LaTeX-bicaption-package-options ()
  191   "Prompt for package options for the bicaption package."
  192   (TeX-load-style "caption")
  193   (TeX-read-key-val t
  194             (append
  195              `(,(list "language"
  196                   (cond ((and (member "babel" (TeX-style-list))
  197                       (LaTeX-babel-active-languages))
  198                      (butlast (LaTeX-babel-active-languages)))
  199                     ((and (member "polyglossia" (TeX-style-list))
  200                       (LaTeX-polyglossia-active-languages))
  201                      (butlast (LaTeX-babel-active-languages)))
  202                     (t nil))))
  203              LaTeX-bicaption-key-val-options
  204              LaTeX-caption-key-val-options)))
  205 
  206 ;;; bicaption.el ends here