3

I've got a heavy class definition and want to modify it for the use with precompiled preambles.


Minimal example

preamble.tex

\documentclass{myClass}
\def\preambleloaded{Precompiled preamble loaded.}

main.tex

\ifdefined\preambleloaded\typeout{\preambleloaded}\else\input{preamble}\fi

\usepackage{blindtext}

\begin{document}
\blindtext
\end{document}

myClass.cls

\def\filename{myClass}

\NeedsTeXFormat{LaTeX2e}
\RequirePackage{fixltx2e}
\ProcessOptions\relax

\LoadClass{scrbook}

\RequirePackage[english]{babel}
\RequirePackage{etoolbox}

\newcommand*{\@Author}{George Orwell}

\AtBeginDocument{

Hello World! My name is \@Author!
\newline

}

To compile the preamble.tex I use:

lualatex -ini -job-name="main" "&lualatex preamble.tex\dump"

and for the main.tex

lualatex -shell-escape "&main main.tex"

in TexStudio with an up-to-date MikTex distribution.

enter image description here

Everything works fine so far and I get

enter image description here


Actual question

Now I'd like to pass the Author name to the class by defining/redefining it in the preamble, something like this:

preamble.tex

\documentclass[Aldous Huxley]{myClass}
\def\preambleloaded{Precompiled preamble loaded.}

or

\documentclass{myClass}
\renewcommand{\@Author}{Aldous Huxley}
\def\preambleloaded{Precompiled preamble loaded.}

How can I do that?

I've also seen this question, but can't manage to apply it to my case.

1 Answers1

3
\documentclass{myClass}
\renewcommand{\@Author}{Aldous Huxley}
\def\preambleloaded{Precompiled preamble loaded.}

would work if @ was a letter at that point (which it isn't here) or simpler just use the class defined \Author command.

This will work:

preamble.tex

\documentclass{myClass}
\Author{Aldous Huxley}
\def\preambleloaded{Precompiled preamble loaded.}

myClass.cls

\def\filename{myClass}

\NeedsTeXFormat{LaTeX2e}
\RequirePackage{fixltx2e}
\ProcessOptions\relax

\LoadClass{scrbook}

\RequirePackage[english]{babel}
\RequirePackage{etoolbox}

\newcommand*{\@Author}{George Orwell}
\newcommand*{\Author}[1]{\renewcommand*{\@Author}{#1}}

\AtBeginDocument{

Hello World! My name is \@Author!
\newline

}
David Carlisle
  • 757,742