Hi,

Rasmus wrote:

> This is probably the most fun change.  It adds special tags PS, ENCL,
> CC, AFTER_CLOSING as in my last patch set, but it uses heading this
> time.  E.g. ENCLs are under the heading * ENCL :ENCL:.  This was
> suggested by Nicolas, and it's nicer.  The ideas comes from
> ox-groff.el file ¹.  Thanks Luis!

This is great! A few things:

- It doesn't work because `org-koma-letter-special-content' is set to
  nil at the beginning of `org-koma-letter-template'. Why is that? If I
  comment it out everything works.

- The function `org-koma-letter--get-tagged-content' does not use the
  `info' argument. Also, the function is not documented.

- The second argument of `org-koma-letter-headline' is misspelled
  (`conents').

- I would remove the formatting from org-koma-letter-ps-prefix and put
  it in the docstring, simply because the separators for \encl and \cc
  are also not formatted in the KOMA-Script defaults.

> One thing I'd like to discuss is whether to adopt headings for TO and
> FROM also.  The Groff exporter already does so for it's letters.  The
> main benefit is that it allows for org-syntax.  IMO it's a lot nicer
> to look at as well.  Check the org-groff site in the footnote for an
> example.

I am not sure about this. I often write a letter below a task in my
Org files so I rely on exporting the subtree only. So I would have to
put the TO address below the letter text which looks weird, but is
doable. On the other hand, being able to use Org syntax and not have to
escape linebreaks with `\\' is a big plus.
 
> I'd be happy to look into this the next time I have a free day for
> programming if you guys (also) find in a more appealing.  (One
> additional benefit would be that for simple documents it wouldn't
> matter whether groff or scrlttr2 was used as backend).

This would be a nice advantage.

Maybe both options could be supported. I.e., use a FROM headline if
available, but fall back on option lines if not? Or is this too
confusing for users?

Cheers,
Viktor
> 
> –Rasmus
> 
> 
> Footnotes: 
>  ¹   
> http://orgmode.org/worg/org-tutorials/org-e-groff-documentation.html#sec-1-5
> 
> -- 
> Powered by magic pixies!

> >From eeaa129b6807465566be881b96a94e14706c9a28 Mon Sep 17 00:00:00 2001
> From: "rasmus.pank" <rasmus.p...@gmail.com>
> Date: Sun, 19 May 2013 21:50:14 +0200
> Subject: [PATCH 3/4] Added support for after closing and after document
>  entities in ox-koma-letter.
> 
> * ox-koma-letter.el (org-koma-letter-special-tags-after-closing): specials 
> tags inserted after =\end{closing}=
> * ox-koma-letter.el (org-koma-letter-special-tags-other): other special tags
> * ox-koma-letter.el (org-koma-letter-special-tags): collect
> the two previoues lists (this might be done in a wrong way).
> * ox-koma-letter.el (org-koma-letter-ps-prefix): a prefix for
> PS since scrlttr does not provide it.
> * ox-koma-letter.el (org-koma-letter-headline): stores content
> in a special list if it is =`org-koma-letter-special-tags'= as
> in ox-groff.  Only returns contents if not tags not in special
> tags.
> * ox-koma-letter.el (org-koma-letter-special-content): holds special
> content temporarily.
> * ox-koma-letter.el (org-koma-letter-template): added support
> for the headings with special tags.
> 
> The following example will now export a sensible manner.
> 
> * my letter
> here's a letter
> * PS :PS:
> it's requires this patch
> * CC :CC:
> Nicolas, Viktor and Alan
> * ENCL :ENCL:
> many patches
> 1. this patch
> 2. another patch.
> * include patches :AFTER_LETTER:
> \myspecial macro
> 
> Namely, content of PS, ENCL and CC headings will be exported after
> \closing{.}  in the order prescribed by
> =`org-koma-letter-special-tags-after-closing'=.  The concent
> of the =AFTER_LETTER= heading will be inserted after
> =\end{letter}=, ideal for e.g. =pdfpages= commands.
> ---
>  contrib/lisp/ox-koma-letter.el | 86 
> +++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 81 insertions(+), 5 deletions(-)
> 
> diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
> index 77d21c7..8ae9fc5 100644
> --- a/contrib/lisp/ox-koma-letter.el
> +++ b/contrib/lisp/ox-koma-letter.el
> @@ -183,6 +183,29 @@ Use `foldmarks:true' to activate default fold marks or
>    :group 'org-export-koma-letter
>    :type 'boolean)
>  
> +(defcustom org-koma-letter-ps-prefix "\\textsc{ps}: "
> +  "The prefix of PS.  Used to construct PS as \"PS-SUFFIX PS\""
> +  :group 'org-export-koma-letter
> +  :type 'string)
> +
> +
> +(defconst org-koma-letter-special-tags-after-closing
> +  '("PS" "ENCL" "CC")
> +  "Headers tags to be inserted after closing")
> +
> +(defconst org-koma-letter-special-tags-other
> +  '("FROM" "AFTER_LETTER")
> +  "Headers tags to be inserted after closing")
> +
> +(defconst org-koma-letter-special-tags
> +  (append org-koma-letter-special-tags-other
> +       org-koma-letter-special-tags-after-closing)
> +  "Header tags with special meaning")
> +
> +(defvar org-koma-letter-special-content nil "holds special
> +content temporarily.")
> +
> +
>  
>  ;;; Define Back-End
>  
> @@ -198,15 +221,18 @@ Use `foldmarks:true' to activate default fold marks or
>      (:opening "OPENING" nil org-koma-letter-opening)
>      (:closing "CLOSING" nil org-koma-letter-closing)
>      (:signature "SIGNATURE" nil org-koma-letter-signature newline)
> +    (:ps-prefix nil "ps-prefix" org-koma-letter-ps-prefix)
>  
>      (:with-backaddress nil "backaddress" org-koma-letter-use-backaddress)
>      (:with-foldmarks nil "foldmarks" org-koma-letter-use-foldmarks)
>      (:with-phone nil "phone" org-koma-letter-use-phone)
>      (:with-email nil "email" org-koma-letter-use-email)
>      (:with-place nil "place" org-koma-letter-use-place)
> +    (:with-after-closing nil "after-closing-order" 
> org-koma-letter-special-tags-after-closing)
>      (:with-subject nil "subject" org-koma-letter-subject-format))
>    :translate-alist '((export-block . org-koma-letter-export-block)
>                    (export-snippet . org-koma-letter-export-snippet)
> +                  (headline . org-koma-letter-headline)
>                    (keyword . org-koma-letter-keyword)
>                    (template . org-koma-letter-template))
>    :menu-entry
> @@ -253,12 +279,47 @@ channel."
>      (if (equal key "KOMA-LETTER") value
>        (org-export-with-backend 'latex keyword contents info))))
>  
> +
> +;; The following is taken from/inspired by ox-grof.el
> +;; Thanks, Luis!
> +
> +(defun org-koma-letter--get-tagged-content  (tag info)
> +  (cdr  (assoc tag org-koma-letter-special-content)))
> +
> +
> +(defun org-koma-letter-headline (headline conents info)
> +  "Transcode a HEADLINE element from Org to LaTeX.
> +CONTENTS holds the contents of the headline.  INFO is a plist
> +holding contextual informatio.n
> +
> +Note that if a headline is tagged with a tag from
> +`org-koma-letter-special-tags' it will not be exported, but
> +stored in `org-koma-letter-special-content' and included at the
> +appropriate place."
> +  (let*
> +      ((tags (and (plist-get info :with-tags)
> +              (org-export-get-tags headline info))))
> +    (if (member (car tags) org-koma-letter-special-tags)
> +     (cond ((member (car tags) '("PS" "ps"))
> +            (progn
> +              (push (cons (car tags) (concat (plist-get info :ps-prefix) 
> contents))
> +                    org-koma-letter-special-content) nil))
> +           (t (progn
> +                (push (cons (car tags) contents)
> +                      org-koma-letter-special-content) nil)))
> +      contents)))
> +
> +
>  ;;;; Template
>  
>  (defun org-koma-letter-template (contents info)
>    "Return complete document string after KOMA Scrlttr2 conversion.
>  CONTENTS is the transcoded contents string.  INFO is a plist
>  holding export options."
> +  ;; FIXME: instead of setq'ing org-koma-letter-special-content and
> +  ;; callying varioues stuff it might be nice to put a big let* around the 
> templace
> +  ;; as in org-groff...
> +  (setq org-koma-letter-special-content nil)
>    (concat
>     ;; Time-stamp.
>     (and (plist-get info :time-stamp-file)
> @@ -327,14 +388,14 @@ holding export options."
>     ;; Subject
>     (let* ((with-subject (plist-get info :with-subject))
>         (subject-format (if (member with-subject '("True" t "true" "TRUE"))
> -                               ;; FIXME: could this be done more elegantly?
> -                               ;; I.e. force lower face of with-subject if 
> string.
> +                           ;; FIXME: could this be done more elegantly?
> +                           ;; I.e. force lower face of with-subject if 
> string.
>                             org-koma-letter-subject-format
>                           with-subject))
>         (subject (org-export-data (plist-get info :title) info)))
>       (concat
>        (when with-subject
> -     (format "\\KOMAoption{subject}{%s}\n\n" subject-format))
> +     (format "\\KOMAoption{subject}{%s}\n" subject-format))
>        (when (and subject with-subject)
>       (format "\\setkomavar{subject}{%s}\n\n" subject))))
>     ;; Letter start
> @@ -346,9 +407,24 @@ holding export options."
>     contents
>     ;; Closing.
>     (format "\n\\closing{%s}\n\n" (plist-get info :closing))
> +   (let (after-closing)
> +     (dolist (ac org-koma-letter-special-tags-after-closing after-closing)
> +       (let ((x (org-koma-letter--get-tagged-content ac info)))
> +      (when x (setq after-closing
> +                    (concat after-closing
> +                            ;; sometimes LaTeX complains about newlines
> +                            ;; at the end of macros.  Remove them.
> +                            (replace-regexp-in-string
> +                             "\n+$" ""
> +                             (format "\\%s{%s}" (downcase ac) x)))))
> +      )))
>     ;; Letter end.
> -   "\\end{letter}\n\\end{document}"))
> -
> +   "\\end{letter}\n"
> +   (let ((x (org-koma-letter--get-tagged-content "AFTER_LETTER" info)))
> +     (when x (format x)))
> +   ;; Document end.
> +   "\\end{document}"
> +   ))
>  
>  
>  ;;; Commands
> -- 
> 1.8.2.3
> 


Reply via email to