Write a letter in org mode

Table of Contents

Goals

Figure 1: Printed sample.pdf

Figure 1: Printed sample.pdf

In order to get the same printout as in figure 1 above, both includepdf lines starting at line 37 here must be uncommented.

  1. Use emacs 1org mode
  2. Compose a new letter with a few keystrokes
  3. Manage letters like e-mails

Setup

Change letter meta variables through a lco file

The 2koma manual at p.484 displays a nice overview of position possibilities:

Figure 2: Schematic of the pseudo-lengths for a letter

Figure 2: Schematic of the pseudo-lengths for a letter

Custom LCO files must be placed in a directory where LaTeX will find them. On GNU/Linux, this defaults to ~/texmf/tex/latex.

Create the folder ~/texmf/tex

mkdir -p ~/texmf/tex

Create a new file ~/texmf/tex/mySN.lco containing these lines:

\ProvidesFile{mySN.lco}[2019/04/22 my_letter-class-option]
\LoadLetterOption{SN}
\let\raggedsignature=\raggedright
\setplength{toaddrvpos}{60mm}
\setplength{backaddrheight}{-3mm}
\setplength{toaddrheight}{25.5mm}
\usepackage[german]{babel}
\endinput

You can test whether foo.lco is recognized by TeX Live by running the command

kpsewhich mySN.lco

After adding a file to the TeX Live path you may have to run

mktexlsr

Create the yasnippets template

Create home/ra.emacs.d/private/snippets/text-mode/exampleLetter containing lines below:

# -*- mode: snippet -*-
# name:myExampleLetter
# key:,ltr
# --
  #+LCO: mySN
  #+OPTIONS: backaddress:t email:nil
  #+OPTIONS: after-closing-order:(after_closing ps encl cc)
  #+OPTIONS: after-letter-order:(after_letter)
  #+OPTIONS: foldmarks:nil phone:nil place:t special-headings:nil subject:t
  #+OPTIONS: title-subject:nil url:nil location:t title:nil

  #+LATEX_CLASS: default-koma-letter
  #+LATEX_HEADER: \setkomavar{signature}{\includegraphics[height=1cm]{/home/ra/Downloads/signature.pdf}\\\\\usekomavar{fromname}}
  #+LaTeX_HEADER: \usepackage{pdfpages}

  #+AUTHOR: Sender Name
  #+FROM_ADDRESS: Acmestreet 1, 5555 Footown
  #+PHONE_NUMBER: 0123456789
  #+URL: example.org
  #+EMAIL: foo@bar.com
  #+TO_ADDRESS: ${1:ReceiverInc}\\\ ${2:JohnDoe}\\\ ${3:SomeStreet}\\\ ${4:ZipTown}\\\Mittelerde
  #+PLACE: MyTown
  #+SUBJECT: ${5:MySubject}
  #+OPENING: ${6:Dear John}
  #+CLOSING: With best regards
  ${0:MyText}
*** PS                                                                   :ps:noexport:
    PS: I must remove the :noexport: tag to display this line in the exported pdf
*** CC                                                                   :cc:
    Jane & Alice
*** ENCL                                                               :encl:
    - A map
    - Another map
*** Included files                                             :after_letter:
    #+BEGIN_EXPORT latex
    % Uncomment line below to include other pdf files
    %\includepdf[pages=-]{/home/ra/Downloads/Map.pdf} %must use absolute path
    %\includepdf[pages=-]{/home/ra/Downloads/OtherMap.pdf} %must use absolute path
    #+END_EXPORT

Workflow (Spacemacs)

  1. Create a new file hitting SPC f f
  2. Enter the filename e.g. sample.org RET
  3. Expand the template we created before hitting ,ltr TAB
  4. Toggle through the fields hitting TAB
  5. Export the pdf hitting , e e k o