1 ;;; pstricks.el --- AUCTeX style for the `pstricks' package.
3 ;; Copyright (C) 2007, 2009 Free Software Foundation, Inc.
5 ;; Author: Holger Sparr <holger.sparr@gmx.net>
6 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
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)
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.
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
29 ;; AUCTeX style file for PSTricks
31 ;; Support for basic PSTricks macros and their arguments. Separate
32 ;; history variables for point, angle, ... arguments.
34 ;; Parameter input completion together with input completion for certain
35 ;; parameters (e.g. linestyle, linecolor and the like).
37 ;; There is a PSTricks-specific support for adding new parameters to
38 ;; existing parameter lists or changing existing ones in optional
39 ;; macro arguments. You might want to make those available through
40 ;; key bindings by using something like
41 ;; (define-key LaTeX-mode-map (kbd "C-c p a")
42 ;; 'LaTeX-pst-parameter-add)
43 ;; (define-key LaTeX-mode-map (kbd "C-c p c")
44 ;; 'LaTeX-pst-parameter-change-value)
45 ;; in a personal style file for PSTricks.
49 ;; 14/06/2007 rewrite of pstricks.el based on Jean-Philippe Georget's
50 ;; pstricks.el version found on <URI:
51 ;; http://www.emacswiki.org/cgi-bin/wiki/pstricks.el>
55 ;; -- Use alist or hash-table for parameter input
56 ;; -- Add more regularly used PSTricks macros
57 ;; -- Prevent errors in AUCTeX modes other than LaTeX mode.
58 ;; -- Check if the functionality for adding and changing parameters
59 ;; can be generalized.
65 (defun TeX-arg-compl-list (list &optional prompt hist)
66 "Input a value after PROMPT with completion from LIST and HISTORY."
67 (let ((first (car list)))
68 (if (and first (listp first))
69 (let ((func (nth 0 first))
70 (prompt (concat (or (nth 1 first) prompt) ": "))
72 (hist (or (nth 3 first) hist))
73 (crm-separator (nth 4 first))
75 (setq list (cdr list))
76 (cond ((eq func 'completing-read-multiple)
77 (setq res (funcall func prompt list nil compl nil hist))
78 (mapconcat 'identity res crm-separator))
79 ((eq func 'completing-read)
81 (funcall func prompt list nil compl nil hist)))))
82 (completing-read (concat prompt ": ") list nil nil nil hist))))
84 ;; XXX: Show default value in prompt. Perhaps extend
85 ;; `TeX-argument-prompt' to do that.
86 (defun LaTeX-pst-what (what prompt default &optional arg)
87 "Ask for WHAT with PROMPT with DEFAULT.
88 The corresponding lists LaTeX-pst-<what>-\\(list\\|history\\)
91 \(Used to define functions named LaTeX-pst-<what>.\))"
92 (let ((list (intern (concat "LaTeX-pst-" what "-list")))
93 (hist (intern (concat "LaTeX-pst-" what "-history"))))
95 (setq arg (TeX-arg-compl-list (symbol-value list) prompt hist)))
98 (add-to-list list arg)
101 (defun LaTeX-pst-input-int (prompt arg)
102 "Return number as string asked for with PROMPT if no number
104 (unless (numberp arg)
105 (setq arg (read-number (concat prompt ": ") 2)))
106 (number-to-string arg))
108 (defun LaTeX-pst-enclose-obj (symbol op cl)
109 "Enclose string returned by the `funcall' SYMBOL in OP and CL
111 (let ((str (funcall symbol)))
112 (if str (insert (char-to-string op) str (char-to-string cl)))))
114 (defun LaTeX-package-parameter-value (param pname)
115 "Ask for possible value of parameter PARAM given as string
116 available through package name PNAME and return \"param=value\"."
117 (add-to-list (intern (concat "LaTeX-" pname "-parameters-name-list"))
119 ;; select predefined set
122 (intern (concat "LaTeX-" pname
123 "-parameters-completion-regexp"))))
125 (symbol-value (intern (concat "LaTeX-" pname
126 "-parameters-boolean-regexp"))))
128 ((string-match cregexp param)
129 (intern (concat "LaTeX-" pname "-"
130 (match-string 0 param) "-list")))
131 ((string-match bregexp param)
132 'LaTeX-pst-boolean-list)))
135 (setq val (TeX-arg-compl-list
136 (symbol-value parlist)
137 (concat "(Press TAB for completions) " param)
138 (intern (concat "LaTeX-" pname
139 "-parameters-value-history"))))
140 ;; FIXME: This looks broken. `compl' is never set and unless ""
141 ;; is added to parlist (at least in the Boolean case), the prompt
142 ;; shown by `TeX-arg-compl-list' will be incorrect.
143 (if (and (not compl) parlist) (add-to-list parlist val))
144 (if (string= val "") "" (concat param "=" val))))
146 (defun LaTeX-package-parameters-pref-and-chosen (param pname noskip)
147 "Set values for elements of PARAM from package PNAME and
148 further explicitly typed in parameters and return a comma
149 separated list as string."
151 (fask (intern (concat "LaTeX-" pname "-parameter-value")))
155 (setq tpara (pop param))
156 (setq parval (funcall fask tpara))
159 (if (or (string= "" allpars) (string= "" parval))
161 ;; ask for parameter names as long as none is given
169 "Parameter name (RET to stop): "
170 (symbol-value (intern
171 (concat "LaTeX-" pname
172 "-parameters-name-list")))
174 (concat "LaTeX-" pname
175 "-parameters-name-history"))))))
176 (setq parval (funcall fask tpara))
177 ;; concat param=value with other ones
180 (if (or (string= "" allpars) (string= "" parval))
185 (intern (concat "LaTeX-" pname "-parameters-history")) allpars)
188 (defun LaTeX-package-parameters (optional pname preparam param)
189 "Ask for parameters and manage several parameter lists for
192 (concat "LaTeX-" pname "-parameters-pref-and-chosen")))
193 (hlist (intern (concat "LaTeX-" pname "-parameters-history")))
196 (intern (concat "LaTeX-" pname "-parameters-name-list")))))
198 (when (and preparam (listp preparam))
199 (setq preparam (funcall fask preparam)))
202 (completing-read-multiple
204 "Params (use <Up,Down> for history or RET for choices): ")
205 nlist nil nil nil hlist))
207 (if (and (string= "" (car param)) (= (length param) 1))
208 (setq param (funcall fask nil t))
209 (setq param (car (symbol-value hlist))))
211 (if (or (string= "" preparam) (eq preparam nil))
213 (concat preparam (if (string= "" param) "" (concat "," param))))
217 (defvar LaTeX-pst-point-list (list "0,0")
218 "A list of values for point in pstricks.")
220 (defvar LaTeX-pst-point-history LaTeX-pst-point-list
221 "History of values for point in pstricks.")
223 (defun LaTeX-pst-point ()
224 "Ask for a point and manage point list."
225 (LaTeX-pst-what "point"
226 (concat "Point (default " (car LaTeX-pst-point-history) ")")
227 (car LaTeX-pst-point-history)))
229 (defun LaTeX-pst-point-in-parens (optional)
230 "Enclose point in parentheses."
231 (LaTeX-pst-enclose-obj 'LaTeX-pst-point ?( ?)))
234 (defvar LaTeX-pst-angle-list (list "0")
235 "A list of values for angle in pstricks.")
237 (defvar LaTeX-pst-angle-history nil
238 "History of values for angle in pstricks.")
240 (defun LaTeX-pst-angle ()
241 "Ask for a angle and manage angle list"
242 (LaTeX-pst-what "angle"
243 (concat "Angle (default " (car LaTeX-pst-angle-list) ")")
244 (car LaTeX-pst-angle-list)))
246 ;;; Extension in one Direction
247 (defvar LaTeX-pst-extdir-list (list "1")
248 "A list of values for extdir in pstricks.")
250 (defvar LaTeX-pst-extdir-history nil
251 "History of values for extdir in pstricks.")
253 (defun LaTeX-pst-extdir (descr)
254 "Ask for a extdir and manage extdir list"
255 (LaTeX-pst-what "extdir"
256 (concat descr " (default " (car LaTeX-pst-extdir-list) ")")
257 (car LaTeX-pst-extdir-list)))
260 (defvar LaTeX-pst-delpoint-list nil
261 "A list of values for delpoint in pstricks.")
263 (defvar LaTeX-pst-delpoint-history nil
264 "History of values for delpoint in pstricks.")
267 (defvar LaTeX-pst-arrows-list
268 '("->" "<-" "<->" ">-<" ">-" "-<" "<<->>" "<<-" "->>" "|-|" "|-" "-|"
269 "|*-|*" "[-]" "[-" "-]" "(-)" "(-" "-)" "*-*" "*-" "-*" "0-0" "0-"
270 "-0" "c-c" "c-" "-c" "C-C" "C-" "-C" "cc-cc" "cc-" "-cc" "|<->|" "|<-"
271 "->|" "|<*->|*" "|<*-" "->|*" "-")
272 "A list of values for arrows in pstricks.")
274 (defvar LaTeX-pst-arrows-history nil
275 "History of values for arrows in pstricks.")
277 ;; XXX: Better ask for arrow start and end separately?
278 ;; `LaTeX-pst-arrows-list' is not exhaustive.
279 (defun LaTeX-pst-arrows ()
280 "Ask for a arrow type and manage arrow type list"
281 (or (LaTeX-pst-what "arrows" "Arrow type" nil) ""))
284 (defvar LaTeX-pst-dotstyle-list
285 '((completing-read "Dot style" nil LaTeX-pst-dotstyle-history)
286 "*" "o" "+" "|" "triangle" "triangle*" "square" "square*" "pentagon"
288 "A list of values for dotstyle in pstricks.")
290 (defvar LaTeX-pst-dotstyle-history nil
291 "History of values for dotstyle in pstricks.")
294 (defvar LaTeX-pst-refpoint-list
295 '((completing-read "Reference point" t LaTeX-pst-refpoint-history)
296 "l" "r" "t" "tl" "lt" "tr" "rt" "b" "bl" "br" "lb" "rb" "B" "Bl"
298 "A list of values for refpoint in pstricks.")
300 (defvar LaTeX-pst-refpoint-history nil
301 "History of values for refpoint in pstricks.")
303 (defun LaTeX-pst-refpoint ()
304 "Ask for a refpoint and manage refpoint list"
305 (LaTeX-pst-what "refpoint" "Reference point" nil))
309 ;; FIXME: Still used?
310 (defvar LaTeX-pst-color-history nil
311 "History of values for color in pstricks.")
313 ;;; Others without History in Completion
315 (defvar LaTeX-pst-style-list
316 '((completing-read "Defined Style" t))
317 "A list of values for user defined styles in pstricks.")
321 (defvar LaTeX-pst-parameters-history nil
322 "History of values for parameters in pstricks.")
324 (defvar LaTeX-pst-parameters-value-history nil
325 "History of parameter values in pstricks.")
327 (defvar LaTeX-pst-basic-parameters-name-list
328 '("arcsep" "arcsepA" "arcsepB" "arrowinset" "arrowlength" "arrows"
329 "arrowscale" "arrowsize" "border" "bordercolor" "boxsep"
330 "bracketlength" "cornersize" "curvature" "dash" "dimen" "dotangle"
331 "dotscale" "dotsep" "dotsize" "dotstyle" "doublecolor" "doubleline"
332 "doublesep" "doubleset" "fillcolor" "fillstyle" "framearc"
333 "framesep" "gangle" "gridcolor" "griddots" "gridlabelcolor"
334 "gridlabels" "gridwidth" "hatchangle" "hatchcolor" "hatchsep"
335 "hatchsepinc" "hatchwidth" "hatchwidthinc" "header" "labelsep"
336 "liftpen" "linearc" "linecolor" "linestyle" "linetype" "linewidth"
337 "rbracketlength" "ref" "runit" "shadow" "shadowangle" "shadowcolor"
338 "shadowsize" "showgrid" "showpoints" "style" "subgridcolor"
339 "subgriddiv" "subgriddots" "subgridwidth" "swapaxes" "tbarsize"
340 "trimode" "unit" "xunit" "yunit")
341 "A list of parameter names in pstricks.")
344 (defvar LaTeX-pst-boolean-list '("true" "false")
345 "List of binary values for key=value completion.")
347 ;; XXX: Colors can actually be given as [-]<color>[!<num>].
348 (defvar LaTeX-pst-color-list
349 '("black" "darkgray" "gray" "lightgray" "white"
350 "red" "green" "blue" "cyan" "magenta" "yellow")
351 "List of colors predefined in PSTricks.")
353 (defvar LaTeX-pst-fillstyle-list
354 '("none" "solid" "vlines" "vlines*" "hlines" "hlines*" "crosshatch"
355 "crosshatch*" "boxfill")
356 "List of fill styles defined in PSTricks.")
358 ;; From PSTricks: PostScript macros for Generic TeX, User's Guide,
359 ;; Timothy Van Zandt, 25 July 2003, Version 97.
360 ;; FIXME: Provide separate variables tailored to the different macros.
361 (defvar LaTeX-pst-basic-parameters-list
362 '(;; Dimensions, coordinates and angles
367 ;; Basic graphics parameters
369 ("linecolor" LaTeX-pst-color-list)
370 ("fillstyle" LaTeX-pst-fillstyle-list)
371 ("fillcolor" LaTeX-pst-color-list)
372 ("arrows" LaTeX-pst-arrows-list)
373 ("showpoints" LaTeX-pst-boolean-list)
374 ;; Lines and polygons
377 ("cornersize" ("relative" "absolute"))
379 ;; Arcs, circles and ellipses
386 ("dotstyle" ("*" "o" "Bo" "x" "+" "B+" "asterisk" "Basterisk" "oplus"
387 "otimes" "|" "B|" "square" "Bsquare" "square*" "diamond"
388 "Bdiamond" "diamond*" "triangle" "Btriangle" "triangle*"
389 "pentagon" "Bpentagon" "pentagon*"))
395 ("gridcolor" LaTeX-pst-color-list)
398 ("gridlabelcolor" LaTeX-pst-color-list)
401 ("subgridcolor" LaTeX-pst-color-list)
404 ("plotstyle" ("dots" "line" "polygon" "curve" "ecurve" "ccurve"))
406 ;; Coordinate systems
408 ("swapaxes" LaTeX-pst-boolean-list)
410 ("linestyle" ("none" "solid" "dashed" "dotted"))
414 ("bordercolor" LaTeX-pst-color-list)
415 ("doubleline" LaTeX-pst-boolean-list)
417 ("doublecolor" LaTeX-pst-color-list)
418 ("shadow" LaTeX-pst-boolean-list)
421 ("shadowcolor" LaTeX-pst-color-list)
422 ("dimen" ("outer" "inner" "middle"))
426 ("hatchcolor" LaTeX-pst-color-list)
428 ("addfillstyle" LaTeX-pst-fillstyle-list)
429 ;; Arrowheads and such
441 ;; Placing and rotating whatever
444 ("labels" ("all" "x" "y" "none"))
445 ("showorigin" LaTeX-pst-boolean-list)
446 ("ticks" ("all" "x" "y" "none"))
447 ("tickstyle" ("full" "top" "bottom"))
449 ("axesstyle" ("axes" "frame" "none"))
453 ("trimode" ("*" "U" "D" "R" "L"))
467 ;; Node connections labels: I
471 ("shortput" ("none" "nab" "tablr" "tab"))
472 ;; Node connection labels: II
474 ;; Attaching labels to nodes
476 ;; Mathematical diagrams and graphs
477 ("mnode" ("R" "r" "C" "f" "p" "circle" "oval" "dia" "tri" "dot" "none"))
478 ("emnode" ("R" "r" "C" "f" "p" "circle" "oval" "dia" "tri" "dot" "none"))
480 ("nodealign" LaTeX-pst-boolean-list)
481 ("mcol" ("l" "r" "c"))
487 "List of keys and values for PSTricks macro arguments.")
489 (defvar LaTeX-pst-parameters-name-list
490 LaTeX-pst-basic-parameters-name-list
491 "A list of all parameters with completion.")
493 (defvar LaTeX-pst-parameters-name-history nil
494 "History of parameter names in pstricks.")
496 (defvar LaTeX-pst-parameters-completion-regexp
497 "\\(arrows\\|linestyle\\|fillstyle\\|color\\|trimode\\|dotstyle\\|\\<style\\)"
498 "Regexp for `string-match'ing a parameter.")
500 (defvar LaTeX-pst-parameters-boolean-regexp
501 "\\(doubleline\\|shadow\\>\\|show[a-zA-Z]+\\)"
502 "Regexp for `string-match'ing a parameter.")
504 (defun LaTeX-pst-parameter-value (param)
505 "See documentation of `LaTeX-package-parameter-value'."
506 (LaTeX-package-parameter-value param "pst"))
508 (defun LaTeX-pst-parameters-pref-and-chosen (param &optional noskip)
509 "See documentation of `LaTeX-package-parameters-pref-and-chosen'."
510 (LaTeX-package-parameters-pref-and-chosen param "pst" noskip))
512 ;; FIXME: This is likely only a transitional function used until all
513 ;; macros got their calls to `TeX-arg-key-val' with tailored parameter
515 (defun LaTeX-pst-parameters (optional)
516 "Prompt for general parameters of a PSTricks argument."
517 (TeX-arg-key-val optional LaTeX-pst-basic-parameters-list))
520 (defun LaTeX-pst-macro-psarc (optional &optional arg)
521 "Return \\psarc arguments after querying."
522 (let ((arrows (LaTeX-pst-arrows))
523 (pnt (if current-prefix-arg nil (LaTeX-pst-point))))
524 (insert (if arrows (format "{%s}" arrows) "")
525 (if pnt (format "(%s)" pnt) "")
526 "{" (LaTeX-pst-extdir "Radius") "}{" (LaTeX-pst-angle) "}{"
527 (LaTeX-pst-angle) "}")))
529 (defun LaTeX-pst-macro-pscircle (optional &optional arg)
530 "Return \\pscircle arguments after querying."
531 (insert "(" (LaTeX-pst-point) "){" (LaTeX-pst-extdir "Radius") "}"))
533 (defun LaTeX-pst-macro-rput (optional &optional arg)
534 "Return \\rput arguments after querying."
535 (let ((refpoint (LaTeX-pst-refpoint))
536 (rotation (if current-prefix-arg (LaTeX-pst-angle) nil)))
537 (insert (if refpoint (concat "[" refpoint "]") "")
539 (concat "{" rotation "}")
540 "") "(" (LaTeX-pst-point) ")")))
542 (defun LaTeX-pst-macro-uput (optional &optional arg)
543 "Return \\uput arguments after querying."
544 (let ((dist (LaTeX-pst-extdir "Distance"))
545 (refpoint (LaTeX-pst-refpoint)))
546 (insert (if dist (concat "{" dist "}") "")
548 (concat "[" (LaTeX-pst-refpoint) "]")
550 "{" (LaTeX-pst-angle) "}(" (LaTeX-pst-point) ")")))
552 (defun LaTeX-pst-macro-multirputps (optional &optional arg)
553 "Return \\multirput or \\multips arguments after querying."
554 (let ((refpoint (LaTeX-pst-refpoint))
555 (rotation (if current-prefix-arg (LaTeX-pst-angle) nil))
556 (pnt (LaTeX-pst-point))
557 (dpnt (LaTeX-pst-what "delpoint" "Increment (default 1,1)" "1,1"))
558 (repi (LaTeX-pst-input-int "Repetitions" nil)))
559 (insert (if refpoint (format "[%s]" refpoint) "")
560 (if rotation (format "{%s}" rotation) "")
561 "(" pnt ")(" dpnt "){" repi "}")))
563 (defun LaTeX-pst-macro-psline (optional &optional arg)
564 "Return \\psline or \\ps[ce]?curve[*] arguments after querying."
565 (let ((arrows (LaTeX-pst-arrows))
566 (pnt1 (LaTeX-pst-point))
567 (pnt2 (LaTeX-pst-point)))
568 (insert (if arrows (format "{%s}" arrows) "") "(" pnt1 ")" )
569 (while (and (not (string= pnt2 "")) (not (string= pnt1 pnt2)))
570 (insert "(" pnt2 ")")
572 (setq pnt2 (LaTeX-pst-point)))))
574 (defun LaTeX-pst-macro-psdots (optional single)
575 "Return \\psdot[s]? arguments after querying."
576 (let* ((pnt1 (LaTeX-pst-point))
577 (pnt2 (if single pnt1 (LaTeX-pst-point))))
578 (insert "(" pnt1 ")")
579 (while (and (not (string= pnt2 "")) (not (string= pnt1 pnt2)))
581 (insert "(" pnt1 ")")
582 (setq pnt2 (LaTeX-pst-point)))))
584 (defun LaTeX-pst-macro-parabola (optional &optional arg)
585 "Return \\parabola arguments after querying."
586 (let ((arrows (LaTeX-pst-arrows)))
587 (insert (if arrows (format "{%s}" arrows) "")
588 "(" (LaTeX-pst-point) ")(" (LaTeX-pst-point) ")")))
590 (defun LaTeX-pst-macro-pnt-twolen (optional prompt1 prompt2)
591 "Return point and 2 paired lengths in separate parens as arguments."
592 ;; insert \psellipse[*]?, \psdiamond or \pstriangle arguments
593 (let ((pnt (if current-prefix-arg nil (LaTeX-pst-point))))
594 (insert (if pnt (format "(%s)" pnt) "")
595 "(" (LaTeX-pst-extdir prompt1) ","
596 (LaTeX-pst-extdir prompt2) ")")))
598 (defun LaTeX-pst-macro-psbezier (optional &optional arg)
599 "Return \\psbezier arguments after querying."
600 (let ((arrows (LaTeX-pst-arrows))
601 (pnt1 (LaTeX-pst-point))
602 (pnt2 (LaTeX-pst-point))
603 (pnt3 (LaTeX-pst-point)))
604 (insert (if arrows (format "{%s}" arrows) "")
605 "(" pnt1 ")(" pnt2 ")")
606 (while (not (string= pnt2 pnt3))
607 (insert "(" pnt3 ")")
609 (setq pnt3 (LaTeX-pst-point)))))
611 (defun LaTeX-pst-macro-pspolygon (optional &optional arg)
612 "Return \\pspolygon arguments after querying."
613 (let ((pnt1 (LaTeX-pst-point))
614 (pnt2 (LaTeX-pst-point))
615 (pnt3 (LaTeX-pst-point)))
616 (insert "(" pnt1 ")(" pnt2 ")")
617 (while (not (string= pnt2 pnt3))
618 (insert "(" pnt3 ")")
620 (setq pnt3 (LaTeX-pst-point)))))
622 (defun LaTeX-pst-macro-psframe (optional &optional arg)
623 "Return \\psframe arguments after querying."
624 (let ((pnt1 (if current-prefix-arg nil (LaTeX-pst-point)))
625 (pnt2 (LaTeX-pst-point)))
626 (insert (if pnt1 (format "(%s)" pnt1) "") "(" pnt2 ")")))
628 (defun LaTeX-pst-macro-psgrid (optional &optional arg)
629 "Return \\psgrid arguments after querying."
630 (let* ((cpref (if current-prefix-arg (car current-prefix-arg) 0))
631 (pnt1 (if (> cpref 4) (LaTeX-pst-point) nil))
632 (pnt2 (if (> cpref 0) (LaTeX-pst-point) nil))
633 (pnt3 (if (> cpref 0) (LaTeX-pst-point) nil)))
634 (insert (if pnt1 (format "(%s)" pnt1) "")
635 (if pnt2 (format "(%s)(%s)" pnt2 pnt3) ""))))
637 (defun LaTeX-pst-macro-newpsobject (&optional arg)
638 "Return \\newpsobject arguments after querying."
639 (insert "{" (read-string "New PSObject Name: ") "}"
640 ;; FIXME: It would be better to use something more confined
641 ;; than `TeX-symbol-list'.
642 "{" (completing-read "Parent Object: " (TeX-symbol-list))
646 (defun LaTeX-pst-env-pspicture (env)
647 "Create new pspicure environment."
648 (let ((opt (multi-prompt-key-value
649 (TeX-argument-prompt t "Options" nil)
650 '(("showgrid") ("shift"))))
651 (p0 (LaTeX-pst-what "point" "Lower left (default 0,0)" "0,0"))
652 (p1 (LaTeX-pst-what "point" "Upper right (default 1,1)" "1,1"))
654 (setq corn (concat (unless (string= "" opt) (format "[%s]" opt))
655 (if (string= "0,0" p0) "" (format "(%s)" p0))
657 (LaTeX-insert-environment env corn)))
659 ;;; Self Parsing -- see (info "(auctex)Hacking the Parser")
660 (defvar LaTeX-auto-pstricks-regexp-list
661 '(("\\\\newps\\(object\\){\\([a-zA-Z]+\\)}{\\([a-zA-Z]+\\)}" (1 2 3)
663 ("\\\\newps\\(fontdot\\){\\([a-zA-Z]+\\)}" (1 2)
665 ("\\\\newps\\(style\\){\\([a-zA-Z]+\\)}" (1 2)
667 ("\\\\define\\(color\\){\\([a-zA-Z]+\\)}{\\(rgb\\|cmyk\\)}" (1 2 3)
669 ("\\\\new\\(rgb\\|hsb\\|cmyk\\)\\(color\\){\\([a-zA-Z]+\\)}" (2 3 1)
670 LaTeX-auto-pstricks))
671 "List of regular expressions to extract arguments of \\newps* macros.")
673 (defvar LaTeX-auto-pstricks nil
674 "Temporary for parsing \\newps* definitions.")
676 (defun LaTeX-pst-cleanup ()
677 "Move symbols from `LaTeX-auto-pstricks' to `TeX-auto-symbol'."
680 (let ((type (car list)))
681 (cond ((string= type "object")
682 (setq TeX-auto-symbol
683 (cons (list (nth 1 list)
684 (caddr (assoc (nth 2 list)
687 ((string= type "fontdot")
688 (add-to-list 'LaTeX-pst-dotstyle-list (nth 1 list) t))
689 ((string= type "style")
690 (add-to-list 'LaTeX-pst-style-list (nth 1 list) t))
691 ((string= type "color")
692 (add-to-list 'LaTeX-pst-color-list (nth 1 list) t)
693 ;; FIXME: Why is an entry with "-" in front added?
694 (add-to-list 'LaTeX-pst-color-list
695 (concat "-" (nth 1 list)) t)))))
696 LaTeX-auto-pstricks))
698 (defun LaTeX-pst-prepare ()
699 "Clear `LaTeX-auto-pstricks' before use."
700 (setq LaTeX-auto-pstricks nil))
702 ;; FIXME: This does not seem to work unless one does a manual reparse.
703 ;; Check e.g. with "\definecolor" and "fillcolor=".
704 (add-hook 'TeX-auto-prepare-hook 'LaTeX-pst-prepare)
705 (add-hook 'TeX-auto-cleanup-hook 'LaTeX-pst-cleanup)
707 ;;; Additional Functionality
708 (defun LaTeX-pst-parameters-add (&optional arg)
709 "With ARG as prefix-argument insert new parameter\(s\) behind
710 nearest backward LaTeX macro in brackets. Without ARG add
711 parameter\(s\) to the already existing ones at the end of the
712 comma separated list. Point has to be within the sexp to modify."
714 (let ((newpara (LaTeX-pst-parameters-pref-and-chosen nil t))
715 (regexp "\\(") beg end check)
718 (re-search-backward "\\\\\\([a-zA-Z]\\)")
720 (insert-pair nil ?[ ?]))
726 (while (re-search-forward "\\([a-zA-Z]+\\)=" end 'limit)
727 (setq regexp (concat regexp
728 (match-string-no-properties 1) "\\|")))
729 (setq regexp (concat (substring regexp 0 -1) ")"))
730 (setq check (string-match regexp newpara))))
732 (insert (if arg "" ",") newpara)
735 "At least one Parameters appears twice. PLEASE CHECK!")))))
736 ;; FIXME: Only define a key for this once it is a general-purpose
737 ;; facility, i.e. not just for pstricks but all types of macros.
738 ;; (define-key LaTeX-mode-map "\C-c\C-x\C-a" 'LaTeX-pst-parameters-add)
740 (defvar LaTeX-pst-value-regexp
741 "\\([-!.a-zA-Z0-9]*\\s\\?[-!.a-zA-Z0-9]+\\)"
742 "Expression matching a parameter value.")
744 (defun LaTeX-pst-parameter-remove-value ()
745 "Remove value of current parameter and return parameter name."
747 (concat "\\(\\s(\\|,\\)[a-zA-Z]+\\([a-zA-Z]\\|=\\|="
748 LaTeX-pst-value-regexp "\\)"))
749 (re-search-forward "\\([a-zA-Z]+\\)=")
750 (let ((para (match-string-no-properties 1)))
751 (re-search-forward LaTeX-pst-value-regexp)
752 (delete-region (match-beginning 1) (match-end 1))
755 (defun LaTeX-pst-parameter-change-value ()
756 "Replace parameter value with a new one."
758 (let* ((para (LaTeX-pst-parameter-remove-value))
762 LaTeX-pst-parameters-completion-regexp para)
765 (concat "LaTeX-pst-" (match-string 0 para) "-list"))))
766 (intern (concat "LaTeX-pst-" (match-string 0 para)
768 (insert (TeX-arg-compl-list (symbol-value symb) "New Value"
769 'LaTeX-pst-parameters-value-history))))
770 ;; FIXME: Only define a key for this once it is a general-purpose
771 ;; facility, i.e. not just for pstricks but all types of macros. (See
772 ;; also `LaTeX-pst-parameters-add'. Note that a parameter change
773 ;; should better be made available through a `C-u' prefix of the
774 ;; binding for the function doing the parameter addition.)
775 ;; (define-key LaTeX-mode-map "\C-c\C-x\C-v" 'LaTeX-pst-parameter-change-value)
780 (unless (member "pst-pdf" TeX-active-styles)
782 (mapc 'TeX-auto-add-regexp LaTeX-auto-pstricks-regexp-list)
783 (LaTeX-add-environments
784 '("pspicture" LaTeX-pst-env-pspicture)
785 "overlaybox" "psclip")
787 '("AltClipMode" 0) '("DontKillGlue" 0) '("KillGlue" 0)
788 '("NormalCoor" 0) '("SpecialCoor" 0) '("PSTricksLoaded" 0)
789 '("PSTricksOff" 0) '("altcolormode" 0) '("pslinecolor" 0)
790 '("pslinestyle" 0) '("pslinetype" 0) '("pslinewidth" 0)
791 '("pslabelsep" 0) '("radian" 0) '("psunit" 0) '("psrunit" 0)
792 '("psxunit" 0) '("psyunit" 0)
793 '("arrows" (TeX-arg-eval LaTeX-pst-arrows))
794 '("clipbox" ["Border"] t)
795 '("closedshadow" [LaTeX-pst-parameters])
796 '("openshadow" [LaTeX-pst-parameters])
797 "closepath" "code" "coor" "curveto" "degrees" "dim" "endpsclip"
798 "file" "fill" "grestore" "gsave" "lineto" "movepath" "moveto"
799 "mrestore" "msave" "newpath" "rcoor" "rcurveto" "rlineto" "rotate"
800 "scale" "stroke" "swapaxes" "translate"
801 '("newcmykcolor" "Name" "Quadruple")
802 '("newrgbcolor" "Name" "Triple") '("newhsbcolor" "Name" "Triple")
803 '("newgray" "Name" "Value")
804 '("newpsobject" LaTeX-pst-macro-newpsobject LaTeX-pst-parameters)
805 '("newpsstyle" "New PSStyle Name" LaTeX-pst-parameters)
806 '("newpsfontdot" "New PSDot Name" ["Factors"]
807 "Fontname" "Character Number (Hex)")
808 '("parabola" [LaTeX-pst-parameters] LaTeX-pst-macro-parabola)
809 '("parabola*" [LaTeX-pst-parameters] LaTeX-pst-macro-parabola)
810 '("psarc" [LaTeX-pst-parameters] LaTeX-pst-macro-psarc)
811 '("psarc*" [LaTeX-pst-parameters] LaTeX-pst-macro-psarc)
812 '("psarcn" [LaTeX-pst-parameters] LaTeX-pst-macro-psarc)
813 '("pswedge" [LaTeX-pst-parameters] LaTeX-pst-macro-psarc)
814 '("psbezier" [LaTeX-pst-parameters] LaTeX-pst-macro-psbezier)
815 '("psbezier*" [LaTeX-pst-parameters] LaTeX-pst-macro-psbezier)
816 '("pscbezier" [LaTeX-pst-parameters] LaTeX-pst-macro-pspolygon)
817 '("pscircle" [LaTeX-pst-parameters] LaTeX-pst-macro-pscircle)
818 '("psccurve" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
819 '("psccurve*" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
820 '("pscurve" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
821 '("pscurve*" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
822 '("pscustom" [LaTeX-pst-parameters])
823 '("psdiamond" [LaTeX-pst-parameters]
824 (LaTeX-pst-macro-pnt-twolen "Width" "Height"))
825 '("pstriangle" [LaTeX-pst-parameters]
826 (LaTeX-pst-macro-pnt-twolen "Width" "Height"))
827 '("psdot" [LaTeX-pst-parameters] (LaTeX-pst-macro-psdots t))
828 '("psdots" [LaTeX-pst-parameters] (LaTeX-pst-macro-psdots nil))
829 '("psecurve" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
830 '("psecurve*" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
831 '("psellipse" [LaTeX-pst-parameters]
832 (LaTeX-pst-macro-pnt-twolen "Radius x" "Radius y"))
833 '("psellipse*" [LaTeX-pst-parameters]
834 (LaTeX-pst-macro-pnt-twolen "Radius x" "Radius y"))
835 '("psframe" [LaTeX-pst-parameters] LaTeX-pst-macro-psframe)
836 '("psframe*" [LaTeX-pst-parameters] LaTeX-pst-macro-psframe)
837 '("psframebox" [LaTeX-pst-parameters] t)
838 '("pscirclebox" [LaTeX-pst-parameters] t)
839 '("psdblframebox" [LaTeX-pst-parameters] t)
840 '("psdiabox" [LaTeX-pst-parameters] t)
841 '("psovalbox" [LaTeX-pst-parameters] t)
842 '("psshadowbox" [LaTeX-pst-parameters] t)
843 '("pstribox" [LaTeX-pst-parameters] t)
844 '("psscalebox" "Scaling Factor(s)" t)
845 '("psscaleboxto" LaTeX-pst-point-in-parens t)
846 '("psgrid" [LaTeX-pst-parameters] LaTeX-pst-macro-psgrid 0)
847 '("psline" [LaTeX-pst-parameters] LaTeX-pst-macro-psline)
849 '("pspolygon" [LaTeX-pst-parameters] LaTeX-pst-macro-pspolygon)
850 '("pspolygon*" [LaTeX-pst-parameters] LaTeX-pst-macro-pspolygon)
851 '("psset" LaTeX-pst-parameters)
852 '("pssetlength" TeX-arg-macro "Length")
853 '("psaddtolength" TeX-arg-macro "Length")
854 '("degrees" ["Full Circle"])
855 '("qdisk" LaTeX-pst-point-in-parens "Radius")
856 '("qline" LaTeX-pst-point-in-parens LaTeX-pst-point-in-parens)
857 "pslongbox" "psrotatedown" "psrotateleft" "psrotateright"
858 '("rput" LaTeX-pst-macro-rput t)
859 '("rput*" LaTeX-pst-macro-rput t)
860 '("cput" [LaTeX-pst-parameters]
861 (TeX-arg-eval LaTeX-pst-angle) LaTeX-pst-point-in-parens t)
862 '("uput" LaTeX-pst-macro-uput t)
863 '("multirput" (LaTeX-pst-macro-multirputps t) t)
864 '("multips" (LaTeX-pst-macro-multirputps nil) t))))
866 ;;; pstricks.el ends here