Exemples

Qty (physpyx.qty.Qty, physpyx.quantity.SiunitxQuantity)

ex-qty.py
from physpyx import Qty

with Qty(__file__, "energy") as qty:
    G = qty("G")  # exporte la constante de la gravitation universelle
    R = qty("RTerre", fmt=".0f")  # enlève la notation scientifique
    m2 = qty("MTerre", fmt=".1e")  # affiche 2 chiffres significatifs
    m1 = qty(75, "kilogram")  # exporte une variable
    # exporte une version en joule et un version dans les unités si de base
    U = (-G * m1 * m2 / R).fmtex(alt={"base": True})
    UkWh = U.fmtex(to="kilowatthour")  # exporte en kWh

    # le mot clé "energy" donné en option de Qty permet de convertir des masses
    # en énergie
    m2H = qty("m2H")  # les masses des nucléides sont par défaut en amu
    c = qty("c", to="kilometer per second", fmt=".3e")  # converti en km/s
    E = m2H.fmtex(to="megaelectronvolt", fmt=".3f")

    # possible d'utiliser des vecteurs
    i = qty(2, "milliampere", alt=True)  # exporte une variable et sa version SI
    L = qty([0, 2, -3], "kilometer")  # exporte un vecteur
    B = qty([1, 0, 2], "tesla")  # exporte un vecteur
    F = i * L.cross(B)  # peut faire des opérations sur des vecteurs

    # possible d'utiliser des centimes et des francs suisses
    cost = qty("ct_per_kwh")  # peut définir des constante personnelles
    bill = (cost * U).fmtex(to="chf")
Code généré automatiquement par Phys\(PyX\)
ex-qty.pyx
\ExplSyntaxOn
\prop_gset_from_keyval:Nn \g_physpyx_pty_prop {
	{G} = {\qty{6.67e-11}{\newton\meter\squared\per\kilogram\squared}},
	{R} = {\qty{6371000}{\meter}},
	{m2} = {\qty{6.0e+24}{\kilogram}},
	{m1} = {\qty{75}{\kilogram}},
	{U} = {\qty{-4.69239e+09}{\joule}},
	{U_alt} = {\qty{-4.69239e+09}{\kilogram\meter\squared\per\second\squared}},
	{UkWh} = {\qty{-1303.44}{\kilo\watthour}},
	{m2H} = {\qty{2.014102}{\amu}},
	{c} = {\qty{2.998e+05}{\kilo\meter\per\second}},
	{E} = {\qty{1876.124}{\mega\electronvolt}},
	{i} = {\qty{2}{\milli\ampere}},
	{i_alt} = {\qty{0.002}{\ampere}},
	{L} = {\begin{pmatrix}\num{0}\\\num{2}\\\num{-3}\end{pmatrix}\unit{\kilo\meter}},
	{B} = {\begin{pmatrix}\num{1}\\\num{0}\\\num{2}\end{pmatrix}\unit{\tesla}},
	{F} = {\begin{pmatrix}\num{8}\\\num{-6}\\\num{-4}\end{pmatrix}\unit{\newton}},
	{cost} = {\qty{30}{\ct\per\kilo\watthour}},
	{bill} = {\qty{-391.032}{\chf}},
}
\ExplSyntaxOff
Code \(\LaTeX\) minimal
ex-qty.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage[
	per-mode = fraction,
	exponent-product = \cdot,
	uncertainty-mode = separate,
]{siunitx} % le rendu des unités se configure dans siunitx


\DeclareSIUnit{\amu}{\atomicmassunit}
\DeclareSIUnit{\watthour}{Wh}
\DeclareSIUnit{\ct}{ct}
\DeclareSIUnit{\chf}{CHF}

