Hi Alan, Alan Schmitt <alan.schm...@polytechnique.org> writes:
> Here is a patch that allows the use of a format string in > custom-lang-environments. Thanks. > * lisp/ox-latex.el (org-latex-custom-lang-environments): extend the > documentation string. Extend. You don’t need the lisp prefix. > * lisp/ox-latex.el (org-latex-src-block): allow a custom language > environment to be a format string to be directly inserted. Allow. > + %c for the formatted source > + %C for the caption > + %f for the float attribute > + %l for an appropriate label it’s a bit sadistic to use %c and %C. Can’t the first be (%s)ource-code? > +For example, > > (setq org-latex-custom-lang-environments > - '((python \"pythoncode\"))) > + '((python \"pythoncode\") > + (ocaml > \"\\\\begin{listing}\\n\\\\begin{minted}{ocaml}%c\\\\end{minted}\\n\\\\caption{%C}\\n\\\\label{%l}\"))) Minor: For the sake of making the ocaml block readable you could add the actual newlines instead of "\n". > would have the effect that if org encounters begin_src python A Python source block. > during latex export it will output LaTeX export it will produce, > \\begin{pythoncode} > <src block body> > - \\end{pythoncode}") > + \\end{pythoncode} > + > +and if org encounters begin_src ocaml during latex export it will Likewise, if Org ... a Ocaml source block ... LaTeX > +output , > + \\begin{listing} > + \\begin{minted}{ocaml} > + <src block body> > + \\end{minted} > + \\caption{<caption>} > + \\label{<label>} > + \\end{listing}") Nitpick: label should be inside caption in the example to be consistent with how captions are normally formatted by ox-latex. Either way is fine though. Also, you need to denote that the defcustom was changed. :version "25.1" :package-version '(Org . "9.0") When you are at it, please add the missing tags, :group and :type. > + (let ((caption-str (org-latex--caption/label-string src-block info)) > + (formatted-src (org-export-format-code-default src-block > info))) > + (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env) I guess technically, you should use org-string-match-p for comparability reasons. Though I think Org-9 will drop older emacsen and xemacs support. > + (Format "\\begin{%s}\n%s\\end{%s}\n" > + custom-env > + (concat (and caption-above-p caption-str) > + formatted-src > + (and (not caption-above-p) caption-str)) > + custom-env) > + (format-spec custom-env > + `((?c . ,formatted-src) I’d use s (or anything but c) here.... > + (?C . ,caption) I’d use lowercase c. > + (?f . ,float) > + (?l . ,(org-latex--label src-block info))))))) > ;; Case 3. Use minted package. > ((eq listings 'minted) > (let* ((caption-str (org-latex--caption/label-string src-block info)) Rasmus -- Look, it is what it is because of what it was