A LaTeX template for business letters (mostly) following German DIN 5008 standard, based on KOMA-Script class 'scrlttr2'.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
During my research on writing letters with LaTeX and KOMA-Script I encountered many great templates on the web. However, none of them met all my requirements so I decided to create my own one. This template offers
- a structured layout, mostly following German DIN 5008 standard,
- a customizable logo placeholder, information block, and footer
- an automatically created vCard QR code with your (company's) contact details, allowing the recipient to store them in their smartphone, and
- code snippets allowing you to
- include OS environmental variables in your letter, e.g. as used in the TeXLetterCreator project,
- create multi-lingual documents.
The project has been developed and tested on the following system:
Info | Description |
---|---|
OS | Debian GNU/Linux 12 (bookworm) |
Kernel | 5.15.90.1-microsoft-standard-WSL2 |
Packages | texlive-latex-recommended (2022.20230122-3) |
texlive-luatex (2022.20230122-3) | |
xz-utils (5.4.1-0.2) |
Please make sure that the following dependencies are installed:
- XZ Utils
- TeX distribution of your choice, e.g. TeX Live
- LuaTeX engine
- Packages (CTAN) afterpage, babel, babel-english, babel-german, catchfile, enumitem, etoolbox, fontawesome5, graphicx, iflang, ifthen, qrcode, scrlayer-scrpage, scrlttr2, sourcesanspro, tabularx, xstring
Below you can find distribution-specific installation instructions.
❗ Please do not forget to install the additional CTAN packages after (!) the distribution-specific package installation.
> sudo apt install texlive-latex-recommended texlive-luatex xz-utils
Some CTAN packages listed above are not included in the distributions' packages. However, they can be manually installed by using the TeX Live package manager tlmgr
.
Before continuing please make sure that tlmgr
's user mode has been initialized by running the following command:
> tlmgr init-usertree
In case you skip this step you may get an error during installation:
(running on Debian, switching to user mode!)
(see /usr/share/doc/texlive-base/README.tlmgr-on-Debian.md)
TLPDB: not a directory, not loading: /home/user/texmf
tlmgr: user mode not initialized, please read the documentation!
Now you can install the required CTAN packages:
> tlmgr install babel-english babel-german blindtext catchfile enumitem fontawesome5 qrcode sourcesanspro xstring
In some cases the installation may fail with a message similar to the following one:
tlmgr: Local TeX Live (2022) is older than remote repository (2023).
Cross release updates are only supported with
update-tlmgr-latest(.sh/.exe) --update
See https://tug.org/texlive/upgrade.html for details.
In those cases the version of the TeX Live system installed via your distribution's package manager does not match the version of tldr
's default repository. To fix this problem:
-
Figure out the year of your local TeX Live system by running the following command:
> tex --version
The output may look like this:
TeX 3.141592653 (TeX Live 2022/Debian)
kpathsea version 6.3.4
Copyright 2022 D.E. Knuth.
... -
Add the repository while replacing
<year>
by the year from step 1 (2022 here).> tlmgr option repository ftp://tug.org/historic/systems/texlive/<year>/tlnet-final
In case you would like to use another mirror please have a look at: https://tug.org/historic/
Next we will install the necessary hyphenation pattern packages. In case you skip this step you may get a warning message when compiling your letter and your LaTeX compiler may use the wrong hyphenation patterns:
> Package babel Warning: No hyphenation patterns were preloaded for
> (babel) the language 'German (new orthography)' into the format.
>
> (babel) Please, configure your TeX system to add them and
> (babel) rebuild the format. Now I will use the patterns
> (babel) preloaded for \language=0 instead on input line 48.
Before continuing please make sure that the following files can be modified by your current user:
> sudo touch \
/var/lib/texmf/tex/generic/config/language.dat \
/var/lib/texmf/tex/generic/config/language.dat.backup
> sudo chown $(id -u):$(id -g) \
/var/lib/texmf/tex/generic/config/language.dat \
/var/lib/texmf/tex/generic/config/language.dat.backup
Then install the hyphenation pattern packages by running:
> tlmgr install hyphen-german
Afterwards, do not forget to revert the file permission changes:
> sudo chown root:root \
/var/lib/texmf/tex/generic/config/language.dat \
/var/lib/texmf/tex/generic/config/language.dat.backup
⚠️ The installation process modifies the system-wideBabel
configuration filelanguage.dat
(see above). Your (Linux) distribution's package manager may also modify this file in the future, e.g. when updating your TeX base installation. This may result in configuration issues so it is recommended to backup this file every time you update your TeX distribution packages.
Optional: In case you have modified the template (and therefore need additional CTAN packages) you may find the following tlmgr
commands useful
# Search for a package that contains a certain file, e.g. 'loadhyph-de-1996.tex'
> tlmgr search --global --file loadhyph-de-1996.tex
# Show which files belong to a certain package, e.g. 'hyphen-german'
> tlmgr info hyphen-german --list
# List installed packages
> tlmgr list --only-installed
Done! You can continue with Installation.
- Clone the repo
> git clone https://github.com/fkemser/GerLaTeXLetter.git
- Customize the template, see Customization.
Before writing your first letter you should customize the template. To do so, please have a look at the following repository files:
.
├── src
│ ├── header.lco Header/Footer/Information Block Template
│ ├── letter.tex Individual Letter
│ ├── logo.png Sample Logo
│ └── template.lco General Letter Template
...
ℹ️ For more information please also have a look at the comments within the files, the KOMA-Script documentation and the KOMA-Script Wiki.
Open header.lco
with your favourite editor and replace the example values by your own ones. Generally speaking it is always about the last {}
of each line.
\renewcommand{\fromgivennames}{Max}
With some variables you are able to not only change their values but also their field descriptor, indicated by []
.
\setkomavar{frombushours1}[Mo - Mi]{08:00 - 17:00}
There are also some variables that allow you to set multi-line text:
\setkomavar{fromroutebus}{%
11 Musterstraße\newline
22 Musterplatz%
}
❗ Please use
\newline
instead of\\
to set a linebreak.
By default, a vCard will be generated from the sender's information and printed as a QR code within the information block. To disable this behaviour, simply comment each of the following lines with a %
at the beginning.
\newplength{fromvcardheight}
\setplength{fromvcardheight}{1.5cm}
To replace the sample logo with your own one, simply replace logo.png
by your own file. To use a different file name simply replace {logo}
by your own filename, without any extension. The file must be located in the src
folder.
\setkomavar{fromlogo}{\includegraphics[height=1.25cm]{logo}}
To disable the logo just comment the above line with a %
at the beginning.
❓But this is the file to write my individual letter, why should I store anything template-related here?
Well, for writing just one single letter you may skip this section. But in case of form letters you need a template which letter.tex
will be the base for.
Edit the following line to change the letter's language:
\usepackage[ngerman]{babel}
⚠️ At the moment, onlyngerman
,english
,USenglish
, andUKenglish
(all case-sensitive) are supported.
This will not only change the information block's descriptors but also any text within the letter for which you have defined language-dependent variables. It also loads language-specific hyphenation patterns.
You can define your own variables by using the following command, where varname
is the variable's name and description
its (optional) description.
\newkomavar[description]{varname}
To use the variable or its description (*
) within the letter just use:
\usekomavar{varname} % Variable
\usekomavar*{varname} % Descriptor
For multi-lingual documents you can define language-dependent values:
% Default
\setkomavar{varname}{value_default}
% ngerman
\IfLanguagePatterns{ngerman}{%
\setkomavar{varname}{value_ngerman}
}{}
The same applies to descriptions:
% Default
\setkomavar*{varname}{description_default}
% ngerman
\IfLanguagePatterns{ngerman}{%
\setkomavar*{varname}{description_ngerman}
}{}
To use your system's environmental variables within your letter:
- Define a new variable where
envvarname
is the environmental variable's name (within your system) andmacroname
the macro (variable) name that you will use within your letter.
\getenv[\macroname]{envvarname}
- In your letter simply use
\macroname
wherever you would like to use the variable's value.
When writing form letters there may be some addressee-related parts that do not change, e.g. subject, closing, etc. You can set them within the Addressee-independent
section.
See Logo section above.
To change the letter's general appearance please edit template.lco
. However, this is only recommended for experienced users.
To write your individual letter, open letter.tex
and edit the following two sections:
Section | Description |
---|---|
ADDRESSEE |
Recipient-related information, e.g. name, address, etc. |
BODY |
Letter body (text) |
❗A manual
\pagebreak
has to be set after each page, otherwise the textwdith will not be calculated correctly.
To create the final PDF of your letter, change into the src
directory and run the following command:
> lualatex letter
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
⚠️ The license above does not apply to the sample logo file/src/logo.png
. For more information please have a look at Logoipsum's terms of license.
Project Link: https://github.com/fkemser/GerLaTeXLetter
- KOMA-Script
- Logoipsum (
src/logo.png
)