summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/lua-physical/src
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-05-09 03:02:17 +0000
committerNorbert Preining <norbert@preining.info>2021-05-09 03:02:17 +0000
commit2cd369d8df4e5fcf26840e6da140091a2f16fa8c (patch)
treee4757d386a1dbde3545992eb48d7265ac7e06638 /macros/luatex/latex/lua-physical/src
parent0f8acc6eb1940c147de1fb17b307dad849cb3915 (diff)
CTAN sync 202105090302
Diffstat (limited to 'macros/luatex/latex/lua-physical/src')
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-astronomical.lua2
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-data.lua2
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-definition.lua8
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-dimension.lua2
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-number.lua52
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-quantity.lua14
-rw-r--r--macros/luatex/latex/lua-physical/src/physical-unit.lua2
-rw-r--r--macros/luatex/latex/lua-physical/src/physical.lua4
8 files changed, 64 insertions, 22 deletions
diff --git a/macros/luatex/latex/lua-physical/src/physical-astronomical.lua b/macros/luatex/latex/lua-physical/src/physical-astronomical.lua
index 48ca5646b8..629832b879 100644
--- a/macros/luatex/latex/lua-physical/src/physical-astronomical.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical-data.lua b/macros/luatex/latex/lua-physical/src/physical-data.lua
index efc1a30ffa..f77eee9f8d 100644
--- a/macros/luatex/latex/lua-physical/src/physical-data.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical-definition.lua b/macros/luatex/latex/lua-physical/src/physical-definition.lua
index cf1576b4c5..5e0ec79a73 100644
--- a/macros/luatex/latex/lua-physical/src/physical-definition.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical-dimension.lua b/macros/luatex/latex/lua-physical/src/physical-dimension.lua
index edd9e65997..03cf315b74 100644
--- a/macros/luatex/latex/lua-physical/src/physical-dimension.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical-number.lua b/macros/luatex/latex/lua-physical/src/physical-number.lua
index 8c278aacfe..bd6a01e451 100644
--- a/macros/luatex/latex/lua-physical/src/physical-number.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical-quantity.lua b/macros/luatex/latex/lua-physical/src/physical-quantity.lua
index d89fdd2836..875a2ee38d 100644
--- a/macros/luatex/latex/lua-physical/src/physical-quantity.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical-unit.lua b/macros/luatex/latex/lua-physical/src/physical-unit.lua
index 65c016449b..5c20722fe1 100644
--- a/macros/luatex/latex/lua-physical/src/physical-unit.lua
+++ b/macros/luatex/latex/lua-physical/src/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/macros/luatex/latex/lua-physical/src/physical.lua b/macros/luatex/latex/lua-physical/src/physical.lua
index 8c8d30171b..6964687357 100644
--- a/macros/luatex/latex/lua-physical/src/physical.lua
+++ b/macros/luatex/latex/lua-physical/src/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