0

I'm working on a personal class where I absolutely need to get a seed number before loading anything in the document. I would like the seed in the class option, something like :

\documentclass[seed=326]{my-class}
\begin{document}

\end{document}

In my class, I want the seed number to be stored in a command called \mycommand if the seed option is used, and I want \mycommand to stay undefined if the option seed is not used.

Does anyone know if something like this is possible, and what should be written in my-class?

2
  • Possible? Sure. How? That depends: will you have other class options or just this one? However, the absolutely easiest way would just be to put \newcommand*{\mycommand}{326} before \documentclass. This will define the macro before anything else (apart from the kernel) is loaded, and the macro will stay undefined if you don't write the line :-)
    – campa
    Commented Mar 19, 2023 at 16:55
  • @campa Thanks for this approach. Anyway, I would like to def \mycommand by the option in the class. I would like to be able to put some other options if needed in the class.
    – Vince
    Commented Mar 19, 2023 at 17:06

1 Answer 1

0

The following sould serve your needs.

\begin{filecontents*}{my-class.cls}
    \ProvidesClass{my-class}
    \LoadClass{article}
    \RequirePackage{xkeyval}
    \DeclareOptionX{seed}{\newcommand{\mycommand}[0]{#1}}
    \ProcessOptionsX
\end{filecontents*}

\documentclass[seed=123]{my-class}

\begin{document}
    Given seed: \mycommand
\end{document}

If you don't provide a seed, the above document will give you an error because \mycommand is undefined, just as you want it.

2
  • Thank you ! How dumb am I, I forgot the [0] when I previously tried this, using xkeyval !
    – Vince
    Commented Mar 19, 2023 at 18:06
  • You're welcome! It should even work without [0]. Commented Mar 19, 2023 at 18:09

You must log in to answer this question.

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