Skip to content

Instantly share code, notes, and snippets.

@jfdm
Created February 24, 2023 13:59
Show Gist options
  • Save jfdm/e1d368d721018324267a9a34c572b961 to your computer and use it in GitHub Desktop.
Save jfdm/e1d368d721018324267a9a34c572b961 to your computer and use it in GitHub Desktop.
Variables in LaTeX using komascript.
\documentclass{article}
\usepackage{xspace}
% The Magic Sauce.
\usepackage{scrletter}
\makeatletter
\newkomavar[urghhh]{documentTitle}
\setkomavar{documentTitle}{\@title}
\newkomavar[urgh]{documentSubTitle}
\setkomavar{documentSubTitle}{}
\newcommand{\subtitle}[1]{\setkomavar{documentSubTitle}{#1}}
\newcommand{\theTitle}{\usekomavar{documentTitle}}
\newcommand{\theSubtitle}{\usekomavar{documentSubTitle}}
\newcommand{\theFullTitle}{%
\theTitle%
\ifkomavarempty{documentSubTitle}
{}
{:\xspace\theSubtitle}}
\makeatother
\title{Foo}
\subtitle{Bar}
\begin{document}
\begin{enumerate}
\item\theTitle{}
\item \theSubtitle{}
\item \theFullTitle{}
\end{enumerate}
\subtitle{}
\begin{enumerate}
\item \theTitle{}
\item \theSubtitle{}
\item \theFullTitle{}
\end{enumerate}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment