1

On TeX.SE arouse some questions, on how to add the -excape-shell option to the actual TeX processor (LaTeX, luaLaTeX, ...). One offered solution would be, to use a %%% Local Variables section at the end of the LaTeX-file.

But Emacs would not be Emacs, if he could not set this feature by his self.

Usually, AUCTeX comes with a lot of predefined supporting Lisp files. Unfortunately, there seems to be no package for the LaTeX package minted. At least, my AUCTeX did not have one. Meanwhile I found an minted.el on https://github.com/giordano/auctex/blob/master/style/minted.el. (Why didn't I see that earlier??) Having not found such file, I sat down and hacked a (not so little) lisp file away. The main gimmick is the last block

(setq LaTeX-command-style '(("" "%(PDF)%(latex) -shell-escape %S%(PDFout)")))

This was copied from the brilliant TeX.SE article https://tex.stackexchange.com/questions/157242/adding-an-option-to-the-pdflatex-call-from-auctex . Other parts where copied and adapted from babel.el or scrbase.el. I am of plan, to send this file to the AUCTeX-team, for accepting it to be distributed with AUCTeX. But before I do so, I would ask to help me, to get an even better file.

Actually, I am having a rather dumb solution, to insert minted-options for some commands and environments (not to be mixed up, with the options for the package itself!). Right now, my function will only ask for one and only key word. I was not possible to to code it in such a way, that you can insert more than one keyword or even present some appropriate values for the given key(s).

Here is a snippet from the file minted.el

(defun LaTeX-minted-package-options ()
  "Prompt for package options for the minted package."
  (TeX-read-key-val
   t
   '(("chapter")
     ("section")
     ("cache" ("true" "false"))
     ("cachedir")
     ("finalizecache" ("true" "false"))
     ("frozencache" ("true" "false"))
     ("draft" ("true" "false"))
     ("final" ("true" "false"))
     ("kpsewhich" ("true" "false"))
     ("langlinenos" ("true" "false"))
     ("newfloat" ("true" "false"))
     ("outputdir"))))
 (defvar LaTeX-minted-language-list
  '("abap"
    "abnf"
    "ada" "ada95" "ada2005"
    "adl"
    "agda"    "yaml"
    "zephir")
  "List of supported languages in package minted.  To obtain the actual list, issue 'pygmentize -L lexers' in a shell.")

;; stolen from babel.el.gz
(defun TeX-arg-minted-lang (optional &optional prompt)
  "Prompt for a language with completion and insert it as argument."
  (TeX-argument-insert
   (completing-read "Language: " LaTeX-minted-language-list) nil))

;; also stolen from babel.el.gz
(defun LaTeX-env-minted-lang (env)
  "Prompt for a language with completion and insert it as argument of ENV."
  (LaTeX-insert-environment
   env (format "{%s}" (completing-read "Language: "
                       LaTeX-minted-language-list))))
(defvar LaTeX-minted-style-list
  '("manni"
    "igor"
    "lovelace"
    "xcode"
    "vim"
    "autumn"
    "vs"
    "rrt"
    "native"
    "perldoc"
    "borland"
    "tango"
    "emacs"
    "friendly"
    "monokai"
    "paraiso-dark"
    "colorful"
    "murphy"
    "bw"
    "pastie"
    "algol_nu"
    "paraiso-light"
    "trac"
    "default"
    "algol"
    "fruity")
  "List of supported styles in package minted.  List was obtained from command 'pygmentize -L styles'.")

(defun TeX-arg-minted-style (optional &optional prompt)
  "Prompt for a style with completion and insert is as optional argument."
  (TeX-argument-insert
   (completing-read "Minted color style: " LaTeX-minted-style-list) nil))
(defvar LaTeX-minted-option-list
  '("autogobble"            ; boolean
    "baselinestretch"           ; dimension
    "breakafter"            ; string
    "breakaftergroup"           ; booelan
    "xleftmargin"           ; dimension
    "xrightmargin")         ; dimension
  "List of options to be given in minted commands and environments.")

(defun TeX-arg-minted-opts (optional &optional prompt)
  "Prompt for an option with completion and insert it as an argument."
  (TeX-argument-insert
   (completing-read "Minted Option: " LaTeX-minted-option-list) nil))
