summaryrefslogtreecommitdiff
path: root/docs/data_spec.tex
blob: 82494c9b7a69b761f16e90b8554e56676bb4f9f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
% Created 2024-03-23 Sat 16:01
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry}
\date{2024 February 24}
\title{7Units Datafile Specification\\\medskip
\large For Version 0.5.0}
\hypersetup{
 pdfauthor={},
 pdftitle={7Units Datafile Specification},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 29.2 (Org mode 9.6.15)}, 
 pdflang={English}}
\begin{document}

\maketitle
\tableofcontents

\newpage
\section{Unit and Prefix Files}
\label{sec:org12eca56}
Unit and prefix files specify the units and prefixes that are available to 7Units.  Their format is intended to be compatible with 7Units's inspiration, \href{https://www.gnu.org/software/units/}{GNU Units}.

Each unit or prefix is specified by a line in the following format:
\begin{verbatim}
<name><one or more whitespace><definition>
\end{verbatim}

The name may not contain whitespace, but the definition can and often will.  Lines can be separated by either a line feed (0x0A) or a carriage return followed by a line feed (0x0D 0x0A).
\subsection{Ignored Lines \& Comments}
\label{sec:org2f8286a}
All of the following should be ignored:
\begin{itemize}
\item Any line containing only whitespace
\item Any trailing whitespace
\item Any characters between a \texttt{\#} (0x23) character and the end of the line.
\end{itemize}

This allows unit and prefix files to be easily organized and divided.
\subsection{Unit Expressions}
\label{sec:orga5cb10a}
The definition part of a unit's line is a unit expression - the same sort of expression you would use in the complex unit converter.

Expressions should be a standard mathematical expression, which can operate on either numbers or units.  The following operators are supported: addition (+), subtraction (-), multiplication (\texttt{*} or no operator), division (\texttt{/} or \texttt{|}), exponentation (\texttt{\textasciicircum{}}; exponent must be a number).  Brackets (\texttt{(} and \texttt{)}) may be used to change order of operations, but otherwise standard BEDMAS order is followed (exponentation first, then multiplication and division, then addition and subtraction), with two exceptions: if a number is multiplied by a unit using spaces, the multiplication will have precedence over division, and division with \texttt{|} has higher precedence than any other operator.  For example, "2 m / 1 m" is equal to the dimensionless value 2, not 2 m\textsuperscript{2}.  An example of a line defining a unit is:
\begin{verbatim}
yard	9 dm + 1.4 cm + 4 mm^2 / 10 mm
\end{verbatim}

If the definition is an exclamation mark (\texttt{!}), this defines a base unit, which is expected to already be stored in the system.
\subsection{Prefixes \& Prefix Expressions}
\label{sec:orgac34dfb}
If a line's name part ends in the ASCII dash (\texttt{-}, 0x2D), it defines a prefix instead of a unit (this dash is not included in the prefix's name).  Prefix expressions are like unit expressions, but the operands are prefixes and numbers, not units and numbers.  Because prefixes do not have a dimension, there are no base prefixes - the exclamation mark is forbidden in prefix expressions.
\section{Dimension Files}
\label{sec:orgb96440f}
Dimension files give names to unit dimensions, so they can be selected in the unit converter to determine which units are shown.  Dimension files are similar to unit and prefix files, except that they use a different set of base \emph{dimensions} (defined with ! as usual), and that addition and subtraction are not supported in dimension expressions.
\section{Metric Exception Files}
\label{sec:org727336c}
Metric exception files list exceptions to the One-Way Conversion rule.  Units included in these files are always shown on both sides of the unit converter, even if One Way Conversion is enabled.  They are just a list of units, one per line.  Ignored lines and comments work the same way as in other data files.
\section{Configuration Files}
\label{sec:orge440794}
A configuration file contains one line for each configuration setting, in the format \texttt{key=value}.  Check the user manual for the list of configurable setting keys.  Ignored lines and comments work the same way as in other data files.
\end{document}