summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/xcolor.el
blob: 06bd28f73b94470bb67dc1caf11ac930d4609dd1 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
;; xcolor.el --- AUCTeX style for `xcolor.sty' (v2.12)  -*- lexical-binding: t; -*-

;; Copyright (C) 2016--2022 Free Software Foundation, Inc.

;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
;; Created: 2015-07-04
;; Keywords: tex

;; 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.

;;; Commentary:

;; This file adds support for `xcolor.sty' (v2.13) from 2021/10/31.
;; `xcolor.sty' is part of TeXLive.

;; `xcolor.sty' and `color.sty' share many command namens, but the
;; number of arguments is not always identical -- `xcolor.sty'
;; commands take more arguments.  In order to make the commands and
;; font-locking work correctly, we follow this strategy: If
;; `xcolor.sty' is loaded after `color.sty', everything works fine.
;; For the way around, we guard the definitions for `color.sty' with:
;;
;;     (unless (member "xcolor" (TeX-style-list))
;;       (<define stuff for color.sty>))
;;
;; to make sure that we define stuff for `color.sty' only if AUCTeX
;; style for `xcolor.sty' is not already loaded.

;;; Code:

;; Needed for compiling `LaTeX-check-insert-macro-default-style':
(require 'latex)

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

(defvar LaTeX-xcolor-core-color-models
  '("rgb" "cmy" "cmyk" "hsb" "gray")
  "List of core color models provided by xcolor.sty.")

(defvar LaTeX-xcolor-num-color-models
  '("RGB" "HTML" "HSB" "Gray" "HsB" "tHsB" "wave")
  "List of integer and decimal color models provided by xcolor.sty.")

(defvar LaTeX-xcolor-pseudo-color-models
  '("named")
  "List of pseudo color models provided by xcolor.sty.")

(defvar LaTeX-xcolor-type-color-models
  '("named" "ps")
  "List of type color models provided by xcolor.sty.")

(defvar LaTeX-xcolor-base-colors
  '("red"    "green" "blue"     "cyan"      "magenta" "yellow" "black"
    "gray"   "white" "darkgray" "lightgray" "brown"   "lime"   "olive"
    "orange" "pink"  "purple"   "teal"      "violet")
  "List of colors defined and always available from xcolor.sty.")

(defvar LaTeX-xcolor-dvipsnames-colors
  '("Apricot"        "Aquamarine"      "Bittersweet"  "Black"
    "Blue"           "BlueGreen"       "BlueViolet"   "BrickRed"
    "Brown"          "BurntOrange"     "CadetBlue"    "CarnationPink"
    "Cerulean"       "CornflowerBlue"  "Cyan"         "Dandelion"
    "DarkOrchid"     "Emerald"         "ForestGreen"  "Fuchsia"
    "Goldenrod"      "Gray"            "Green"        "GreenYellow"
    "JungleGreen"    "Lavender"        "LimeGreen"    "Magenta"
    "Mahogany"       "Maroon"          "Melon"        "MidnightBlue"
    "Mulberry"       "NavyBlue"        "OliveGreen"   "Orange"
    "OrangeRed"      "Orchid"          "Peach"        "Periwinkle"
    "PineGreen"      "Plum"            "ProcessBlue"  "Purple"
    "RawSienna"      "Red"             "RedOrange"    "RedViolet"
    "Rhodamine"      "RoyalBlue"       "RoyalPurple"  "RubineRed"
    "Salmon"         "SeaGreen"        "Sepia"        "SkyBlue"
    "SpringGreen"    "Tan"             "TealBlue"     "Thistle"
    "Turquoise"      "Violet"          "VioletRed"    "White"
    "WildStrawberry" "Yellow"          "YellowGreen"  "YellowOrange")
  "List of colors defined by package option dvipsnames from xcolor.sty.")

