texlive[59138] Master/texmf-dist: lua-physical (8may21)

commits+karl at tug.org commits+karl at tug.org
Sat May 8 23:08:12 CEST 2021


Revision: 59138
          http://tug.org/svn/texlive?view=revision&revision=59138
Author:   karl
Date:     2021-05-08 23:08:12 +0200 (Sat, 08 May 2021)
Log Message:
-----------
lua-physical (8may21)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE
    trunk/Master/texmf-dist/doc/lualatex/lua-physical/README.md
    trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdf
    trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex
    trunk/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical-data.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical-definition.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical-number.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical-unit.lua
    trunk/Master/texmf-dist/scripts/lua-physical/physical.lua

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf
    trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex

Modified: trunk/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/doc/lualatex/lua-physical/LICENSE	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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

Modified: trunk/Master/texmf-dist/doc/lualatex/lua-physical/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/lua-physical/README.md	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/doc/lualatex/lua-physical/README.md	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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
 

Modified: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical.tex	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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 @@
 	round-mode=off
 }
 
+\DeclareSIUnit\unitless{}
+
 \DeclareSIUnit\fahrenheit{\ensuremath{{}^{\circ}}F}
 
+\DeclareSIUnit\inch{in}
+
 % config listings
 \lstdefinelanguage{lua}
 {
@@ -152,7 +156,7 @@
 
 \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
@@ -159,7 +163,7 @@
 
 
 \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 @@
 \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 @@
   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 @@
     )
   }%
 }
+
+% 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 @@
 \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 @@
   s = 10 * _m
   t = 2 * _s
 
-  v = s/t
+  v = s / t
 \end{luacode}
 
 \leftbar
@@ -272,18 +304,57 @@
 \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. 
+
+
+
+
 %------------------------------------------------------------
 \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}.
 
-\pagebreak
 
+\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.
+
+
 \begin{lstlisting}[caption=Volume of a cuboid.,label=lst:Volume of Cuboid]
 \begin{luacode}
   a = 12 * _cm
@@ -290,7 +361,7 @@
   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 @@
 \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 @@
   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 @@
   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 @@
 
 
 
+
+
+
 %------------------------------------------------------------
 \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{lstlisting}[caption=Time of flight.,label=lst:Time of flight]
+
 \begin{luacode}
-  a = N(2,0.1) * _m
-  b = N(3,0.1) * _m
-
-  A = (a*b):to(_m^2)
+  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
 
+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|. 
 
-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.
-
 \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 @@
 
 \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,11 +599,55 @@
 \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*}
+
+
+
+
 %------------------------------------------------------------
 \newpage
 \subsection{Mathematical operations}
@@ -561,10 +712,6 @@
 
 
 
-
-
-
-
 %------------------------------------------------------------
 \newpage
 \section{Supported Units}
@@ -681,6 +828,12 @@
 
 
 
+
+
+
+
+
+
 %------------------------------------------------------------
 \subsection{Base Units}
 \label{ch:base units}
@@ -700,7 +853,7 @@
 \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 @@
 \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,7 +948,56 @@
 
 
 
+% 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
 \subsection{Constants}
@@ -807,7 +1009,7 @@
 \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 @@
 \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,7 +1174,12 @@
 
 
 
+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
 \subsection{Other Non-SI units}
@@ -1399,6 +1557,8 @@
 % 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.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,7 +2735,39 @@
 \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}
   Returns the mean value of |n|.
@@ -2730,11 +3020,11 @@
 
 
 \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 @@
 
 
 \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 @@
 
 
 \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 @@
 
 
 \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 @@
 
 
 \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 @@
   \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 @@
 
 
 \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 @@
 
 
 \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 @@
 
 
 \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 @@
 
 
 \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 @@
 \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 @@
 \printindex[lua]
 
 
+
+
+
+
+
 \end{document}

Added: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf	2021-05-08 21:08:12 UTC (rev 59138)

Property changes on: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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}


Property changes on: trunk/Master/texmf-dist/doc/lualatex/lua-physical/lua-physical_example.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-data.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-data.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-data.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-definition.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-definition.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-definition.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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 @@
 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 @@
 -- 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,9 +292,11 @@
 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)
 
 
 
+
 -- OTHER NON-SI UNITS
 -- ******************
 

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -3,7 +3,7 @@
 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

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-number.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-number.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-number.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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 @@
 -- 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 @@
 
 
 -- 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 @@
 	-- 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 @@
 		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 @@
 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)

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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 @@
 	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().."}"

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical-unit.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical-unit.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical-unit.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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

Modified: trunk/Master/texmf-dist/scripts/lua-physical/physical.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/lua-physical/physical.lua	2021-05-08 21:07:46 UTC (rev 59137)
+++ trunk/Master/texmf-dist/scripts/lua-physical/physical.lua	2021-05-08 21:08:12 UTC (rev 59138)
@@ -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
 



More information about the tex-live-commits mailing list.