Menu

HowTo_NewLCO

How to create LCO files for simple letter designs using the example of the Geoinformatics student council at the University of Münster

Although the standard forms for letters offered by scrlttr2 and scrletter are perfectly adequate for most private individuals, the desire to adapt them to one's own needs very quickly arises in the more business-related area. This was also the case in 2008 at the Geoinformatics student council of the Westfälische Wilhelms-Universität Münster. A wrapper class and a letter class option file were therefore created there for precisely this purpose, which was also kindly made available in the KOMA Script Documentation Project at the time. A revised version of the former lco file can serve well as a general example. However, for the purpose of generalization and to make it clear that this is no longer an official file of the student council, some texts have been replaced by placeholders.

Corporate Identity

The most complicated part is certainly the implementation of the layout or corporate identity, ultimately the design of the letterhead. We therefore start with the letter configuration option file (formerly letter class option file) for this purpose and call it fsgi-ci.lco:

\ProvidesFile{fsgi-ci.lco}[2025-06-02 v1.0 unsupported Letter Configuration File (Corporate Identity)]

What should always be the same here is the sender in the letterhead. We have the special feature that the name consists of several parts, namely the student council itself, the name of the university and the name of the institute. Another special feature is that the name of the student council should always be set in bold small caps. We therefore first define three new variables:

\newkomavar[\studentcouncilname]{studentcouncil}
\newkomavar[\universityname]{university}
\newkomavar[\institurename]{institute}

and one new font element:

\newkomafont{studentcouncil}{\scshape\bfseries}

and than use these for new form of the sender's name:

\setkomavar{fromname}{%
  {\usekomafont{studentcouncil}{\usekomavar{studentcouncil}}}\\%
  \usekomavar{university}\\
  \usekomavar{institute}
}

As can be seen, we no longer have a clear separation between form and content here. In addition, the end of line for the first line was not specified within the font switch as is actually recommended. The reason for this is that \\ has a special meaning within the signature, for example, which leads to an error message if \\ is used within a group. The second problem can of course also be easily avoided by explicitly setting signature. The solution to the first problem, the separation of form and content, could be solved by defining your own letter header using the variable firsthead instead of a predefined one, as shown in other examples in the wiki.

Since the letterhead should be right-aligned and a logo left-aligned, we can also set the corresponding options here:

\KOMAoptions{fromalign=right,fromlogo=true}

We will postpone the definition of the logo until later.

At this point, however, we want to ensure that the preferred font is loaded, if this is still possible. Because lco files can also be explicitly loaded after \begin{document}, but font packages can only be loaded before, we secure this here. We use the KOMA script instruction \if@atdocument, which looks like an internal instruction but is released for authors of lco files.

\if@atdocument
  \normalfont
  \Ifstrstart{\f@family}{Libertinus}{}{%
    \LCOWarningNoLine{fsgi-ci}{%
      cannot load Libertinus\MessageBreak
      after \string\begin{document}%
    }
  }%
\else
  \RequirePackage{libertinus}
\fi

If fsgi-ci is loaded after \begin{document}, the system first checks whether the default font is already Libertinus. If this is not the case, a warning is issued. If loaded before \begin{document} the font package is requested directly.

To the right of the addressee, some further information should appear, namely the room, the telephone number and the e-mail address. To do this, we define a new variable for the room. All other required variables already exist:

\newkomavar[\usekomavar*{roomseparator}\usekomavar{roomseparator}]{room}
\newkomavar[\roomname]{roomseparator}
\setkomavar{roomseparator}{: }
\providecaptionname{english,USenglish,GBenglish,american}{\roomname}{Room}
\providecaptionname{ngerman,naustrian,nswiss}{\roomname}{Raum}

The definition split into room and roomseparator may seem cumbersome, but is actually exactly the same as other variables whose output can be activated in the header. And simplifies the definition of location:

\setkomavar{location}{%
  \raggedleft\footnotesize
  \Ifkomavarempty{room}{}{%
    \textsf{\textbf{\usekomavar*{room}}}%
    \usekomavar{room}\\
  }%
  \Ifkomavarempty{fromphone}{}{%
    \textsf{\textbf{\usekomavar*{fromphone}}}%
    \usekomavar{fromphone}\\
  }%
  \Ifkomavarempty{fromemail}{}{%
    \textsf{\textbf{\usekomavar*{fromemail}}}%
    \usekomavar{fromemail}\\
  }%
}%
\KOMAoption{locfield}{wide}