\ExplSyntaxOn
\prop_new:N \g_physpyx_pty_prop
\NewDocumentCommand{\pyx}{sm}{
  \IfBooleanTF{#1}
  { \prop_get:NnNT \g_physpyx_pty_prop {#2 _alt} \l_tmpa_tl { \tl_use:N \l_tmpa_tl } }
  { \prop_get:NnNT \g_physpyx_pty_prop {#2} \l_tmpa_tl { \tl_use:N \l_tmpa_tl } }
}
\file_input:n {ex-qty.pyx}
\ExplSyntaxOff

\begin{document}
\pagestyle{empty}
\begin{align}
  U 
  &= -G\frac{mM}{R} \\
  &= -\pyx{G}\frac{\pyx{m1}\cdot\pyx{m2}}{\pyx{R}} \\
  &= \pyx{U} \\
  &= \pyx*{U} \\
  &= \pyx{UkWh} \\
  \text{bill} &= \pyx{UkWh}\cdot\pyx{cost} = \pyx{bill} \\
  E 
  &= mc^2 \\
  &= \pyx{m2H}\left(\pyx{c}\right)^2 = \pyx{E} \\
  i &= \pyx*{i} \\
  \vec{F} 
  &= i\vec{L}\wedge\vec{B}
  = \pyx{i}\pyx{L}\wedge\pyx{B}
  = \pyx{F}
\end{align}
\end{document}
ex-qty.pdf

NuclideTable (physpyx.nuclides.NuclideTable, physpyx.physpyx.PhysPyX)

ex-nuclides.py
from physpyx import NuclideTable, PhysPyX

nt = NuclideTable()
nuclides = nt.range(N=range(137, 140), Z=range(95, 98))

with PhysPyX(__file__) as tex:
    with tex.begin("tikzpicture", o=["xscale=1.3, yscale=0.8"]):
        tex(NuclideTable.define_colors())
        tex(NuclideTable.axis(nuclides))
        tex(NuclideTable.legend(nuclides, x=140.5, y=97, vertical=True))
        for nuclide in nuclides:
            tex(nuclide.to_tex(with_symbol=True, with_decay=False, with_mass=True))
Code généré automatiquement par Phys\(PyX\)
ex-nuclides.pyx
\begin{tikzpicture}[xscale=1.3, yscale=0.8]
	\definecolor{3f80ae}{HTML}{3f80ae}
	\definecolor{52b552}{HTML}{52b552}
	\definecolor{52b552}{HTML}{52b552}
	\definecolor{7d7ad6}{HTML}{7d7ad6}
	\definecolor{d67d7a}{HTML}{d67d7a}
	\definecolor{ca5753}{HTML}{ca5753}
	\definecolor{c7522a}{HTML}{c7522a}
	\definecolor{e5c185}{HTML}{e5c185}
	\definecolor{fbf2c4}{HTML}{fbf2c4}
	\definecolor{74a892}{HTML}{74a892}
	\definecolor{52b552}{HTML}{52b552}
	\definecolor{a0a0a0}{HTML}{a0a0a0}
	\draw[<->] (136.9, 98) node[left]{$Z$} |- (140, 94.9) node[below]{$N$};
	\draw (137.5, 95) -- ++(0,-0.2) node[below]{$137$};
	\draw (138.5, 95) -- ++(0,-0.2) node[below]{$138$};
	\draw (139.5, 95) -- ++(0,-0.2) node[below]{$139$};
	\draw (137, 95.5) -- ++(-0.2,0) node[left]{$95$};
	\draw (137, 96.5) -- ++(-0.2,0) node[left]{$96$};
	\draw (137, 97.5) -- ++(-0.2,0) node[left]{$97$};
	\fill[color=3f80ae!60] (140.5, 97) rectangle ++(1, 1) node[midway, black]{$\alpha$};
	\fill[color=d67d7a!60] (140.5, 96) rectangle ++(1, 1) node[midway, black]{$\beta^+$};
	\fill[color=52b552!60] (140.5, 95) rectangle ++(1, 1) node[midway, black]{SF};
	\fill[color=d67d7a!60] (137, 95) rectangle ++(1,1);
	\fill[color=3f80ae!60] (138, 95) -- (138, 95.24494897427832) -- (137.75505102572168, 95) -- cycle;
	\node[anchor=north] at (137.5, 96) {\ce{^232Am}};
	\node[anchor=south] at (137.5, 95) {\tiny{\num{232.046613}}};
	\fill[color=d67d7a!60] (137, 96) rectangle ++(1,1);
	\fill[color=3f80ae!60] (138, 96) -- (138, 96.63245553203367) -- (137.36754446796633, 96) -- cycle;
	\node[anchor=north] at (137.5, 97) {\ce{^233Cm}};
	\node[anchor=south] at (137.5, 96) {\tiny{\num{233.050771}}};
	\fill[color=3f80ae!60] (137, 97) rectangle ++(1,1);
	\fill[color=d67d7a!60] (138, 97) -- (138, 97.63245553203367) -- (137.36754446796633, 97) -- cycle;
	\node[anchor=north] at (137.5, 98) {\ce{^234Bk}};
	\node[anchor=south] at (137.5, 97) {\tiny{\num{234.057322}}};
	\fill[color=d67d7a!60] (138, 95) rectangle ++(1,1);
	\fill[color=3f80ae!60] (139, 95) -- (139, 95.3) -- (138.7, 95) -- cycle;
	\node[anchor=north] at (138.5, 96) {\ce{^233Am}};
	\node[anchor=south] at (138.5, 95) {\tiny{\num{233.046468}}};
	\fill[color=3f80ae!60] (138, 96) rectangle ++(1,1);
	\fill[color=52b552!60] (139, 96) -- (139, 96.89442719099992) -- (138.10557280900008, 96) -- cycle;
	\fill[color=d67d7a!60] (138, 97) -- (138, 96.36754446796633) -- (138.63245553203367, 97) -- cycle;
	\node[anchor=north] at (138.5, 97) {\ce{^234Cm}};
	\node[anchor=south] at (138.5, 96) {\tiny{\num{234.050159}}};
	\fill[color=d67d7a!60] (139, 95) rectangle ++(1, 1);
	\node[anchor=north] at (139.5, 96) {\ce{^234Am}};
	\node[anchor=south] at (139.5, 95) {\tiny{\num{234.047731}}};
	\fill[color=3f80ae!60] (139, 96) rectangle ++(1, 1);
	\node[anchor=north] at (139.5, 97) {\ce{^235Cm}};
	\node[anchor=south] at (139.5, 96) {\tiny{\num{235.051545}}};
	\fill[color=d67d7a!60] (139, 97) rectangle ++(1,1);
	\fill[color=3f80ae!60] (140, 97) -- (140, 97.58309518948452) -- (139.41690481051546, 97) -- cycle;
	\node[anchor=north] at (139.5, 98) {\ce{^236Bk}};
	\node[anchor=south] at (139.5, 97) {\tiny{\num{236.057479}}};
\end{tikzpicture}
Code \(\LaTeX\) minimal
ex-nuclides.tex
\documentclass[tikz]{standalone}
\usepackage{mhchem}
\usepackage{siunitx}

\begin{document}
\input{ex-nuclides.pyx}
\end{document}
ex-nuclides.pdf

Orbit (physpyx.astronomy.Orbit, physpyx.physpyx.PhysPyX)

ex-orbit.py
from physpyx import PhysPyX, Orbit
from physpyx.helper import coord

with PhysPyX(__file__) as tex:
    steps = 3000
    n_points = 120
    every = int(steps / n_points)
    with tex.newcommand("OrbitCoordinates"):
        tex(coord(x) for x in Orbit(a=4, b=3, mu=3).run(steps=steps, every=every))
Code généré automatiquement par Phys\(PyX\)
ex-orbit.pyx
\NewDocumentCommand{\OrbitCoordinates}{}{
	(1.3542486889354093, 0.0)
	(1.3073028361553185, 0.4586359192108653)
	(1.1750541229359974, 0.8880350416412112)
	(0.9783393868782775, 1.2697849670954542)
	(0.739514969374724, 1.5981050159188919)
	(0.47644850053195253, 1.8753255500261716)
	(0.20147671000272666, 2.1071589987332873)
	(-0.07746645348770206, 2.2999610968340574)
	(-0.35544958962202805, 2.459577051753288)
	(-0.6294662608952812, 2.591003432780773)
	(-0.897717317784548, 2.6983866744521365)
	(-1.1591574667331028, 2.785133123595151)
	(-1.413213297108269, 2.8540393632531527)
	(-1.6596078501353122, 2.9074107350789418)
	(-1.898250642867213, 2.9471597564629017)
	(-2.129168023080252, 2.974884798269761)
	(-2.3524586099022473, 2.9919320090423063)
	(-2.5682645274316696, 2.99944382544834)
	(-2.776752708504136, 2.99839701411854)
	(-2.978102698981336, 2.989632627563301)
	(-3.1724987056115777, 2.973879729998397)
	(-3.3601244411853433, 2.9517743141008297)
	(-3.541159828291138, 2.923874489695973)
	(-3.7157789451860768, 2.8906727660759755)
	(-3.884148804567279, 2.8526060541155065)
	(-4.0464286910522445, 2.810063867459796)
	(-4.202769872169159, 2.763395091657931)
	(-4.35331555694791, 2.7129136068878053)
	(-4.498201016091175, 2.658902986895292)
	(-4.637553804775841, 2.6016204487865733)
	(-4.771494047649096, 2.5413001915636015)
	(-4.900134758327411, 2.478156232974621)
	(-5.023582174527235, 2.4123848322932844)
	(-5.141936096084963, 2.3441665695074176)
	(-5.255290217394527, 2.2736681379485564)
	(-5.363732448769066, 2.2010438967718327)
	(-5.467345223308906, 2.1264372212582514)
	(-5.56620578729924, 2.049981682171646)
	(-5.660386473155282, 1.9718020799895475)
	(-5.749954954611714, 1.892015355456807)
	(-5.8349744843085265, 1.8107313943650722)
	(-5.915504114222792, 1.7280537415704111)
	(-5.991598899582048, 1.644080236893886)
	(-6.063310087002055, 1.5589035836028702)
	(-6.130685287644402, 1.4726118585627748)
	(-6.193768636203881, 1.3852889718158201)
	(-6.2526009365237725, 1.2970150822347624)
	(-6.307219794608782, 1.2078669749736906)
	(-6.357659739764674, 1.1179184056637872)
	(-6.403952334547195, 1.0272404156516293)
	(-6.4461262741514105, 0.9359016220315618)
	(-6.484207475820252, 0.843968485763516)
	(-6.518219158797822, 0.7515055607801311)
	(-6.5481819153004315, 0.6585757266607805)
	(-6.574113772926985, 0.5652404071756548)
	(-6.596030248880401, 0.47155977677277106)
	(-6.613944396323224, 0.3775929568892689)
	(-6.62786684314392, 0.2833982038095139)
	(-6.637805823364953, 0.18903308966322063)
	(-6.643767201379787, 0.09455467805344794)
	(-6.645754489163136, 1.9695724527223502e-05)
	(-6.64376885655692, -0.09451529837855933)
	(-6.637809134693067, -0.18899374534572655)
	(-6.627871812573546, -0.2833589185375478)
	(-6.613951026787301, -0.3775537545266798)
	(-6.596038544302872, -0.47152068143136355)
	(-6.57412373823434, -0.5652014432892988)
	(-6.548193556436287, -0.6585369190620733)
	(-6.518232482740589, -0.7514669347802331)
	(-6.4842224906040125, -0.8439300672358954)
	(-6.446142988890121, -0.9358634375002911)
	(-6.403970759462375, -1.027202492385139)
	(-6.357679886216718, -1.1178807717749626)
	(-6.307241675132125, -1.2078296595272888)
	(-6.252624564866058, -1.2969781153633555)
	(-6.193794027369381, -1.3852523848454712)
	(-6.130712457941983, -1.4725756841499438)
	(-6.06333905409786, -1.558867855884235)
	(-5.991629682557333, -1.6440449916509157)
	(-5.915536733637047, -1.728019016411007)
	(-5.8350089622683825, -1.8106972289247025)
	(-5.749991314845834, -1.8919817916222452)
	(-5.66042474109562, -1.9717691621486038)
	(-5.566245990168995, -2.049949457492996)
	(-5.4673873902174215, -2.126405740006199)
	(-5.36377661081391, -2.2010132126616946)
	(-5.255336407770911, -2.273638308549432)
	(-5.141984350202379, -2.344137656700508)
	(-5.0236325301331455, -2.4123569027954264)
	(-4.900187255637312, -2.4781293589388067)
	(-4.771548729481827, -2.5412744512707257)
	(-4.637610716692427, -2.6015959274456724)
	(-4.498260206534156, -2.6588797775735986)
	(-4.353377077376965, -2.712891811596682)
	(-4.20283377718645, -2.7633748226271164)
	(-4.046495038508035, -2.81004524864028)
	(-3.884217655631852, -2.852589222961643)
	(-3.715850364367743, -2.8906578756706023)
	(-3.5412338833708574, -2.9238617112995295)
	(-3.3602012030249475, -2.9517638402279465)
	(-3.1725782477725626, -2.9738717781549777)
	(-2.97818509706145, -2.9896274448162417)
	(-2.7768380390541005, -2.9983948827220344)
	(-2.5683528662459247, -2.999445069819685)
	(-2.3525500293725004, -2.9919370044715787)
	(-2.129262588135816, -2.9748939818683353)
	(-1.898348404766315, -2.9471736410120903)
	(-1.6597088369541517, -2.9074299266356793)
	(-1.4133174990964263, -2.854064583596091)
	(-1.1592648135879795, -2.7851652388090615)
	(-0.8978276430445705, -2.698426731017975)
	(-0.6295792455653816, -2.591052702104056)
	(-0.3555646720567602, -2.4596370822136)
	(-0.07758268448228753, -2.3000337669490842)
	(0.20136089945285307, -2.107246550685628)
	(0.47633566256484083, -1.8754305482481743)
	(0.7394091680350947, -1.5982301001919461)
	(0.9782468249587891, -1.269932137271925)
	(1.1749834344801002, -0.8882041088960798)
	(1.3072638845318036, -0.4588221815306432)
	(1.3543252108982853, -0.00019296397889198222)
}
Code \(\LaTeX\) minimal
ex-orbit.tex
\documentclass[tikz]{standalone}

\input{ex-orbit.pyx}

\begin{document}
\begin{tikzpicture}
  \draw[blue] plot[mark=*, only marks, mark size=1] coordinates {\OrbitCoordinates};
  \fill[orange] circle (0.2cm);
\end{tikzpicture}
\end{document}
ex-orbit.pdf