Skip to main content

Intelligent interface between Python-computed values and your LaTeX work

Project description

ResultWizard

Intelligent interface between Python-computed values and your LaTeX work

[!important]
ResultWizard is currently fully functional but still in its alpha stage. We're happy to receive your feedback. Basic usage is as follows. A more comprehensive documentation will be available as soon as the package is stable.

Installation & usage

Install the package via pip.

pip install resultwizard

Then you can use ResultWizard in your Python code:

import resultwizard as wiz
wiz.config_init(print_auto=True)

# your complex calculations
# ...
value = 42.0
uncertainty = 3.14
wiz.res("length atom", value, uncertainty, r"\per\mm\cubed")

wiz.export("results.tex")

Then add the following line to your LaTeX document right before \begin{document}:

\input{results.tex}

Note that ResultWizard requires the following LaTeX packages: siunitx and ifthen. They are imported in the results.tex file via \usepackage{...} statements. The package ifthen is always presented in a LaTeX distribution. You may have to install the siunitx package, which is a widely used package in the scientific community to typeset units, e.g. you can use strings like \kg\per\cm.

You can now go ahead and reference the variable in your LaTeX document in any math environment, e.g.:

\begin{align}
    \resLengthAtom
\end{align}

You can also only use a specific part of the result, e.g. the unit, the value itself etc.

\begin{align}
    \resLengthAtom[unit]
\end{align}

Troubleshooting: LaTeX doesn't build

If your LaTeX document doesn't build, there might be several reasons. Try to find out what's wrong by looking at the log file of your LaTeX compiler (sometimes you have to scroll way up to find the error responsible for the failing build). Also open the results.tex file to see if your editor/IDE shows any errors there. You might encounter one of the following errors:

[!WARNING] This troubleshooting section does not yet apply to the first alpha release of ResultWizard. It's just here for one of the next alpha versions.

Package siunitx: Invalid number.

TL;DR: You have an old version of siunitx. Please update it or use the siunitx_fallback option in the config_init method.

In version v3.1.0 (2022-04-25), siunitx introduced "support for multiple uncertainty values in both short and long form in input". We make use of this feature in ResultWizard.

Unfortunately, it may be the case that you're using an older version of siunitx. Especially if you've installed LaTeX via a package manager (e.g. you installed siunitx via sudo apt install texlive-science). To determine your version, include the following line in your LaTeX document:

\listfiles % add this before \begin{document}

Then, compile your document and check the log for the version of siunitx. If it's older than v3.1.0 (2022-04-25), don't despair. We have two solutions for you:

Solution 1: Don't update siunitx and stick with your old version

Sure, fine, we won't force you to update siunitx (although we'd recommend it). To keep using your old version, specify the following key in the config_init method:

wiz.config_init(siunitx_fallback=True)

Note that with this "solution", you won't be able to fully customize the output of the result in your LaTeX document. For example, we will use a ± between the value and the uncertainty, e.g. 3.14 ± 0.02. You won't be able to change this in your sisetup by doing:

\sisetup{separate-uncertainty=false}

to get another format like 3.14(2). There are also some other siunitx options that won't work with ResultWizard, e.g. exponent-product. If you're fine with this, go ahead and use the siunitx_fallback option. If not, consider updating siunitx to at least version v3.1.0.

Solution 2: Update siunitx (recommended)

How the update process works depends on your LaTeX distribution and how you installed it. E.g. you might be using TeX Live on Ubuntu and installed packages via apt, e.g. sudo apt install texlive-science (which includes the LaTeX siunitx). These pre-built packages are often outdated, e.g. for Ubuntu 22.04 LTS (jammy), the siunitx package that comes with the texlive-science package is 3.0.4. Therefore, you might have to update siunitx manually. See an overview on how to install individual LaTeX packages on Linux here.

A quick solution might be to simply install a new version of siunitx manually to your system. There's a great and short Ubuntu guide on how to install LaTeX packages manually here. The following commands are based on this guide. We will download the version 3.1.11 (2022-12-05) from GitHub (this is the last version before 3.2 where things might get more complicated to install) and install it locally. Nothing too fancy. Execute the following commands in your terminal:

# Install "unzip", a tool to extract zip files
sudo apt install unzip

# Download v3.1.11 of siunitx from GitHub
curl -L https://github.com/josephwright/siunitx/releases/download/v3.1.11/siunitx-ctan.zip > siunitx-ctan-3.1.11.zip

# Unzip the file
unzip ./siunitx-ctan-3.1.11.zip
cd siunitx/

# Run LaTeX on the .ins file to produce a usable .sty file
# (The .sty file is needed when you use \usepackage{siunitx}
# in your LaTeX document)
latex siunitx.ins

# Create a new directory in your home directory
# to store the new package .sty file
mkdir -p ~/texmf/tex/latex/siunitx
cp siunitx.sty ~/texmf/tex/latex/siunitx/

# Make LaTeX recognize the new package by pointing it to the new directory
texhash ~/texmf/

# 🙌 Done. Try to rebuild your LaTeX document again.

# If you don't wan't the new siunitx version anymore, just run the following
# command to remove the .sty file. LaTeX will then use the version of siunitx
# it finds somewhere else in your system.
rm ~/texmf/tex/latex/siunitx/siunitx.sty

Compiling your latex document again, you should see version v3.1.11 of siunitx in the log file. And it should build, yeah 🎉. Don't forget to remove the \listfiles from your LaTeX document to avoid cluttering your log file (which is ironic for LaTeX, we know).

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

resultwizard-0.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

resultwizard-0.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file resultwizard-0.1.tar.gz.

File metadata

  • Download URL: resultwizard-0.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for resultwizard-0.1.tar.gz
Algorithm Hash digest
SHA256 786a10c898beec27671ef32b5c7dd9afce52973380439ee17b23504835b3ebbd
MD5 bb27ca4c07763052912e709783ece34e
BLAKE2b-256 eae20036ad6d0a92b9dfbd5b8bf167e04835a368dadf38144986603ce7cc6e72

See more details on using hashes here.

File details

Details for the file resultwizard-0.1-py3-none-any.whl.

File metadata

  • Download URL: resultwizard-0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for resultwizard-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66fa2983e290b89b3073f8db1d4b712b83011f0fdfc1c35905116632504584c7
MD5 6cafb900692a691dce099e860b84bba8
BLAKE2b-256 ca454f8c4ee2c8670cca372e5d9e995b23765025bdadece0e14cd7244b41d8f7

See more details on using hashes here.

Supported by

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