[Tex/LaTex] Use \newcommand with a variable inside a style file

macrospackage-writing

I have the following code which I put inside the preamble of my LaTeX documents:

\newcommand{\modulecode}{SESG6025}
\newcommand{\lecturetitle}{Interpolation}

In this case, that means that when I'm writing my lecture notes I can just use \modulecode to refer to the module code. I'm trying to create a style file to use for my lecture notes, and want to have some way that I can define what the module code is (that is, some way of setting the variable) in each document, so that I can then refer to it as above using \modulecode.

I can't seem to find how to do this through Google, but I'm sure it must be a fairly simple request. Any ideas?

Best Answer

do you mean something like this?

\newcommand\setmodulecode[1]{\def\modulecode{#1}}
\setmodulecode{COMP6023}

if you have it inside a style file then do something like

\newcommand\setmodulecode[1]{\def\@modulecode{#1}}
\setmodulecode{COMP6023}

to prevent overwriting by a user. Alternatively use \setmodulecode{} for the first definition.