(defvar LaTeX-xcolor-svgnames-colors
  '("AliceBlue"      "DarkTurquoise" "LightSalmon"       "PaleVioletRed"
    "AntiqueWhite"   "DarkViolet"    "LightSeaGreen"     "PapayaWhip"
    "Aqua"           "DeepPink"      "LightSkyBlue"      "PeachPuff"
    "Aquamarine"     "DeepSkyBlue"   "LightSlateBlue"    "Peru"
    "Azure"          "DimGray"       "LightSlateGray"    "Pink"
    "Beige"          "DimGrey"       "LightSlateGrey"    "Plum"
    "Bisque"         "DodgerBlue"    "LightSteelBlue"    "PowderBlue"
    "Black"          "FireBrick"     "LightYellow"       "Purple"
    "BlanchedAlmond" "FloralWhite"   "Lime"              "Red"
    "Blue"           "ForestGreen"   "LimeGreen"         "RosyBrown"
    "BlueViolet"     "Fuchsia"       "Linen"             "RoyalBlue"
    "Brown"          "Gainsboro"     "Magenta"           "SaddleBrown"
    "BurlyWood"      "GhostWhite"    "Maroon"            "Salmon"
    "CadetBlue"      "Gold"          "MediumAquamarine"  "SandyBrown"
    "Chartreuse"     "Goldenrod"     "MediumBlue"        "SeaGreen"
    "Chocolate"      "Gray"          "MediumOrchid"      "Seashell"
    "Coral"          "Green"         "MediumPurple"      "Sienna"
    "CornflowerBlue" "GreenYellow"   "MediumSeaGreen"    "Silver"
    "Cornsilk"       "Grey"          "MediumSlateBlue"   "SkyBlue"
    "Crimson"        "Honeydew"      "MediumSpringGreen" "SlateBlue"
    "Cyan"           "HotPink"       "MediumTurquoise"   "SlateGray"
    "DarkBlue"       "IndianRed"     "MediumVioletRed"   "SlateGrey"
    "DarkCyan"       "Indigo"        "MidnightBlue"      "Snow"
    "DarkGoldenrod"  "Ivory"         "MintCream"         "SpringGreen"
    "DarkGray"       "Khaki"         "MistyRose"         "SteelBlue"
    "DarkGreen"      "Lavender"      "Moccasin"          "Tan"
    "DarkGrey"       "LavenderBlush" "NavajoWhite"       "Teal"
    "DarkKhaki"      "LawnGreen"     "Navy"              "Thistle"
    "DarkMagenta"    "LemonChiffon"  "NavyBlue"          "Tomato"
    "DarkOliveGreen" "LightBlue"     "OldLace"           "Turquoise"
    "DarkOrange"     "LightCoral"    "Olive"             "Violet"
    "DarkOrchid"     "LightCyan"     "OliveDrab"         "VioletRed"
    "DarkRed"        "LightGoldenrod" "Orange"           "Wheat"
    "DarkSalmon"     "LightGoldenrodYellow" "OrangeRed"  "White"
    "DarkSeaGreen"   "LightGray"     "Orchid"            "WhiteSmoke"
    "DarkSlateBlue"  "LightGreen"    "PaleGoldenrod"     "Yellow"
    "DarkSlateGray"  "LightGrey"     "PaleGreen"         "YellowGreen"
    "DarkSlateGrey"  "LightPink"     "PaleTurquoise")
  "List of colors defined by package option svgnames from xcolor.sty.")

