summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-05-08 21:08:12 +0000
committerKarl Berry <karl@freefriends.org>2021-05-08 21:08:12 +0000
commit133820dd1b17c0bf8eff446e5d93ba14366ed518 (patch)
treead74a90711712592d5a7433272fed9800f3a0fa8
parent514e219a0e98fc0ed5910a7a9473ea716307a637 (diff)
lua-physical (8may21)
git-svn-id: svn://tug.org/texlive/trunk@59138 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/lualatex/lua-physical/LICENSE2
-rw-r--r--Master/texmf-dist/doc/lualatex/lua-physical/README.md4
-rw-r--r--Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdfbin303528 -> 317820 bytes
-rw-r--r--Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex574
-rw-r--r--Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdfbin0 -> 52565 bytes
-rw-r--r--Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex138
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua2
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-data.lua2
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-definition.lua8
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-dimension.lua2
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-number.lua52
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-quantity.lua14
-rw-r--r--Master/texmf-dist/scripts/lua-physical/physical-unit.lua2
-rwxr-xr-xMaster/texmf-dist/scripts/lua-physical/physical.lua4
14 files changed, 644 insertions, 160 deletions
diff --git a/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE b/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE
index 408f06f14d2..8e40f98ea6b 100644
--- a/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE
+++ b/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Master/texmf-dist/doc/lualatex/lua-physical/README.md b/Master/texmf-dist/doc/lualatex/lua-physical/README.md
index 830574a5da8..6959ba2d395 100644
--- a/Master/texmf-dist/doc/lualatex/lua-physical/README.md
+++ b/Master/texmf-dist/doc/lualatex/lua-physical/README.md
@@ -2,9 +2,9 @@
Author: Thomas Jenni
-Version: 1.0.3
+Version: 1.0.5
-Date: 2020-09-09
+Date: 2021-05-08
License: MIT
diff --git a/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdf b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdf
index 577bf24f05d..ea5221c92b9 100644
--- a/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdf
+++ b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex
index 331a17d23e5..0402419df8a 100644
--- a/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex
+++ b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex
@@ -42,7 +42,7 @@
% lua code and lua-physical command definitions
\begin{luacode}
-physical = require("physical")
+physical = require('src.physicalx')
N = physical.Number
Q = physical.Quantity
\end{luacode}
@@ -70,8 +70,12 @@ Q = physical.Quantity
round-mode=off
}
+\DeclareSIUnit\unitless{}
+
\DeclareSIUnit\fahrenheit{\ensuremath{{}^{\circ}}F}
+\DeclareSIUnit\inch{in}
+
% config listings
\lstdefinelanguage{lua}
{
@@ -152,14 +156,14 @@ Q = physical.Quantity
\lstset{language=[LaTex]Tex}
-\title{The \textsc{lua-physical} library \\\ \\\normalsize Version 1.0.3}
+\title{The \textsc{lua-physical} library \\\ \\\normalsize Version 1.0.5}
\author{Thomas Jenni}
\date{\today}
\maketitle
\begin{abstract}
-\noindent |lua-physical| is a pure Lua library, which provides functions and objects for the computation of physical quantities. A physical quantity is the product of a numerical value and a physical unit. The package has been written, to simplify the creation physics problem sets. The package provides units of the SI and the imperial system. Furthermore, an almost complete set of international currencies are supported, however without realtime exchange rates. In order to display the numbers with measurement uncertainties, the package is able to perform gaussian error propagation.
+\noindent |lua-physical| is a pure Lua library, which provides functions and objects for the computation of physical quantities. The package has been written, to simplify the creation physics problem sets. The package provides units of the SI and the imperial system. In order to display the numbers with measurement uncertainties, the package is able to perform gaussian error propagation.
\end{abstract}
@@ -170,27 +174,33 @@ Q = physical.Quantity
\newpage
\section{Introduction}
-The author of this package is a physics teacher at the high school \emph{Kantonsschule Zug}, Switzerland. The main use of this package is to write physics problem sets. \LuaLaTeX{} does make it possible to integrate physical calculations directly. The package has been in use since 2016. Many bugs have been found and fixed. Nevertheless it still is possible, that some were not found yet. Therefore the author recommends not to use this package in industry or science. If one does so, it's the responsability of the user to check results for plausability. If the user finds some bugs, they can be reported at github.com.
+The author of this package is a physics teacher at the high school \emph{Kantonsschule Zug}, Switzerland. The main use of this package is to write physics problem sets. It is possible to integrate physical calculations directly into \LuaLaTeX{}. The package has been in use since 2016. Many bugs have been found and fixed. Nevertheless it still is possible, that some were not found yet. Therefore the author recommends not to use this package in industry or science. If one does so, it's the responsability of the user to check results for plausability. If the user finds some bugs, they can be reported at github.com.
\subsection{Dependencies}
-In principle this library is standalone, but it is compatible with the |siunitx| package. Calculation results can be written to \LuaLaTeX{} directly by calling the |tosiunitx()| method. If the preamble in the next section is used, the printing is done by the |\q{}| macro.
+This is a standalone library. However, it is compatible with the |siunitx| package. The results of calculations can be printed to \LuaLaTeX{} by calling the |physical.Quantity.tosiunitx()| method. It is recommended to use a macro for this purpose. The preamble in the next section, simplifies the printing of quantities by the macros |\q{}|, |\qs{}| and |\qu{}|.
\section{Loading}
-This package is a pure Lua library. Therefore one has to require it explicitly by calling |require("physical")|. For printing physical quanties, the |siunitx| is supported. It's recommended to define a macro like |\q| to convert the lua quantity object to a |siunitx| expression.
+By calling |require("physical")| the |lua-physical| library is loaded. The following \LuaLaTeX{} preamble loads the |lua-physical| package, does some configuration of the |siunitx| package and defines the macros |\q{}|, |\qs{}| and |\qu{}| for printing physical quantities.
-The following \LaTeX{} preamble loads the |lua-physical| package and creates a macro |\q| for printing physical quantities.
\nopagebreak
+
\begin{lstlisting}[language=Tex, caption=basic preamble, label=lst:basic preamble]
\usepackage{luacode}
\usepackage{siunitx}
-% configure siunitx
+% initialize the lua-physical package
+\begin{luacode*}
+ physical = require("physical")
+ N = physical.Number
+\end{luacode*}
+
+% configure the siunitx package
\sisetup{
output-decimal-marker = {.},
per-mode = symbol,
@@ -200,15 +210,10 @@ The following \LaTeX{} preamble loads the |lua-physical| package and creates a m
round-mode = off
}
-% load the lua-physical package
-\begin{luacode*}
- physical = require("physical")
- N = physical.Number
-\end{luacode*}
-
-
+% declare the unitless unit (siunitx package)
+\DeclareSIUnit\unitless{}
-% print a physical quantity
+% print a quantity using the \SI{}{} macro.
\newcommand{\q}[1]{%
\directlua{
tex.print(
@@ -219,9 +224,36 @@ The following \LaTeX{} preamble loads the |lua-physical| package and creates a m
)
}%
}
-\end{lstlisting}
+% print a quantity in scientific notation using \SI{}{} macro.
+\newcommand{\qs}[1]{%
+ \directlua{
+ tex.print(
+ physical.Quantity.tosiunitx(
+ #1,
+ "scientific-notation=true,exponent-to-prefix=false,
+ round-integer-to-decimal=true"
+ )
+ )
+ }%
+}
+
+% print the unit of a quantity using the \si{} macro
+\newcommand{\qu}[1]{%
+ \directlua{
+ tex.print(
+ physical.Quantity.tosiunitx(
+ #1,
+ nil,
+ physical.Quantity.SIUNITX_si
+ )
+ )
+ }%
+}
+
+\end{lstlisting}
+\pagebreak
\subsection{License}
This code is freely distributable under the terms of the MIT license.\\
@@ -241,19 +273,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
\label{ch:usage}
%------------------------------------------------------------
-Given the basic preamble, units can be used in lua code directly. By convention, all units have an underscore in front of them, i.e.\ meter is |_m|, second is |_s|. All available units are listed in section~\ref{ch:Supported Units}. The following example illustrates the use of this library.
+Given the basic preamble~\ref{lst:basic preamble}, units can be used in lua code directly. By convention, all units have an underscore in front of them, i.e.\ meter is |_m|, second is |_s|. For a complete list of all available units, see section~\ref{ch:Supported Units}. The following example illustrates the use of this library.
\begin{lstlisting}[caption=Velocity of a car.,label=lst:Car Velocity]
\begin{luacode}
- s = 10 * _m
+ d = 10 * _m
t = 2 * _s
- v = s/t
+ v = d / t
\end{luacode}
-A car travels $\q{s}$ in $\q{t}$. calculate its velocity.
+A car travels $\q{d}$ in $\q{t}$. Calculate its velocity.
%
\begin{equation*}
- v=\frac{s}{t} = \frac{\q{s}}{\q{t}} = \underline{\q{v}}
+ v=\frac{d}{t} = \frac{\q{d}}{\q{t}} = \underline{\q{v}}
\end{equation*}
\end{lstlisting}
@@ -261,7 +293,7 @@ A car travels $\q{s}$ in $\q{t}$. calculate its velocity.
s = 10 * _m
t = 2 * _s
- v = s/t
+ v = s / t
\end{luacode}
\leftbar
@@ -272,7 +304,14 @@ A car travels $\q{s}$ in $\q{t}$. Calculate its velocity.
\end{equation*}
\endleftbar
-In the above listing~\ref{lst:Car Velocity}, the variable |s| stands for displacement and has the unit meter |_m|, the variable |t| stands for time and is given in seconds |_s|. If mathematical operations are done on them, new physical quantities are created. In the problem above, the velocity |v| is calculated by dividing |s| by |t|. The instance |v| has the derived unit \si{\m\per\s}. By using the macro |\q{}| all quantities can be printed to the \LuaLaTeX{} code directly.
+
+
+
+
+
+
+
+In the above listing~\ref{lst:Car Velocity}, the variable |s| stands for displacement and has the unit meter |_m|, the variable |t| stands for time and is given in seconds |_s|. If physical quantities are divided or multiplied, derived quantities are created. In the example problem above, the velocity |v| has the unit |_m/_s|. By using the macro |\q{}| all quantities can be printed to the \LuaLaTeX{} code directly.
@@ -280,9 +319,41 @@ In the above listing~\ref{lst:Car Velocity}, the variable |s| stands for displac
%------------------------------------------------------------
\subsection{Unit conversion}
-Very often, the result of a calculation has to be converted to another unit. In listing~\ref{lst:Volume of Cuboid} the task is to calculate the volume of a cuboid. The length of the edges are given in different units. The volume is calculated by multipling all three lengths, the unit of the result is \si{\cm\mm\m}. If the unit \si{\cm\cubed} is preferred, it has to be converted explicitly. The conversion function is called |to()| and is available on all physical quantitiy instances. At first this looks a bit cumbersome. The reason of this behaviour is, that the software is not able to guess the unit of the result. In many cases, like in the example here, it's not clear what unit the result sould have. Therefore the user has always to give the target unit explicitly.
+It is often the case, that the result of a calculation has to be converted to other units. Lets assume, that in the problem of listing~\ref{lst:Car Velocity}, the velocity should be determined in |_km/_h|. This can be done using the |:to()| method, which is available on all quantity objects, see ~\ref{lst:Car Velocity2}.
+
+
+\begin{lstlisting}[caption=Velocity of a car in kilometers per hour.,label=lst:Car Velocity2]
+\begin{luacode}
+ d = 10 * _m
+ t = 2 * _s
+ v = (s / t):to(_km/_h)
+\end{luacode}
+
+A car travels $\q{d}$ in $\q{t}$. Calculate its velocity in $\qu{_km/_h}$.
+%
+\begin{equation*}
+ v = \frac{d}{t} = \frac{\q{d}}{\q{t}} = \underline{\q{v}}
+\end{equation*}
+\end{lstlisting}
+
+
+\begin{luacode}
+ d = 10 * _m
+ t = 2 * _s
+
+ v = (d / t):to(_km/_h)
+\end{luacode}
+
+\leftbar
+A car travels $\q{d}$ in $\q{t}$. Calculate its velocity in $\qu{_km/_h}$.
+%
+\begin{equation*}
+ v = \frac{d}{t} = \frac{\q{d}}{\q{t}} = \underline{\q{v}}
+\end{equation*}
+\endleftbar
+
+Another example is given in listing~\ref{lst:Volume of Cuboid}. The task is to calculate the volume of a cuboid. The length of the edges are given in different units. The result of the multiplication has the unit \si{\cm\mm\m}. If the unit \si{\cm\cubed} is preferred, it has to be converted explicitly. At first this looks a bit cumbersome. The reason of this behaviour is, that the software is not able to guess the unit of the result. In many cases, like in the example problem, it's not clear what unit the volume should have. Is it |_m^3|, |_cm^3| or |_L|? The user has to give that convertion explicitly.
-\pagebreak
\begin{lstlisting}[caption=Volume of a cuboid.,label=lst:Volume of Cuboid]
\begin{luacode}
@@ -290,7 +361,7 @@ Very often, the result of a calculation has to be converted to another unit. In
b = 150 * _mm
c = 1.5 * _m
- V = a*b*c
+ V = ( a * b * c ):to(_dm^3)
\end{luacode}
Find the volume of a rectangular cuboid with lengths $\q{a}$,
@@ -299,8 +370,7 @@ $\q{b}$ and $\q{c}$.
\begin{equation*}
V= a \cdot b \cdot c
= \q{a} \cdot \q{b} \cdot \q{c}
- = \q{V}
- = \underline{\q{V:to(_dm^3)}}
+ = \underline{\q{V}}
\end{equation*}
\end{lstlisting}
@@ -309,7 +379,7 @@ $\q{b}$ and $\q{c}$.
b = 150 * _mm
c = 1.5 * _m
- V = a*b*c
+ V = ( a * b * c ):to(_dm^3)
\end{luacode}
\leftbar
@@ -319,17 +389,53 @@ Find the volume of a rectangular cuboid with lengths $\q{a}$, $\q{b}$ and $\q{c}
V= a \cdot b \cdot c
= \q{a} \cdot \q{b} \cdot \q{c}
= \q{V}
- = \underline{\q{V:to(_dm^3)}}
+ = \underline{\q{V}}
\end{equation*}
\endleftbar
+The |siunitx| package has definitions or all SI units plus some non-SI units. If a quantity has a unit, which is not defined by the |siunitx| package, it has to be declared using the |\DeclareSIUnit| macro.
+
+\begin{lstlisting}[caption=Non-SI units.,label=lst:Non-SI units]
+% add this declaration to the preamble
+\DeclareSIUnit\inch{in}
+
+
+% document
+\begin{luacode}
+ l = 12 * _in
+\end{luacode}
+
+Convert $\q{l}$ to the unit $\qu{_cm}$.
+%
+\begin{equation*}
+ l = \q{l} \cdot \frac{\q{_in:to(_cm)}}{\qu{_in}} = \q{l:to(_cm)}
+\end{equation*}
+\end{lstlisting}
+
+\begin{luacode}
+ l = 12 * _in
+\end{luacode}
+
+\leftbar
+Convert $\q{l}$ (inches) to the unit $\qu{_cm}$.
+%
+\begin{equation*}
+ l = \q{l} \cdot \frac{\q{_in:to(_cm)}}{\qu{_in}} = \underline{ \q{l:to(_cm)} }
+\end{equation*}
+\endleftbar
+
+
+
+
+
+
%------------------------------------------------------------
\subsubsection{Temperature Conversion}
-Most physical units transform linearly. Exceptions are the unit degree Celsius |_degC| and degree Fahrenheit |_degF|. These units are ambigous and can be interpreted as temperature differences or as an absolute temperatures. In the latter case, the conversion to base units is not a linear, but an affine transformation. This is because degree Celsius and degree Fahrenheit scales have their zero points at different temperatures compared to the unit Kelvin.
+Most physical units transform linearly. Exceptions are temperature units lie degree Celsius |_degC| and degree Fahrenheit |_degF|. These units are ambigous and can be interpreted as temperature differences or as an absolute temperatures. In the latter case, the conversion to base units is not a linear, but an affine transformation. This is because degree Celsius and degree Fahrenheit scales have their zero points at different temperatures compared to the unit Kelvin.
By default |_degC| and |_degF| units are temperature differences. If one wants to have it converted absolutely, it has to be done adding / subtracting |_degC_0 = 273.15*_K| or |_degF_0 = (273.15 - 32*(5/9)) * _K|,
the zero point temperatures of the scales.
@@ -402,61 +508,61 @@ In the following problem, listing~\ref{lst:temperature conversion}, the task is
+
+
+
%------------------------------------------------------------
\subsection{Uncertainty Propagation}
-The package supports uncertainty propagation. To create a number with an uncertainty, an instance of |physical.Number| has to be created, see listing~\ref{lst:rectangular area}. It has to be remembered, that |N| is a alias for |physical.Number|. The first argument of the constructor |N(mean, uncertainty)| is the mean value and the second one the uncertainty of the measurement. If the proposed preamble \ref{lst:basic preamble} is used, the uncertainty is by default seperated from the mean value by a plus-minus sign.
+The |lua-physical| library supports uncertainty propagation. To create a number with an uncertainty, an instance of |physical.Number| has to be created. It has to be remembered, that |N| is a alias for |physical.Number|. The first argument of the constructor |N(mean, uncertainty)| is the mean value and the second one the uncertainty of the measurement.
For the uncertainty propagation the gaussian formula
\begin{equation*}
\Delta f = \sqrt{ \left(\frac{\partial f}{x_1} \cdot \Delta x_1\right)^2 + \dots + \left(\frac{\partial f}{x_n} \cdot \Delta x_2 \right)^2 }
\end{equation*}
-is used. This formula is a good estimation for the uncertainty $\Delta f$, if the quantities $x_1, \dots, x_n$ the function $f$ depends on, have no correlation. Further, the function $f$ has to change linear, if quantities $x_i$ are changed in the range of their uncertainties.
+is used. This formula is a good estimation for the uncertainty $\Delta f$, if the quantities $x_1, \dots, x_n$ the function $f$ depends on, have no correlation. Further, the function $f$ has to change linearly, if quantities $x_i$ are changed in the range of their uncertainties.
+The example in listing~\ref{lst:Time of flight} shows the usage of |N()|. At the defintion of the distance and the speed of light, the constants are given with full precision, i.e. The distance |_au| is $\q{_au:to(_km)}$ and |_c| is $\q{_c:to(_km/_s)}$. By multipling these quantities with $|N(1,0.0001)|$ the precision is reduced. The uncertainty propagation takes care of rounding the resulting time |t| to the correct precision. For printing, the macro |\qs{}| for scientific notation is used.
-\begin{lstlisting}[caption=Uncertainty in area calculation.,label=lst:rectangular area]
-\begin{luacode}
- a = N(2,0.1) * _m
- b = N(3,0.1) * _m
+\begin{lstlisting}[caption=Time of flight.,label=lst:Time of flight]
- A = (a*b):to(_m^2)
+\begin{luacode}
+ d = N(1,0.0001) * ( _au ):to(_km)
+ v = N(1,0.0001) * ( _c ):to(_km/_s)
+ t = ( d/v ):to(_min)
\end{luacode}
-Calculate the area of a rectangle with lengths $\q{a}$ and $\q{b}$.
+Calculate the time, a lightray travels from the surface of the sun to the earth.
+The mean distance from the sun to the eart is $\qs{d}$. The speed of light is $\qs{v}$.
%
\begin{equation*}
- A = a \cdot b
- = \q{a} \cdot \q{b}
- = \underline{\q{A}}
+ t = \frac{d}{v} = \frac{\q{d}}{\q{v}} = \underline{\q{t}}
\end{equation*}
\end{lstlisting}
\begin{luacode}
- a = N(2,0.1) * _m
- b = N(3,0.1) * _m
-
- A = (a*b):to(_m^2)
+ N.omitUncertainty = true
+ d = N(1,0.0001) * ( _au ):to(_km)
+ v = N(1,0.0001) * ( _c ):to(_km/_s)
+ t = ( d/v ):to(_min)
\end{luacode}
\leftbar
-Calculate the area of a rectangle with lengths $\q{a}$ and $\q{b}$.
+Calculate the time, a lightray travels from the surface of the sun to the earth.
+The mean distance from the sun to the eart is $\qs{d}$. The speed of light is $\qs{v}$.
%
\begin{equation*}
- A = a \cdot b
- = \q{a} \cdot \q{b}
- = \underline{\q{A}}
+ t = \frac{d}{v} = \frac{\qs{d}}{\qs{v}} = \underline{\q{t}}
\end{equation*}
\endleftbar
-
-Instead of printing the uncertainties, one can use the uncertainty calculation to provide significant digits and omit it.
-
-In the following problem, listing~\ref{lst:volume of ideal gas}, the task is to find the volume of an ideal gas. Given are pressure |p| in |_bar|, amount of substance |n| in |_mol| and temperature |T| in degree celsius |_degC|. In order to do the calculation, one has to convert |T|, which is given as an absolute temperature in degree celsius to the base unit Kelvin first. By setting |N.omitUncertainty = true|, all uncertainties are not printed.
+Another example is given in listing~\ref{lst:volume of ideal gas}, the task is to find the volume of an ideal gas. Given are pressure |p| in |_bar|, amount of substance |n| in |_mol| and absolute temperature |T| in degree celsius |_degC|.
\begin{lstlisting}[caption=Volume of an ideal gas.,label=lst:volume of ideal gas]
\begin{luacode}
N.omitUncertainty = true
+
p = N(1.013,0.0001) * _bar
n = N(1,0.01) * _mol
T = N(30,0.1) * _degC
@@ -476,6 +582,7 @@ An ideal gas ($\q{n}$) has a pressure of $\q{p}$ and a temperature of $\q{T}$. C
\begin{luacode}
N.omitUncertainty = true
+
p = N(1.013,0.0001) * _bar
n = N(1,0.01) * _mol
T = N(30,0.1) * _degC
@@ -492,7 +599,51 @@ An ideal gas ($\q{n}$) has a pressure of $\q{p}$ and a temperature of $\q{T}$. C
\end{equation*}
\endleftbar
-This example shows, that the result has only two digits. If more digits are needed, the uncertainties of the given quantities should be smaller.
+This example shows, that the result has only two digits. If more digits are needed, the uncertainties of the given quantities should be made smaller.
+
+
+
+%------------------------------------------------------------
+\subsubsection{Print the Uncertainty explicitly}
+
+It is possible to print the uncertainty explicitly. By default the parameter |N.omitUncertainty| is set to |true|. In listing~\ref{lst:rectangular area} it is set to |false| and the uncertainty is printed.
+
+
+\begin{lstlisting}[caption=Uncertainty in area calculation.,label=lst:rectangular area]
+\begin{luacode}
+ N.omitUncertainty = false
+
+ a = N(2,0.1) * _m
+ b = N(3,0.1) * _m
+
+ A = ( a * b ):to(_m^2)
+\end{luacode}
+
+Calculate the area of a rectangle with lengths $\q{a}$ and $\q{b}$.
+%
+\begin{equation*}
+ A = a \cdot b
+ = \q{a} \cdot \q{b}
+ = \underline{\q{A}}
+\end{equation*}
+\end{lstlisting}
+
+\begin{luacode}
+ N.omitUncertainty = false
+
+ a = N(2,0.1) * _m
+ b = N(3,0.1) * _m
+
+ A = ( a * b ):to(_m^2)
+\end{luacode}
+
+Calculate the area of a rectangle with lengths $\q{a}$ and $\q{b}$.
+%
+\begin{equation*}
+ A = a \cdot b
+ = \q{a} \cdot \q{b}
+ = \underline{\q{A}}
+\end{equation*}
@@ -561,10 +712,6 @@ N_0 * Q.exp(-lambda * t)
-
-
-
-
%------------------------------------------------------------
\newpage
\section{Supported Units}
@@ -681,6 +828,12 @@ yobi & |Yi| & |1208925819614629174706176| \\
+
+
+
+
+
+
%------------------------------------------------------------
\subsection{Base Units}
\label{ch:base units}
@@ -700,7 +853,7 @@ The |lua-physical| library has nine base quantities. These are the seven basis u
\thead{Quantity} & \thead{Unit} & \thead{Symbol} & \thead{Dim.} & \thead{Definition} \\\hline
number \protect\footnotemark &
--- &
+unitless &
|_1| &
$\mathrm{1}$ &
The dimensionless number one. \\
@@ -723,7 +876,7 @@ The SI unit of length. It is defined by taking the fixed numercial value of the
\end{table}
\footnotetext[1]{
- The number one is a unit with dimension zero. Stricly speaking it is not a base unit.
+ The number one is a unit with dimension zero. It is not a base unit stricty speaking.
}
@@ -795,6 +948,55 @@ The value of the currency Euro. \\\hline
+% lua function for printing dimension names.
+\begin{luacode}
+function getdim(q)
+ local str = q.dimension:__tostring()
+
+ str = string.gsub(str,"%[","")
+ str = string.gsub(str,"%]","")
+
+ return str
+end
+
+function strtoidx(str)
+ local s,n = string.gsub(str,"%_","\\_")
+ return s
+end
+\end{luacode}
+
+% print unit table
+\newcommand{\unittable}[1]{
+ \begin{table}[H]
+ \centering
+ \begin{tabularx}{\linewidth}{%
+ >{\setlength\hsize{1\hsize}}X%
+ l%
+ l%
+ >{\setlength\hsize{1\hsize}}X%
+ }
+ \thead{Quantity} & \thead{Unit} & \thead{Symbol} & \thead{Definition} \\\hline
+
+ #1
+
+ \hline
+ \end{tabularx}
+ \end{table}
+}
+
+% print unit table row
+\newcommand{\printunit}[3][]{
+ \ifthenelse{\equal{#1}{}}{
+ \directlua{tex.print(getdim(#2))}
+ }{
+ #1
+ } &
+ \directlua{tex.print(#2.unit.name)} &
+ |#2| &
+ \mbox{|#3|}\index[unit]{\directlua{tex.print(#2.unit.name)} \texttt{\directlua{tex.print( strtoidx("#2") )}}} \\
+}
+
+
%------------------------------------------------------------
\newpage
@@ -807,7 +1009,7 @@ All physical constants are taken from the NIST webpage \cite{nist19}.
\newcommand{\printconstant}[2]{
\directlua{tex.print(#1.unit.name)} &
|#1| &
- \mbox{|#2|}\index[unit]{\directlua{tex.print(#1.unit.name)} \texttt{\directlua{tex.print( strtoidx("#1") )}}}\\
+ \mbox{|#2|}\index[unit]{\directlua{tex.print(#1.unit.name)} \texttt{\directlua{tex.print(strtoidx("#1"))}}}\\
}
\begin{table}[H]
@@ -879,55 +1081,6 @@ All physical constants are taken from the NIST webpage \cite{nist19}.
\label{ch:coherent derived units}
All units in this section are coherent derived units from the SI base units with special names, \cite[118]{bipm06}.
-
-% lua function for printing dimension names.
-\begin{luacode}
-function getdim(q)
- local str = q.dimension:__tostring()
-
- str = string.gsub(str,"%[","")
- str = string.gsub(str,"%]","")
-
- return str
-end
-
-function strtoidx(str)
- local s,n = string.gsub(str,"%_","\\_")
- return s
-end
-\end{luacode}
-
-% print unit table
-\newcommand{\unittable}[1]{
- \begin{table}[H]
- \centering
- \begin{tabularx}{\linewidth}{%
- >{\setlength\hsize{1\hsize}}X%
- l%
- l%
- >{\setlength\hsize{1\hsize}}X%
- }
- \thead{Quantity} & \thead{Unit} & \thead{Symbol} & \thead{Definition} \\\hline
-
- #1
-
- \hline
- \end{tabularx}
- \end{table}
-}
-
-% print unit table row
-\newcommand{\printunit}[3][]{
- \ifthenelse{\equal{#1}{}}{
- \directlua{tex.print(getdim(#2))}
- }{
- #1
- } &
- \directlua{tex.print(#2.unit.name)} &
- |#2| &
- \mbox{|#3|}\index[unit]{\directlua{tex.print(#2.unit.name)} \texttt{\directlua{tex.print( strtoidx("#2") )}}} \\
-}
-
\unittable{
\printunit[Plane Angle\protect\footnotemark]{_rad}{_1}
\printunit[Solid Angle\protect\footnotemark]{_sr}{_rad^2}
@@ -1021,6 +1174,11 @@ The nominal values of solar, terrestrial and jovial quantities are taken from IA
+The mass of the sun is proposed to be used as the astronomical mass unit.
+%\unittable{
+% \printunit[Mass]{_M_S}{N(1.98847e30,0.00007e30) * _kg}
+%}
+
%------------------------------------------------------------
\newpage
@@ -1399,6 +1557,8 @@ International currency which are pegged to other currencies.
% shortcut for method definitions
\newcommand{\method}[2]{\subsection*{|#1.#2|}\index[lua]{\texttt{#1.#2}}}
+\newcommand{\variable}[2]{\subsection*{|#1.#2|}\index[lua]{\texttt{#1.#2}}}
+
\newcommand{\subtitle}[1]{\noindent \\\textbf{#1}}
% set listings language to lua
@@ -2369,11 +2529,109 @@ N.seperateUncertainty = true
N.format = N.DECIMAL
\end{luacode}
-It does arithmetics with gaussian error propagation. A number instance has a mean value called |x| and an uncertainty value called |dx|.
+This class enhances the Lua number with an uncertainty and gaussian error propagation. A number instance has a mean value called |x| and an uncertainty value called |dx|.
+
+
+
+\variable{N}{omitUncertainty=true}
+\begin{quote}
+This variable controls, wether the uncertainty |dx| is printed or not. The default value is |true|, i.e. the uncertainty is omitted.
+\end{quote}
+
+\begin{lstlisting}
+n = N(45,0.012)
+
+N.omitUncertainty = false
+print(n)
+`
+\begin{luacode}
+n = N(45,0.012)
+
+N.omitUncertainty = false
+tex.write(tostring(n))
+\end{luacode}
+`
+
+N.omitUncertainty = true
+print(n)
+`
+\begin{luacode}
+N.omitUncertainty = true
+tex.write(tostring(n))
+\end{luacode}
+`
+\end{lstlisting}
+
+
+\variable{N}{seperateUncertainty=true}
+\begin{quote}
+This variable controls, how the uncertainty is printed. If set to |false|, the parenthesis notation is used. If set to |true| the plus minus notation is used. The default value is |true|.
+\end{quote}
+
+\begin{lstlisting}
+n = N(56,0.025)
+
+N.seperateUncertainty = false
+print(n)
+`
+\begin{luacode}
+n = N(56,0.025)
+
+N.omitUncertainty = false
+N.seperateUncertainty = false
+
+tex.write(tostring(n))
+\end{luacode}
+`
+
+N.seperateUncertainty = true
+print(n)
+`
+\begin{luacode}
+N.seperateUncertainty = true
+tex.write(tostring(n))
+\end{luacode}
+`
+\end{lstlisting}
+
+
+\variable{N}{format=N.SCIENTIFIC}
+\begin{quote}
+This variable controls, how the number is printed. If set to |N.SCIENTIFIC|, scientific notation is used. If set to |N.DECIMAL| the decimal notation is used. The default value is |N.SCIENTIFIC|.
+\end{quote}
+
+\begin{lstlisting}
+n = N(12000000,0.1)
+
+N.format = N.SCIENTIFIC
+print(n)
+`
+\begin{luacode}
+n = N(12000000,0.1)
+
+N.omitUncertainty = true
+
+N.format = N.SCIENTIFIC
+
+tex.write(tostring(n))
+\end{luacode}
+`
+
+N.format = N.DECIMAL
+print(n)
+`
+\begin{luacode}
+N.format = N.DECIMAL
+tex.write(tostring(n))
+\end{luacode}
+`
+\end{lstlisting}
+
+
\method{N}{new(n=nil)}
\begin{quote}
- This is the copy Constructor. It copies a given number object. If |n| is |nil|, an instance representing number zero with uncertainty zero is created.
+ This is the copy Constructor for the |Number| class. It copies a given number object. If |n| is |nil|, an instance representing number zero with uncertainty zero is created.
\begin{description}
\item |n| : |Number|\\
@@ -2477,6 +2735,38 @@ tex.write(tostring(n_4))
\end{quote}
+\method{N}{tosiunitx()}
+\begin{quote}
+ Converts the number to an siunitx string.
+
+ \subtitle{Parameters / Return}
+ \begin{description}
+ \item returns : |string|
+ \end{description}
+
+\begin{lstlisting}
+N.omitUncertainty = false
+N.seperateUncertainty = true
+
+n = N(5.25,0.0045)
+print( n:tosiunitx() )
+`
+\begin{luacode}
+N.omitUncertainty = false
+N.seperateUncertainty = true
+
+n = N(1.25,0.0023)
+tex.write(tostring(n:tosiunitx()))
+
+N.omitUncertainty = true
+N.seperateUncertainty = false
+\end{luacode}
+`
+\end{lstlisting}
+
+\end{quote}
+
+
\method{N}{mean(n)}
\begin{quote}
@@ -2730,11 +3020,11 @@ tex.write(tostring(n:cos()))
\begin{lstlisting}
-n = N(1.5,0.01)
+n = N(1.5,0.001)
print( n:tan() )
`
\begin{luacode}
-n = N(1.5,0.01)
+n = N(1.5,0.001)
tex.write(tostring(n:tan()))
\end{luacode}
`
@@ -2761,11 +3051,11 @@ tex.write(tostring(n:tan()))
\begin{lstlisting}
-n = N(0.99,0.1)
+n = N(0.99,0.001)
print( n:asin() )
`
\begin{luacode}
-n = N(0.99,0.1)
+n = N(0.99,0.001)
tex.write(tostring(n:asin()))
\end{luacode}
`
@@ -2792,11 +3082,11 @@ tex.write(tostring(n:asin()))
\begin{lstlisting}
-n = N(0.99,0.1)
+n = N(0.99,0.001)
print( n:acos() )
`
\begin{luacode}
-n = N(0.99,0.1)
+n = N(0.99,0.001)
tex.write(tostring(n:acos()))
\end{luacode}
`
@@ -2823,11 +3113,11 @@ tex.write(tostring(n:acos()))
\begin{lstlisting}
-n = N(1,0.1)
+n = N(1,0.001)
print( n:atan() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(1,0.001)
tex.write(tostring(n:atan()))
\end{luacode}
`
@@ -2859,11 +3149,11 @@ tex.write(tostring(n:atan()))
\begin{lstlisting}
-n = N(1,0.1)
+n = N(1,0.001)
print( n:sinh() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(1,0.001)
tex.write(tostring(n:sinh()))
\end{luacode}
`
@@ -2895,11 +3185,11 @@ tex.write(tostring(n:sinh()))
\end{align*}
\begin{lstlisting}
-n = N(1,0.1)
+n = N(1,0.001)
print( n:cosh() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(1,0.001)
tex.write(tostring(n:cosh()))
\end{luacode}
`
@@ -2932,11 +3222,11 @@ tex.write(tostring(n:cosh()))
\begin{lstlisting}
-n = N(1,0.1)
+n = N(1,0.001)
print( n:tanh() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(1,0.001)
tex.write(tostring(n:tanh()))
\end{luacode}
`
@@ -2969,11 +3259,11 @@ tex.write(tostring(n:tanh()))
\begin{lstlisting}
-n = N(1,0.1)
+n = N(1,0.001)
print( n:asinh() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(1,0.001)
tex.write(tostring(n:asinh()))
\end{luacode}
`
@@ -3007,11 +3297,11 @@ tex.write(tostring(n:asinh()))
\begin{lstlisting}
-n = N(1,0.1)
+n = N(2,0.001)
print( n:acosh() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(2,0.001)
tex.write(tostring(n:acosh()))
\end{luacode}
`
@@ -3044,11 +3334,11 @@ tex.write(tostring(n:acosh()))
\begin{lstlisting}
-n = N(1,0.1)
+n = N(-0.5,0.0001)
print( n:atanh() )
`
\begin{luacode}
-n = N(1,0.1)
+n = N(-0.5,0.0001)
tex.write(tostring(n:atanh()))
\end{luacode}
`
@@ -3077,13 +3367,22 @@ tex.write(tostring(n:atanh()))
\vspace{1em}
}
+\vhist{V1.0.5}{2021/05/08}{Minor release}{
+ The unitmacro |\textbackslash number| had some collision with other packages. The unitless unit has been renamed from |\textbackslash number| to |\textbackslash unitless|. The declaration in the preamble |\textbackslash DeclareSIUnit\textbackslash number\{\}| has therefore to be replaced with |\textbackslash DeclareSIUnit\textbackslash unitless\{\}|. \\
+ \ \\
+ The parsing of uncertainty values in the package |siunitx| has changed. It was incompatible with the output of |Number.\_\_tostring()|. To mitigate this issue a new method |Number.tosiunitx()| has been added.
+}
+
+\vhist{V1.0.4}{2020/09/15}{Minor release}{
+ Changed default value of |Number.omitUncertainty| and |Number.seperateUncertainty| to |true|. Documentation added.
+}
\vhist{V1.0.3}{2020/09/09}{Minor release}{
Changed foldername |physical| to |src|. Changed Classvariables |Q.siunitx\_SI|, |Q.siunitx\_num| and |Q.siunitx\_si| to uppercase |Q.SIUNITX\_SI|, |Q.SIUNITX\_num| and |Q.SIUNITX\_si|.
}
\vhist{V1.0.2}{2020/09/07}{Minor release}{
- Path issues resolved. Docs corrected.
+ Path issues resolved. Documentation added.
}
\vhist{V1.0.1}{2020/09/05}{Minor release}{
@@ -3119,4 +3418,9 @@ tex.write(tostring(n:atanh()))
\printindex[lua]
+
+
+
+
+
\end{document}
diff --git a/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf
new file mode 100644
index 00000000000..729338946a1
--- /dev/null
+++ b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex
new file mode 100644
index 00000000000..70c729193d5
--- /dev/null
+++ b/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex
@@ -0,0 +1,138 @@
+%!TEX program = lualatex
+
+% Copyright (c) 2021 Thomas Jenni
+
+% Permission is hereby granted, free of charge, to any person obtaining a copy
+% of this software and associated documentation files (the "Software"), to deal
+% in the Software without restriction, including without limitation the rights
+% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+% copies of the Software, and to permit persons to whom the Software is
+% furnished to do so, subject to the following conditions:
+
+% The above copyright notice and this permission notice shall be included in all
+% copies or substantial portions of the Software.
+
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+% SOFTWARE.
+
+\documentclass{article}
+
+\usepackage{luacode}
+\usepackage{siunitx}
+\usepackage{amsmath}
+
+% siunitx config
+\sisetup{
+ output-decimal-marker = {.},
+ per-mode = symbol,
+ separate-uncertainty = false,
+ add-decimal-zero = true,
+ exponent-product = \cdot,
+ round-mode=off
+}
+
+% empty unit
+\DeclareSIUnit\unitless{}
+
+\DeclareSIUnit\inch{in}
+
+% init lua-physical
+\begin{luacode}
+physical = require("physical")
+N = physical.Number
+\end{luacode}
+
+
+\newcommand{\q}[1]{%
+ \directlua{tex.print(physical.Quantity.tosiunitx(#1,"add-decimal-zero=true,scientific-notation=fixed,exponent-to-prefix=false"))}%
+}
+
+\newcommand{\qs}[1]{%
+ \directlua{tex.print(physical.Quantity.tosiunitx(#1,"scientific-notation=true,exponent-to-prefix=false,round-integer-to-decimal=true"))}%
+}
+
+\newcommand{\qt}[1]{%
+ \directlua{tex.print(physical.Quantity.tosiunitx(#1,"scientific-notation=engineering,exponent-to-prefix=true,round-integer-to-decimal=true"))}%
+}
+
+\newcommand{\qn}[1]{%
+ \directlua{tex.print(physical.Quantity.tosiunitx(#1,"add-decimal-zero=true,scientific-notation=fixed,exponent-to-prefix=false",1))}%
+}
+
+\newcommand{\qu}[1]{%
+ \directlua{tex.print(physical.Quantity.tosiunitx(#1,nil,2))}%
+}
+
+
+
+
+
+\begin{document}
+
+\section*{Example for the {\tt lua-physical} package}.
+
+Compile this Lua\LaTeX file with the command `{\tt lualatex lua-physical\_example.tex}'.
+
+
+
+\begin{enumerate}
+
+\begin{luacode}
+a = 12 * _cm
+b = 150 * _mm
+c = 1.5 * _m
+
+V = ( a * b * c ):to(_dm^3)
+\end{luacode}
+
+\item Find the volume of a cuboid with lengths $\q{a}$,
+$\q{b}$ and $\q{c}$.
+%
+\begin{equation*}
+ V= a \cdot b \cdot c
+ = \q{a} \cdot \q{b} \cdot \q{c}
+ = \underline{\q{V}}
+\end{equation*}
+
+
+
+
+
+\begin{luacode}
+l = 12 * _in
+\end{luacode}
+
+\item Convert $\q{l}$ to the unit $\qu{_cm}$.
+%
+\begin{equation*}
+ l = \q{l} \cdot \frac{\q{_in:to(_cm)}}{\qu{_in}} = \q{l:to(_cm)}
+\end{equation*}
+
+
+
+
+
+\begin{luacode}
+N.omitUncertainty = true
+
+d = N(1,0.0001) * ( _au ):to(_km)
+v = N(1,0.0001) * ( _c ):to(_km/_s)
+t = ( d/v ):to(_min)
+\end{luacode}
+
+\item Calculate the time, a lightray travels from the surface of the sun to the earth.
+The mean distance from the sun to the eart is $\qs{d}$. The speed of light is $\q{v}$.
+%
+\begin{equation*}
+ t = \frac{d}{v} = \frac{\qs{d}}{\q{v}} = \underline{\q{t}}
+\end{equation*}
+
+\end{enumerate}
+
+
+\end{document}
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua b/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua
index 48ca5646b86..629832b8790 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua
@@ -1,7 +1,7 @@
--[[
Astronomical data
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-data.lua b/Master/texmf-dist/scripts/lua-physical/physical-data.lua
index efc1a30ffaf..f77eee9f8d9 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-data.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-data.lua
@@ -1,7 +1,7 @@
--[[
This file contains the methods for accessing physical data.
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-definition.lua b/Master/texmf-dist/scripts/lua-physical/physical-definition.lua
index cf1576b4c54..5e0ec79a73c 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-definition.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-definition.lua
@@ -2,7 +2,7 @@
This file contains the definitions for dimensions, prefixes,
SI, Imperial and U.S. Survey units
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -119,7 +119,7 @@ Q.definePrefix("Ki", "kibi", 1024)
local IEC_prefixes = {"Ki","Mi","Gi","Ti","Pi","Ei","Zi","Yi"}
-- define the dimensionless base quantity for real numbers
-Q.define("1", "number", Q(1))
+Q.define("1", "unitless", Q(1))
-- define SI base units
Q.defineBase("m", "meter", L)
@@ -276,6 +276,8 @@ Q.define("t", "tonne", 1e3 * _kg)
-- https://arxiv.org/pdf/1605.09788.pdf
-- https://arxiv.org/pdf/1510.07674.pdf
+Q.define("mag", "magnitude", _1)
+
Q.define("R_S_nom", "nomsolradius", 6.957e8 * _m)
Q.define("S_S_nom", "nomsolirradiance", 1361 * _W/_m^2)
Q.define("L_S_nom", "nomsolluminosity", 3.828e26 * _W)
@@ -290,6 +292,8 @@ Q.define("Re_J_nom", "nomjoveqradius", 7.1492e7 * _m)
Q.define("Rp_J_nom", "nomjovpolradius", 6.6854e7 * _m)
Q.define("GM_J_nom", "nomjovmassparameter", 1.2668653e17 * _m^3*_s^-2)
+Q.define("M_S", "solmass", N(1.98847e30,0.00007e30) * _kg)
+
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua b/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua
index edd9e65997e..03cf315b74d 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua
@@ -3,7 +3,7 @@ The Dimension class keeps track of the dimenionality of a physical quantity.
It can be used to perform validity checks on mathematical operations such as
addition and subtraction.
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-number.lua b/Master/texmf-dist/scripts/lua-physical/physical-number.lua
index 8c278aacfee..bd6a01e4513 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-number.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-number.lua
@@ -2,7 +2,7 @@
This file contains the number class which allows to do
calculations with uncertainties.
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -39,12 +39,12 @@ setmetatable(Number, {
-- allows to set a default uncertainty, i.e. (5.6) will become (5.60 +/- 0.05)
Number.defaultUncertainty = 0.5
--- Switch for writing uncertainty or not
-Number.omitUncertainty = false
+-- Switch for writing the uncertainty or not
+Number.omitUncertainty = true
-- If true, the plus-minus notation will be used, otherwise the uncertainty
-- will be appended to the value in parentheses.
-Number.seperateUncertainty = false
+Number.seperateUncertainty = true
-- number format "decimal" or "scientific"
Number.DECIMAL = 0
@@ -196,12 +196,20 @@ end
-- plus minus notation, i.e. (5.040 +/- 0.001)
-function Number:toPlusMinusNotation(format)
+function Number:toPlusMinusNotation(format, parenthesis, pmsign)
if format == nil then
format = Number.format
end
+ if parenthesis == nil then
+ parenthesis = true
+ end
+
+ if pmsign == nil then
+ pmsign = " +/- "
+ end
+
local m, e = self._frexp(self._x)
local dm, de = self._frexp(self._dx)
@@ -216,13 +224,15 @@ function Number:toPlusMinusNotation(format)
-- In the decimal format, the numbers are given as decimals, i.e. (0.02 +/- 0.001)
if format == Number.DECIMAL then
if de - udigit >= 0 then
- str = self._flt2str(self._x, 0).." +/- "..self._flt2str(self._dx, 0)
+ str = self._flt2str(self._x, 0)..pmsign..self._flt2str(self._dx, 0)
else
local digits = math.abs(-de + udigit)
- str = self._flt2str(self._x, digits).." +/- "..self._flt2str(self._dx, digits)
+ str = self._flt2str(self._x, digits)..pmsign..self._flt2str(self._dx, digits)
end
- str = "("..str..")"
+ if parenthesis then
+ str = "("..str..")"
+ end
-- In the scientific format, the numbers are written with powers of ten, i.e. (2.0 +/- 0.1) e-2
elseif format == Number.SCIENTIFIC then
@@ -232,13 +242,15 @@ function Number:toPlusMinusNotation(format)
de = de - e
if de >= 0 then
- str = self._flt2str(m, 0).." +/- "..self._flt2str(dm, 0)
+ str = self._flt2str(m, 0)..pmsign..self._flt2str(dm, 0)
else
local digits = math.abs(-de + udigit)
- str = self._flt2str(m, digits).." +/- "..self._flt2str(dm, digits)
+ str = self._flt2str(m, digits)..pmsign..self._flt2str(dm, digits)
end
- str = "("..str..")"
+ if parenthesis then
+ str = "("..str..")"
+ end
if e ~= 0 then
str = str.."e"..e
@@ -341,6 +353,24 @@ function Number:__tostring()
end
+-- convert number to a string
+function Number:tosiunitx()
+
+ if self._dx == 0 then
+ return tostring(self._x)
+
+ elseif Number.omitUncertainty then
+ return self:toOmitUncertaintyNotation()
+
+ elseif Number.seperateUncertainty then
+ return self:toPlusMinusNotation(Number.format, false, "+-")
+
+ else
+ return self:toParenthesisNotation()
+ end
+
+end
+
-- equal
-- Two physical numbers are equal if they have the same value and uncertainty
function Number.__eq(n1,n2)
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua b/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua
index d89fdd2836b..875a2ee38d3 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua
@@ -1,7 +1,7 @@
--[[
This file contains the quantity class
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -424,10 +424,18 @@ function Quantity:tosiunitx(param,mode)
end
if mode == Quantity.SIUNITX_SI then
- return "\\SI"..param.."{"..tostring(self.value).."}".."{"..self.unit:tosiunitx().."}"
+ if type(self.value) == "number" then
+ return "\\SI"..param.."{"..tostring(self.value).."}".."{"..self.unit:tosiunitx().."}"
+ else
+ return "\\SI"..param.."{"..self.value:tosiunitx().."}".."{"..self.unit:tosiunitx().."}"
+ end
elseif mode == Quantity.SIUNITX_num then
- return "\\num"..param.."{"..tostring(self.value).."}"
+ if type(self.value) == "number" then
+ return "\\num"..param.."{"..tostring(self.value).."}"
+ else
+ return "\\num"..param.."{"..self.value:tosiunitx().."}"
+ end
elseif mode == Quantity.SIUNITX_si then
return "\\si"..param.."{"..self.unit:tosiunitx().."}"
diff --git a/Master/texmf-dist/scripts/lua-physical/physical-unit.lua b/Master/texmf-dist/scripts/lua-physical/physical-unit.lua
index 65c016449b0..5c20722fe15 100644
--- a/Master/texmf-dist/scripts/lua-physical/physical-unit.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical-unit.lua
@@ -2,7 +2,7 @@
This file contains the unit class. It task is keeping
track of the unit terms.
-Copyright (c) 2020 Thomas Jenni
+Copyright (c) 2021 Thomas Jenni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Master/texmf-dist/scripts/lua-physical/physical.lua b/Master/texmf-dist/scripts/lua-physical/physical.lua
index 8c8d30171b8..69646873576 100755
--- a/Master/texmf-dist/scripts/lua-physical/physical.lua
+++ b/Master/texmf-dist/scripts/lua-physical/physical.lua
@@ -3,8 +3,8 @@
lua-physical
Author: Thomas Jenni
-Version: 1.0.3
-Date: 2020-09-09
+Version: 1.0.5
+Date: 2021-05-08
License: MIT