From mboxrd@z Thu Jan 1 00:00:00 1970 From: Viktor Rosenfeld Subject: [PATCH] Improve configurability of ox-koma-letter Date: Sun, 21 Apr 2013 19:59:57 +0200 Message-ID: <20130421175957.GA7821@cartman> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BOKacYhQ+x31HxR3" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTyYZ-000537-5q for emacs-orgmode@gnu.org; Sun, 21 Apr 2013 14:00:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTyYW-0000qn-VM for emacs-orgmode@gnu.org; Sun, 21 Apr 2013 14:00:07 -0400 Received: from mail-bk0-x230.google.com ([2a00:1450:4008:c01::230]:40315) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTyYW-0000me-KS for emacs-orgmode@gnu.org; Sun, 21 Apr 2013 14:00:04 -0400 Received: by mail-bk0-f48.google.com with SMTP id jf3so2300663bkc.21 for ; Sun, 21 Apr 2013 11:00:03 -0700 (PDT) Content-Disposition: inline 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: emacs-orgmode@gnu.org --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I've hacked the ox-koma-letter exporter to make it more configurable. See the Changelog of the attached patch, hopefully I've followed the Changelog guidelines propertly. Also, I could not find an ox-koma-letter tutorial on Worg. I would be willing to create such a tutorial, maybe next weekend. Can anybody edit the contents on Worg or do I need special priviledges? Cheers, Viktor --BOKacYhQ+x31HxR3 Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: attachment; filename="ox-koma-letter.patch" Content-Transfer-Encoding: 8bit KOMA scrlttr2 export: Improve export configuration options. * ox-koma-letter.el (org-koma-letter-sender): New option for the letter's author. (org-koma-letter-from-address): Do not set default personal information. (org-koma-letter-phone-number): Do not set default personal information. (org-koma-letter-email): New option for the sender's email. (org-koma-letter-place): Specify the letter's place. (org-koma-letter-opening): Gendered opening. (org-koma-letter-closing): More business-like closing (org-koma-letter-use-subject): Configure the appearance of the subject line. (org-koma-letter-use-backaddress): Configure the presence of the backaddress. (org-koma-letter-use-foldmarks): Configure the presence of foldmarks. (org-koma-letter-use-phone): Configure the presence of the sender's phone number. (org-koma-letter-use-email): Configure the presence of the sender's email address. (org-koma-letter-use-place): Configure the presence of the letter's place. (koma-letter): Add new options to koma-letter export backend (org-koma-letter-template): Better KOMA configuration; support for multiple LCO files. This patch changes the KOMA-letter exporter in four ways: * Same hotkeys as the LaTeX exporter Use =L= (instead of =K=) to export to a buffer, =l= (instead of =k=) to export to a file, and =O= (instead of =o=) to open the PDF file. This was already suggested by Rasmus (http://thread.gmane.org/gmane.emacs.orgmode/67026). * Setting of KOMA variables LCO files are loaded first and KOMA variables are only set in the LaTeX output if their value is not nil. This way most configuration options can be set once in an LCO file and overwritten if needed. Consider for example an LCO file =DefaultAddress.lco= in =~/texmf/tex/latex=. #+BEGIN_SRC latex \ProvidesFile{DefaultAddress.lco} \setkomavar{fromname}{Max Mustermann} \setkomavar{fromaddress}{Musterstraße 1\\12345 Musterstadt} #+END_SRC The default address can then be overwritten in the actual letter. Note the additional country in the address below. #+LCO: DefaultAddress #+FROM_ADDRESS: Musterstraße 1\\12345 Musterstadt\\Germany * Setting of KOMA options The presence of the sender's phone and email, the letter's place and subject, as well as foldmarks and the backaddress are configurable. Consider: #+OPTIONS: subject:titled place:nil phone:t email:t foldmarks:nil backaddress:nil Note, that except for =subject=, all options are boolean, e.g., they accept the values =t= and =nil=. Subject can also be nil to surpress printing, or otherwise any possible value for the KOMA option subject, i.e., afteropening, beforeopening, centered, left, right, titled, underlined, or untitled. * Multiple LCO files Multiple LCO files, separated by spaces, can be specified. This way one can add optional behavior to the letter export. Consider, e.g., an LCO file with a default address and a simple textual signature: #+BEGIN_SRC latex \ProvidesFile{Default.lco} % default address \setkomavar{fromname}{Max Mustermann} \setkomavar{fromaddress}{Musterstraße 1\\12345 Musterstadt} % default signature \renewcommand*{\raggedsignature}{\raggedright} \setkomavar{signature}{\usekomavar{fromname}} #+END_SRC And a second LCO file defining a signature graphic: #+BEGIN_SRC latex \ProvidesFile{Signed.lco} % use signature graphic \usepackage{graphicx} \setkomavar{signature}{\\[-2.5\baselineskip]\includegraphics{/home/he-sk/org/data/12/441E34-D2DE-4207-9B4A-23A4DA7AF870/Unterschrift.png}\\[-0.9\baselineskip]\usekomavar{fromname}} #+END_SRC Then, a signed letter can be created as follows: #+LCO: Default Signed diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 1ffb455..31ccd89 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -80,23 +80,38 @@ :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-closing "See you soon," - "Koma-Letter's closing, as a string." +(defcustom org-koma-letter-sender nil + "Sender's name, as a string." :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-from-address "Somewhere \\ Over the rainbow." +(defcustom org-koma-letter-from-address nil "Sender's address, as a string." :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-opening "Dear Sir," +(defcustom org-koma-letter-phone-number nil + "Sender's phone number, as a string." + :group 'org-export-koma-letter + :type 'string) + +(defcustom org-koma-letter-email nil + "Sender's email, as a string." + :group 'org-export-koma-letter + :type 'string) + +(defcustom org-koma-letter-place nil + "Place from which the letter is sent." + :group 'org-export-koma-letter + :type 'string) + +(defcustom org-koma-letter-opening "Dear Madam or Sir," "Letter's opening, as a string." :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-phone-number "00-00-00-00" - "Sender's phone number, as a string." +(defcustom org-koma-letter-closing "Sincerely yours," + "Koma-Letter's closing, as a string." :group 'org-export-koma-letter :type 'string) @@ -105,28 +120,68 @@ :group 'org-export-koma-letter :type 'string) +(defcustom org-koma-letter-use-subject "untitled" + "Use the title as the letter's subject." + :group 'org-export-koma-letter + :type 'string) + +(defcustom org-koma-letter-use-backaddress t + "Print return address in small line above to address." + :group 'org-export-koma-letter + :type 'boolean) + +(defcustom org-koma-letter-use-foldmarks t + "Print foldmarks." + :group 'org-export-koma-letter + :type 'boolean) + +(defcustom org-koma-letter-use-phone t + "Print sender's phone number." + :group 'org-export-koma-letter + :type 'boolean) + +(defcustom org-koma-letter-use-email t + "Print sender's email address." + :group 'org-export-koma-letter + :type 'boolean) + +(defcustom org-koma-letter-use-place t + "Print the letter's place next to the date." + :group 'org-export-koma-letter + :type 'boolean) + ;;; Define Back-End (org-export-define-derived-backend 'koma-letter 'latex :options-alist - '((:closing "CLOSING" nil org-koma-letter-closing) + '((:lco "LCO" nil org-koma-letter-class-option-file) + (:sender "SENDER" nil org-koma-letter-sender newline) (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) - (:lco "LCO" nil org-koma-letter-class-option-file) - (:opening "OPENING" nil org-koma-letter-opening) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) - (:signature "SIGNATURE" nil nil newline) - (:to-address "TO_ADDRESS" nil nil newline)) + (:email "EMAIL" nil org-koma-letter-email) + (:to-address "TO_ADDRESS" nil nil newline) + (:place "PLACE" nil org-koma-letter-place) + (:opening "OPENING" nil org-koma-letter-opening) + (:closing "CLOSING" nil org-koma-letter-closing) + (:signature "SIGNATURE" nil org-koma-letter-signature newline) + + (: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-subject nil "subject" org-koma-letter-use-subject)) :translate-alist '((export-block . org-koma-letter-export-block) (export-snippet . org-koma-letter-export-snippet) (keyword . org-koma-letter-keyword) (template . org-koma-letter-template)) :menu-entry '(?k "Export with KOMA Scrlttr2" - ((?K "As LaTeX buffer" org-koma-letter-export-as-latex) - (?k "As LaTeX file" org-koma-letter-export-to-latex) + ((?L "As LaTeX buffer" org-koma-letter-export-as-latex) + (?l "As LaTeX file" org-koma-letter-export-to-latex) (?p "As PDF file" org-koma-letter-export-to-pdf) - (?O "As PDF file and open" + (?o "As PDF file and open" (lambda (a s v b) (if a (org-koma-letter-export-to-pdf t s v b) (org-open-file (org-koma-letter-export-to-pdf nil s v b)))))))) @@ -197,22 +252,53 @@ holding export options." (concat (plist-get info :latex-header) (plist-get info :latex-header-extra)))) info))))) - ;; Define "From" data. - (format "\\setkomavar{fromname}{%s}\n" - (org-export-data (plist-get info :author) info)) - (format "\\setkomavar{fromaddress}{%s}\n" (plist-get info :from-address)) - (format "\\setkomavar{signature}{%s}\n" (plist-get info :signature)) - (format "\\setkomavar{fromemail}{%s}\n" - (org-export-data (plist-get info :email) info)) - (format "\\setkomavar{fromphone}{%s}\n" (plist-get info :phone-number)) + (let ((lco (plist-get info :lco)) + (sender (plist-get info :sender)) + (from-address (plist-get info :from-address)) + (phone-number (plist-get info :phone-number)) + (email (plist-get info :email)) + (signature (plist-get info :signature))) + (concat + ;; Letter Class Option File + (when lco + (let ((lco-files (split-string lco " ")) + (lco-def "")) + (dolist (lco-file lco-files lco-def) + (setq lco-def (format "%s\\LoadLetterOption{%s}\n" lco-def lco-file))) + lco-def)) + ;; Define "From" data. + (when sender (format "\\setkomavar{fromname}{%s}\n" sender)) + (when from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address)) + (when phone-number (format "\\setkomavar{fromphone}{%s}\n" phone-number)) + (when email (format "\\setkomavar{fromemail}{%s}\n" email)) + (when signature (format "\\setkomavar{signature}{%s}\n" signature)))) ;; Date. (format "\\date{%s}\n" (org-export-data (org-export-get-date info) info)) - ;; Letter Class Option File - (format "\\LoadLetterOption{%s}\n" (plist-get info :lco)) - ;; Letter start. + ;; Place + (let ((with-place (plist-get info :with-place)) + (place (plist-get info :place))) + (when (or place (not with-place)) + (format "\\setkomavar{place}{%s}\n" (if with-place place "")))) + ;; KOMA options + (let ((with-backaddress (plist-get info :with-backaddress)) + (with-foldmarks (plist-get info :with-foldmarks)) + (with-phone (plist-get info :with-phone)) + (with-email (plist-get info :with-email))) + (concat + (format "\\KOMAoption{backaddress}{%s}\n" (if with-backaddress "true" "false")) + (format "\\KOMAoption{foldmarks}{%s}\n" (if with-foldmarks "true" "false")) + (format "\\KOMAoption{fromphone}{%s}\n" (if with-phone "true" "false")) + (format "\\KOMAoption{fromemail}{%s}\n" (if with-email "true" "false")))) + ;; Document start "\\begin{document}\n\n" - (format "\\setkomavar{subject}{%s}\n\n" - (org-export-data (plist-get info :title) info)) + ;; Subject + (let ((with-subject (plist-get info :with-subject))) + (when with-subject + (concat + (format "\\KOMAoption{subject}{%s}\n" with-subject) + (format "\\setkomavar{subject}{%s}\n\n" + (org-export-data (plist-get info :title) info))))) + ;; Letter start (format "\\begin{letter}{%%\n%s}\n\n" (or (plist-get info :to-address) "no address given")) ;; Opening. --BOKacYhQ+x31HxR3--