[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] interaction between org-latex-custom-lang-environments and name
From: |
Rasmus |
Subject: |
Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex |
Date: |
Wed, 25 Nov 2015 10:57:06 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
Hi Alan,
Alan Schmitt <address@hidden> 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
- [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/16
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/20
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Rasmus, 2015/11/20
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/20
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/23
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Rasmus, 2015/11/23
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/24
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Rasmus, 2015/11/24
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/25
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex,
Rasmus <=
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/27
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Rasmus, 2015/11/27
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Alan Schmitt, 2015/11/30
- Re: [O] interaction between org-latex-custom-lang-environments and name when exporting to latex, Rasmus, 2015/11/30