[Tex/LaTex] Emacs AucTeX Customization – Adding templates

auctexemacs

Is it possible to customize emacs (with AucTeX) so that new templates can be added for quicker typesetting. For example, If I want to prepare a letter that has a particular format, then I would like to create a sample letter tex file and save it as a macro or environment and call it and just pass the required parameters like the date, the name , the content and so on and generate the pdf?

Best Answer

After quite some time I was very happy to find this: https://github.com/capitaomorte/yasnippet

I'm using templates, e.g. for letters, but for inserting code as well. A part of this letter snippet follows:

# -*- mode: snippet -*-
# contributor: XX
# key: YXZ-let
# group: skeleton
# name: \documentclass{scrlettr2} ...
# --
\documentclass[12pt,ngerman,zippelius8]{scrlttr2}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}


\setkomavar{Sachbearbeiter}{my secretary...}


\begin{document}

\begin{letter}{${1:Name}\\\
    ${2:Strasse}\\\
    ${3:PLZ Ort}\\\[1.5cm]
    ${4:$$(yas/choose-value '("Vorab per Telefax: " "Per Telefax: " "Vorab per E-mail: " "Per E-mail: " " "))}
    \emph{${5: }}
    }

But beware, there are many things that can be inserted fast using the build-in AUCTeX commands. E.g. the fastest way to insert an environment ist C-c C-e.

The code above is the beginning of a snippet. So the syntax is the syntax of yassnippet and not LaTeX. The part after the initial lines beginning with a # will be inserted as template.