AUCTeX Sync -- New Style Files
[packages] / xemacs-packages / auctex / style / xcolor.el
1 ;; xcolor.el --- AUCTeX style for `xcolor.sty' (v2.12)
2
3 ;; Copyright (C) 2016--2017 Free Software Foundation, Inc.
4
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Created: 2015-07-04
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 `xcolor.sty' (v2.12) from 2016/05/11.
30 ;; `xcolor.sty' is part of TeXLive.
31
32 ;; `xcolor.sty' and `color.sty' share many command namens, but the
33 ;; number of arguments is not always identical -- `xcolor.sty'
34 ;; commands take more arguments.  In order to make the commands and
35 ;; font-locking work correctly, we follow this strategy: If
36 ;; `xcolor.sty' is loaded after `color.sty', everything works fine.
37 ;; For the way around, we guard the definitions for `color.sty' with:
38 ;;
39 ;;     (unless (member "xcolor" (TeX-style-list))
40 ;;       (<define stuff for color.sty>))
41 ;;
42 ;; to make sure that we define stuff for `color.sty' only if AUCTeX
43 ;; style for `xcolor.sty' is not already loaded.
44
45 ;;; Code:
46
47 (defvar LaTeX-xcolor-core-color-models
48   '("rgb" "cmy" "cmyk" "hsb" "gray")
49   "List of core color models provided by xcolor.sty.")
50
51 (defvar LaTeX-xcolor-num-color-models
52   '("RGB" "HTML" "HSB" "Gray" "HsB" "tHsB" "wave")
53   "List of integer and decimal color models provided by xcolor.sty.")
54
55 (defvar LaTeX-xcolor-pseudo-color-models
56   '("named")
57   "List of pseudo color models provided by xcolor.sty.")
58
59 (defvar LaTeX-xcolor-type-color-models
60   '("named" "ps")
61   "List of type color models provided by xcolor.sty.")
62
63 (defvar LaTeX-xcolor-base-colors
64   '("red"    "green" "blue"     "cyan"      "magenta" "yellow" "black"
65     "gray"   "white" "darkgray" "lightgray" "brown"   "lime"   "olive"
66     "orange" "pink"  "purple"   "teal"      "violet")
67   "List of colors defined and always available from xcolor.sty.")
68
69 (defvar LaTeX-xcolor-dvipsnames-colors
70   '("Apricot"        "Aquamarine"      "Bittersweet"  "Black"
71     "Blue"           "BlueGreen"       "BlueViolet"   "BrickRed"
72     "Brown"          "BurntOrange"     "CadetBlue"    "CarnationPink"
73     "Cerulean"       "CornflowerBlue"  "Cyan"         "Dandelion"
74     "DarkOrchid"     "Emerald"         "ForestGreen"  "Fuchsia"
75     "Goldenrod"      "Gray"            "Green"        "GreenYellow"
76     "JungleGreen"    "Lavender"        "LimeGreen"    "Magenta"
77     "Mahogany"       "Maroon"          "Melon"        "MidnightBlue"
78     "Mulberry"       "NavyBlue"        "OliveGreen"   "Orange"
79     "OrangeRed"      "Orchid"          "Peach"        "Periwinkle"
80     "PineGreen"      "Plum"            "ProcessBlue"  "Purple"
81     "RawSienna"      "Red"             "RedOrange"    "RedViolet"
82     "Rhodamine"      "RoyalBlue"       "RoyalPurple"  "RubineRed"
83     "Salmon"         "SeaGreen"        "Sepia"        "SkyBlue"
84     "SpringGreen"    "Tan"             "TealBlue"     "Thistle"
85     "Turquoise"      "Violet"          "VioletRed"    "White"
86     "WildStrawberry" "Yellow"          "YellowGreen"  "YellowOrange")
87   "List of colors defined by package option dvipsnames from xcolor.sty.")
88
89 (defvar LaTeX-xcolor-svgnames-colors
90   '("AliceBlue"      "DarkTurquoise" "LightSalmon"       "PaleVioletRed"
91     "AntiqueWhite"   "DarkViolet"    "LightSeaGreen"     "PapayaWhip"
92     "Aqua"           "DeepPink"      "LightSkyBlue"      "PeachPuff"
93     "Aquamarine"     "DeepSkyBlue"   "LightSlateBlue"    "Peru"
94     "Azure"          "DimGray"       "LightSlateGray"    "Pink"
95     "Beige"          "DimGrey"       "LightSlateGrey"    "Plum"
96     "Bisque"         "DodgerBlue"    "LightSteelBlue"    "PowderBlue"
97     "Black"          "FireBrick"     "LightYellow"       "Purple"
98     "BlanchedAlmond" "FloralWhite"   "Lime"              "Red"
99     "Blue"           "ForestGreen"   "LimeGreen"         "RosyBrown"
100     "BlueViolet"     "Fuchsia"       "Linen"             "RoyalBlue"
101     "Brown"          "Gainsboro"     "Magenta"           "SaddleBrown"
102     "BurlyWood"      "GhostWhite"    "Maroon"            "Salmon"
103     "CadetBlue"      "Gold"          "MediumAquamarine"  "SandyBrown"
104     "Chartreuse"     "Goldenrod"     "MediumBlue"        "SeaGreen"
105     "Chocolate"      "Gray"          "MediumOrchid"      "Seashell"
106     "Coral"          "Green"         "MediumPurple"      "Sienna"
107     "CornflowerBlue" "GreenYellow"   "MediumSeaGreen"    "Silver"
108     "Cornsilk"       "Grey"          "MediumSlateBlue"   "SkyBlue"
109     "Crimson"        "Honeydew"      "MediumSpringGreen" "SlateBlue"
110     "Cyan"           "HotPink"       "MediumTurquoise"   "SlateGray"
111     "DarkBlue"       "IndianRed"     "MediumVioletRed"   "SlateGrey"
112     "DarkCyan"       "Indigo"        "MidnightBlue"      "Snow"
113     "DarkGoldenrod"  "Ivory"         "MintCream"         "SpringGreen"
114     "DarkGray"       "Khaki"         "MistyRose"         "SteelBlue"
115     "DarkGreen"      "Lavender"      "Moccasin"          "Tan"
116     "DarkGrey"       "LavenderBlush" "NavajoWhite"       "Teal"
117     "DarkKhaki"      "LawnGreen"     "Navy"              "Thistle"
118     "DarkMagenta"    "LemonChiffon"  "NavyBlue"          "Tomato"
119     "DarkOliveGreen" "LightBlue"     "OldLace"           "Turquoise"
120     "DarkOrange"     "LightCoral"    "Olive"             "Violet"
121     "DarkOrchid"     "LightCyan"     "OliveDrab"         "VioletRed"
122     "DarkRed"        "LightGoldenrod" "Orange"           "Wheat"
123     "DarkSalmon"     "LightGoldenrodYellow" "OrangeRed"  "White"
124     "DarkSeaGreen"   "LightGray"     "Orchid"            "WhiteSmoke"
125     "DarkSlateBlue"  "LightGreen"    "PaleGoldenrod"     "Yellow"
126     "DarkSlateGray"  "LightGrey"     "PaleGreen"         "YellowGreen"
127     "DarkSlateGrey"  "LightPink"     "PaleTurquoise")
128   "List of colors defined by package option svgnames from xcolor.sty.")
129
130 (defvar LaTeX-xcolor-x11names-colors
131   '("AntiqueWhite1"     "DeepSkyBlue1"  "LightYellow1"  "RoyalBlue1"
132     "AntiqueWhite2"     "DeepSkyBlue2"  "LightYellow2"  "RoyalBlue2"
133     "AntiqueWhite3"     "DeepSkyBlue3"  "LightYellow3"  "RoyalBlue3"
134     "AntiqueWhite4"     "DeepSkyBlue4"  "LightYellow4"  "RoyalBlue4"
135     "Aquamarine1"       "DodgerBlue1"   "Magenta1"      "Salmon1"
136     "Aquamarine2"       "DodgerBlue2"   "Magenta2"      "Salmon2"
137     "Aquamarine3"       "DodgerBlue3"   "Magenta3"      "Salmon3"
138     "Aquamarine4"       "DodgerBlue4"   "Magenta4"      "Salmon4"
139     "Azure1"            "Firebrick1"    "Maroon1"       "SeaGreen1"
140     "Azure2"            "Firebrick2"    "Maroon2"       "SeaGreen2"
141     "Azure3"            "Firebrick3"    "Maroon3"       "SeaGreen3"
142     "Azure4"            "Firebrick4"    "Maroon4"       "SeaGreen4"
143     "Bisque1"           "Gold1"         "MediumOrchid1" "Seashell1"
144     "Bisque2"           "Gold2"         "MediumOrchid2" "Seashell2"
145     "Bisque3"           "Gold3"         "MediumOrchid3" "Seashell3"
146     "Bisque4"           "Gold4"         "MediumOrchid4" "Seashell4"
147     "Blue1"             "Goldenrod1"    "MediumPurple1" "Sienna1"
148     "Blue2"             "Goldenrod2"    "MediumPurple2" "Sienna2"
149     "Blue3"             "Goldenrod3"    "MediumPurple3" "Sienna3"
150     "Blue4"             "Goldenrod4"    "MediumPurple4" "Sienna4"
151     "Brown1"            "Green1"        "MistyRose1"    "SkyBlue1"
152     "Brown2"            "Green2"        "MistyRose2"    "SkyBlue2"
153     "Brown3"            "Green3"        "MistyRose3"    "SkyBlue3"
154     "Brown4"            "Green4"        "MistyRose4"    "SkyBlue4"
155     "Burlywood1"        "Honeydew1"     "NavajoWhite1"  "SlateBlue1"
156     "Burlywood2"        "Honeydew2"     "NavajoWhite2"  "SlateBlue2"
157     "Burlywood3"        "Honeydew3"     "NavajoWhite3"  "SlateBlue3"
158     "Burlywood4"        "Honeydew4"     "NavajoWhite4"  "SlateBlue4"
159     "CadetBlue1"        "HotPink1"      "OliveDrab1"    "SlateGray1"
160     "CadetBlue2"        "HotPink2"      "OliveDrab2"    "SlateGray2"
161     "CadetBlue3"        "HotPink3"      "OliveDrab3"    "SlateGray3"
162     "CadetBlue4"        "HotPink4"      "OliveDrab4"    "SlateGray4"
163     "Chartreuse1"       "IndianRed1"    "Orange1"       "Snow1"
164     "Chartreuse2"       "IndianRed2"    "Orange2"       "Snow2"
165     "Chartreuse3"       "IndianRed3"    "Orange3"       "Snow3"
166     "Chartreuse4"       "IndianRed4"    "Orange4"       "Snow4"
167     "Chocolate1"        "Ivory1"        "OrangeRed1"    "SpringGreen1"
168     "Chocolate2"        "Ivory2"        "OrangeRed2"    "SpringGreen2"
169     "Chocolate3"        "Ivory3"        "OrangeRed3"    "SpringGreen3"
170     "Chocolate4"        "Ivory4"        "OrangeRed4"    "SpringGreen4"
171     "Coral1"            "Khaki1"        "Orchid1"       "SteelBlue1"
172     "Coral2"            "Khaki2"        "Orchid2"       "SteelBlue2"
173     "Coral3"            "Khaki3"        "Orchid3"       "SteelBlue3"
174     "Coral4"            "Khaki4"        "Orchid4"       "SteelBlue4"
175     "Cornsilk1"         "LavenderBlush1" "PaleGreen1"    "Tan1"
176     "Cornsilk2"         "LavenderBlush2" "PaleGreen2"    "Tan2"
177     "Cornsilk3"         "LavenderBlush3" "PaleGreen3"    "Tan3"
178     "Cornsilk4"         "LavenderBlush4" "PaleGreen4"    "Tan4"
179     "Cyan1"             "LemonChiffon1" "PaleTurquoise1" "Thistle1"
180     "Cyan2"             "LemonChiffon2" "PaleTurquoise2" "Thistle2"
181     "Cyan3"             "LemonChiffon3" "PaleTurquoise3" "Thistle3"
182     "Cyan4"             "LemonChiffon4" "PaleTurquoise4" "Thistle4"
183     "DarkGoldenrod1"    "LightBlue1"    "PaleVioletRed1" "Tomato1"
184     "DarkGoldenrod2"    "LightBlue2"    "PaleVioletRed2" "Tomato2"
185     "DarkGoldenrod3"    "LightBlue3"    "PaleVioletRed3" "Tomato3"
186     "DarkGoldenrod4"    "LightBlue4"    "PaleVioletRed4" "Tomato4"
187     "DarkOliveGreen1"   "LightCyan1"    "PeachPuff1"     "Turquoise1"
188     "DarkOliveGreen2"   "LightCyan2"    "PeachPuff2"     "Turquoise2"
189     "DarkOliveGreen3"   "LightCyan3"    "PeachPuff3"     "Turquoise3"
190     "DarkOliveGreen4"   "LightCyan4"    "PeachPuff4"     "Turquoise4"
191     "DarkOrange1"       "LightGoldenrod1" "Pink1"        "VioletRed1"
192     "DarkOrange2"       "LightGoldenrod2" "Pink2"        "VioletRed2"
193     "DarkOrange3"       "LightGoldenrod3" "Pink3"        "VioletRed3"
194     "DarkOrange4"       "LightGoldenrod4" "Pink4"        "VioletRed4"
195     "DarkOrchid1"       "LightPink1"    "Plum1"          "Wheat1"
196     "DarkOrchid2"       "LightPink2"    "Plum2"          "Wheat2"
197     "DarkOrchid3"       "LightPink3"    "Plum3"          "Wheat3"
198     "DarkOrchid4"       "LightPink4"    "Plum4"          "Wheat4"
199     "DarkSeaGreen1"     "LightSalmon1"  "Purple1"        "Yellow1"
200     "DarkSeaGreen2"     "LightSalmon2"  "Purple2"        "Yellow2"
201     "DarkSeaGreen3"     "LightSalmon3"  "Purple3"        "Yellow3"
202     "DarkSeaGreen4"     "LightSalmon4"  "Purple4"        "Yellow4"
203     "DarkSlateGray1"    "LightSkyBlue1" "Red1"           "Gray0"
204     "DarkSlateGray2"    "LightSkyBlue2" "Red2"           "Green0"
205     "DarkSlateGray3"    "LightSkyBlue3" "Red3"           "Grey0"
206     "DarkSlateGray4"    "LightSkyBlue4" "Red4"           "Maroon0"
207     "DeepPink1"         "LightSteelBlue1" "RosyBrown1"   "Purple0"
208     "DeepPink2"         "LightSteelBlue2" "RosyBrown2"
209     "DeepPink3"         "LightSteelBlue3" "RosyBrown3"
210     "DeepPink4"         "LightSteelBlue4" "RosyBrown4")
211   "List of colors defined by package option x11names from xcolor.sty.")
212
213 (defvar LaTeX-xcolor-color-models
214   (append LaTeX-xcolor-core-color-models
215           LaTeX-xcolor-num-color-models
216           LaTeX-xcolor-pseudo-color-models)
217   "Combine three variables `LaTeX-xcolor-core-color-models',
218 `LaTeX-xcolor-num-color-models' and `LaTeX-xcolor-pseudo-color-models'.")
219
220 (defun LaTeX-xcolor-color-models (&optional no-named)
221   "Return the value of variable `LaTeX-xcolor-color-models'.
222 If NO-NAMED is non-nil, remove \"named\" and return the
223 remainder."
224   (if no-named
225       (remove "named" LaTeX-xcolor-color-models)
226     (symbol-value 'LaTeX-xcolor-color-models)))
227
228 ;; Needed for auto-parsing.
229 (require 'tex)
230
231 ;; Setup AUCTeX parser for \definecolor(set):
232 (TeX-auto-add-type "xcolor-definecolor" "LaTeX")
233 (TeX-auto-add-type "xcolor-definecolorset" "LaTeX")
234
235 (defvar LaTeX-xcolor-definecolor-regexp
236   (eval-when-compile
237     `(,(concat "\\\\"
238                (regexp-opt '("definecolor"  "providecolor"
239                              "preparecolor" "colorlet"))
240                "\\(?:\\[\\(?:[^]]*\\)\\]\\)?{\\([^}]+\\)}")
241       1 LaTeX-auto-xcolor-definecolor))
242   "Match the argument of various color defining macros from xcolor package.")
243
244 (defvar LaTeX-xcolor-definecolorset-regexp
245   `(,(concat "\\\\\\(?:define\\|provide\\|prepare\\)"
246              "colorset"
247              "\\(?:\\[\\(?:[^]]*\\)\\]\\)?"
248              "{\\(?:[^}]+\\)}"
249              "{\\([^}]+\\)}"
250              "{\\([^}]+\\)}"
251              "{\\([^}]+\\)}")
252     (1 2 3) LaTeX-auto-xcolor-definecolorset)
253   "Match the argument of various color-set defining macros from
254 xcolor package.")
255
256 (defun LaTeX-xcolor-auto-prepare ()
257   "Clear `LaTeX-auto-xcolor-definecolor' before parsing."
258   (setq LaTeX-auto-xcolor-definecolor nil
259         LaTeX-auto-xcolor-definecolorset nil))
260
261 (defun LaTeX-xcolor-auto-cleanup ()
262   "Process the parsed elements from `LaTeX-auto-xcolor-definecolorset'."
263   (dolist (colset (LaTeX-xcolor-definecolorset-list))
264     (let ((head (car colset))
265           (tail (cadr colset))
266           (cols (split-string
267                  (TeX-replace-regexp-in-string "[ %\n\r\t]" "" (nth 2 colset))
268                  "\\(,[^;]+;\\|,[^;]+$\\)" t)))
269       (dolist (color cols)
270         (LaTeX-add-xcolor-definecolors (concat head color tail))))))
271
272 (add-hook 'TeX-auto-prepare-hook #'LaTeX-xcolor-auto-prepare t)
273 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-xcolor-auto-cleanup t)
274 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
275
276 (defun TeX-arg-xcolor-definecolor (optional)
277   "Insert arguments of \\definecolor and similar macros from
278 xcolor.sty."
279   ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
280   (let* ((xcoltype  (completing-read
281                      (TeX-argument-prompt t nil "Type")
282                      LaTeX-xcolor-type-color-models))
283          (xcolname  (TeX-read-string
284                      (TeX-argument-prompt optional nil "Color name")))
285          (xcolmodel (completing-read
286                      (TeX-argument-prompt optional nil "Model (list)")
287                      (if (string= xcoltype "named")
288                          (LaTeX-xcolor-color-models t)
289                        LaTeX-xcolor-color-models)))
290          (xcolspec  (if (string= xcolmodel "named")
291                         (completing-read
292                          (TeX-argument-prompt optional nil "Color")
293                          (LaTeX-xcolor-definecolor-list))
294                       (TeX-read-string
295                        (TeX-argument-prompt optional nil (concat xcolmodel " spec (list)"))))))
296     (when (and xcoltype (not (string= xcoltype "")))
297       (insert (format "[%s]" xcoltype)))
298     (TeX-argument-insert xcolname optional)
299     (LaTeX-add-xcolor-definecolors xcolname)
300     (TeX-argument-insert xcolmodel optional)
301     (TeX-argument-insert xcolspec optional)))
302
303 (defun TeX-arg-xcolor-definecolorset (optional)
304   "Insert arguments of \\definecolorset and similar macros from
305 xcolor.sty."
306   (let ((xcoltype (completing-read
307                    (TeX-argument-prompt t nil "Type")
308                    LaTeX-xcolor-type-color-models))
309         (xcolmodel (completing-read
310                     (TeX-argument-prompt optional nil "Model")
311                     (LaTeX-xcolor-color-models t))))
312     (when (and xcoltype (not (string= xcoltype "")))
313       (insert (format "[%s]" xcoltype)))
314     (TeX-argument-insert xcolmodel optional)))
315
316 (defun TeX-arg-xcolor (optional)
317   "Insert arguments of various color commands from xcolor.sty."
318   ;; \color{<name>} or \color[<model-list>]{<spec-list>}
319   (let* ((xcolmodel (completing-read
320                      (TeX-argument-prompt t nil "Model (list)")
321                      (LaTeX-xcolor-color-models t)))
322          (xcolor (if (and xcolmodel (not (string= xcolmodel "")))
323                      (TeX-read-string
324                       (TeX-argument-prompt optional nil (concat xcolmodel " spec (list)")))
325                    (completing-read
326                     (TeX-argument-prompt optional nil "Color")
327                     (LaTeX-xcolor-definecolor-list)))))
328     (when (and xcolmodel (not (string= xcolmodel "")))
329       (insert (format "[%s]" xcolmodel)))
330     (TeX-argument-insert xcolor optional)))
331
332 (defun TeX-arg-xcolor-fcolorbox (optional)
333   "Insert arguments of \\fcolorbox from xcolor.sty."
334   ;;\fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background spec>}{<text>}
335   (let* ((xfrmodel (completing-read
336                     (TeX-argument-prompt t nil "(Frame) Color model")
337                     LaTeX-xcolor-color-models))
338          (xfrspec  (if (or (string= xfrmodel "")
339                            (string= xfrmodel "named"))
340                        (completing-read
341                         (TeX-argument-prompt optional nil "Frame color spec")
342                         (LaTeX-xcolor-definecolor-list))
343                      (TeX-read-string
344                       (TeX-argument-prompt optional nil "Frame color spec"))))
345          (xbgmodel (completing-read
346                     (TeX-argument-prompt t nil "Background Color model")
347                     LaTeX-xcolor-color-models))
348          (xbgspec  (if (or (string= xfrmodel "")
349                            (string= xfrmodel "named")
350                            (string= xbgmodel "")
351                            (string= xbgmodel "named"))
352                        (completing-read
353                         (TeX-argument-prompt optional nil "Background color spec")
354                         (LaTeX-xcolor-definecolor-list))
355                      (TeX-read-string
356                       (TeX-argument-prompt optional nil "Background color spec")))))
357     (when (and xfrmodel (not (string= xfrmodel "")))
358       (insert (format "[%s]" xfrmodel)))
359     (TeX-argument-insert xfrspec optional)
360     (when (and xbgmodel (not (string= xbgmodel "")))
361       (insert (format "[%s]" xbgmodel)))
362     (TeX-argument-insert xbgspec optional)))
363
364
365 (TeX-add-style-hook
366  "xcolor"
367  (lambda ()
368    ;; Add color to the parser.
369    (TeX-auto-add-regexp LaTeX-xcolor-definecolor-regexp)
370    (TeX-auto-add-regexp LaTeX-xcolor-definecolorset-regexp)
371
372    ;; Add list of colors which are always available.
373    (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-base-colors)
374
375    ;; Add dvips colors in conjunction with `dvipsnames*?'.
376    (when (or (LaTeX-provided-package-options-member "xcolor" "dvipsnames")
377              (LaTeX-provided-package-options-member "xcolor" "dvipsnames*"))
378      (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-dvipsnames-colors))
379
380    ;; For `svgnames*?'
381    (when (or (LaTeX-provided-package-options-member "xcolor" "svgnames")
382              (LaTeX-provided-package-options-member "xcolor" "svgnames*"))
383      (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-svgnames-colors))
384
385    ;; For `x11ames*?'
386    (when (or (LaTeX-provided-package-options-member "xcolor" "x11names")
387              (LaTeX-provided-package-options-member "xcolor" "x11names*"))
388      (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-x11names-colors))
389
390    (TeX-add-symbols
391     ;; 2.5.2 Color definition in xcolor
392     ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
393     '("definecolor" TeX-arg-xcolor-definecolor)
394
395     ;; \providecolor[<type>]{<name>}{<model-list>}{<spec-list>}
396     '("providecolor" TeX-arg-xcolor-definecolor)
397
398     ;; \colorlet[<type>]{<name>}[<num model>]{<color>}
399     '("colorlet"
400       [ TeX-arg-eval completing-read
401                      (TeX-argument-prompt optional nil "Type")
402                      LaTeX-xcolor-type-color-models ]
403       (TeX-arg-eval
404        (lambda ()
405          (let ((xcolor (TeX-read-string
406                         (TeX-argument-prompt optional nil "Color"))))
407            (LaTeX-add-xcolor-definecolors xcolor)
408            (format "%s" xcolor))))
409       [ TeX-arg-eval completing-read
410                      (TeX-argument-prompt optional nil "Model")
411                      (LaTeX-xcolor-color-models t) ]
412       (TeX-arg-eval completing-read
413                     (TeX-argument-prompt optional nil "Color")
414                     (LaTeX-xcolor-definecolor-list)))
415
416     ;; 2.5.3 Defining sets of colors
417     ;; \definecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
418     '("definecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)
419
420     ;; \providecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
421     '("providecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)
422
423     ;; 2.5.4 Immediate and deferred definitions
424     ;; \preparecolor[<type>]{<name>}{<model-list>}{<spec-list>}
425     '("preparecolor" TeX-arg-xcolor-definecolor)
426
427     ;; \preparecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
428     '("preparecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)
429
430     ;; \definecolors{<id-list>}
431     '("definecolors" t)
432
433     ;; \providecolors{<id-list>}
434     '("providecolors" t)
435
436     ;; 2.6 Color application
437     ;; 2.6.1 Standard color commands
438
439     ;; \color{<name>} or \color[<model>]{<color spec>}
440     '("color" TeX-arg-xcolor)
441
442     ;; \textcolor{<name>}{<text>} or
443     ;; \textcolor[<model>]{<color spec>}{<text>}
444     '("textcolor" TeX-arg-xcolor "Text")
445
446     ;; \pagecolor{<name>} or
447     ;; \pagecolor[<model>]{<color spec>}
448     '("pagecolor" TeX-arg-xcolor)
449
450     ;; \nopagecolor
451     '("nopagecolor" 0)
452
453     ;; 2.6.2 Colored boxes
454     ;; \colorbox{<name>}{<text>} or
455     ;; \colorbox[<model>]{<color spec>}{<text>}
456     '("colorbox" TeX-arg-xcolor "Text")
457
458     ;; \fcolorbox{<frame color>}{<box color>}{<text>} or
459     ;; \fcolorbox[<model>]{<frame spec>}{<background spec>}{<text>} or
460     ;; \fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background spec>}{<text>}
461     '("fcolorbox" TeX-arg-xcolor-fcolorbox "Text")
462
463     ;; 2.6.4 Color testing
464     ;; \testcolor{<name>} or
465     ;; \testcolor[<model>]{<color spec>}
466     '("testcolor" TeX-arg-xcolor)
467
468     ;; 2.7 Color blending
469     '("blendcolors"
470       (TeX-arg-eval completing-read
471                     (TeX-argument-prompt optional nil "Mix expr")
472                     (LaTeX-xcolor-definecolor-list)))
473     '("blendcolors*"
474       (TeX-arg-eval completing-read
475                     (TeX-argument-prompt optional nil "Mix expr")
476                     (LaTeX-xcolor-definecolor-list)))
477
478     ;; 2.8 Color masks and separation
479     '("maskcolors"
480       [ TeX-arg-eval completing-read
481                      (TeX-argument-prompt optional nil "Model")
482                      (LaTeX-xcolor-color-models t) ]
483       (TeX-arg-eval completing-read
484                     (TeX-argument-prompt optional nil "Color")
485                     (LaTeX-xcolor-definecolor-list)))
486
487     ;; 2.9 Color series
488     '("definecolorseries"
489       "Name"
490       (TeX-arg-eval completing-read
491                     (TeX-argument-prompt optional nil "Core model")
492                     LaTeX-xcolor-core-color-models)
493       (TeX-arg-eval completing-read
494                     (TeX-argument-prompt optional nil "Method")
495                     '("step" "grad" "last"))
496       [ t ] nil [ nil ] nil)
497
498     '("resetcolorseries" [ "Div." ] "Name")
499
500     ;; 2.13 Color information
501     ;; \extractcolorspec{<color>}{<cmd>}
502     '("extractcolorspec"
503       (TeX-arg-eval completing-read
504                     (TeX-argument-prompt optional nil "Color")
505                     (LaTeX-xcolor-definecolor-list))
506       (TeX-arg-define-macro "Command: \\"))
507
508     ;; \extractcolorspecs{<color>}{<model-cmd>}{<color-cmd>}
509     '("extractcolorspecs"
510       (TeX-arg-eval completing-read
511                     (TeX-argument-prompt optional nil "Color")
512                     (LaTeX-xcolor-definecolor-list))
513       (TeX-arg-define-macro "Model command: \\")
514       (TeX-arg-define-macro "Color command: \\"))
515
516     ;; \tracingcolors = <integer>
517     '("tracingcolors"
518       (TeX-arg-literal "="))
519
520     ;; 2.14 Color conversion
521     ;; \convertcolorspec{<model>}{<spec>}{<target model>}{cmd>}
522     '("convertcolorspec"
523       (TeX-arg-eval completing-read
524                     (TeX-argument-prompt optional nil "Model")
525                     (LaTeX-xcolor-color-models))
526       (TeX-arg-eval TeX-read-string
527                     (TeX-argument-prompt optional nil "Spec"))
528       (TeX-arg-eval completing-read
529                     (TeX-argument-prompt optional nil "Model")
530                     (LaTeX-xcolor-color-models t))
531       (TeX-arg-define-macro "Macro: \\")) ) ; close TeX-add-symbols
532
533    ;; 2.12 Color in tables
534    ;; These commands are available with `table' package option
535    (when (LaTeX-provided-package-options-member "xcolor" "table")
536      ;; Run style hook to colortbl.sty
537      (TeX-run-style-hooks "colortbl")
538
539      ;; Add additional commands:
540      (TeX-add-symbols
541       ;; \rowcolors[<commands>]{<row>}{<odd-row color>}{<even-row color>}
542       '("rowcolors"
543         (TeX-arg-conditional (y-or-n-p "With optional commands? ")
544                              ( [ t ] )
545                              (ignore))
546         "Row"
547         (TeX-arg-eval completing-read
548                       (TeX-argument-prompt optional nil "Odd-row color")
549                       (LaTeX-xcolor-definecolor-list))
550         (TeX-arg-eval completing-read
551                       (TeX-argument-prompt optional nil "Even-row color")
552                       (LaTeX-xcolor-definecolor-list)))
553       '("rowcolors*"
554         (TeX-arg-conditional (y-or-n-p "With optional commands? ")
555                              ( [ t ] )
556                              (ignore))
557         "Row"
558         (TeX-arg-eval completing-read
559                       (TeX-argument-prompt optional nil "Odd-row color")
560                       (LaTeX-xcolor-definecolor-list))
561         (TeX-arg-eval completing-read
562                       (TeX-argument-prompt optional nil "Even-row color")
563                       (LaTeX-xcolor-definecolor-list)))
564       '("showrowcolors" 0)
565       '("hiderowcolors" 0))
566      (LaTeX-add-counters "rownum"))
567
568    ;; 2.6.4 Color testing
569    (LaTeX-add-environments
570     '("testcolors" LaTeX-env-args
571       [ TeX-arg-eval mapconcat #'identity
572                      (TeX-completing-read-multiple
573                       (TeX-argument-prompt optional nil "Color models")
574                       (LaTeX-xcolor-color-models t))
575                      "," ] ))
576
577    ;; Fontification
578    (when (and (featurep 'font-latex)
579               (eq TeX-install-font-lock 'font-latex-setup))
580      (font-latex-add-keywords '(("color"             "[{")
581                                 ("pagecolor"         "[{"))
582                               'type-declaration)
583      (font-latex-add-keywords '(("textcolor"         "[{{")
584                                 ("colorbox"          "[{{" )
585                                 ("fcolorbox"         "[{[{{"))
586                               'type-command)
587      (font-latex-add-keywords '(("definecolor"       "[{{{")
588                                 ("providecolor"      "[{{{")
589                                 ("colorlet"          "[{[{")
590                                 ("definecolorset"    "[{{{{")
591                                 ("providecolorset"   "[{{{{")
592                                 ("preparecolor"      "[{{{")
593                                 ("preparecolorset"   "[{{{{")
594                                 ("definecolors"      "{")
595                                 ("providecolors"     "{")
596                                 ("testcolor"         "[{")
597                                 ("blendcolors"       "*{")
598                                 ("maskcolors"        "[{")
599                                 ("definecolorseries" "{{{[{[{")
600                                 ("resetcolorseries"  "[{")
601                                 ("extractcolorspec"  "{{")
602                                 ("extractcolorspecs" "{{{")
603                                 ("convertcolorspec"  "{{{{")
604                                 ("rowcolors"         "*[{{{"))
605                               'function)))
606  LaTeX-dialect)
607
608 (defvar LaTeX-xcolor-package-options
609   '(;; options that determine the color driver
610     "dvips" "xdvi" "dvipdf" "dvipdfm" "dvipdfmx" "pdftex" "dvipsone"
611     "dviwindo" "emtex" "dviwin" "oztex" "textures" "pctexps" "pctexwin"
612     "pctexhp" "pctex32" "truetex" "tcidvi" "vtex" "xetex"
613
614     ;; options that determine the target color model
615     "natural" "rgb" "cmy" "cmyk" "hsb" "gray" "RGB" "HTML"
616     "HSB" "Gray" "monochrome"
617
618     ;; options that control predefined colors loading
619     "dvipsnames" "dvipsnames*" "svgnames" "svgnames*" "x11names" "x11names*"
620
621     ;; options that determine which other packages to load
622     "table" "fixpdftex" "hyperref"
623
624     ;; options that influence the behaviour of other commands
625     "prologue" "kernelfbox" "xcdraw" "noxcdraw" "fixinclude"
626     "showerrors" "hideerrors")
627   "Package options for the xcolor package.")
628
629 ;;; xcolor.el ends here