From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Florian Beck <fb@miszellen.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Modifying the exporter
Date: Wed, 13 Feb 2013 15:03:00 +0100 [thread overview]
Message-ID: <87liascnvv.fsf@gmail.com> (raw)
In-Reply-To: <8738x16rli.fsf_-_@sophokles.streitblatt.de> (Florian Beck's message of "Wed, 13 Feb 2013 00:27:05 +0100")
Florian Beck <fb@miszellen.de> writes:
> 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))
Why don't you simply replace (or add, if needed) optional argument from
sectioning command with `replace-regexp-in-string' instead of building
the whole string again? Like the following (untested):
#+begin_src emacs-lisp
(defun fb/org-latex-headline (headline contents info)
(let ((original-hl (org-export-with-backend 'latex headline contents info))
(toc-title (org-element-property :toc-title headline)))
(cond ((not toc-title) original-hl)
((string-match "\\`\\.*?\\*?\\[\\([^]]\\)\\]" original-hl)
(replace-match toc-title nil nil original-hl 1))
(t (replace-regexp-in-string
"\\`\\.*?\\*?" (concat "\\&" toc-title) original-hl)))))
#+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.)
Writing translators for headlines links and tables is usually a major
undertaking when creating a new back-end. That's why there are so many
tools to operate on these elements in ox.el.
Anyway, this is not bad, as you forked a 3k locs back-end with about 30
locs.
> 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.
In your perfect world, there would be billions of variables, depending
on the element, the back-end and the task. Customization is still
important, so I offer generic tools when variables are not enough.
Note that I might implement this feature at one point, but I still have
to think about its specifications.
Regards,
--
Nicolas Goaziou
prev parent reply other threads:[~2013-02-13 14:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-10 16:09 org-latex-classes with functions, incomplete doc Florian Beck
2013-02-10 17:06 ` Nicolas Goaziou
2013-02-10 17:51 ` Florian Beck
2013-02-10 18:20 ` Nicolas Goaziou
2013-02-10 18:59 ` Florian Beck
2013-02-10 21:52 ` Nicolas Goaziou
2013-02-12 23:27 ` Modifying the exporter (was: org-latex-classes with functions, incomplete doc) Florian Beck
2013-02-13 14:03 ` Nicolas Goaziou [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87liascnvv.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=fb@miszellen.de \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.