From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Extending org-koma-letter.el Date: Sun, 29 Jul 2012 20:31:08 +0200 Message-ID: <87txwq4gfi.fsf@gmail.com> References: <8762a2l6f7.fsf@googlemail.com> <2012-07-06T20-54-34@devnull.Karl-Voit.at> <87zk7cplfv.fsf@gmail.com> <87r4rxjhp3.fsf_-_@pank.eu> 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]:58416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvYKC-0004zW-I1 for emacs-orgmode@gnu.org; Sun, 29 Jul 2012 14:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SvYKB-0001dY-8v for emacs-orgmode@gnu.org; Sun, 29 Jul 2012 14:34:44 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:54713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvYKA-0001cg-UL for emacs-orgmode@gnu.org; Sun, 29 Jul 2012 14:34:43 -0400 Received: by wgbez12 with SMTP id ez12so3399402wgb.30 for ; Sun, 29 Jul 2012 11:34:42 -0700 (PDT) In-Reply-To: <87r4rxjhp3.fsf_-_@pank.eu> (rasmus@gmx.us's message of "Fri, 27 Jul 2012 17:24:08 +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: Rasmus Cc: emacs-orgmode@gnu.org Hello, Rasmus writes: > Thanks. It's wonderful writing letters with the new latex exporter. > You should consider adding it to org_contrib. As you have noticed, it is not complete enough. Also, I haven't looked at the documentation thoroughly and don't know what is possible to do. On the other hand, I think that Org deserves a serious letter package. If you want to maintain and improve it, I'm all for adding it to contrib directory. >> It's far from being complete. See it as a proof of concept. Feel free >> to upgrade it. > I need two further features to fully adopt org-koma-letter.el, but I am > not sure how to proceed (I still haven't found too much [non-programmer] > documentation on how to hack the new org-exporter). If you have any question, just ask here. > First, it should allow for contents after \closing{=C2=B7}, e.g. \ps{=C2= =B7} and > \encl{=C2=B7}. Second, it should allow for arbitrary LaTeX command > \end{letter}, e.g. \includepdf{=C2=B7}. This is a reasonable suggestion, indeed. > Thus, I basically want to extend org-koma-letter-template to include to > extra content-like elements. > > (defun org-koma-letter-template (contents info) > ... > ... > (format "\n\\closing{%s}\n\n" (plist-get info :closing)) > ;; appendix in letter > appendix > ;; Letter ends. > "\\end{letter}\n" > after-letter > ;; Document ends. > "\\end{document}" > > > I am not sure how to implement this. I want it to operate on tags. So > I want > #+begin_src > * my-encl :appendix: > #+latex:\encl{ > - doc 1 > - doc 2 > #+latex:} > #+end_src The #+latex: ... parts are ugly. You may implement an #+attr_koma: :enclosure t syntax, for example. > to /not/ be part of contents, but be recognized as appendix inserted > after the signature. Likewise headlines with tag :afterletter: should > only be inserted after \end{letter}. > > Could anyone provide any hints as to how to archive this behavior. (I > can't really understand all the details by just reading the API...). While in the template, you have to search for headlines with a certain tag (you could also do the same with properties), and treat them the way you want. Parse tree is found in communication channel (INFO argument) via: (plist-get info :parse-tree) You can skim through it and collect headlines matching a criteria with `org-element-map'. Here, the criteria is that "appendix" has to be a member of headline's tags. These tags are obtained with `org-export-get-tags'. Hence: #+begin_src emacs-lisp (org-element-map (plist-get info :parse-tree) 'headline (lambda (h)=20 (and (member "appendix" (org-export-get-tags h info)) h)) info) #+end_src will return a list of all headlines with the "appendix" tag. Now, what you want to do with them is up to you. You may simply want to export them right here, in the template. This is done with `org-export-data'. #+begin_src emacs-liso (mapconcat (lambda (h) (org-export-data h info)) ;; List of "appendix" headlines (org-element-map (plist-get info :parse-tree) 'headline (lambda (h) (and (member "appendix" (org-export-get-tags h info)) h)) info) "") #+end_src Though, if you transcode them outside of \begin{letter}...\end{letter}, you probably don't want to also see them within that environment. In other words, you have to tell the function transcoding headlines, `org-koma-letter-headline', to ignore (that is return a nil value) headlines with an "appendix" tag when it sees one. On the other hand, if the headline has no such tag, you may want to delegate its transcoding to e-latex backend instead. You can use something like the following: #+begin_src emacs-lisp (defun org-koma-letter-headline (headline contents info) "Transcode a HEADLINE element into KOMA Scrlttr2 code. CONTENTS is nil. INFO is a plist used as a communication channel." (unless (member "appendix" (org-export-get-tags headline info)) (funcall (cdr (assq 'headline org-e-latex-translate-alist)) headline contents info))) #+end_src HTH, Regards, --=20 Nicolas Goaziou