I'm writing an invoice class and I want to keep the actual tex
file as clean as possible, so that the code does not scare off the non-techies.
My ultimative goal would be to define a variable in the invoice.cls
file and later set a value to it by a very simple and clean command in the main.tex
. Something like \address{Street, Number}{ZIP Code Town}{Country}
and \name{First name}{Last name}
and \bankDetails{IBAN number}{Bank Swift Code}
Keep in mind, that I have to use the values of these variables in the invoice.cls
file.
At the moment I defined a newcommand in the class file and gave it some optional arguments. By calling the command and passing the arguments I had a code like the one above. The thing is, that I need to access the name variable at multiple places and I don't want that the end user has to enter his name several times as arguments… It would be nice to define these variables globally and access them whenever I need them.
Like with
\newcommand{\firstName}{John}
\newcommand{\lastName}{Doe}
\newcommand{\name}{\firstName\,\lastName}
But you'll understand that
\name{John}{Doe}
would be much cleaner.
Best Answer
I am a great fan of
expl3
and itsproperty
'variable' feature, i.e. akey
- based storage of data. As long as the amount of keys is not too largeprop
lists are very convenient.A key might be
FirstName
orZip
.The macro
\StoreInvoiceData
stores the keys given asFirstName=foo
,IBAN=US345342342
etc into the relevantkey
slot of the property list, named\g_sam_invoice_prop
here. The key-value-interface of the macro must not be confused with thekeys
of the property list, although the storage mechanism in the background is identical. Thekey=
name is the same as the property key name, this is not mandatory but convenient in order to remember the names.The order of specification does not matter at all.
Use
\GetInvoiceData{foo}
for example in order to extract the value of thefoo
key.Version for checking whether a key is given