3

I have a class in which an option is to state a code and the resulting programme of study is represented at various points throughout a document. The option also changes a number of other blocks of text related to each programme. For example:

\DeclareOption{AK3696}{\def\degreetitle{Bachelor of Arts (Honours)}}

However, there are 156 codes and while having 156 options declared works, it really grates. I would prefer to have all the codes and programme names in a separate file that can be easily updated (these may change twice each year with old ones deleted and new ones added).

Is there a way, using \DeclareOption, to define the programme codes and programme names in an array of structured objects and using the programme code as a pointer?

The array should not include the class code, for example in the form below:

"AK3696","Bachelor of Arts (Honours)"

"AK3656","Bachelor of Applied Science (Honours)"

"AK3670","Bachelor of Art and Design (Honours)"

"AK3712","Bachelor of Business with Honours"

"AK3687","Bachelor of Computer and Information Sciences (Honours)"

3
  • Do you want to pull the data out of a .csv? Commented May 5, 2016 at 4:06
  • Ideally, yes. But for now it is sufficient to have a text file that can be read. Commented May 7, 2016 at 6:51
  • My apologies. I should add that I would also like to remove the class code text from the file and be reduced to a comma separated list. I have edited the question to include this. Commented May 7, 2016 at 7:32

1 Answer 1

1

The question is a bit too generic. I'd exploit the \DeclareOption* feature:

\DeclareOption*{\edef\alanclass@givencode{\CurrentOption}}

After \ProcessOptions you can input your code file in the format

%% file alanclasscodes.def
\alanclass@code{AK3696}{%
  \def\degreetitle{Bachelor of Arts (Honours)}%
}
%%% and so on for the other codes

by doing

\def\alanclass@code#1#2{%
  \def\next{#1}%
  \ifx\alanclass@givencode\next
    #2%
  \fi
}
\input{alanclasscodes.def}

so the TeX code relative to the chosen options is executed and the others are discarded.

5
  • Unfortunately, this did not work, no matter how I altered it. Is it because there may be a restriction on the number of \DeclareOption* statements? Clearly there already exists \DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}} Commented May 7, 2016 at 19:49
  • @Alan There can be only one \DeclareOption* statement. I can't read your mind or your class. Commented May 7, 2016 at 19:51
  • Hmm. Thanks. I thought so. As it happens, merely putting in \input{programmes.def} into the group of option declarations allows an external file to be read. Half way to the goal :) Commented May 7, 2016 at 19:52
  • @Alan Yes, if you are happy of having the .def file with the format \DeclareOption{<option>}{<code>} Commented May 7, 2016 at 19:54
  • It will do until I can find a longer term solution. Thank you for helping to clarify the issues. Commented May 7, 2016 at 19:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.