4

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?

5
  • Basically it sounds like passing a parameter to the package. Did you have a look at some package guide? Commented Jan 4, 2011 at 14:42
  • I've had a look at that, but I'm not sure exactly what I need to look for. I could do this by passing a parameter to a package, but I can't see how to do that with passing strings rather than just options. What I was actually thinking of was creating a command (using \newcommand possibly) in the style file that would allow me to do something like \setmodulecode{COMP6023} in my document. That would seem to me to be the easiest way - and I'd guess it is fairly simple. Is that so?
    – robintw
    Commented Jan 4, 2011 at 14:57
  • I thought of packages like hyperref and fixme, which support options of the form key=value. Commented Jan 4, 2011 at 15:09
  • That sounds good, as an alternative to the other answers presented. Is it fairly easy to do that?
    – robintw
    Commented Jan 4, 2011 at 15:18
  • I don't know. But it's a good question! Commented Jan 4, 2011 at 15:25

1 Answer 1

6

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.

4
  • You were quicker. Just one thing: you wrote \setmodulcode instead of \setmodulecode. Commented Jan 4, 2011 at 15:07
  • Thanks - that works well :-) The only problem I have is that I then want to use \modulecode in a bit of fancyhdr code as below. This code is inside my style file, but is failing - presumably because it can't see \modulecode at the time that it is run (as it is defined in the preamble of the document). Is there a way around this: \fancyhead{} \lhead{\modulecode} \rhead{\lecturetitle}
    – robintw
    Commented Jan 4, 2011 at 15:13
  • @robintw: make your definitions before you load fancyhdr. If it doesn't work create a minimal example.
    – user2478
    Commented Jan 4, 2011 at 15:18
  • As usual, in the process of making the minimal example I found the problem. Apologies - I really must do that before asking! Thanks for your help.
    – robintw
    Commented Jan 4, 2011 at 15:22

You must log in to answer this question.

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