(defvar LaTeX-xcolor-x11names-colors
  '("AntiqueWhite1"     "DeepSkyBlue1"  "LightYellow1"  "RoyalBlue1"
    "AntiqueWhite2"     "DeepSkyBlue2"  "LightYellow2"  "RoyalBlue2"
    "AntiqueWhite3"     "DeepSkyBlue3"  "LightYellow3"  "RoyalBlue3"
    "AntiqueWhite4"     "DeepSkyBlue4"  "LightYellow4"  "RoyalBlue4"
    "Aquamarine1"       "DodgerBlue1"   "Magenta1"      "Salmon1"
    "Aquamarine2"       "DodgerBlue2"   "Magenta2"      "Salmon2"
    "Aquamarine3"       "DodgerBlue3"   "Magenta3"      "Salmon3"
    "Aquamarine4"       "DodgerBlue4"   "Magenta4"      "Salmon4"
    "Azure1"            "Firebrick1"    "Maroon1"       "SeaGreen1"
    "Azure2"            "Firebrick2"    "Maroon2"       "SeaGreen2"
    "Azure3"            "Firebrick3"    "Maroon3"       "SeaGreen3"
    "Azure4"            "Firebrick4"    "Maroon4"       "SeaGreen4"
    "Bisque1"           "Gold1"         "MediumOrchid1" "Seashell1"
    "Bisque2"           "Gold2"         "MediumOrchid2" "Seashell2"
    "Bisque3"           "Gold3"         "MediumOrchid3" "Seashell3"
    "Bisque4"           "Gold4"         "MediumOrchid4" "Seashell4"
    "Blue1"             "Goldenrod1"    "MediumPurple1" "Sienna1"
    "Blue2"             "Goldenrod2"    "MediumPurple2" "Sienna2"
    "Blue3"             "Goldenrod3"    "MediumPurple3" "Sienna3"
    "Blue4"             "Goldenrod4"    "MediumPurple4" "Sienna4"
    "Brown1"            "Green1"        "MistyRose1"    "SkyBlue1"
    "Brown2"            "Green2"        "MistyRose2"    "SkyBlue2"
    "Brown3"            "Green3"        "MistyRose3"    "SkyBlue3"
    "Brown4"            "Green4"        "MistyRose4"    "SkyBlue4"
    "Burlywood1"        "Honeydew1"     "NavajoWhite1"  "SlateBlue1"
    "Burlywood2"        "Honeydew2"     "NavajoWhite2"  "SlateBlue2"
    "Burlywood3"        "Honeydew3"     "NavajoWhite3"  "SlateBlue3"
    "Burlywood4"        "Honeydew4"     "NavajoWhite4"  "SlateBlue4"
    "CadetBlue1"        "HotPink1"      "OliveDrab1"    "SlateGray1"
    "CadetBlue2"        "HotPink2"      "OliveDrab2"    "SlateGray2"
    "CadetBlue3"        "HotPink3"      "OliveDrab3"    "SlateGray3"
    "CadetBlue4"        "HotPink4"      "OliveDrab4"    "SlateGray4"
    "Chartreuse1"       "IndianRed1"    "Orange1"       "Snow1"
    "Chartreuse2"       "IndianRed2"    "Orange2"       "Snow2"
    "Chartreuse3"       "IndianRed3"    "Orange3"       "Snow3"
    "Chartreuse4"       "IndianRed4"    "Orange4"       "Snow4"
    "Chocolate1"        "Ivory1"        "OrangeRed1"    "SpringGreen1"
    "Chocolate2"        "Ivory2"        "OrangeRed2"    "SpringGreen2"
    "Chocolate3"        "Ivory3"        "OrangeRed3"    "SpringGreen3"
    "Chocolate4"        "Ivory4"        "OrangeRed4"    "SpringGreen4"
    "Coral1"            "Khaki1"        "Orchid1"       "SteelBlue1"
    "Coral2"            "Khaki2"        "Orchid2"       "SteelBlue2"
    "Coral3"            "Khaki3"        "Orchid3"       "SteelBlue3"
    "Coral4"            "Khaki4"        "Orchid4"       "SteelBlue4"
    "Cornsilk1"         "LavenderBlush1" "PaleGreen1"    "Tan1"
    "Cornsilk2"         "LavenderBlush2" "PaleGreen2"    "Tan2"
    "Cornsilk3"         "LavenderBlush3" "PaleGreen3"    "Tan3"
    "Cornsilk4"         "LavenderBlush4" "PaleGreen4"    "Tan4"
    "Cyan1"             "LemonChiffon1" "PaleTurquoise1" "Thistle1"
    "Cyan2"             "LemonChiffon2" "PaleTurquoise2" "Thistle2"
    "Cyan3"             "LemonChiffon3" "PaleTurquoise3" "Thistle3"
    "Cyan4"             "LemonChiffon4" "PaleTurquoise4" "Thistle4"
    "DarkGoldenrod1"    "LightBlue1"    "PaleVioletRed1" "Tomato1"
    "DarkGoldenrod2"    "LightBlue2"    "PaleVioletRed2" "Tomato2"
    "DarkGoldenrod3"    "LightBlue3"    "PaleVioletRed3" "Tomato3"
    "DarkGoldenrod4"    "LightBlue4"    "PaleVioletRed4" "Tomato4"
    "DarkOliveGreen1"   "LightCyan1"    "PeachPuff1"     "Turquoise1"
    "DarkOliveGreen2"   "LightCyan2"    "PeachPuff2"     "Turquoise2"
    "DarkOliveGreen3"   "LightCyan3"    "PeachPuff3"     "Turquoise3"
    "DarkOliveGreen4"   "LightCyan4"    "PeachPuff4"     "Turquoise4"
    "DarkOrange1"       "LightGoldenrod1" "Pink1"        "VioletRed1"
    "DarkOrange2"       "LightGoldenrod2" "Pink2"        "VioletRed2"
    "DarkOrange3"       "LightGoldenrod3" "Pink3"        "VioletRed3"
    "DarkOrange4"       "LightGoldenrod4" "Pink4"        "VioletRed4"
    "DarkOrchid1"       "LightPink1"    "Plum1"          "Wheat1"
    "DarkOrchid2"       "LightPink2"    "Plum2"          "Wheat2"
    "DarkOrchid3"       "LightPink3"    "Plum3"          "Wheat3"
    "DarkOrchid4"       "LightPink4"    "Plum4"          "Wheat4"
    "DarkSeaGreen1"     "LightSalmon1"  "Purple1"        "Yellow1"
    "DarkSeaGreen2"     "LightSalmon2"  "Purple2"        "Yellow2"
    "DarkSeaGreen3"     "LightSalmon3"  "Purple3"        "Yellow3"
    "DarkSeaGreen4"     "LightSalmon4"  "Purple4"        "Yellow4"
    "DarkSlateGray1"    "LightSkyBlue1" "Red1"           "Gray0"
    "DarkSlateGray2"    "LightSkyBlue2" "Red2"           "Green0"
    "DarkSlateGray3"    "LightSkyBlue3" "Red3"           "Grey0"
    "DarkSlateGray4"    "LightSkyBlue4" "Red4"           "Maroon0"
    "DeepPink1"         "LightSteelBlue1" "RosyBrown1"   "Purple0"
    "DeepPink2"         "LightSteelBlue2" "RosyBrown2"
    "DeepPink3"         "LightSteelBlue3" "RosyBrown3"
    "DeepPink4"         "LightSteelBlue4" "RosyBrown4")
  "List of colors defined by package option x11names from xcolor.sty.")

