emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: alan.schmitt@polytechnique.org
Cc: emacs-orgmode@gnu.org
Subject: Re: interaction between org-latex-custom-lang-environments and name when exporting to latex
Date: Wed, 25 Nov 2015 10:57:06 +0100	[thread overview]
Message-ID: <87610qbdvx.fsf@gmx.us> (raw)
In-Reply-To: <m2a8q2wlts.fsf@polytechnique.org> (Alan Schmitt's message of "Wed, 25 Nov 2015 08:59:59 +0100")

Hi Alan,

Alan Schmitt <alan.schmitt@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

  reply	other threads:[~2015-11-25  9:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 12:59 interaction between org-latex-custom-lang-environments and name when exporting to latex Alan Schmitt
2015-11-20  7:55 ` Alan Schmitt
2015-11-20 10:41   ` Rasmus
2015-11-20 11:06     ` Alan Schmitt
2015-11-23 11:13     ` Alan Schmitt
2015-11-23 17:54       ` Rasmus
2015-11-24  8:07         ` Alan Schmitt
2015-11-24 13:14           ` Rasmus
2015-11-25  7:59             ` Alan Schmitt
2015-11-25  9:57               ` Rasmus [this message]
2015-11-27 16:27                 ` Alan Schmitt
2015-11-27 21:05                   ` Rasmus
2015-11-30 12:12                     ` Alan Schmitt
2015-11-30 13:11                       ` Rasmus
2015-12-01  8:14                         ` Alan Schmitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87610qbdvx.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).