(TeX-add-style-hook
 "minted"
 (lambda ()
   (TeX-run-style-hooks
    "keyval" "kvoptions" "fancyvrb" "float"
    "ifthen" "calc" "shellesc" "ifplatform"
    "pdftexcmds" "etoolbox" "xstring" "lineno"
    "framed" "xcolor" "newfloat")
   (TeX-add-symbols
    '("mint" [ TeX-arg-minted-opts ] TeX-arg-minted-lang)
    '("mintinline" [ TeX-arg-minted-opts ] TeX-arg-minted-lang 1)
    '("inputminted" [ TeX-arg-minted-opts ] TeX-arg-minted-lang TeX-arg-file-name)
    '("usemintedstyle" [TeX-arg-minted-lang] TeX-arg-minted-style)
    '("setminted" [TeX-arg-minted-lang] TeX-arg-minted-opts)
    '("setmintedinline" [TeX-arg-minted-lang] TeX-arg-minted-opts)
    "listoflistings"
    "listingscaption"
    "listoflistingscaption"
    "listoflistings"
    '("newminted" ["new environment name"] TeX-arg-minted-lang TeX-arg-minted-opts)
    '("newmint" ["new macro name"] TeX-arg-minted-lang TeX-arg-minted-opts)
    '("newmintinline" ["new macro name"] TeX-arg-minted-lang TeX-arg-minted-opts)
    '("newmintedfile" ["new macro name"] TeX-arg-minted-lang TeX-arg-minted-opts))
   (LaTeX-add-environments
    "Verbatim" 
    '("minted" LaTeX-env-minted-lang)
    "listings"
    )
   (LaTeX-add-counters
    "FancyVerbLineBreakLast")
   (LaTeX-add-saveboxes
    "FV")))
;; This is from
;; https://tex.stackexchange.com/questions/157242/adding-an-option-to-the-pdflatex-call-from-auctex
(setq LaTeX-command-style '(("" "%(PDF)%(latex) -shell-escape %S%(PDFout)")))

My file is somewhat longer, as I excluded some of the never ending list of languages and command options. Despite, this should be a MWE.

Can anybody give me some hints on how to improve the function TeX-arg-minted-opts?

I am sure, there will be an alist involved. On the one side of the alist, there need to be all allowed options, on the other side, there must be a function, to insert t or nil for a boolean, e. g. 5pt for a dimension, ...

The left side of the alist is already present in my file. The right side is completely missing.

EDIT: meanwhile I found some minted.el on github. I will study that. Just for the learning effect: any answers are still appreciated.

How to code this?

1
  • As clearly explained in the description of my repository on github, it is a mirror of official AUCTeX. The file style for minted is in AUCTeX, which version of the package are you using?
    – giordano
    Commented Dec 27, 2016 at 20:32

2 Answers 2

1

Preamble: contrary to what you're claiming, a minted.el is in AUCTeX since December 2014 and is pretty advanced, please base your future work on it. Maybe you're using an outdated version of AUCTeX?

The github repository you linked is my personal mirror of the official AUCTeX repository, as clearly explained in the description to the repository. See https://savannah.gnu.org/git/?group=auctex for how to access the official repository.


Answer: the function TeX-arg-minted-opts you proposed (which, BTW, should be named LaTeX-arg-minted-opts for consistency with other functions) is useless as it can be replaced by (TeX-arg-key-val LaTeX-minted-package-options-list).

2
  • I am using AUCTeX 11.88. Have to update, I see. I think, your answer is not correct. At least to me, my function TeX-arg-minted-opts was inserting some code into my LaTeX-document. It was not useless. I still haven't found TeX-arg-key-val, you mentioned.
    – Jan
    Commented Dec 28, 2016 at 12:05
  • TeX-arg-key-val is in latex.el, it was introduced there in 2009.
    – giordano
    Commented Dec 28, 2016 at 14:30
0

@giordano has stated correctly, that my AUCTeX-version is slightly outdated. I've got version 11.88 from November 2014. I'll update, I promise.

Nevertheless, it was a very good coding lesson for myself. According to @giordano tip to use TeX-arg-key-val, I searched for, but couldn't also find that in my version of AUCTeX. Therefore I changed over to use TeX-read-key-val, which I have previously used before.

Here is my solution, to insert minted-commands or environments and asking in the minibuffer the list of possible options with key=value and completion:

This is my complete function, with all possible options. It still could be polished even more :-)

(defun TeX-arg-minted-opts (optional &optional prompt)
  "Prompt for an option with completion and insert it as an argument."
  (TeX-argument-insert
   (TeX-read-key-val
    optional
    '(("autogobble" ("true" "false"))          ; boolean
      ("baselinestretch" ("1.5pt"))        ; dimension
      ("breakafter" ("string"))            ; string
      ("breakaftergroup" ("true" "false"))     ; booelan
      ("breakaftersymbolpre" ("string"))       ; string
      ("breakaftersymbolpost" ("string"))      ; string
     ("breakanywhere" ("true" "false"))        ; boolean
     ("breakanywheresymbolpre" ("string"))     ; string
     ("breakanywheresymbolpost" ("string"))    ; string
     ("breakautoindent" ("true" "false"))      ; boolean
     ("breakbefore" ("string"))            ; string
     ("breakbeforegroup" ("true" "false"))     ; boolean
     ("breakbeforesymbolpre" ("string"))       ; string
     ("breakbeforesymbolpost" ("string"))      ; string
     ("breakbytoken" ("true" "false"))         ; boolean
     ("breakbytokenanywhere" ("true" "false")) ; boolean
     ("breakindent" ("1.5pt"))             ; dimension
     ("breaklines" ("true" "false"))           ; boolean
     ("breaksymbol" ("string"))            ; string
     ("breaksymbolright" ("string"))           ; string
     ("breaksymbolindent" ("1.5pt"))           ; dimension
     ("breaksymbolindentleft" ("1.5pt"))       ; dimension
     ("breaksymbolindentright" ("1.5pt"))      ; dimension
     ("breaksymbolsep" ("1.5pt"))          ; dimension
     ("breaksymbolsepleft" ("1.5pt"))          ; dimension
     ("breaksymbolsepright" ("1.5pt"))         ; dimension
     ("bgcolor" ("string"))            ; string
     ("codetagify" ("list of strings"))        ; list of strings
     ("curlyquotes" ("true" "false"))          ; boolean
     ("encoding" ("string"))               ; string
     ("escapeinside" ("string"))           ; string
     ("firstline" ("5"))               ; integer
     ("firstnumber" ("5"))             ; integer
     ("fontfamily" ("string"))             ; string
     ("fontseries" ("string"))             ; string
     ("fontsize" ("string"))               ; string
     ("fontshape" ("string"))              ; string
     ("Formatcom" ("\cmd"))            ; macro
     ("frame")                     ;
     ("framerule")                 ;
     ("framesep" ("1.5pt"))            ; dimension
     ("funcnamehighlighting" ("true" "false")) ; boolean
     ("gobble" ("5"))                  ; integer
     ("highlightcolor" ("string"))         ; string
     ("highlightcolor" ("string"))         ; string
     ("keywordcase" ("string"))            ; string
     ("label" ("string"))              ; string
     ("labelposition")                 ;
     ("lastline" ("5"))                ; integer
     ("linenos" ("true" "false"))          ; boolean
     ("numberfirstline" ("true" "false"))      ; boolena
     ("numbers")                   ; 
     ("mathescape" ("true" "false"))           ; boolean
     ("numberblanklines" ("true" "false"))     ; boolean
     ("numbersep" ("1.5pt"))               ; dimension
     ("obeytabs" ("true" "false"))         ; boolean
     ("outencoding" ("string"))            ; string
     ("python3" ("true" "false"))          ; boolean
     ("resetmargins" ("true" "false"))         ; boolean
     ("rulecolor" ("color-cmd"))           ; color command
     ("samepage" ("true" "false"))         ; booelan
     ("showspaces" ("true" "false"))           ; boolean
     ("showtabs" ("true" "false"))         ; boolean
     ("space" ("\cmd"))                ; macro
     ("spacecolor" ("string"))             ; string
     ("startinline" ("true" "false"))          ; boolean
     ("style" ("string"))              ; string
     ("stepnumber" ("5"))              ; integer
     ("stepnumberfromfirst" ("true" "false"))  ; boolean
     ("stepnumberoffsetvalues" ("true" "false")) ; boolean
     ("stripall" ("true" "false"))         ; boolean
     ("stripnl" ("true" "false"))          ; boolean
     ("tab" ("\cmd"))                  ; macro
     ("tabcolor" ("string"))               ; string
     ("tabsize" ("5"))                 ; integer
     ("texcl" ("true" "false"))            ; boolean
     ("texcomments" ("true" "false"))          ; boolean
     ("xleftmargin" ("1.5pt"))             ; dimension
     ("xrightmargin" ("1.5pt"))            ; dimension
      )
    ) optional prompt))
4
  • If you read the definition of TeX-arg-key-val function you would have found that this function is indeed useless. Please, take confidence with the base code of a project if you plan to contribute to it.
    – giordano
    Commented Dec 28, 2016 at 14:59
  • @giordano: I was mislead by the fact, that I hadn't a minted.el on my computer and using google didn't result any useful. Meanwhile I know better and won't ask for upload any more.
    – Jan
    Commented Dec 28, 2016 at 15:44
  • I guess you're using AUCTeX provided by Debian, or Ubuntu, but that package tends often to be outdated with little chances to upgrade it. Currently Debian (and hence Ubuntu) ships with a two-year-old version of AUCTeX. By far, the best way to install the package is through Emacs's built-in package manager (ELPA), and you'll receive often updates (usually every few months). But if you plan to contribute, you should really use the development version, otherwise you'll risk to duplicate other people's work and waste your time (as in this case).
    – giordano
    Commented Dec 28, 2016 at 18:40
  • Anyway, you're very welcome to contribute to AUCTeX, there is always so much to do about adding support for new style files and improving old ones. Have a look at gnu.org/software/auctex/development.html and remember that if you want to write new code, working on the development version is mandatory (as it is for any another software out there) ;-)
    – giordano
    Commented Dec 28, 2016 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.