(defvar LaTeX-xcolor-color-models
  (append LaTeX-xcolor-core-color-models
          LaTeX-xcolor-num-color-models
          LaTeX-xcolor-pseudo-color-models)
  "Combine three variables `LaTeX-xcolor-core-color-models',
`LaTeX-xcolor-num-color-models' and `LaTeX-xcolor-pseudo-color-models'.")

(defun LaTeX-xcolor-color-models (&optional no-named)
  "Return the value of variable `LaTeX-xcolor-color-models'.
If NO-NAMED is non-nil, remove \"named\" and return the
remainder."
  (if no-named
      (remove "named" LaTeX-xcolor-color-models)
    LaTeX-xcolor-color-models))

;; Needed for auto-parsing.
(require 'tex)

;; Setup AUCTeX parser for \definecolor(set):
(TeX-auto-add-type "xcolor-definecolor" "LaTeX")
(TeX-auto-add-type "xcolor-definecolorset" "LaTeX")

(defvar LaTeX-xcolor-definecolor-regexp
  (eval-when-compile
    `(,(concat "\\\\"
               (regexp-opt '("definecolor"  "providecolor"
                             "preparecolor" "colorlet"))
               "\\(?:\\[\\(?:[^]]*\\)\\]\\)?{\\([^}]+\\)}")
      1 LaTeX-auto-xcolor-definecolor))
  "Match the argument of various color defining macros from xcolor package.")

(defvar LaTeX-xcolor-definecolorset-regexp
  `(,(concat "\\\\\\(?:define\\|provide\\|prepare\\)"
             "colorset"
             "\\(?:\\[\\(?:[^]]*\\)\\]\\)?"
             "{\\(?:[^}]+\\)}"
             "{\\([^}]+\\)}"
             "{\\([^}]+\\)}"
             "{\\([^}]+\\)}")
    (1 2 3) LaTeX-auto-xcolor-definecolorset)
  "Match the argument of various color-set defining macros from
xcolor package.")

(defun LaTeX-xcolor-auto-prepare ()
  "Clear `LaTeX-auto-xcolor-definecolor' before parsing."
  (setq LaTeX-auto-xcolor-definecolor nil
        LaTeX-auto-xcolor-definecolorset nil))

(defun LaTeX-xcolor-auto-cleanup ()
  "Process the parsed elements from `LaTeX-auto-xcolor-definecolorset'."
  (dolist (colset (LaTeX-xcolor-definecolorset-list))
    (let ((head (car colset))
          (tail (cadr colset))
          (cols (split-string
                 (replace-regexp-in-string "[ %\n\r\t]" "" (nth 2 colset))
                 "\\(,[^;]+;\\|,[^;]+$\\)" t)))
      (dolist (color cols)
        (LaTeX-add-xcolor-definecolors (concat head color tail))))))

(add-hook 'TeX-auto-prepare-hook #'LaTeX-xcolor-auto-prepare t)
(add-hook 'TeX-auto-cleanup-hook #'LaTeX-xcolor-auto-cleanup t)
(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)

(defun TeX-arg-xcolor-definecolor (optional)
  "Insert arguments of \\definecolor and similar macros from xcolor.sty."
  ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
  (let* ((TeX-last-optional-rejected nil)
         (xcoltype  (LaTeX-check-insert-macro-default-style
                     (completing-read
                      (TeX-argument-prompt t nil "Type")
                      LaTeX-xcolor-type-color-models)))
         (xcolname  (TeX-read-string
                     (TeX-argument-prompt optional nil "Color name")))
         (xcolmodel (completing-read
                     (TeX-argument-prompt optional nil "Model (list)")
                     (if (string= xcoltype "named")
                         (LaTeX-xcolor-color-models t)
                       LaTeX-xcolor-color-models)))
         (xcolspec  (if (string= xcolmodel "named")
                        (completing-read
                         (TeX-argument-prompt optional nil "Color")
                         (LaTeX-xcolor-definecolor-list))
                      (TeX-read-string
                       (TeX-argument-prompt optional nil (concat xcolmodel " spec (list)"))))))
    (when (and xcoltype (not (string= xcoltype "")))
      (insert (format "[%s]" xcoltype)))
    (TeX-argument-insert xcolname optional)
    (LaTeX-add-xcolor-definecolors xcolname)
    (TeX-argument-insert xcolmodel optional)
    (TeX-argument-insert xcolspec optional)))

(defun TeX-arg-xcolor-definecolorset (optional)
  "Insert arguments of \\definecolorset and similar macros from xcolor.sty."
  (let* ((TeX-last-optional-rejected nil)
         (xcoltype (LaTeX-check-insert-macro-default-style
                    (completing-read
                     (TeX-argument-prompt t nil "Type")
                     LaTeX-xcolor-type-color-models)))
         (xcolmodel (completing-read
                     (TeX-argument-prompt optional nil "Model")
                     (LaTeX-xcolor-color-models t))))
    (when (and xcoltype (not (string= xcoltype "")))
      (insert (format "[%s]" xcoltype)))
    (TeX-argument-insert xcolmodel optional)))

(defun TeX-arg-xcolor (optional)
  "Insert arguments of various color commands from xcolor.sty."
  ;; \color{<name>} or \color[<model-list>]{<spec-list>}
  (let* ((TeX-last-optional-rejected nil)
         (xcolmodel (LaTeX-check-insert-macro-default-style
                     (completing-read
                      (TeX-argument-prompt t nil "Model (list)")
                      (LaTeX-xcolor-color-models t))))
         (xcolor (if (and xcolmodel (not (string= xcolmodel "")))
                     (TeX-read-string
                      (TeX-argument-prompt optional nil (concat xcolmodel " spec (list)")))
                   (completing-read
                    (TeX-argument-prompt optional nil "Color")
                    (LaTeX-xcolor-definecolor-list)))))
    (when (and xcolmodel (not (string= xcolmodel "")))
      (insert (format "[%s]" xcolmodel)))
    (TeX-argument-insert xcolor optional)))

(defun TeX-arg-xcolor-fcolorbox (optional)
  "Insert arguments of \\fcolorbox from xcolor.sty."
  ;;\fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background spec>}{<text>}
  (let* ((TeX-last-optional-rejected nil)
         (xfrmodel (LaTeX-check-insert-macro-default-style
                    (completing-read
                     (TeX-argument-prompt t nil "(Frame) Color model")
                     LaTeX-xcolor-color-models)))
         ;; Set `TeX-last-optional-rejected' acc. to `xfrmodel'
         (TeX-last-optional-rejected (or (not xfrmodel)
                                         (and xfrmodel (string= xfrmodel ""))))
         (xfrspec  (if (or (null xfrmodel)
                           (string= xfrmodel "")
                           (string= xfrmodel "named"))
                       (completing-read
                        (TeX-argument-prompt optional nil "Frame color spec")
                        (LaTeX-xcolor-definecolor-list))
                     (TeX-read-string
                      (TeX-argument-prompt optional nil "Frame color spec"))))
         (xbgmodel (LaTeX-check-insert-macro-default-style
                    (completing-read
                     (TeX-argument-prompt t nil "Background Color model")
                     LaTeX-xcolor-color-models)))
         (xbgspec  (if (or (null xfrmodel)
                           (string= xfrmodel "")
                           (string= xfrmodel "named")
                           (null xbgmodel)
                           (string= xbgmodel "")
                           (string= xbgmodel "named"))
                       (completing-read
                        (TeX-argument-prompt optional nil "Background color spec")
                        (LaTeX-xcolor-definecolor-list))
                     (TeX-read-string
                      (TeX-argument-prompt optional nil "Background color spec")))))
    (when (and xfrmodel (not (string= xfrmodel "")))
      (insert (format "[%s]" xfrmodel)))
    (TeX-argument-insert xfrspec optional)
    (when (and xbgmodel (not (string= xbgmodel "")))
      (insert (format "[%s]" xbgmodel)))
    (TeX-argument-insert xbgspec optional)))

(TeX-add-style-hook
 "xcolor"
 (lambda ()
   ;; Add color to the parser.
   (TeX-auto-add-regexp LaTeX-xcolor-definecolor-regexp)
   (TeX-auto-add-regexp LaTeX-xcolor-definecolorset-regexp)

   ;; Add list of colors which are always available.
   (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-base-colors)

   ;; Add dvips colors in conjunction with `dvipsnames*?'.
   (when (or (LaTeX-provided-package-options-member "xcolor" "dvipsnames")
             (LaTeX-provided-package-options-member "xcolor" "dvipsnames*"))
     (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-dvipsnames-colors))

   ;; For `svgnames*?'
   (when (or (LaTeX-provided-package-options-member "xcolor" "svgnames")
             (LaTeX-provided-package-options-member "xcolor" "svgnames*"))
     (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-svgnames-colors))

   ;; For `x11ames*?'
   (when (or (LaTeX-provided-package-options-member "xcolor" "x11names")
             (LaTeX-provided-package-options-member "xcolor" "x11names*"))
     (apply #'LaTeX-add-xcolor-definecolors LaTeX-xcolor-x11names-colors))

   (TeX-add-symbols
    ;; 2.5.2 Color definition in xcolor
    ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
    '("definecolor" TeX-arg-xcolor-definecolor)

    ;; \providecolor[<type>]{<name>}{<model-list>}{<spec-list>}
    '("providecolor" TeX-arg-xcolor-definecolor)

    ;; \colorlet[<type>]{<name>}[<num model>]{<color>}
    '("colorlet"
      [ TeX-arg-eval completing-read
        (TeX-argument-prompt t nil "Type")
        LaTeX-xcolor-type-color-models ]
      (TeX-arg-eval
       (lambda ()
         (let ((xcolor (TeX-read-string
                        (TeX-argument-prompt nil nil "Color"))))
           (LaTeX-add-xcolor-definecolors xcolor)
           (format "%s" xcolor))))
      [ TeX-arg-eval completing-read
        (TeX-argument-prompt t nil "Model")
        (LaTeX-xcolor-color-models t) ]
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Color")
                    (LaTeX-xcolor-definecolor-list)))

    ;; 2.5.3 Defining sets of colors
    ;; \definecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
    '("definecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)

    ;; \providecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
    '("providecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)

    ;; 2.5.4 Immediate and deferred definitions
    ;; \preparecolor[<type>]{<name>}{<model-list>}{<spec-list>}
    '("preparecolor" TeX-arg-xcolor-definecolor)

    ;; \preparecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
    '("preparecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)

    ;; \definecolors{<id-list>}
    '("definecolors" t)

    ;; \providecolors{<id-list>}
    '("providecolors" t)

    ;; 2.6 Color application
    ;; 2.6.1 Standard color commands

    ;; \color{<name>} or \color[<model>]{<color spec>}
    '("color" TeX-arg-xcolor)

    ;; \textcolor{<name>}{<text>} or
    ;; \textcolor[<model>]{<color spec>}{<text>}
    '("textcolor" TeX-arg-xcolor "Text")

    ;; \mathcolor{<name>}{<math>} or
    ;; \mathcolor[<model>]{<color spec>}{<math>}
    '("mathcolor" TeX-arg-xcolor "Math")

    ;; \pagecolor{<name>} or
    ;; \pagecolor[<model>]{<color spec>}
    '("pagecolor" TeX-arg-xcolor)

    ;; \nopagecolor
    '("nopagecolor" 0)

    ;; 2.6.2 Colored boxes
    ;; \colorbox{<name>}{<text>} or
    ;; \colorbox[<model>]{<color spec>}{<text>}
    '("colorbox" TeX-arg-xcolor "Text")

    ;; \fcolorbox{<frame color>}{<box color>}{<text>} or
    ;; \fcolorbox[<model>]{<frame spec>}{<background spec>}{<text>} or
    ;; \fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background spec>}{<text>}
    '("fcolorbox" TeX-arg-xcolor-fcolorbox "Text")

    ;; 2.6.4 Color testing
    ;; \testcolor{<name>} or
    ;; \testcolor[<model>]{<color spec>}
    '("testcolor" TeX-arg-xcolor)

    ;; 2.7 Color blending
    '("blendcolors"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Mix expr")
                    (LaTeX-xcolor-definecolor-list)))
    '("blendcolors*"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Mix expr")
                    (LaTeX-xcolor-definecolor-list)))

    ;; 2.8 Color masks and separation
    '("maskcolors"
      [ TeX-arg-eval completing-read
        (TeX-argument-prompt t nil "Model")
        (LaTeX-xcolor-color-models t) ]
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Color")
                    (LaTeX-xcolor-definecolor-list)))

    ;; 2.9 Color series
    '("definecolorseries"
      "Name"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Core model")
                    LaTeX-xcolor-core-color-models)
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Method")
                    '("step" "grad" "last"))
      [ t ] nil [ nil ] nil)

    '("resetcolorseries" [ "Div." ] "Name")

    ;; 2.13 Color information
    ;; \extractcolorspec{<color>}{<cmd>}
    '("extractcolorspec"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Color")
                    (LaTeX-xcolor-definecolor-list))
      (TeX-arg-define-macro "Command: \\"))

    ;; \extractcolorspecs{<color>}{<model-cmd>}{<color-cmd>}
    '("extractcolorspecs"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Color")
                    (LaTeX-xcolor-definecolor-list))
      (TeX-arg-define-macro "Model command: \\")
      (TeX-arg-define-macro "Color command: \\"))

    ;; \tracingcolors = <integer>
    '("tracingcolors"
      (TeX-arg-literal "="))

    ;; 2.14 Color conversion
    ;; \convertcolorspec{<model>}{<spec>}{<target model>}{cmd>}
    '("convertcolorspec"
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Model")
                    (LaTeX-xcolor-color-models))
      (TeX-arg-eval TeX-read-string
                    (TeX-argument-prompt nil nil "Spec"))
      (TeX-arg-eval completing-read
                    (TeX-argument-prompt nil nil "Model")
                    (LaTeX-xcolor-color-models t))
      (TeX-arg-define-macro "Macro: \\")) ) ; close TeX-add-symbols

   ;; 2.12 Color in tables
   ;; These commands are available with `table' package option
   (when (LaTeX-provided-package-options-member "xcolor" "table")
     ;; Run style hook to colortbl.sty
     (TeX-run-style-hooks "colortbl")

     ;; Add additional commands:
     (TeX-add-symbols
      ;; \rowcolors[<commands>]{<row>}{<odd-row color>}{<even-row color>}
      '("rowcolors"
        (TeX-arg-conditional (y-or-n-p "With optional commands? ")
                             ( [ t ] )
                             (ignore))
        "Row"
        (TeX-arg-eval completing-read
                      (TeX-argument-prompt nil nil "Odd-row color")
                      (LaTeX-xcolor-definecolor-list))
        (TeX-arg-eval completing-read
                      (TeX-argument-prompt nil nil "Even-row color")
                      (LaTeX-xcolor-definecolor-list)))
      '("rowcolors*"
        (TeX-arg-conditional (y-or-n-p "With optional commands? ")
                             ( [ t ] )
                             (ignore))
        "Row"
        (TeX-arg-eval completing-read
                      (TeX-argument-prompt nil nil "Odd-row color")
                      (LaTeX-xcolor-definecolor-list))
        (TeX-arg-eval completing-read
                      (TeX-argument-prompt nil nil "Even-row color")
                      (LaTeX-xcolor-definecolor-list)))
      '("showrowcolors" 0)
      '("hiderowcolors" 0))
     (LaTeX-add-counters "rownum"))

   ;; 2.6.4 Color testing
   (LaTeX-add-environments
    '("testcolors" LaTeX-env-args
      [ TeX-arg-eval mapconcat #'identity
        (TeX-completing-read-multiple
         (TeX-argument-prompt t nil "Color models")
         (LaTeX-xcolor-color-models t))
        "," ] ))

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("color"             "[{")
                                ("pagecolor"         "[{"))
                              'type-declaration)
     (font-latex-add-keywords '(("textcolor"         "[{{")
                                ("colorbox"          "[{{" )
                                ("fcolorbox"         "[{[{{"))
                              'type-command)
     (font-latex-add-keywords '(("definecolor"       "[{{{")
                                ("providecolor"      "[{{{")
                                ("colorlet"          "[{[{")
                                ("definecolorset"    "[{{{{")
                                ("providecolorset"   "[{{{{")
                                ("preparecolor"      "[{{{")
                                ("preparecolorset"   "[{{{{")
                                ("definecolors"      "{")
                                ("providecolors"     "{")
                                ("testcolor"         "[{")
                                ("blendcolors"       "*{")
                                ("maskcolors"        "[{")
                                ("definecolorseries" "{{{[{[{")
                                ("resetcolorseries"  "[{")
                                ("extractcolorspec"  "{{")
                                ("extractcolorspecs" "{{{")
                                ("convertcolorspec"  "{{{{")
                                ("rowcolors"         "*[{{{"))
                              'function)))
 TeX-dialect)

(defvar LaTeX-xcolor-package-options
  '(;; options that determine the color driver
    "dvipdf" "dvipdfm" "dvipdfmx" "dvips" "dvipsone" "dvisvgm"
    "dviwin" "dviwindo" "emtex" "luatex" "oztex" "pctex32"
    "pctexhp" "pctexps" "pctexwin" "pdftex" "tcidvi" "textures"
    "truetex" "vtex" "xdvi" "xetex"

    ;; options that determine the target color model
    "natural" "rgb" "cmy" "cmyk" "hsb" "gray" "RGB" "HTML"
    "HSB" "Gray" "monochrome"

    ;; options that control predefined colors loading
    "dvipsnames" "dvipsnames*" "svgnames" "svgnames*" "x11names" "x11names*"

    ;; options that determine which other packages to load
    "table" "fixpdftex" "hyperref"

    ;; options that influence the behaviour of other commands
    "prologue" "kernelfbox" "xcdraw" "noxcdraw" "fixinclude"
    "showerrors" "hideerrors")
  "Package options for the xcolor package.")

;;; xcolor.el ends here