I'm after a definition of a command that could have multiple values to use in different contexts. The use case for this would be in a custom class that uses two languages simultaneously, or I guess any situation where a variable could have different values depending on the environment. After searching information on \newcommand
and things related to it, I'm still a bit puzzled about things.
As I understand it, a simple implementation would be:
\newcommand\varname{text value}
However, having different commands for same things gets ugly in my eye. For example, I have in front of me an old class with commands like Doctype
and Doctypefin
for the Finnish version. Instead, I'd like to use the command like this:
% Definitions
\title{en}{Title Of The Document}
\title{fi}{Dokumentin otsikko}
% Use in class environments or tex files
\title{en} % -> "Title Of The Document"
\title{fi} % -> "Dokumentin otsikko"
Is there any way to construct such a macro or definition?
Ideally, specifying unseen categories (here languages) would not be a problem, but I can see it would be reasonable to require specifying the accepted values in the class file. Also, like in the example below, I think it would be acceptable to have a separate command for outputting the variable, if that's a problem.
I've tried to take note of the way other class commands are constructed. There's a handy MakeStringVar
command that constructs a variable, and if not set, displays a default text. That default text functionality would be very useful for the new command, because loads of the environments in the class use the definitions to output text to title pages etc.
\newcommand\MakeStringVar[2][\relax]{%
\ifx#1\relax%
\expandafter\newcommand\csname Emit#2\endcsname{%
{\scriptsize (Use {\tt\textbackslash #2} to replace this text.)}}%
\else%
\expandafter\newcommand\csname Emit#2\endcsname{#1}%
\fi%
\expandafter\newcommand\csname #2\endcsname[1]{%
\expandafter\renewcommand\csname Emit#2\endcsname{##1}%
}%
}
It is used like so:
\MakeStringVar{Major} % Definition in class
\Major{Major subject name} % Set value in pre-document
\EmitMajor % Used in environments in class -> "Major subject name"
But I'm a newbie when it comes to LaTeX, so I'm not sure where to even begin. I have a feeling the above command could be expanded in some manner, but I really don't know the limitations of LaTeX macros.
\title[en]{<English title>}
and\title[fi]{<Finnish title>}
(say) together with\thetitle[en]
(for<English title>
) and/or\thetitle[fi]
(for<Finnish title>
). Note the use of\title
for defining the title and\thetitle
to set the title in the document. Also, the language choice is presented as an optional argument, where you can specify some default (likeen
for English, say).