From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Beck Subject: Modifying the exporter (was: org-latex-classes with functions, incomplete doc) Date: Wed, 13 Feb 2013 00:27:05 +0100 Message-ID: <8738x16rli.fsf_-_@sophokles.streitblatt.de> References: <87txpkrvzi.fsf@sophokles.streitblatt.de> <87bobsf68g.fsf@gmail.com> <87zjzcqcq8.fsf@sophokles.streitblatt.de> <877gmgf2ts.fsf@gmail.com> <87halkq9kq.fsf@sophokles.streitblatt.de> <87liavet10.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:58301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5PFy-00050i-LR for emacs-orgmode@gnu.org; Tue, 12 Feb 2013 18:27:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5PFv-0004fK-Q4 for emacs-orgmode@gnu.org; Tue, 12 Feb 2013 18:27:22 -0500 Received: from mo6-p00-ob.rzone.de ([2a01:238:20a:202:5300::1]:47044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5PFv-0004et-Gm for emacs-orgmode@gnu.org; Tue, 12 Feb 2013 18:27:19 -0500 In-Reply-To: <87liavet10.fsf@gmail.com> (Nicolas Goaziou's message of "Sun, 10 Feb 2013 22:52:11 +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: Nicolas Goaziou Cc: emacs-orgmode@gnu.org Nicolas Goaziou writes: > Anyway, we're back to step one: if you want to handle headlines > differently (i.e. by adding your own properties), you need to fork > `latex' back-end, as explained before. If you encounter problems, you > can post back here. Ok, I took some time to extract a minimal example. It works fine, but on a very low level (see below). Again, the goal is to add an optional argument to sectioning command. The best way I could come up with is this (I omit the `fb/org-export-pdf' function): #+BEGIN_SRC emacs-lisp (defun fb/org-export-modify-headline (headline string) (if (string-match (rx string-start "\\" (group-n 1 (0+ "sub")) (group-n 2 (or "part" "chapter" "section" "paragraph")) (group-n 3 (zero-or-one "\*")) "{" (group-n 4 (minimal-match (0+ (not (any "}"))))) "}") string) (let* ((level (match-string 1 string)) (type (match-string 2 string)) (stars (match-string 3 string)) (title (match-string 4 string)) (toc-title (org-element-property :toc-title headline)) (new-hl (format "\\%s%s%s%s{%s}" (or level "") type (or stars "") (if toc-title (format "[%s]" toc-title) "") title))) (replace-match new-hl t t string 0)) string)) (defun fb/org-latex-headline (headline contents info) (fb/org-export-modify-headline headline (org-export-with-backend 'latex headline contents info))) (org-export-define-derived-backend fb/org-export-pdf latex :translate-alist ((headline . fb/org-latex-headline)) :options-alist ((:toc-title "TOC_TITLE" nil nil t)) :menu-entry (?l 99 ((?d "Export PDF file" fb/org-export-pdf)))) #+END_SRC As you can see, I pull apart the string and then put it back together. (Relatively straightforward in this case, much more involved for, say, links.) In a perfect world, I would have access to these elements and the format string, so I could either modify them before calling `org-export-with-backend' or assemble the string myself. -- Florian Beck