auctex-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-diffs] [elpa] externals/auctex 906ac31 55/67: Add new style/pyth


From: Tassilo Horn
Subject: [AUCTeX-diffs] [elpa] externals/auctex 906ac31 55/67: Add new style/pythontex.el
Date: Fri, 8 Feb 2019 11:40:39 -0500 (EST)

branch: externals/auctex
commit 906ac31426a84d79d1cfb6ad12fd06bd755935aa
Author: Arash Esbati <address@hidden>
Commit: Arash Esbati <address@hidden>

    Add new style/pythontex.el
    
    * Makefile.in (STYLESRC): Add new style.
    
    * style/pythontex.el: New file.
---
 Makefile.in        |   2 +-
 style/pythontex.el | 570 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 571 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index a5bf496..3c07c16 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -165,7 +165,7 @@ STYLESRC = style/prosper.el \
           style/arabxetex.el style/australian.el style/newzealand.el \
           style/xltabular.el style/marginnote.el style/thmtools.el \
           style/ocg-p.el     style/ocgx.el      style/thm-restate.el \
-          style/dashundergaps.el
+          style/pythontex.el style/dashundergaps.el
 
 STYLEELC = $(STYLESRC:.el=.elc)
 
diff --git a/style/pythontex.el b/style/pythontex.el
new file mode 100644
index 0000000..6aecb93
--- /dev/null
+++ b/style/pythontex.el
@@ -0,0 +1,570 @@
+;;; pythontex.el --- AUCTeX style for `pythontex.sty' (v0.16)
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+
+;; Author: Arash Esbati <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2018-12-01
+;; 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 `pythontex.sty' v0.16 from
+;; 2017/07/20.  `pythontex.sty' is part of TeXLive.
+
+;;; Code:
+
+;; Silence the compiler:
+;; `LaTeX-fancyvrb-key-val-options-local' will be defined after
+;; loading `fvextra.el' which loads `fancyvrb.el' in return:
+(defvar LaTeX-fancyvrb-key-val-options-local)
+
+;; These are provided by `font-latex.el':
+(defvar font-latex-syntactic-keywords-extra)
+(declare-function font-latex-add-keywords
+                 "font-latex"
+                 (keywords class))
+(declare-function font-latex-update-font-lock
+                 "font-latex"
+                 (&optional syntactic-kws))
+
+;; The next two are provided by `newfloat.el':
+(declare-function LaTeX-add-newfloat-DeclareFloatingEnvironments
+                 "newfloat"
+                 (&rest newfloat-declarefloatingenvironments))
+(declare-function LaTeX-newfloat-auto-cleanup
+                 "newfloat" ())
+
+;; Needed for auto-parsing:
+(require 'tex)
+
+(defvar LaTeX-pythontex-pygmentize-program (executable-find "pygmentize")
+  "Path to pygmentize executable.")
+
+(defvar LaTeX-pythontex-language-list nil
+  "List containing languages provided by pymentize program.")
+
+(defun LaTeX-pythontex-language-list (&rest _ignored)
+  "Return a list of languages provided by pymentize program.
+Update the variable `LaTeX-pythontex-language-list' if still nil."
+  (or LaTeX-pythontex-language-list
+      (when LaTeX-pythontex-pygmentize-program
+       (with-temp-buffer
+         (shell-command (concat LaTeX-pythontex-pygmentize-program " -L 
lexers")
+                        (current-buffer))
+         (goto-char (point-min))
+         (let (languages)
+           (while (re-search-forward "^\*[[:space:]]\([^:]+\):" nil t)
+             (dolist (lang (split-string (match-string 1) "[[:space:],]" t))
+               (push lang languages)))
+           (setq LaTeX-pythontex-language-list languages))))))
+
+(defvar LaTeX-pythontex-package-options-list
+  `(("usefamily"         ("py" "sympy" "pylab" "rb" "ruby" "jl" "julia" 
"octave"))
+    ("gobble"            ("none" "auto"))
+    ("beta"              ("true" "false"))
+    ("runall"            ("true" "false"))
+    ("rerun"             ("never" "modified" "errors" "warnings" "always"))
+    ("hashdependencies"  ("true" "false"))
+    ("autoprint"         ("true" "false"))
+    ("autostdout"        ("true" "false"))
+    ("debug")
+    ("makestderr"        ("true" "false"))
+    ("stderrfilename"    ("full" "session" "genericfile" "genericscript"))
+    ("pyfuture"          ("none" "all" "default"))
+    ("pyconfuture"       ("none" "all" "default"))
+    ("upquote"           ("true" "false"))
+    ("fixlr"             ("true" "false"))
+    ("keeptemps"         ("all" "code" "none"))
+    ("prettyprinter"     ("pygments" "fancyvrb"))
+    ("prettyprintinline" ("true" "false"))
+    ("pygments"          ("true" "false"))
+    ("pyginline"         ("true" "false"))
+    ("pyglexer"          ,(LaTeX-pythontex-language-list))
+    ("pygopt"            ("style" "texcomments" "mathescape"))
+    ("fvextfile")
+    ("pyconbanner"       ("none" "standard" "default" "pyversion"))
+    ("pyconfilename"     ("stdin" "console"))
+    ("depythontex"       ("true" "false")))
+  "Package options for the pythontex package.")
+
+(defun LaTeX-pythontex-package-options ()
+  "Prompt for package options for the pythontex package."
+  (TeX-read-key-val t LaTeX-pythontex-package-options-list))
+
+(defvar LaTeX-pythontex-family-list
+  '("py" "sympy" "pylab" "rb" "ruby" "jl" "julia" "octave")
+  "List of language families provided by pythontex package.")
+
+(defun LaTeX-env-pythontex (environment)
+  "Insert ENVIRONMENT provided by pythontex package."
+  (let ((session (TeX-read-string
+                 (TeX-argument-prompt t nil "Session")))
+       (fvkeyval (TeX-read-key-val t LaTeX-fancyvrb-key-val-options-local)))
+    (LaTeX-insert-environment environment
+                             (concat
+                              (when (and session (not (string= session "")))
+                                (concat LaTeX-optop session LaTeX-optcl))
+                              ;; We need an extra pair of brackets
+                              ;; when no session is given but
+                              ;; key=vals are available
+                              (when (and session (string= session "")
+                                         fvkeyval (not (string= fvkeyval "")))
+                                (concat LaTeX-optop LaTeX-optcl))
+                              (when (and fvkeyval (not (string= fvkeyval "")))
+                                (concat LaTeX-optop fvkeyval LaTeX-optcl))))))
+
+;; Setup for \saveprintpythontex & \savestdoutpythontex &
+;; \savestderrpythontex
+(TeX-auto-add-type "pythontex-savecontent" "LaTeX")
+
+(defvar LaTeX-pythontex-savecontent-regexp
+  `(,(concat "\\"
+            (regexp-opt '("saveprintpythontex"
+                          "savestdoutpythontex"
+                          "savestderrpythontex")
+                        "\(?:")
+            "{\([^}]+\)}")
+    1 LaTeX-auto-pythontex-savecontent)
+  "Matches the argument of \save(print|stdout|stderr)pythontex macros.")
+
+;; Setup for \setpythontexlistingenv:
+(TeX-auto-add-type "pythontex-setpythontexlistingenv" "LaTeX")
+
+(defvar LaTeX-pythontex-setpythontexlistingenv-regexp
+  '("\\setpythontexlistingenv{\([^}]+\)}"
+    1 LaTeX-auto-pythontex-setpythontexlistingenv)
+  "Matches the argument of \setpythontexlistingenv macro.")
+
+(defun LaTeX-pythontex-auto-prepare ()
+  "Clear various `LaTeX-auto-pythontex-*' before parsing."
+  (setq LaTeX-auto-pythontex-savecontent nil
+       LaTeX-auto-pythontex-setpythontexlistingenv nil))
+
+(defun LaTeX-pythontex-auto-cleanup ()
+  "Process the parsing results for \setpythontexlistingenv macro."
+  ;; Use `LaTeX-add-newfloat-DeclareFloatingEnvironments' on parsed
+  ;; elements and then run `LaTeX-newfloat-auto-cleanup'.
+  (dolist (env (mapcar #'car (LaTeX-pythontex-setpythontexlistingenv-list)))
+    (LaTeX-add-newfloat-DeclareFloatingEnvironments `(,env "verbatim")))
+  (LaTeX-newfloat-auto-cleanup))
+
+(add-hook 'TeX-auto-prepare-hook #'LaTeX-pythontex-auto-prepare t)
+(add-hook 'TeX-auto-cleanup-hook #'LaTeX-pythontex-auto-cleanup t)
+(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+
+(defun LaTeX-pythontex-add-syntactic-keywords-extra (type macro)
+  "Add MACRO from pythontex.sty to `font-latex-syntactic-keywords-extra'


reply via email to

[Prev in Thread] Current Thread [Next in Thread]