TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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?

share|improve this question
Basically it sounds like passing a parameter to the package. Did you have a look at some package guide? – Carsten Thiel Jan 4 '11 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 Jan 4 '11 at 14:57
I thought of packages like hyperref and fixme, which support options of the form key=value. – Carsten Thiel Jan 4 '11 at 15:09
That sounds good, as an alternative to the other answers presented. Is it fairly easy to do that? – robintw Jan 4 '11 at 15:18
I don't know. But it's a good question! – Carsten Thiel Jan 4 '11 at 15:25
up vote 6 down vote accepted

do you mean something like this?


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


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

share|improve this answer
You were quicker. Just one thing: you wrote \setmodulcode instead of \setmodulecode. – Bruno Le Floch Jan 4 '11 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 Jan 4 '11 at 15:13
@Bruno: thanks, is corrected – Herbert Jan 4 '11 at 15:17
@robintw: make your definitions before you load fancyhdr. If it doesn't work create a minimal example. – Herbert Jan 4 '11 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 Jan 4 '11 at 15:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.