* Use \unit for value and uncertainty
@ 2016-09-25 18:11 Florian Leupold
2016-10-31 16:30 ` Florian Leupold
0 siblings, 1 reply; 5+ messages in thread
From: Florian Leupold @ 2016-09-25 18:11 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 250 bytes --]
Dear list
Is it possible to use the units module (in MKIV) for value plusminus uncertainty in a way similar to the \SI command in LaTeX, like
\unit{(1.59\pm2)e-19 coulomb} or
\unit{1.59(2)e-19 coulomb}?
Thanks and best regards,
Florian
[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Use \unit for value and uncertainty
2016-09-25 18:11 Use \unit for value and uncertainty Florian Leupold
@ 2016-10-31 16:30 ` Florian Leupold
2016-11-02 10:27 ` Henri Menke
0 siblings, 1 reply; 5+ messages in thread
From: Florian Leupold @ 2016-10-31 16:30 UTC (permalink / raw)
To: ConTeXt List
Hello!
There does not seem to be a simple solution to using \unit with uncertainties, see below.
Could someone maybe point me to the relevant source code for the parser for \unit in MKIV? Then I would try to modify/improve the code myself.
Thanks a lot and best regards,
Florian
> On 25.09.16, at 20:11, Florian Leupold <fleupold@posteo.net> wrote:
>
> Dear list
>
> Is it possible to use the units module (in MKIV) for value plusminus uncertainty in a way similar to the \SI command in LaTeX, like
> \unit{(1.59\pm2)e-19 coulomb} or
> \unit{1.59(2)e-19 coulomb}?
>
> Thanks and best regards,
> Florian
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive : http://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Use \unit for value and uncertainty
2016-10-31 16:30 ` Florian Leupold
@ 2016-11-02 10:27 ` Henri Menke
0 siblings, 0 replies; 5+ messages in thread
From: Henri Menke @ 2016-11-02 10:27 UTC (permalink / raw)
To: mailing list for ConTeXt users
On 10/31/2016 05:30 PM, Florian Leupold wrote:
> Hello!
>
> There does not seem to be a simple solution to using \unit with uncertainties, see below.
>
> Could someone maybe point me to the relevant source code for the parser for \unit in MKIV? Then I would try to modify/improve the code myself.
phys-dim.mkiv
https://github.com/contextgarden/context-mirror/blob/beta/tex/context/base/mkiv/phys-dim.mkiv
phys-dim.lua
https://github.com/contextgarden/context-mirror/blob/beta/tex/context/base/mkiv/phys-dim.lua
>
> Thanks a lot and best regards,
> Florian
>
>
>> On 25.09.16, at 20:11, Florian Leupold <fleupold@posteo.net> wrote:
>>
>> Dear list
>>
>> Is it possible to use the units module (in MKIV) for value plusminus uncertainty in a way similar to the \SI command in LaTeX, like
>> \unit{(1.59\pm2)e-19 coulomb} or
>> \unit{1.59(2)e-19 coulomb}?
>>
>> Thanks and best regards,
>> Florian
>> ___________________________________________________________________________________
>> If your question is of interest to others as well, please add an entry to the Wiki!
>>
>> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
>> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
>> archive : http://foundry.supelec.fr/projects/contextrev/
>> wiki : http://contextgarden.net
>> ___________________________________________________________________________________
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Use \unit for value and uncertainty
@ 2020-05-09 10:39 Benjamin Buchmuller
2020-05-09 12:52 ` Otared Kavian
0 siblings, 1 reply; 5+ messages in thread
From: Benjamin Buchmuller @ 2020-05-09 10:39 UTC (permalink / raw)
To: fleupold, henrimenke; +Cc: mailing list for ConTeXt users
I know this is quite an old thread, but here is a minimal parser (\units with an “s”) that wraps around \digits and \unit to produce an acceptable output.
As I frequently need to write ranges (or measures of uncertainty), I find it convenient to able to type
\units{4.0 to 5.0 centi meter}
than
\digits{4.0}\,to\,\unit{5.0 centi meter}.
Also, the parser will take care of exponents and bracket them accordingly. :D
ranges: keyword “to”: 4.0 – 5.0 cm
SEM: keyword “se”: 4.5 ± 0.5 cm
SD: keyword “sd”: 4.5 (0.5) cm
If no keyword is present, the default behaviour is \unit{…}.
The code is not perfect (and the level of abstraction potentially not yet sufficient to make it part of the phys-dim.mkiv source), but maybe helpful.
\starttext
\startluacode
userdata = userdata or {}
function userdata.units(input)
tbl = string.explode(input)
if tbl[2] == "to" then
context.digits(tbl[1])
context.phys_units_space()
context("--")
context.phys_units_space()
context.unit(table.concat(tbl, " ", 3))
elseif tbl[2] == "se" then
local sx1 = string.split(tbl[1], "e")
local sx2 = string.split(tbl[3], "e")
if (sx1[2] == sx2[2]) and not (sx1[2] == nil) then
context("(")
context.digits(sx1[1])
context.phys_units_space()
context("±")
context.phys_units_space()
context.digits(sx2[1])
context(")")
context.digits("e" .. sx1[2])
context.phys_units_space()
context.unit(table.concat(tbl, " ", 4))
else
context.digits(tbl[1])
context.phys_units_space()
context("±")
context.phys_units_space()
context.unit(table.concat(tbl, " ", 3))
end
elseif tbl[2] == "sd" then
local sx1 = string.split(tbl[1], "e")
local sx2 = string.split(tbl[3], "e")
if (sx1[2] == sx2[2]) and not (sx1[2] == nil) then
context.digits(sx1[1])
context.phys_units_space()
context("(")
context.digits(sx2[1])
context(")")
context.digits("e" .. sx1[2])
context.phys_units_space()
context.unit(table.concat(tbl, " ", 4))
else
context.digits(tbl[1])
context.phys_units_space()
context("(")
context.digits(tbl[3])
context(")")
context.unit(table.concat(tbl, " ", 4))
end
else
context.unit(table.concat(tbl, " "))
end
end
\stopluacode
\def\units#1{\ctxlua{userdata.units("#1")}}
Car 1 drives \units{4 to 5.2 kilo meter per hour}.
Car 2 drives \units{30.1 to 40.5 kilo meter per hour}.
Car 3 drives \units{40.= to 50.= kilo meter per hour}.
The average speed was \units{35,000 se 5000 meter per hour}.
The average speed was \units{35e3 se 0.5e3 meter per hour}.
The average speed was \units{35.2e3 se 5e2 meter per hour}.
\stoptext
The average speed was \units{35.2 se 5e2 meter per hour}.
The average speed was \units{_3.2 sd 5 meter per hour}.
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Use \unit for value and uncertainty
2020-05-09 10:39 Benjamin Buchmuller
@ 2020-05-09 12:52 ` Otared Kavian
0 siblings, 0 replies; 5+ messages in thread
From: Otared Kavian @ 2020-05-09 12:52 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi Benjamin,
Thanks for sharing your nice code, which is very useful.
However I wanted to let you know that it seems it does not work correctly with LuaMetaTeX version 2020.04.30 11:10, even though it works fine with ConTeXt mkiv.
Best regards: Otared K.
> On 9 May 2020, at 12:39, Benjamin Buchmuller <benjamin.buchmuller@gmail.com> wrote:
>
> I know this is quite an old thread, but here is a minimal parser (\units with an “s”) that wraps around \digits and \unit to produce an acceptable output.
>
> As I frequently need to write ranges (or measures of uncertainty), I find it convenient to able to type
>
> \units{4.0 to 5.0 centi meter}
>
> than
>
> \digits{4.0}\,to\,\unit{5.0 centi meter}.
>
> Also, the parser will take care of exponents and bracket them accordingly. :D
>
> ranges: keyword “to”: 4.0 – 5.0 cm
> SEM: keyword “se”: 4.5 ± 0.5 cm
> SD: keyword “sd”: 4.5 (0.5) cm
>
> If no keyword is present, the default behaviour is \unit{…}.
>
> The code is not perfect (and the level of abstraction potentially not yet sufficient to make it part of the phys-dim.mkiv source), but maybe helpful.
>
> \starttext
>
> \startluacode
> userdata = userdata or {}
>
> function userdata.units(input)
>
> tbl = string.explode(input)
>
> if tbl[2] == "to" then
> context.digits(tbl[1])
> context.phys_units_space()
> context("--")
> context.phys_units_space()
> context.unit(table.concat(tbl, " ", 3))
> elseif tbl[2] == "se" then
> local sx1 = string.split(tbl[1], "e")
> local sx2 = string.split(tbl[3], "e")
> if (sx1[2] == sx2[2]) and not (sx1[2] == nil) then
> context("(")
> context.digits(sx1[1])
> context.phys_units_space()
> context("±")
> context.phys_units_space()
> context.digits(sx2[1])
> context(")")
> context.digits("e" .. sx1[2])
> context.phys_units_space()
> context.unit(table.concat(tbl, " ", 4))
> else
> context.digits(tbl[1])
> context.phys_units_space()
> context("±")
> context.phys_units_space()
> context.unit(table.concat(tbl, " ", 3))
> end
> elseif tbl[2] == "sd" then
> local sx1 = string.split(tbl[1], "e")
> local sx2 = string.split(tbl[3], "e")
> if (sx1[2] == sx2[2]) and not (sx1[2] == nil) then
> context.digits(sx1[1])
> context.phys_units_space()
> context("(")
> context.digits(sx2[1])
> context(")")
> context.digits("e" .. sx1[2])
> context.phys_units_space()
> context.unit(table.concat(tbl, " ", 4))
> else
> context.digits(tbl[1])
> context.phys_units_space()
> context("(")
> context.digits(tbl[3])
> context(")")
> context.unit(table.concat(tbl, " ", 4))
> end
> else
> context.unit(table.concat(tbl, " "))
> end
>
> end
> \stopluacode
>
> \def\units#1{\ctxlua{userdata.units("#1")}}
>
> Car 1 drives \units{4 to 5.2 kilo meter per hour}.
>
> Car 2 drives \units{30.1 to 40.5 kilo meter per hour}.
>
> Car 3 drives \units{40.= to 50.= kilo meter per hour}.
>
> The average speed was \units{35,000 se 5000 meter per hour}.
>
> The average speed was \units{35e3 se 0.5e3 meter per hour}.
>
> The average speed was \units{35.2e3 se 5e2 meter per hour}.
>
> \stoptext
>
> The average speed was \units{35.2 se 5e2 meter per hour}.
>
> The average speed was \units{_3.2 sd 5 meter per hour}.
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-05-09 12:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-25 18:11 Use \unit for value and uncertainty Florian Leupold
2016-10-31 16:30 ` Florian Leupold
2016-11-02 10:27 ` Henri Menke
2020-05-09 10:39 Benjamin Buchmuller
2020-05-09 12:52 ` Otared Kavian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).