summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/fancyref.el
blob: 22fd1c1732bfbf0878ed69d6ca4b45fd8d8eeb7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
;;; fancyref.el --- AUCTeX style file with support for fancyref.sty  -*- lexical-binding: t; -*-

;; Copyright (C) 1999, 2014, 2015, 2018, 2020 Free Software Foundation, Inc.

;; Author: Carsten Dominik <dominik@strw.leidenuniv.nl>
;; Maintainer: auctex-devel@gnu.org

;; This file is part of AUCTeX.

;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Code:

(require 'tex)
(require 'latex)

;; Silence the compiler:
(declare-function font-latex-add-keywords
                  "font-latex"
                  (keywords class))

(TeX-add-style-hook
 "fancyref"
 (lambda ()
   (TeX-add-symbols

    ;; The macros with label arguments
    '("fref" [ TeX-arg-fancyref-format ] TeX-arg-ref)
    '("Fref" [ TeX-arg-fancyref-format ] TeX-arg-ref)

    ;; The macros which define new prefixes and formats
    '("fancyrefchangeprefix" TeX-arg-macro "Prefix")
    '("Frefformat" TeX-arg-fancyref-format TeX-arg-macro "Output")
    '("frefformat" TeX-arg-fancyref-format TeX-arg-macro "Output")

    ;; The delimiter
    "fancyrefargdelim"

    ;; All those names and abbreviations.
    ;; Part
    "fancyrefpartlabelprefix" 
    "Frefpartname" "frefpartname"   
    ;; Chapter
    "fancyrefchalabelprefix"
    "Frefchaname" "frefchaname"   
    ;; Section
    "fancyrefseclabelprefix"
    "Frefsecname" "frefsecname"
    ;; Equation
    "fancyrefeqlabelprefix"
    "Frefeqname" "frefeqname"   
    ;; Figure
    "fancyreffiglabelprefix"
    "Freffigname" "freffigname" "Freffigshortname"
    ;; Footnote
    "fancyreffnlabelprefix"
    "Freffnname" "freffnname"   
    ;; Item
    "fancyrefitemlabelprefix"
    "Frefitemname" "frefitemname" 
    ;; Table
    "fancyreftablabelprefix"
    "Freftabname" "freftabname" "Freftabshortname"
    ;; Page
    "Frefpgname" "frefpgname" "Frefpgshortname"
    ;; On
    "Frefonname" "frefonname" 
    ;; See
    "Frefseename" "frefseename"

    ;; The spacing macros
    "fancyrefloosespacing" "fancyreftightspacing" "fancyrefdefaultspacing"

    ;; And the hook
    "fancyrefhook")

   ;; Insatall completion for labels and formats
   (setq TeX-complete-list
         (append
          '(("\\\\[fF]ref\\(\\[[^]]*\\]\\)?{\\([^{}\n\r\\%,]*\\)" 
             2 LaTeX-label-list "}")
            ("\\\\[fF]ref\\[\\([^{}\n\r\\%,]*\\)" 
             1 LaTeX-fancyref-formats "]")
            ("\\\\[fF]refformat{\\([^{}\n\r\\%,]*\\)"
             1 LaTeX-fancyref-formats "}"))
          TeX-complete-list))
   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("fref" "[{") ("Fref" "[{")) 'reference))

   ;; Activate RefTeX reference style.
   (and LaTeX-reftex-ref-style-auto-activate
        (fboundp 'reftex-ref-style-activate)
        (reftex-ref-style-activate "Fancyref")))
 TeX-dialect)

;; The following list keeps a list of available format names
;; Note that this list is only updated when a format is used, not
;; during buffer parsing.  We could install a regexp to look for
;; formats, but this would not work in multifile documents since the
;; formats are not written out to the auto files.
;; For now, we just leave it at that.
(defvar LaTeX-fancyref-formats '(("plain") ("vario") ("margin") ("main"))
  "List of formats for fancyref.")

(defun LaTeX-fancyref-formats () LaTeX-fancyref-formats)

(defun TeX-arg-fancyref-format (optional &optional prompt _definition)
  "Prompt for a fancyref format name.
If the user gives an unknown name, add it to the list."
  (let ((format (completing-read (TeX-argument-prompt optional prompt "Format")
                                 LaTeX-fancyref-formats)))
    (if (not (string-equal "" format))
        (add-to-list 'LaTeX-fancyref-formats (list format)))
    (TeX-argument-insert format optional)))

(defvar LaTeX-fancyref-package-options '("english" "german" "loose"
                                         "margin" "paren" "plain" "tight"
                                         "vario")
  "Package options for the fancyref package.")

;;; fancyref.el ends here