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.3.0.tar.gz (190.6 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.3.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for show_your_work_utils-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f48804939a3296b2b3f9a322f81f93bf0f973011555902e19962ff5129a4acd1
MD5 900b9d094af184c901966824dbd6e53d
BLAKE2b-256 a0666e0ab7d32534c86196b789554bb356d0aca71b8d214dce911caeee11607b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for show_your_work_utils-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd4928662a1615a0e14636644c6e9d74855b06e36d712c55a7ec471113d12b48
MD5 21a695ed6bdc817453709356603e5592
BLAKE2b-256 5b2fb22ef9bb725f329215591efc1fb8779a191a81c8008e1c35f9c2bd7dccf0

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