Skip to main content

Add your description here

Project description

Show your work!

show-your-work is a Python module to help with writing solutions to physics problems with numerical answers. It relies on other modules to do most of the heavy lifting.

Installing

Show-your-work is available on PyPi. The package is named show-your-work-utils to avoid potential name conflicts. Install it with your favorite package manager (mine is uv).

$ pip install show-your-work-utils
$ uv add show-your-work-utils
$ rye add show-your-work-utils
$ poetry add show-your-work-utils

Motivation

When writing detailed example problems for a physics class, we often need to plug numerical values into an equation and compute a numerical result. show-your-work allows you to write an equation in latex, add numerical substitutions for each term in the equations, produce the latex of your equation with numerical values substituted in, and then evaluate the equation with the given numerical values.

It is especially handy when used with tools like compudoc.

From the doc/examples directory

% main.tex.cd
\documentclass[]{article}

\usepackage{siunitx}
\usepackage{physics}
\usepackage{graphicx}
\usepackage{fullpage}

\author{C.D. Clark III}
\title{show-your-work/compudoc example}

\begin{document}
\maketitle

% {{{
% from show_your_work import Expression, Equation
% import pint
% ureg = pint.UnitRegistry()
% Q_ = ureg.Quantity
% def Lx_filter(input,fmt=""):
%   text = fmt_filter(input,fmt+"Lx")
%   return text
% jinja2_env.filters["Lx"] = Lx_filter
% line_eq = Equation(r"\\v{y} = \\v{m}\\v{x} + \\v{b}")
% print(line_eq.latex)
% }}}
$$
{{ line_eq.latex }}
$$
This gives the relationship between a dependent variable $y$ on an independent variable $x$.
% {{{
% slope = 3
% y_intercept = 2
% val = 10
% }}}
For example, for a slope $m = {{slope}}$ and y-intercept $b = {{y_intercept}}$, the value for $y$ at $x = {{val}}$ would be
% {{{
% line_eq.rhs.add_substitution('m',slope)
% line_eq.rhs.add_substitution('b',y_intercept)
% line_eq.rhs.add_substitution('x',val)
% }}}
$$
{{ line_eq.latex_with_substitutions }} = {{line_eq.rhs.eval()}}
$$
% {{{
% kinematics_eq1 = Equation( r"\\v{x} = \\v{v} \\v{t} + \\v{x_0}", "meter")
% v = Q_(60,'mph').to("km/hr")
% t = Q_(40,'min')
% x0 = Q_(150,'yd').to("m")
% kinematics_eq1.rhs.add_substitution('v',v)
% kinematics_eq1.rhs.add_substitution('t',t)
% kinematics_eq1.rhs.add_substitution('x_0',x0)
% }}}
Now, when dealing with physical quantities, we will have to consider units. Take an example from kinematics. The
position of an object traveling at constant speed is given by the equation,
$$
{{kinematics_eq1.latex}},
$$
which is just the equation for a line with $v$ as the slope and $x0$ as the y-intercept. If a car is traveling at
$v = {{v|Lx}}$ and we didn't start the stop watch until we were {{x0|Lx}} out of town, the car's distance from town
after traveling for {{t|Lx}} would be:
$$
{{kinematics_eq1.latex_with_substitutions}} = {{kinematics_eq1.rhs.eval(Q_)|Lx}}
$$



\end{document}

This template file can be rendered to LaTeX with compudoc and then compiled to a PDF with latexmk:

$ compudoc main.tex.cd
$ latexmk main

which will give this PDF

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

show_your_work_utils-0.2.0.tar.gz (189.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

show_your_work_utils-0.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file show_your_work_utils-0.2.0.tar.gz.

File metadata

File hashes

Hashes for show_your_work_utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c716e2f873bf89ca27685e8869f4dc5d1b6d65d3e470a92ca3e8519ba884f2f3
MD5 a77f4e6180001b82a17f0f8ca3e62322
BLAKE2b-256 90c44a06335822ccc0c8916000de9e9bfce5074c79a078b09e462b4aeae55dee

See more details on using hashes here.

File details

Details for the file show_your_work_utils-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for show_your_work_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0439e311220b252a5030c840155aa4419c684a125fcc13e6fac95156b613742c
MD5 964383a5140199248f6bd1b65defe3f3
BLAKE2b-256 e72827b3a95b5d0343e061767783e18bca2a20d8601041eac16cd46365faaefa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page