0

I'm deriving my own class from scrartcl but wan to introduce variables as in scrlttr2 for the user of the class to set several values. I find the \setkomavar resp. \usekomavar mechanism with key, value and description quite convenient.

Is there any way of using komavars if I'm not using the scrlttr2 class?

My actual problem

Currently I get Undefined control sequence. \setkomavar if I use \setkomavar.

My new class will have a title page which includes an address and a logo which I want to set with komavars as it is done in scrlttr2. To define this titlepage I renew the \maketitle command, which is not available if I would derive my class from scrlttr2.

12
  • No, \newkomavar is only defined in scrlttr2.cls (and will be in scrletter.sty). You could however extract it from the definition.
    – Johannes_B
    Nov 27, 2014 at 9:26
  • There are other ways for the user to set variables. What do you have in mind? A short example (great if its compilable) will make it easier to help.
    – Johannes_B
    Nov 27, 2014 at 9:27
  • Ok, I hope I could make my point a little bit more understandable with this edit. Nov 27, 2014 at 9:44
  • Please look at the very bottom of this answer: How to add a flyleaf code?
    – Johannes_B
    Nov 27, 2014 at 9:46
  • Ok, that looks good in the way that I could add titlepages to scrlttr with this package but I will not be able to change the descriptions of the values Gutachter, 2. Gutachter, … in your example. Nov 27, 2014 at 9:52

2 Answers 2

4

With the current version of KOMA-script you get package scrletter which is is still in beta. It provides the ability to write letters with the with the article, report or book class of KOMA-script. Hence, it defines the mechanism you want.
In the following a simple example to set the page header with the name.

\documentclass{scrartcl}
\usepackage{blindtext}
\usepackage{scrletter}
\newkomavar[Autor:]{name}
\setkomavar{name}{White Gecko}
\usepackage{scrlayer-scrpage}
\ohead*{\usekomavar*{name}~\usekomavar{name}}
\begin{document}
\blinddocument
\end{document}
3

A good general replacement for komavar is \csdef, \csuse from etoolbox as explained here: https://tex.stackexchange.com/a/37429/11820

A usage scenario is this:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{simplevar}[2014/11/27 simplevar package]

\RequirePackage{etoolbox}

% Set a value for a key
\newcommand\setVar[2]{\csdef{simpleVarValue#1}{#2}}
% Get the value for the key
\newcommand\getVar[1]{\csuse{simpleVarValue#1}}

% Set a label for a key
\newcommand\setLabel[2]{\csdef{simpleVarLabel#1}{#2}}
% Get the label for a key
\newcommand\getLabel[1]{\csuse{simpleVarLabel#1}}

\endinput

It could also be extended to use the same syntax as komavar or maybe one could introduce a kind of namespace to make the simpleVar… part configurable.

2
  • 1
    Sounds interesting. Can you extend the answer and show us an example?
    – Johannes_B
    Nov 27, 2014 at 13:23
  • Under the hood, the scrlttr2 does something pretty simmilar. But KOMA does some tests to issue errors when the user inputs faulty stuff.
    – Johannes_B
    Nov 27, 2014 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .