| 1 |
\documentclass[a4paper]{ltxdoc} |
| 2 |
\usepackage{globalvals} |
| 3 |
\usepackage{siunitx} |
| 4 |
|
| 5 |
\begin{document} |
| 6 |
\title{\textsf{globalvals} -- Resuable variables \\ |
| 7 |
for use in large projects} |
| 8 |
\author{Charles Baynham} |
| 9 |
\date{2019/02/06 (v\,1.1)} |
| 10 |
\MaintainedBy{% |
| 11 |
This file is maintained by Charles Baynham.\\% |
| 12 |
Bug reports can be opened at\\% |
| 13 |
\url{https://github.com/charlesbaynham/globalvals}. |
| 14 |
} |
| 15 |
\maketitle |
| 16 |
|
| 17 |
\noindent |
| 18 |
The \textsf{globalvals} package allow the user to declare a variable which can then be used anywhere else in a document, including before it was declared. This can be useful in large projects, where value can be entered once and automatically updated throughout the document, without having to maintain a seperate file full of definitions. |
| 19 |
|
| 20 |
This is done by putting the definitions into the .aux files, therefore requiring two runs to get it right. |
| 21 |
|
| 22 |
It implements two commands: |\defVal{|\meta{key}|}{|\meta{value}|}| and |\useVal{<key>}|. |\defVal| |
| 23 |
sets up a global variable and |\useVal| recalls it. |
| 24 |
|
| 25 |
Using |\defVal| twice with the same \meta{key} will result in an error. Using |\useVal| for an undefined |
| 26 |
value will output the text ``\textsc{??}''. |
| 27 |
|
| 28 |
\section{Defining a value} |
| 29 |
\label{sec:defining} |
| 30 |
|
| 31 |
\DescribeMacro{\defVal} |
| 32 |
% |
| 33 |
Defining a macro can be done using the command |
| 34 |
\begin{quote} |
| 35 |
|\defVal{|\meta{key}|}{|\meta{value}|}| |
| 36 |
\end{quote} |
| 37 |
|
| 38 |
For example, you might call |
| 39 |
\begin{quote} |
| 40 |
|\defVal{software_version}{v1.65}| |
| 41 |
\end{quote} |
| 42 |
\defVal{software_version}{v1.65} |
| 43 |
|
| 44 |
\meta{value}s will be expanded, so you can also embed macros within your variables, e.g.: |
| 45 |
\begin{quote} |
| 46 |
|\defVal{fractional_stability}{\SI{10E-16}{\per\sqrt\second}}| |
| 47 |
\end{quote} |
| 48 |
\defVal{fractional_stability}{\SI{10E-16}{\per\sqrt\second}} |
| 49 |
|
| 50 |
\section{Using a variable} |
| 51 |
|
| 52 |
\DescribeMacro{\useVal} |
| 53 |
To use a defined variable, use the command |
| 54 |
\begin{quote} |
| 55 |
|\useVar{|\meta{key}|}| |
| 56 |
\end{quote} |
| 57 |
|
| 58 |
For instance, the values saved in section \ref{sec:defining} could be recalled using |
| 59 |
\begin{quote} |
| 60 |
|\useVal{software_version}| |
| 61 |
\end{quote} |
| 62 |
and |
| 63 |
\begin{quote} |
| 64 |
|\useVal{fractional_stability}| |
| 65 |
\end{quote} |
| 66 |
% |
| 67 |
to give ``\useVal{software_version}'' and ``\useVal{fractional_stability}''. |
| 68 |
|
| 69 |
Importantly, values may be used \textbf{before they are defined}. This is handy if you e.g.\ would like to refer to a quantity in your abstract but it's most sensible defined in a later chapter. Like so: |
| 70 |
\begin{quote} |
| 71 |
|The clock's fractional accuracy is estimated as| \\ |
| 72 |
|\useVal{an_important_quantity}.| \\ |
| 73 |
... \\ |
| 74 |
|\defVal{an_important_quantity}{\num{1E-18}}| |
| 75 |
\end{quote} |
| 76 |
to give |
| 77 |
\begin{quote} |
| 78 |
The clock's fractional accuracy is estimated as |
| 79 |
\useVal{an_important_quantity}. |
| 80 |
\defVal{an_important_quantity}{\num{1E-18}} |
| 81 |
\end{quote} |
| 82 |
|
| 83 |
\end{document} |