"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/pythontex.el" (18 Oct 2020, 20940 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "pythontex.el": 12.2_vs_12.3.

    1 ;;; pythontex.el --- AUCTeX style for `pythontex.sty' (v0.16)
    2 
    3 ;; Copyright (C) 2018, 2020 Free Software Foundation, Inc.
    4 
    5 ;; Author: Arash Esbati <arash@gnu.org>
    6 ;; Maintainer: auctex-devel@gnu.org
    7 ;; Created: 2018-12-01
    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 `pythontex.sty' v0.16 from
   30 ;; 2017/07/20.  `pythontex.sty' is part of TeXLive.
   31 
   32 ;;; Code:
   33 
   34 ;; Silence the compiler:
   35 ;; `LaTeX-fancyvrb-key-val-options-local' will be defined after
   36 ;; loading `fvextra.el' which loads `fancyvrb.el' in return:
   37 (defvar LaTeX-fancyvrb-key-val-options-local)
   38 
   39 ;; These are provided by `font-latex.el':
   40 (defvar font-latex-syntactic-keywords-extra)
   41 (declare-function font-latex-add-keywords
   42           "font-latex"
   43           (keywords class))
   44 (declare-function font-latex-set-syntactic-keywords
   45           "font-latex")
   46 
   47 ;; The next two are provided by `newfloat.el':
   48 (declare-function LaTeX-add-newfloat-DeclareFloatingEnvironments
   49           "newfloat"
   50           (&rest newfloat-declarefloatingenvironments))
   51 (declare-function LaTeX-newfloat-auto-cleanup
   52           "newfloat" ())
   53 
   54 ;; Needed for auto-parsing:
   55 (require 'tex)
   56 
   57 (defvar LaTeX-pythontex-pygmentize-program (executable-find "pygmentize")
   58   "Path to pygmentize executable.")
   59 
   60 (defvar LaTeX-pythontex-language-list nil
   61   "List containing languages provided by pymentize program.")
   62 
   63 (defun LaTeX-pythontex-language-list (&rest _ignored)
   64   "Return a list of languages provided by pymentize program.
   65 Update the variable `LaTeX-pythontex-language-list' if still nil."
   66   (or LaTeX-pythontex-language-list
   67       (when LaTeX-pythontex-pygmentize-program
   68     (with-temp-buffer
   69       (shell-command (concat LaTeX-pythontex-pygmentize-program " -L lexers")
   70              (current-buffer))
   71       (goto-char (point-min))
   72       (let (languages)
   73         (while (re-search-forward "^\\*[[:space:]]\\([^:]+\\):" nil t)
   74           (dolist (lang (split-string (match-string 1) "[[:space:],]" t))
   75         (push lang languages)))
   76         (setq LaTeX-pythontex-language-list languages))))))
   77 
   78 (defvar LaTeX-pythontex-package-options-list
   79   `(("usefamily"         ("py" "sympy" "pylab" "rb" "ruby" "jl" "julia" "octave"))
   80     ("gobble"            ("none" "auto"))
   81     ("beta"              ("true" "false"))
   82     ("runall"            ("true" "false"))
   83     ("rerun"             ("never" "modified" "errors" "warnings" "always"))
   84     ("hashdependencies"  ("true" "false"))
   85     ("autoprint"         ("true" "false"))
   86     ("autostdout"        ("true" "false"))
   87     ("debug")
   88     ("makestderr"        ("true" "false"))
   89     ("stderrfilename"    ("full" "session" "genericfile" "genericscript"))
   90     ("pyfuture"          ("none" "all" "default"))
   91     ("pyconfuture"       ("none" "all" "default"))
   92     ("upquote"           ("true" "false"))
   93     ("fixlr"             ("true" "false"))
   94     ("keeptemps"         ("all" "code" "none"))
   95     ("prettyprinter"     ("pygments" "fancyvrb"))
   96     ("prettyprintinline" ("true" "false"))
   97     ("pygments"          ("true" "false"))
   98     ("pyginline"         ("true" "false"))
   99     ("pyglexer"          ,(LaTeX-pythontex-language-list))
  100     ("pygopt"            ("style" "texcomments" "mathescape"))
  101     ("fvextfile")
  102     ("pyconbanner"       ("none" "standard" "default" "pyversion"))
  103     ("pyconfilename"     ("stdin" "console"))
  104     ("depythontex"       ("true" "false")))
  105   "Package options for the pythontex package.")
  106 
  107 (defun LaTeX-pythontex-package-options ()
  108   "Prompt for package options for the pythontex package."
  109   (TeX-read-key-val t LaTeX-pythontex-package-options-list))
  110 
  111 (defvar LaTeX-pythontex-family-list
  112   '("py" "sympy" "pylab" "rb" "ruby" "jl" "julia" "octave")
  113   "List of language families provided by pythontex package.")
  114 
  115 (defun LaTeX-env-pythontex (environment)
  116   "Insert ENVIRONMENT provided by pythontex package."
  117   (let ((session (TeX-read-string
  118           (TeX-argument-prompt t nil "Session")))
  119     (fvkeyval (TeX-read-key-val t LaTeX-fancyvrb-key-val-options-local)))
  120     (LaTeX-insert-environment environment
  121                   (concat
  122                    (when (and session (not (string= session "")))
  123                  (concat LaTeX-optop session LaTeX-optcl))
  124                    ;; We need an extra pair of brackets
  125                    ;; when no session is given but
  126                    ;; key=vals are available
  127                    (when (and session (string= session "")
  128                       fvkeyval (not (string= fvkeyval "")))
  129                  (concat LaTeX-optop LaTeX-optcl))
  130                    (when (and fvkeyval (not (string= fvkeyval "")))
  131                  (concat LaTeX-optop fvkeyval LaTeX-optcl))))))
  132 
  133 ;; Setup for \saveprintpythontex & \savestdoutpythontex &
  134 ;; \savestderrpythontex
  135 (TeX-auto-add-type "pythontex-savecontent" "LaTeX")
  136 
  137 (defvar LaTeX-pythontex-savecontent-regexp
  138   `(,(concat "\\\\"
  139          (regexp-opt '("saveprintpythontex"
  140                "savestdoutpythontex"
  141                "savestderrpythontex")
  142              "\\(?:")
  143          "{\\([^}]+\\)}")
  144     1 LaTeX-auto-pythontex-savecontent)
  145   "Matches the argument of \\save(print|stdout|stderr)pythontex macros.")
  146 
  147 ;; Setup for \setpythontexlistingenv:
  148 (TeX-auto-add-type "pythontex-setpythontexlistingenv" "LaTeX")
  149 
  150 (defvar LaTeX-pythontex-setpythontexlistingenv-regexp
  151   '("\\\\setpythontexlistingenv{\\([^}]+\\)}"
  152     1 LaTeX-auto-pythontex-setpythontexlistingenv)
  153   "Matches the argument of \\setpythontexlistingenv macro.")
  154 
  155 (defun LaTeX-pythontex-auto-prepare ()
  156   "Clear various `LaTeX-auto-pythontex-*' before parsing."
  157   (setq LaTeX-auto-pythontex-savecontent nil
  158     LaTeX-auto-pythontex-setpythontexlistingenv nil))
  159 
  160 (defun LaTeX-pythontex-auto-cleanup ()
  161   "Process the parsing results for \\setpythontexlistingenv macro."
  162   ;; Use `LaTeX-add-newfloat-DeclareFloatingEnvironments' on parsed
  163   ;; elements and then run `LaTeX-newfloat-auto-cleanup'.
  164   (dolist (env (mapcar #'car (LaTeX-pythontex-setpythontexlistingenv-list)))
  165     (LaTeX-add-newfloat-DeclareFloatingEnvironments `(,env "verbatim")))
  166   (LaTeX-newfloat-auto-cleanup))
  167 
  168 (add-hook 'TeX-auto-prepare-hook #'LaTeX-pythontex-auto-prepare t)
  169 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-pythontex-auto-cleanup t)
  170 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
  171 
  172 (defun LaTeX-pythontex-add-syntactic-keywords-extra (type macro)
  173   "Add MACRO from pythontex.sty to `font-latex-syntactic-keywords-extra'.
  174 TYPE is one of the symbols `brace' or `delim' indicating how
  175 verbatim text is enclosed after the macro.  MACRO is a string or
  176 a list of strings."
  177   (let ((syntax (if (eq type 'brace)
  178             '((1 "|") (2 "|"))
  179           '((1 "\"") (2 ".") (3 "\""))))
  180     regexp)
  181     (when (listp macro)
  182       (setq macro (regexp-opt macro "\\(?:")))
  183     (setq regexp `(,(concat
  184              ;; The backslash
  185              (regexp-quote TeX-esc)
  186              ;; Name of the macro(s)
  187              macro
  188              ;; The first mandatory argument is the lexer
  189              "\\(?:{[^}]+}\\)"
  190              ;; With 'brace, allow braced sub-groups otherwise
  191              ;; we stop matching too early.  With 'delim, copy
  192              ;; font-latex.el:
  193              (if (eq type 'brace)
  194              (concat "\\({\\)"
  195                  "\\(?:[^}{]*"
  196                  "\\(?:{[^}{]*"
  197                  "\\(?:{[^}{]*"
  198                  "\\(?:{[^}{]*}[^}{]*\\)*"
  199                  "}[^}{]*\\)*"
  200                  "}[^}{]*\\)*"
  201                  "\\)"
  202                  "\\(}\\)")
  203                (concat
  204             ;; Opening delimiter
  205             "\\([^a-z@*\n\f{]\\).*?"
  206             ;; Closing delimiter
  207             "\\(" (regexp-quote TeX-esc) "*\\)\\(\\1\\)")))))
  208     (add-to-list 'font-latex-syntactic-keywords-extra (append regexp syntax))))
  209 
  210 (TeX-add-style-hook
  211  "pythontex"
  212  (lambda ()
  213 
  214    ;; Load only the relevant style hooks within AUCTeX
  215    (TeX-run-style-hooks "fvextra" "newfloat")
  216 
  217    ;; Add pythontex to the parser:
  218    (TeX-auto-add-regexp LaTeX-pythontex-savecontent-regexp)
  219    (TeX-auto-add-regexp LaTeX-pythontex-setpythontexlistingenv-regexp)
  220 
  221    ;; We need this for Filling:
  222    (make-local-variable 'LaTeX-indent-environment-list)
  223 
  224    ;; 4.2.4 Default families
  225    (let* ((verb-macs '(;; python
  226                "py" "pyc" "pys" "pyv" "pyb"
  227                "pycon" "pyconc" "pyconv"
  228                ;; Python + pylab (matplotlib module)
  229                "pylab" "pylabc" "pylabs" "pylabv" "pylabb"
  230                "pylabcon" "pylabconc" "pylabconv"
  231                ;; Python + SymPy
  232                "sympy" "sympyc" "sympys" "sympyv" "sympyb"
  233                "sympycon" "sympyconc" "sympyconv"))
  234       (verb-envs '(;;python
  235                "pycode" "pysub" "pyverbatim" "pyblock"
  236                "pyconsole" "pyconcode" "pyconverbatim"
  237                ;; Python + pylab (matplotlib module)
  238                "pylabcode" "pylabsub" "pylabverbatim" "pylabblock"
  239                "pylabconsole" "pylabconcode" "pylabconverbatim"
  240                ;; Python + SymPy
  241                "sympycode" "sympysub" "sympyverbatim" "sympyblock"
  242                "sympyconsole" "sympyconcode" "sympyconverbatim"))
  243       (verb-envs-regexp (regexp-opt verb-envs "\\(?:")))
  244      (apply #'TeX-add-symbols
  245         (mapcar (lambda (mac)
  246               (list mac [ "Session" ] 'TeX-arg-verb-delim-or-brace))
  247             verb-macs))
  248      (apply #'LaTeX-add-environments
  249         (mapcar (lambda (env)
  250               (list env 'LaTeX-env-pythontex))
  251             verb-envs))
  252      ;; Filling:
  253      (dolist (mac verb-macs)
  254        (add-to-list 'LaTeX-verbatim-macros-with-delims-local mac)
  255        (add-to-list 'LaTeX-verbatim-macros-with-braces-local mac))
  256      (dolist (env verb-envs)
  257        (add-to-list 'LaTeX-indent-environment-list
  258             `(,env current-indentation) t))
  259      ;; Fontification
  260      (when (and (fboundp 'font-latex-add-keywords)
  261         (fboundp 'font-latex-set-syntactic-keywords)
  262         (boundp 'font-latex-syntactic-keywords-extra)
  263         (eq TeX-install-font-lock 'font-latex-setup))
  264        (font-latex-add-keywords (mapcar (lambda (mac)
  265                       (list mac "["))
  266                     verb-macs)
  267                 'textual)
  268        ;; We can't use the fontification provided when verbatim
  269        ;; environments are added to
  270        ;; `LaTeX-verbatim-environments-local' -- pythontex
  271        ;; environments have 2 optional arguments and `font-latex.el'
  272        ;; recognizes only 1 optional which breaks the fontification.
  273        ;; We add the envs to `font-latex-syntactic-keywords-extra' and
  274        ;; define a customized regexp to match 2 optional arguments.
  275        (add-to-list 'font-latex-syntactic-keywords-extra
  276             `(,(concat
  277             "^[ \t]*\\\\begin *{\\(?:"
  278             verb-envs-regexp
  279             "\\)}"
  280             "[ \t]*\\(?:%.*\n[ \t]*\\)?"
  281             "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)\\{0,2\\}"
  282             "\\(\n\\|.\\)")
  283               (1 "|" t)))
  284        (add-to-list 'font-latex-syntactic-keywords-extra
  285             `(,(concat "\\(\\\\\\)end *{\\(?:"
  286                    verb-envs-regexp
  287                    "\\)}")
  288               (1 "|" t))))
  289      ;; Tell font-lock about the update.
  290      (font-latex-set-syntactic-keywords))
  291 
  292    (TeX-add-symbols
  293     ;; 4.2.5 Custom code
  294     ;; pythontexcustomc[<position>]{<family>}{<code>}
  295     '("pythontexcustomc"
  296       [ TeX-arg-eval completing-read
  297     (TeX-argument-prompt optional nil "Position")
  298     '("begin" "end") ]
  299       (TeX-arg-eval completing-read
  300             (TeX-argument-prompt optional nil "Family")
  301             LaTeX-pythontex-family-list)
  302       t)
  303 
  304     ;; 4.2.7 Formatting of typeset code
  305     ;; \setpythontexfv[<family>]{<fancyvrb settings>}
  306     '("setpythontexfv"
  307       [ TeX-arg-eval completing-read
  308     (TeX-argument-prompt optional nil "Family")
  309     LaTeX-pythontex-family-list ]
  310       (TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local))
  311 
  312     ;; \setpythontexprettyprinter[<family>]{<printer>}
  313     '("setpythontexprettyprinter"
  314       [ TeX-arg-eval completing-read
  315     (TeX-argument-prompt optional nil "Family")
  316     (cons "auto" LaTeX-pythontex-family-list) ]
  317       (TeX-arg-eval completing-read
  318             (TeX-argument-prompt optional nil "Printer")
  319             '("text" "bw" "fancyvrb" "pygments")))
  320 
  321     ;; \setpythontexpyglexer[<family>]{<pygments lexer>}
  322     '("setpythontexpyglexer"
  323       [ TeX-arg-eval completing-read
  324     (TeX-argument-prompt optional nil "Family")
  325     LaTeX-pythontex-family-list ]
  326       (TeX-arg-eval completing-read
  327             (TeX-argument-prompt optional nil "Pygments lexer")
  328             (LaTeX-pythontex-language-list)))
  329 
  330     ;; \setpythontexpygopt[<family>]{<pygments options>}
  331     '("setpythontexpygopt"
  332       [ TeX-arg-eval completing-read
  333     (TeX-argument-prompt optional nil "Family")
  334     LaTeX-pythontex-family-list ]
  335       (TeX-arg-key-val
  336        (("style") ("texcomments") ("mathescape"))))
  337 
  338     ;; 4.2.8 Access to printed content (stdout)
  339     ;; \printpythontex[<mode>][<options>]
  340     '("printpythontex"
  341       [ TeX-arg-eval completing-read
  342     (TeX-argument-prompt optional nil "Mode")
  343     '("raw" "verb" "verbatim") ]
  344       [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ] )
  345 
  346     ;; \stdoutpythontex[<mode>][<options>]
  347     '("stdoutpythontex"
  348       [ TeX-arg-eval completing-read
  349     (TeX-argument-prompt optional nil "Mode")
  350     '("raw" "verb" "verbatim") ]
  351       [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ] )
  352 
  353     ;;\saveprintpythontex{<name>}
  354     '("saveprintpythontex"
  355       (TeX-arg-eval (lambda ()
  356               (let ((name (TeX-read-string
  357                    (TeX-argument-prompt optional nil "Name"))))
  358             (LaTeX-add-pythontex-savecontents name)
  359             (format "%s" name)))))
  360 
  361     ;;\savestdoutpythontex{<name>}
  362     '("savestdoutpythontex"
  363       (TeX-arg-eval (lambda ()
  364               (let ((name (TeX-read-string
  365                    (TeX-argument-prompt optional nil "Name"))))
  366             (LaTeX-add-pythontex-savecontents name)
  367             (format "%s" name)))))
  368 
  369     ;; \useprintpythontex[<verbatim options>][<fancyvrb options>]{<name>}
  370     ;; I assume <verbatim options> is meant to be <mode>
  371     '("useprintpythontex"
  372       [ TeX-arg-eval completing-read
  373     (TeX-argument-prompt optional nil "Mode")
  374     '("raw" "verb" "verbatim") ]
  375       [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
  376       (TeX-arg-eval completing-read
  377             (TeX-argument-prompt optional nil "Name")
  378             (LaTeX-pythontex-savecontent-list)))
  379 
  380     ;; \usestdoutpythontex[<verbatim options>][<fancyvrb options>]{<name>}
  381     ;; I assume <verbatim options> is meant to be <mode>
  382     '("usestdoutpythontex"
  383       [ TeX-arg-eval completing-read
  384     (TeX-argument-prompt optional nil "Mode")
  385     '("raw" "verb" "verbatim") ]
  386       [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
  387       (TeX-arg-eval completing-read
  388             (TeX-argument-prompt optional nil "Name")
  389             (LaTeX-pythontex-savecontent-list)))
  390 
  391     ;; \stderrpythontex[<mode>][<fancyvrb options>]
  392     '("stderrpythontex"
  393       [ TeX-arg-eval completing-read
  394     (TeX-argument-prompt optional nil "Mode")
  395     '("raw" "verb" "verbatim") ]
  396       [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ] )
  397 
  398 
  399     ;;\savestderrpythontex{<name>}
  400     '("savestderrpythontex"
  401       (TeX-arg-eval (lambda ()
  402               (let ((name (TeX-read-string
  403                    (TeX-argument-prompt optional nil "Name"))))
  404             (LaTeX-add-pythontex-savecontents name)
  405             (format "%s" name)))))
  406 
  407     ;; \usestderrpythontex[<mode>][<fancyvrb options>]{<name>}
  408     '("usestderrpythontex"
  409       [ TeX-arg-eval completing-read
  410     (TeX-argument-prompt optional nil "Mode")
  411     '("raw" "verb" "verbatim") ]
  412       [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
  413       (TeX-arg-eval completing-read
  414             (TeX-argument-prompt optional nil "Name")
  415             (LaTeX-pythontex-savecontent-list)))
  416 
  417     ;;\setpythontexautoprint{<boolean>}
  418     '("setpythontexautoprint"
  419       (TeX-arg-eval completing-read
  420             (TeX-argument-prompt optional nil "Boolean value")
  421             '("true" "false")))
  422 
  423     ;; \setpythontexautostdout{<boolean>}
  424     '("setpythontexautostdout"
  425       (TeX-arg-eval completing-read
  426             (TeX-argument-prompt optional nil "Boolean value")
  427             '("true" "false")))
  428 
  429     ;; 4.3 Pygments commands and environments
  430     ;; \pygment{<lexer>}<opening delim><code><closing delim>
  431     '("pygment"
  432       (TeX-arg-eval completing-read
  433             (TeX-argument-prompt optional nil "Lexer")
  434             (LaTeX-pythontex-language-list))
  435       TeX-arg-verb-delim-or-brace)
  436 
  437     ;; \inputpygments[<fancyvrb settings>]{<lexer>}{<external file>}
  438     '("inputpygments"
  439       [ TeX-arg-eval LaTeX-fancyvrb-key-val-options-local ]
  440       (TeX-arg-eval completing-read
  441             (TeX-argument-prompt optional nil "Lexer")
  442             (LaTeX-pythontex-language-list))
  443       TeX-arg-file-name)
  444 
  445     ;; \setpygmentsfv[<lexer>]{<fancyvrb settings>}
  446     '("setpygmentsfv"
  447       [ TeX-arg-eval completing-read
  448     (TeX-argument-prompt optional nil "Lexer")
  449     (LaTeX-pythontex-language-list) ]
  450       (TeX-arg-eval LaTeX-fancyvrb-key-val-options-local))
  451 
  452     ;; \setpygmentspygopt[<lexer>]{<pygments options>}
  453     '("setpygmentspygopt"
  454       [ TeX-arg-eval completing-read
  455     (TeX-argument-prompt optional nil "Lexer")
  456     (LaTeX-pythontex-language-list) ]
  457       (TeX-arg-key-val
  458        (("style") ("texcomments") ("mathescape"))))
  459 
  460     ;; \setpygmentsprettyprinter{<printer>}
  461     '("setpygmentsprettyprinter"
  462       (TeX-arg-eval completing-read
  463             (TeX-argument-prompt optional nil "Printer")
  464             '("text" "bw" "fancyvrb" "pygments")))
  465 
  466     ;; 4.5  Advanced PythonTeX usage
  467     ;; \setpythontexcontext{<key-value pairs>}
  468     '("setpythontexcontext" t)
  469 
  470     ;; \restartpythontexsession{<counter value(s)>}
  471     '("restartpythontexsession" t)
  472 
  473     ;; \setpythontexoutputdir{<output directory>}
  474     '("setpythontexoutputdir" t)
  475 
  476     ;; \setpythontexworkingdir{<working directory>}
  477     '("setpythontexworkingdir" t)
  478 
  479     ;; 4.5  Advanced PythonTeX usage
  480     '("setpythontexcontext" t)
  481     '("restartpythontexsession" TeX-arg-counter)
  482     '("setpythontexoutputdir" t)
  483     '("setpythontexworkingdir" t) )
  484 
  485    ;; 4.4.1 Listings float
  486    ;; Only add it if not already defined somewhere else.
  487    (unless (assoc-string "listing" (LaTeX-environment-list))
  488      (LaTeX-add-newfloat-DeclareFloatingEnvironments
  489       '("listing" "verbatim")))
  490 
  491    ;; Cater for \setpythontexlistingenv:
  492    (TeX-add-symbols
  493     '("setpythontexlistingenv"
  494       (TeX-arg-eval
  495        (lambda ()
  496      (let ((name (TeX-read-string
  497               (TeX-argument-prompt optional nil "Listing environment name"))))
  498        (LaTeX-add-newfloat-DeclareFloatingEnvironments `(,name "verbatim"))
  499        (LaTeX-newfloat-auto-cleanup)
  500        (format "%s" name))))))
  501 
  502    (LaTeX-add-environments
  503     ;; 4.2.5 Custom code
  504     '("pythontexcustomcode" LaTeX-env-args
  505       [ TeX-arg-eval completing-read
  506     (TeX-argument-prompt optional nil "Position")
  507     '("begin" "end") ]
  508       (TeX-arg-eval completing-read
  509             (TeX-argument-prompt optional nil "Family")
  510             LaTeX-pythontex-family-list))
  511 
  512     ;; \begin{pygments}[<fancyvrb settings>]{<lexer>}
  513     '("pygments" LaTeX-env-args
  514       [ TeX-arg-eval LaTeX-fancyvrb-key-val-options-local ]
  515       (TeX-arg-eval completing-read
  516             (TeX-argument-prompt optional nil "Lexer")
  517             (LaTeX-pythontex-language-list))) )
  518 
  519    ;; Filling
  520    (add-to-list 'LaTeX-indent-environment-list
  521         '("pythontexcustomcode" current-indentation) t)
  522    (add-to-list 'LaTeX-indent-environment-list
  523         '("pygments" current-indentation) t)
  524    (add-to-list 'LaTeX-verbatim-environments-local "pythontexcustomcode")
  525    (add-to-list 'LaTeX-verbatim-environments-local "pygments")
  526 
  527    ;; Fontification
  528    (when (and (fboundp 'font-latex-add-keywords)
  529           (eq TeX-install-font-lock 'font-latex-setup))
  530      (font-latex-add-keywords '(("pythontexcustomc"         "[{{")
  531                 ("setpythontexfv"           "[{")
  532                 ("setpythontexprettyprinter" "[{")
  533                 ("setpythontexpyglexer"     "[{")
  534                 ("setpythontexpygopt"       "[{")
  535                 ("printpythontex"           "[[")
  536                 ("stdoutpythontex"          "[[")
  537                 ("saveprintpythontex"       "{")
  538                 ("savestdoutpythontex"      "{")
  539                 ("useprintpythontex"        "[[{")
  540                 ("usestdoutpythontex"       "[[{")
  541                 ("stderrpythontex"          "[[")
  542                 ("savestderrpythontex"      "{")
  543                 ("usestderrpythontex"       "[[{")
  544                 ("setpythontexautoprint"    "{")
  545                 ("setpythontexautostdout"   "{")
  546                 ("inputpygments"            "[{{")
  547                 ("setpygmentsfv"            "[{")
  548                 ("setpygmentspygopt"        "[{")
  549                 ("setpygmentsprettyprinter" "{")
  550                 ("setpythontexcontext"      "{")
  551                 ("restartpythontexsession"  "{")
  552                 ("setpythontexoutputdir"    "{")
  553                 ("setpythontexworkingdir"   "{")
  554                 ("setpythontexlistingenv"   "{")
  555                 ("setpythontexcontext"      "{")
  556                 ("restartpythontexsession"  "{")
  557                 ("setpythontexoutputdir"    "{")
  558                 ("setpythontexworkingdir"   "{"))
  559                   'function)
  560      (font-latex-add-keywords '(("pygment" "{"))
  561                   'textual)
  562      (LaTeX-pythontex-add-syntactic-keywords-extra 'brace "pygment")
  563      (LaTeX-pythontex-add-syntactic-keywords-extra 'delim "pygment")
  564      ;; Tell font-lock about the update.
  565      (font-latex-set-syntactic-keywords)))
  566  LaTeX-dialect)
  567 
  568 ;;; pythontex.el ends here