As can be seen, the name of the room field is not permanently assigned to ”Room“, but is defined as language-dependent. This means that it can be easily changed as required, for example using \renewcaptionname{ngerman}{\roomname}{Zimmer}, also depending on the language.

All that's missing now is a suitable page footer. Here we make it easy for ourselves. Only the homepage should be output, if one is defined:

\setkomavar{firstfoot}{%
  \Ifkomavarempty{fromurl}{}{%
    \centering
    \textsf{\textbf{\usekomavar*{fromurl}}}%
    \usekomavar{fromurl}\\
  }%
}

That's all.

Data

In addition to the design, data for the variables, both those preset in scrlttr2 and scrletter and those newly defined in fsgi-co.lco, are of course also required. To do this, we define another letter configuration option file fsgi.lco:

\ProvidesFile{fsgi.lco}[2025-06-02 v1.0 unsupported Letter Configuration File (Corporate Identity + Data)]
\LoadLetterOption{fsgi-ci}
\setkomavar{studentcouncil}{Fachschaft Geodäddy}
\setkomavar{university}{Westerwälder Wilhelminen-Universität}
\setkomavar{institute}{Insitut für Geodäddy}
\setkomavar{fromaddress}{Kaldentalweg~2\\94184 Monster}
\setkomavar{backaddress}{Fachschaft Geodäddy\\\usekomavar{fromaddress}}
\setkomafont{fromname}{\sffamily}
\setkomafont{fromaddress}{\sffamily}
\@ifundefined{includesvg}{%
  \if@atdocument\else\RequirePackage{svg}\fi
}{}
\setkomavar{fromlogo}{%
  \@ifundefined{includesvg}{%
    \missingsvgwarning
  }{%
    \includesvg[width=3cm]{Gabepacman.svg}%
  }%
}
\newcommand*{\missingsvgwarning}{%
  \LCOWarningNoLine{fsgi}{%
    To use logo Gabepacman.svg you need\MessageBreak
    to use either\MessageBreak
    \space\space\string\LoadLetterOption{fsgi}\MessageBreak
    or\MessageBreak
    \space\space\string\usepackage{svg}\MessageBreak
    in your document preamble.\MessageBreak
    Leaving logo empty%
  }%
  \global\let\missingsvgwarning\relax
}
\setkomavar{room}{3.6}
\setkomavar{fromphone}{+49\,123\,45-6789}
\setkomavar{fromemail}{fsgi@um.invalid}
\setkomavar{fromurl}{https://fsgi.um.invalid}

However, the logo Gabepacman.svg used in the example not only requires the svg package, but also the LuaLaTeX call with the --shell-escape option. Therefore, if you prefer to use one of the pixel files also available on WikiMedia Commons, you can simply use fsgi-pixel.lco:

\begin{filecontents*}[overwrite]{fsgi-pixel.lco}
\LoadLetterOption{fsgi}
\setkomavar{fromlogo}{%
  \@ifundefined{includegraphics}{%
    \missinggraphicxwarning
  }{%
    \includegraphics[width=3cm]{Gabepacman.svg.png}
  }%
}
\newcommand*{\missinggraphicxwarning}{%
  \LCOWarningNoLine{fsgi}{%
    To use logo Gabepacman.svg.png you\MessageBreak
    need to use either\MessageBreak
    \space\space\string\LoadLetterOption{fsgi-pixel}\MessageBreak
    or\MessageBreak
    \space\space\string\usepackage{graphicx}\MessageBreak
    in your document preamble.\MessageBreak
    Leaving logo empty%
  }%
  \global\let\missinggraphicxwarning\relax
}
\end{filecontents*}

In both examples, it is again ensured that svg or graphicx is not inadvertently loaded after \begin{document}. The trick of a separate instruction for the warning also ensures that the warning is only issued once if necessary. When using fsgi-pixel.lco instead of fsgi.lco, of course, no --shell-escape is required.

Example

If the chairperson now wants to write a letter, he/she naturally does not want to sign his/her name and then of course uses \setkomavar{signature}{Geolinus\\(Chairman)} and then gets, for example:

Figure: Example letter from the chairman

Concluding remarks

The original files that were used in Münster until 2016 defined a few more variables such as chairPerson, assistant and presence. However, these are not required for the demonstration of an lco file and have therefore been omitted. A table with URL, geo information, IRC channel and OpenPGP hash was also used in the footer of the original. This has also been omitted in this example. On the other hand, current mechanisms were used in the example shown and extensions such as the use of font elements or the test for empty variables were added and it is shown how package dependencies can be controlled in lco files without preventing their usability after \begin{document}.


Related

Wiki (English): HowTo_Letter

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.