"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/beamer.el" (18 Oct 2020, 13734 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 "beamer.el": 12.2_vs_12.3.

    1 ;;; beamer.el --- AUCTeX style for the latex-beamer class
    2 
    3 ;; Copyright (C) 2003-2005, 2008, 2013-2016, 2018, 2020 Free Software Foundation, Inc.
    4 
    5 ;; Author: Thomas Baumann <thomas.baumann@ch.tum.de>
    6 ;; Created: 2003-12-20
    7 ;; Keywords: tex
    8 
    9 ;; This file is part of AUCTeX.
   10 
   11 ;; AUCTeX is free software; you can redistribute it and/or modify it
   12 ;; under the terms of the GNU General Public License as published by
   13 ;; the Free Software Foundation; either version 3, or (at your option)
   14 ;; any later version.
   15 
   16 ;; AUCTeX is distributed in the hope that it will be useful, but
   17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
   18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19 ;; General Public License for more details.
   20 
   21 ;; You should have received a copy of the GNU General Public License
   22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
   23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   24 ;; 02110-1301, USA.
   25 
   26 ;;; Commentary:
   27 
   28 ;; This file adds support for the latex-beamer class.
   29 
   30 ;;; Code:
   31 
   32 ;; Silence the compiler:
   33 (declare-function font-latex-add-keywords
   34           "font-latex"
   35           (keywords class))
   36 
   37 (defun LaTeX-beamer-after-insert-env (env start _end)
   38   "Do beamer-specific stuff after the insertion of an environment."
   39   ;; Add `fragile' as an optional argument to the frame environment if
   40   ;; a verbatim environment is inserted.
   41   (when (and (TeX-member env (LaTeX-verbatim-environments) 'string-equal)
   42          (save-excursion
   43            (goto-char start)
   44            (string-equal (LaTeX-current-environment) "frame")))
   45     (save-excursion
   46       (when (re-search-backward "\\\\begin[ \t]*{frame}" nil t)
   47     (let ((end-of-begin (match-end 0)))
   48       (goto-char end-of-begin)
   49       (while (forward-comment 1))
   50       (if (eq (char-after) (string-to-char LaTeX-optop))
   51           (progn
   52         (forward-char)
   53         (insert "fragile")
   54         (unless (looking-at (concat "[ \t]*" LaTeX-optcl))
   55           (insert ",")))
   56         (goto-char end-of-begin)
   57         (insert "[fragile]")))))))
   58 
   59 (defvar LaTeX-beamer-frametitle-history nil
   60   "History of frame titles in beamer.")
   61 
   62 (TeX-add-style-hook
   63  "beamer"
   64  (lambda ()
   65    (add-hook 'LaTeX-after-insert-env-hooks 'LaTeX-beamer-after-insert-env nil t)
   66 
   67    (TeX-run-style-hooks "amsmath" "amssymb" "amsthm" "color" "geometry"
   68             "hyperref" "inputenc" "translator" "xcolor")
   69 
   70    (unless LaTeX-beamer-section-labels-flag
   71      (make-local-variable 'LaTeX-section-hook)
   72      (setq LaTeX-section-hook
   73        '(LaTeX-section-heading
   74          LaTeX-section-title
   75          LaTeX-section-section)))
   76 
   77    (setq LaTeX-item-list
   78      (append '(("itemize" . LaTeX-item-beamer)
   79            ("enumerate" . LaTeX-item-beamer))
   80          LaTeX-item-list))
   81 
   82    (setq LaTeX-default-document-environment "frame")
   83 
   84    (LaTeX-paragraph-commands-add-locally "frametitle")
   85 
   86    (TeX-add-symbols
   87     '("alert" [ TeX-arg-beamer-overlay-spec ] 1)
   88     '("alt" [ TeX-arg-beamer-overlay-spec ] 2)
   89     '("beamerbutton" 1)
   90     '("beamergotobutton" 1)
   91     '("beamerreturnbutton" 1)
   92     '("beamerskipbutton" 1)
   93     '("frame" TeX-arg-beamer-frametitle)
   94     '("frametitle"
   95       (TeX-arg-eval TeX-read-string "Title: " nil 'LaTeX-beamer-frametitle-history))
   96     '("hyperlink" [ TeX-arg-beamer-overlay-spec ] 2)
   97     '("hyperlinkslideprev" [ TeX-arg-beamer-overlay-spec ] 1)
   98     '("hyperlinkslidenext" [ TeX-arg-beamer-overlay-spec ] 1)
   99     '("hyperlinkframestart" [ TeX-arg-beamer-overlay-spec ] 1)
  100     '("hyperlinkframeend" [ TeX-arg-beamer-overlay-spec ] 1)
  101     '("hyperlinkframestartnext" [ TeX-arg-beamer-overlay-spec ] 1)
  102     '("hyperlinkframeendprev" [ TeX-arg-beamer-overlay-spec ] 1)
  103     '("hyperlinkpresentationstart" [ TeX-arg-beamer-overlay-spec ] 1)
  104     '("hyperlinkpresentationend" [ TeX-arg-beamer-overlay-spec ] 1)
  105     '("hyperlinkappendixstart" [ TeX-arg-beamer-overlay-spec ] 1)
  106     '("hyperlinkappendixend" [ TeX-arg-beamer-overlay-spec ] 1)
  107     '("hyperlinkdocumentstart" [ TeX-arg-beamer-overlay-spec ] 1)
  108     '("hyperlinkdocumentend" [ TeX-arg-beamer-overlay-spec ] 1)
  109     '("hypertarget" [ TeX-arg-beamer-overlay-spec ] 2)
  110     '("institute" 1)
  111     '("invisible" [ TeX-arg-beamer-overlay-spec ] 1)
  112     '("label" [ TeX-arg-beamer-overlay-spec ] 1)
  113     '("logo" 1)
  114     '("note" TeX-arg-beamer-note 1)
  115     '("only" [ TeX-arg-beamer-overlay-spec ] 1)
  116     '("onslide" [ TeX-arg-beamer-overlay-spec ])
  117     '("partpage")
  118     '("pause" ["Slide number"])
  119     '("structure" [ TeX-arg-beamer-overlay-spec ] 1)
  120     '("temporal" [ TeX-arg-beamer-overlay-spec ] 3)
  121     '("titlepage")
  122     '("titlegraphic" 1)
  123     '("uncover" [ TeX-arg-beamer-overlay-spec ] 1)
  124     '("usetheme" LaTeX-arg-beamer-theme)
  125     '("useinnertheme" LaTeX-arg-beamer-inner-theme)
  126     '("useoutertheme" LaTeX-arg-beamer-outer-theme)
  127     '("usecolortheme" LaTeX-arg-beamer-color-theme)
  128     '("usefonttheme" LaTeX-arg-beamer-font-theme)
  129     '("usetheme" LaTeX-arg-beamer-theme)
  130     '("visible" [ TeX-arg-beamer-overlay-spec ] 1))
  131 
  132    (LaTeX-add-environments
  133     '("actionenv")
  134     '("alertblock" 1)
  135     '("beamerboxesrounded" 1)
  136     '("block" (lambda (env &rest ignore)
  137         (LaTeX-insert-environment
  138          env (format "{%s}" (TeX-read-string "Title: ")))))
  139     '("column" "Width")
  140     "columns"
  141     "columnsonlytextwidth"
  142     '("exampleblock" 1)
  143     '("frame"  (lambda (env &rest ignore)
  144          (let ((title (TeX-read-string "(Optional) Title: " nil
  145                            'LaTeX-beamer-frametitle-history)))
  146            (LaTeX-insert-environment env)
  147            (unless (zerop (length title))
  148              (save-excursion
  149                (LaTeX-find-matching-begin)
  150                (end-of-line)
  151                (LaTeX-newline)
  152                (insert (format "\\frametitle{%s}" title))
  153                ;; This works because \frametitle is a
  154                ;; paragraph command.
  155                (backward-char)
  156                (LaTeX-fill-paragraph))))))
  157     '("onlyenv" (lambda (env &rest ignore)
  158           (LaTeX-insert-environment
  159            env
  160            (let ((overlay (TeX-read-string "(Optional) Overlay: ")))
  161              (unless (zerop (length overlay))
  162                (format "<%s>" overlay))))))
  163     '("overlayarea" "Area width" "Area height")
  164     '("overprint"  (lambda (env &rest ignore)
  165              (LaTeX-insert-environment
  166               env
  167               (let ((width (TeX-read-string "(Optional) Area width: ")))
  168             (unless (zerop (length width))
  169               (format "[%s]" width))))))
  170     "semiverbatim")
  171 
  172    (LaTeX-largest-level-set "section")
  173    (LaTeX-add-counters "lecture" "part" "section" "subsection" "subsubsection"
  174                "subsectionslide" "framenumber" "figure" "table"
  175                "beamerpauses")
  176    (LaTeX-add-pagestyles "navigation")
  177    (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
  178         '("semiverbatim" current-indentation) t)
  179    (add-to-list 'LaTeX-verbatim-environments-local "semiverbatim")
  180 
  181    ;; Fontification
  182    (when (and (featurep 'font-latex)
  183           (eq TeX-install-font-lock 'font-latex-setup))
  184      (font-latex-add-keywords '(("title" "[{")
  185                 ("subtitle" "[{")
  186                 ("author" "[{")
  187                 ("date" "[{")
  188                 ("frametitle" "<[{")) 'slide-title)))
  189  LaTeX-dialect)
  190 
  191 (defun TeX-arg-beamer-overlay-spec (optional &optional prompt)
  192   "Prompt for overlay specification.
  193 If OPTIONAL is non-nil, insert the specification only if
  194 non-empty and enclosed in \"<>\".  PROMPT replaces the standard
  195 one."
  196   (let ((TeX-arg-opening-brace "<")
  197         (TeX-arg-closing-brace ">"))
  198     (TeX-argument-insert
  199      (TeX-read-string
  200       (TeX-argument-prompt optional prompt "Overlay"))
  201      optional)
  202     (indent-according-to-mode)))
  203 
  204 (defun TeX-arg-beamer-frametitle (_optional &optional _prompt)
  205   "Prompt for the frametitle."
  206   (let ((title (TeX-read-string "Title: " nil 'LaTeX-beamer-frametitle-history)))
  207     (if (not (zerop (length title)))
  208         (insert TeX-grop TeX-esc "frametitle" TeX-grop
  209         title TeX-grcl TeX-grcl)
  210       (insert TeX-grop TeX-grcl))))
  211 
  212 (defun LaTeX-item-beamer ()
  213   "Insert a new item with an optional overlay argument. You
  214 can turn off the prompt for the overlay argument by setting
  215 `LaTeX-beamer-item-overlay-flag' to nil. Calling the function
  216 with a prefix argument prompts for the overlay specification
  217 unconditionally."
  218   (if (listp current-prefix-arg)
  219       (setq current-prefix-arg (car current-prefix-arg))
  220     current-prefix-arg)
  221   (TeX-insert-macro "item")
  222   (delete-horizontal-space)
  223   (if (or current-prefix-arg LaTeX-beamer-item-overlay-flag)
  224       (TeX-arg-beamer-overlay-spec 0))
  225   (insert " ")
  226   (indent-according-to-mode))
  227 
  228 (defun TeX-arg-beamer-note (_optional &optional _prompt)
  229   "Prompt for overlay specification and optional argument."
  230   (let ((overlay (TeX-read-string "(Optional) Overlay: "))
  231         (options (TeX-read-string "(Optional) Options: ")))
  232     (unless (zerop (length overlay))
  233       (insert "<" overlay ">"))
  234     (unless (zerop (length options))
  235       (insert "[" options "]"))
  236     (indent-according-to-mode)))
  237 
  238 (defun LaTeX-beamer-search-themes (&optional regexp extensions length)
  239   "Search for beamer themes matching REGEXP with EXTENSIONS.
  240 The function removes the first LENGTH characters and the
  241 extension of the file and returns a list of strings.  LENGTH may
  242 also be a string.  Then the length of the string is used."
  243   (let* ((match (or regexp "^beamertheme[A-Z]"))
  244      (exts  (or extensions '("tex" "sty")))
  245      (chars (cond ((integerp length)
  246                length)
  247               ((stringp length)
  248                (string-width length))
  249               ;; Try some DWIM magic...
  250               ((and (not length)
  251                 (string-match "beamer[A-Za-z0-9]*theme" match))
  252                (- (match-end 0) (match-beginning 0)))
  253               (t (error "Invalid length: `%s'" length)))))
  254     ;; (message "match=`%s' chars=`%s'" match chars)
  255     (TeX-delete-duplicate-strings
  256      (delete nil
  257          (mapcar
  258           (lambda (file)
  259         (let ((case-fold-search nil))
  260           (and (numberp (string-match match file))
  261                (substring file chars))))
  262           (TeX-search-files nil exts t t))))))
  263 
  264 (defun LaTeX-arg-beamer-theme (&rest _ignore)
  265   "Prompt for beamer theme with completion."
  266   (TeX-argument-insert
  267    (completing-read
  268     (TeX-argument-prompt nil nil "Theme")
  269     (mapcar 'list
  270         (cond ((eq LaTeX-beamer-themes 'local)
  271            (set (make-local-variable 'LaTeX-beamer-themes)
  272             (LaTeX-beamer-search-themes)))
  273           ((functionp LaTeX-beamer-themes)
  274            (funcall LaTeX-beamer-themes))
  275           ((listp LaTeX-beamer-themes)
  276            LaTeX-beamer-themes)
  277           (t (error
  278               "`LaTeX-beamer-themes' should be a list: `%s'"
  279               LaTeX-beamer-themes))))
  280     nil nil nil)
  281    t))
  282 
  283 (defun LaTeX-arg-beamer-inner-theme (&rest _ignore)
  284   "Prompt for beamer inner theme with completion."
  285   (TeX-argument-insert
  286    (completing-read
  287     (TeX-argument-prompt nil nil "Theme")
  288     (mapcar 'list
  289         (cond ((eq LaTeX-beamer-inner-themes 'local)
  290            (set (make-local-variable 'LaTeX-beamer-inner-themes)
  291             (LaTeX-beamer-search-themes "^beamerinnertheme")))
  292           ((functionp LaTeX-beamer-inner-themes)
  293            (funcall LaTeX-beamer-inner-themes))
  294           ((listp LaTeX-beamer-inner-themes)
  295            LaTeX-beamer-inner-themes)
  296           (t (error
  297               "`LaTeX-beamer-inner-themes' should be a list: `%s'"
  298               LaTeX-beamer-inner-themes))))
  299     nil nil nil)
  300    t))
  301 
  302 (defun LaTeX-arg-beamer-outer-theme (&rest _ignore)
  303   "Prompt for beamer outer theme with completion."
  304   (TeX-argument-insert
  305    (completing-read
  306     (TeX-argument-prompt nil nil "Theme")
  307     (mapcar 'list
  308         (cond ((eq LaTeX-beamer-outer-themes 'local)
  309            (set (make-local-variable 'LaTeX-beamer-outer-themes)
  310             (LaTeX-beamer-search-themes "^beameroutertheme")))
  311           ((functionp LaTeX-beamer-outer-themes)
  312            (funcall LaTeX-beamer-outer-themes))
  313           ((listp LaTeX-beamer-outer-themes)
  314            LaTeX-beamer-outer-themes)
  315           (t (error
  316               "`LaTeX-beamer-outer-themes' should be a list: `%s'"
  317               LaTeX-beamer-outer-themes))))
  318     nil nil nil)
  319    t))
  320 
  321 (defun LaTeX-arg-beamer-color-theme (&rest _ignore)
  322   "Prompt for beamer color theme with completion."
  323   (TeX-argument-insert
  324    (completing-read
  325     (TeX-argument-prompt nil nil "Theme")
  326     (mapcar 'list
  327         (cond ((eq LaTeX-beamer-color-themes 'local)
  328            (set (make-local-variable 'LaTeX-beamer-color-themes)
  329             (LaTeX-beamer-search-themes "^beamercolortheme")))
  330           ((functionp LaTeX-beamer-color-themes)
  331            (funcall LaTeX-beamer-color-themes))
  332           ((listp LaTeX-beamer-color-themes)
  333            LaTeX-beamer-color-themes)
  334           (t (error
  335               "`LaTeX-beamer-color-themes' should be a list: `%s'"
  336               LaTeX-beamer-color-themes))))
  337     nil nil nil)
  338    t))
  339 
  340 (defun LaTeX-arg-beamer-font-theme (&rest _ignore)
  341   "Prompt for beamer font theme with completion."
  342   (TeX-argument-insert
  343    (completing-read
  344     (TeX-argument-prompt nil nil "Theme")
  345     (mapcar 'list
  346         (cond ((eq LaTeX-beamer-font-themes 'local)
  347            (set (make-local-variable 'LaTeX-beamer-font-themes)
  348             (LaTeX-beamer-search-themes "^beamerfonttheme")))
  349           ((functionp LaTeX-beamer-font-themes)
  350            (funcall LaTeX-beamer-font-themes))
  351           ((listp LaTeX-beamer-font-themes)
  352            LaTeX-beamer-font-themes)
  353           (t (error
  354               "`LaTeX-beamer-font-themes' should be a list: `%s'"
  355               LaTeX-beamer-font-themes))))
  356     nil nil nil)
  357    t))
  358 
  359 (defun LaTeX-beamer-class-options ()
  360   "Read the beamer class options from the user."
  361   (TeX-load-style "hyperref")
  362   (TeX-read-key-val t '(("usepdftitle" ("false")) ("envcountsect")
  363             ("notheorems") ("noamsthm") ("compress") ("t") ("c")
  364             ("leqno") ("fleqn") ("handout") ("trans") ("pdftex")
  365             ("nativepdf") ("pdfmark") ("dvips") ("dviwindo")
  366             ("dvipsone") ("vtex") ("ps2pdf") ("ignorenonframetext")
  367             ("noamssymb") ("bigger") ("smaller") ("8pt") ("9pt")
  368             ("10pt") ("11pt") ("12pt") ("14pt") ("17pt") ("20pt")
  369             ("draft") ("CJK") ("cjk") ("pgf")
  370             ("hyperref" LaTeX-hyperref-package-options-list)
  371             ("color") ("xcolor") ("ucs") ("utf8x") ("utf8")
  372             ("aspectratio" ("1610" "169" "149" "54" "43" "32")))))
  373 
  374 ;;; beamer.el ends here