[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-devel] Beginnings of TikZ support
From: |
Matthew Leach |
Subject: |
[AUCTeX-devel] Beginnings of TikZ support |
Date: |
Tue, 22 Mar 2016 19:01:43 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
Hi all,
I've began tackling the (rather daunting) task of writing an AUCTeX
style for TikZ. I'm not sure if has been attempted before, but I'm
hoping that what I have will prove to be a solid starting point.
Please see the attached patch and feedback is much appreciated :-).
Thanks,
--
Matt
>From 1f7393c5c8bfc6fb8f36f9bed4f07d289f6e75ec Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Tue, 22 Mar 2016 18:51:27 +0000
Subject: [PATCH] Add the beginnings of TikZ support.
* style/tikz.el: New
* doc/changes.texi: Document TikZ style.
* Makefile.in: Add TikZ style to the build.
---
Makefile.in | 2 +-
doc/changes.texi | 5 +++
style/tikz.el | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+), 1 deletion(-)
create mode 100644 style/tikz.el
diff --git a/Makefile.in b/Makefile.in
index 471ff21..b390c66 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -154,7 +154,7 @@ STYLESRC = style/prosper.el \
style/fontenc.el style/Alegreya.el style/gloss-italian.el \
style/newfloat.el style/subcaption.el style/AlegreyaSans.el \
style/hologo.el style/theorem.el style/ntheorem.el \
- style/splitidx.el
+ style/splitidx.el style/tikz.el
STYLEELC = $(STYLESRC:.el=.elc)
diff --git a/doc/changes.texi b/doc/changes.texi
index 9d39db2..9d36f09 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -12,6 +12,11 @@
@itemize @bullet
@item
address@hidden now has limited support for the TikZ package. For the moment,
+this includes some basic support for prompting the user of arguments to
+the @samp{\draw} macro.
+
address@hidden
When inserting a new float, @AUCTeX{} will now prompt for a
short-caption if the length of the caption provided is greater than a
certain size. This size is controlled via a new user option
diff --git a/style/tikz.el b/style/tikz.el
new file mode 100644
index 0000000..05ac794
--- /dev/null
+++ b/style/tikz.el
@@ -0,0 +1,123 @@
+;;; tikz.el --- AUCTeX style for `tikz.sty'
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Matthew Leach <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2016-22-03
+;; Keywords: tex tikz
+
+;; 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 some support for `tikz.sty'
+
+;;; Code:
+
+(defun TeX-TikZ-get-opt-arg-string (arg &optional open close)
+ "Return a string for optional arguments.
+If ARG is nil or \"\", return \"\". Otherwise return \"OPEN ARG
+CLOSE\". If OPEN or CLOSE are nil, set them to `LaTeX-optop' and
+`LaTeX-optcl' respectively."
+ (unless (or open close)
+ (progn
+ (setq open LaTeX-optop)
+ (setq close LaTeX-optcl)))
+ (if (and arg (> (length arg) 0))
+ (concat open arg close)
+ ""))
+
+(defun TeX-TikZ-arg-rect-point (unused)
+ "Prompt the user for a point on the Cartesian plane.
+Ask the user for an X and Y coordinate, and return the string
+\"(X,Y)\"."
+ (let ((x (TeX-read-string (TeX-argument-prompt nil nil "X-coordinate")))
+ (y (TeX-read-string (TeX-argument-prompt nil nil "Y-coordinate"))))
+ (concat " (" x ", " y") ")))
+
+(defun TeX-TikZ-arg-polar-point (unused)
+ "Prompt the user for a point on the polar plane.
+Ask the user for r and theta values, and return the string
+\"(THETA:R)\"."
+ (let ((r (TeX-read-string (TeX-argument-prompt nil nil "R")))
+ (theta (TeX-read-string (TeX-argument-prompt nil nil "Theta"))))
+ (concat " (" theta ":" r ") ")))
+
+(defun TeX-TikZ-arg-node (unused)
+ "Prompt the user for the deatils of a node.
+Ask the user for the name and text for a node and return the
+string \"node[OPTIONS](NAME){TEXT}\".".
+ (let ((options (TeX-read-string (TeX-argument-prompt t nil "Options" )))
+ (name (TeX-read-string (TeX-argument-prompt t nil "Name")))
+ (text (TeX-read-string (TeX-argument-prompt nil nil "Text"))))
+ (concat "node"
+ (TeX-TikZ-get-opt-arg-string options)
+ (TeX-TikZ-get-opt-arg-string name "(" ")")
+ TeX-grop text TeX-grcl " ")))
+
+(defun TeX-TikZ-get-arg-type (types)
+ "Prompt the user for the next argument type.
+TYPES is a list of possible types that the user can specify."
+ (completing-read "Next argument type (RET to finish): " types nil t))
+
+(defun TeX-TikZ-macro-arg (function-alist)
+ "Prompt the user for arguments to compose a TikZ macro.
+FUNCTION-ALIST is a mapping of argument-types to functions. The
+user is repeatedly prompted for the next argument-type; they can
+choose form the cars in FUNCTION-ALIST and the appropriate
+function is then called. If the user enters \"\", then the macro
+is finished."
+ (let* ((options (TeX-read-string (TeX-argument-prompt t nil "Options")))
+ (argument-types `("" ,@(mapcar 'car function-alist)))
+ (argument-type (TeX-TikZ-get-arg-type argument-types)))
+
+ ;; Insert the macro options.
+ (insert (TeX-TikZ-get-opt-arg-string options)
+ " ")
+
+ ;; Iteratively prompt the user for TikZ's arguments until "" is
+ ;; returned.
+ (while (not (string= argument-type ""))
+ (insert (funcall
+ (cadr (assoc argument-type TeX-TikZ-draw-arg-function-map))
+ argument-type))
+ (setq argument-type (TeX-TikZ-get-argument-type argument-types)))
+
+ ;; Finish the macro.
+ (insert ";")))
+
+(defconst TeX-TikZ-draw-arg-function-map
+ '(("Rect Point" TeX-TikZ-arg-rect-point)
+ ("Polar Point" TeX-TikZ-arg-polar-point)
+ ("Node" TeX-TikZ-arg-node)
+ ("--" identity)
+ ("-+" identity))
+ "An alist of argument type names to their respecitve functions
+ for TikZ's \draw macro.")
+
+(defun TeX-TikZ-draw-arg (optional)
+ (TeX-TikZ-macro-arg TeX-TikZ-draw-arg-function-map))
+
+(TeX-add-style-hook
+ "tikz"
+ (lambda ()
+ (TeX-add-symbols
+ '("draw" (TeX-TikZ-draw-arg)))
+ (LaTeX-add-environments
+ '("tikzpicture"))))
--
2.7.4
- [AUCTeX-devel] Beginnings of TikZ support,
Matthew Leach <=
- Re: [AUCTeX-devel] Beginnings of TikZ support, Mosè Giordano, 2016/03/22
- Re: [AUCTeX-devel] Beginnings of TikZ support, Matthew Leach, 2016/03/25
- Re: [AUCTeX-devel] Beginnings of TikZ support, Tassilo Horn, 2016/03/26
- Re: [AUCTeX-devel] Beginnings of TikZ support, Matthew Leach, 2016/03/27
- Re: [AUCTeX-devel] Beginnings of TikZ support, Matthew Leach, 2016/03/27
- Re: [AUCTeX-devel] Beginnings of TikZ support, Tassilo Horn, 2016/03/27
- Re: [AUCTeX-devel] Beginnings of TikZ support, Tassilo Horn, 2016/03/27
- Re: [AUCTeX-devel] Beginnings of TikZ support, Matthew Leach, 2016/03/28
- Re: [AUCTeX-devel] Beginnings of TikZ support, Mosè Giordano, 2016/03/29
- Re: [AUCTeX-devel] Beginnings of TikZ support, Matthew Leach, 2016/03/29