emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: Extending org-koma-letter.el
Date: Sun, 29 Jul 2012 20:31:08 +0200	[thread overview]
Message-ID: <87txwq4gfi.fsf@gmail.com> (raw)
In-Reply-To: <87r4rxjhp3.fsf_-_@pank.eu> (rasmus@gmx.us's message of "Fri, 27 Jul 2012 17:24:08 +0100")

Hello,

Rasmus <rasmus@gmx.us> 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{·}, e.g. \ps{·} and
> \encl{·}.  Second, it should allow for arbitrary LaTeX command
> \end{letter}, e.g. \includepdf{·}.

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) 
    (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,

-- 
Nicolas Goaziou

  reply	other threads:[~2012-07-29 18:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05 12:49 Org/LaTeX set-up for business letters? Thorsten Jolitz
2012-07-05 13:12 ` suvayu ali
2012-07-05 19:00   ` Thorsten Jolitz
2012-07-05 22:00     ` suvayu ali
2012-07-05 22:47       ` Thorsten Jolitz
2012-07-06  8:47         ` Michael Strey
2012-07-06 16:35           ` Thorsten Jolitz
2012-07-06 18:11             ` suvayu ali
2012-07-06 19:11               ` Thorsten Jolitz
2012-07-06 19:23                 ` Bastien
2012-07-06 19:44                   ` Nicolas Goaziou
2012-07-07  2:42             ` Mehul Sanghvi
2012-07-07 11:48               ` Thorsten Jolitz
2012-07-07  1:55         ` Vikas Rawal
2012-07-07 11:58           ` Thorsten Jolitz
2012-07-08 10:34             ` Sebastien Vauban
2012-07-06 19:08 ` HowTo: Letter template method using yasnippet (was: Org/LaTeX set-up for business letters?) Karl Voit
2012-07-06 22:35   ` HowTo: Letter template method using yasnippet Nicolas Goaziou
2012-07-07  0:34     ` Thorsten Jolitz
2012-07-07  9:35     ` Karl Voit
2012-07-08  9:08     ` AW
2012-07-08 13:34       ` Nicolas Goaziou
2012-07-08 14:57         ` AW
2012-07-27 16:24     ` Extending org-koma-letter.el (was: HowTo: Letter template method using yasnippet) Rasmus
2012-07-29 18:31       ` Nicolas Goaziou [this message]
2012-07-31 10:14         ` Extending org-koma-letter.el Luis Anaya
2012-08-03  8:19           ` Nicolas Goaziou
2012-08-03 14:23             ` Luis Anaya
2012-08-03 16:24               ` Bastien
2012-08-04  0:40                 ` Luis Anaya
2012-11-06 15:31                 ` Alan Schmitt
2012-11-13 22:56                   ` Nicolas Goaziou
2012-11-14 16:48                     ` Alan Schmitt
2012-11-20  3:14                       ` Luis Anaya
2012-11-22 16:07                     ` Alan Schmitt
2012-11-22 16:32                       ` Rasmus
2012-11-22 16:40                       ` Nicolas Goaziou
2012-11-23  8:34                         ` Alan Schmitt
2012-11-23 11:51                           ` Nicolas Goaziou
2012-11-26  8:01                             ` Alan Schmitt
2012-11-26 12:48                               ` Bastien

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=87txwq4gfi.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /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).