From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: org-latex-classes with functions, incomplete doc Date: Sun, 10 Feb 2013 18:06:55 +0100 Message-ID: <87bobsf68g.fsf@gmail.com> References: <87txpkrvzi.fsf@sophokles.streitblatt.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4aN1-0007YW-Rq for emacs-orgmode@gnu.org; Sun, 10 Feb 2013 12:07:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U4aN0-000528-Di for emacs-orgmode@gnu.org; Sun, 10 Feb 2013 12:07:15 -0500 Received: from wi-in-x0229.1e100.net ([2a00:1450:400c:c05::229]:52503 helo=mail-wi0-x229.google.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4aN0-000523-6P for emacs-orgmode@gnu.org; Sun, 10 Feb 2013 12:07:14 -0500 Received: by mail-wi0-f169.google.com with SMTP id l13so2520037wie.2 for ; Sun, 10 Feb 2013 09:07:13 -0800 (PST) In-Reply-To: <87txpkrvzi.fsf@sophokles.streitblatt.de> (Florian Beck's message of "Sun, 10 Feb 2013 17:09:53 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Florian Beck Cc: emacs-orgmode@gnu.org Hello, Florian Beck writes: > the docstring for `org-latex-classes' says: > > "Instead of a list of sectioning commands, you can also specify > a function name. That function will be called with two > parameters, the (reduced) level of the headline, and a predicate > non-nil when the headline should be numbered. It must return > a format string in which the section title will be added." > > This is wrong. The way this function is called in `org-latex-headline' > requires it to return a string with TWO format specifiers, e.g. > "\section{%%s}%%s\n", the second where the CONTENT of the section is > being added. Maybe `org-latex-headline' should add "%%s\n" itself =E2=80= =93 as > it does for other cases? Indeed. It's now the case. Thanks for reporting this. > Also, I'm using this to add an optional argument to my sections. Can I > expect this to work? (i.e. being called in a context where the variables > `info' and `headline' are defined?) > > #+BEGIN_SRC emacs-lisp > (defun fb/latex-sections (level numbered) > (let* ((level (1- level)) > (sec-name (nth level fb/latex-section-names)) > (sec (when sec-name > (format "\\%s%s%s{%%s}\n%%s" > sec-name > (if numbered "" "*") > ;; "" > (or (when (plist-get info :toc-title) > (let ((toc-title (org-element-property :t= oc-title headline))) > (when toc-title (format "[%s]" toc-titl= e)))) > "") > )))) > sec)) > #+END_SRC Actually, the proper way to do this is to define a derived back-end with a custom headline translation function. #+begin_src emacs-lisp (org-export-define-derived-backend my-latex latex :translate-alist ((headline . fb/my-latex-headline))) (defun fb/my-latex-headline (headline contents info) ... Do whatever you want here) #+end_src Also, you can use `org-export-with-backend' as a fallback case for your custom function. >From there you can use: (org-export-to-buffer 'my-latex "*My own export*") or, (org-export-to-file 'my-latex "some-file.tex") You may wrap the previous calls into an interactive command (just copy and adapt from those in ox-latex.el). For example: #+begin_src emacs-lisp (defun fb/my-latex-export-to-latex (&optional async subtreep visible-only body-only ext-plist) (interactive) (let ((outfile (org-export-output-file-name ".tex" subtreep))) (if async (org-export-async-start (lambda (f) (org-export-add-to-stack f 'my-latex)) `(expand-file-name (org-export-to-file 'my-latex ,outfile ,subtreep ,visible-only ,body-only ',ext-plist))) (org-export-to-file 'my-latex outfile subtreep visible-only body-only ext-plist)))) #+end_src Optionally, you can add an entry in the dispatcher for your new command: #+begin_src emacs-lisp (org-export-define-derived-backend my-latex latex :translate-alist ((headline . fb/my-latex-headline)) :menu-entry (?l 2 ((?m "With my special extension" fb/my-latex-export-to-latex)))) #+end_src Regards, --=20 Nicolas Goaziou