Skip to content

Datax-package/LaTeXDatax.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LaTeXDatax.py

Import calculated values from a python script into a LaTeX document. This is a python interface for the datax LaTeX package [ctan].

Installation

pip install LaTeXDatax

Usage

In a python script:

from LaTeXDatax import datax
datax(
		filename = "data.tex",
		a = "Literal string",
		b = 3.141592,
		c = (3.141592,"\\meter"),
		d = (3.141592,"\\meter","%.2g"),
		e = (3.141592,"%.2g"),
     )

In the LaTeX document:

\documentclass{article}
\usepackage{siunitx}
\usepackage{datax}
\begin{document}
	The length was measured as \(d=\datax{d}\).
\end{document}

If you want to save a dictionary of variables, you can use the double splat operator:

variables = {
		"a" : "Literal string",
		"b" : 3.141592,
		"c" : (3.141592,"\\meter"),
		"d" : (3.141592,"\\meter","%.2g"),
		"e" : (3.141592,"%.2g"),
    }
datax(filename="data.tex", **variables) # Note the asterisks

Pint integration

from pint import Quantity
from LaTeXDatax import datax
datax(filename = "data.tex", E = Quantity(24,"kg m / s^2"))

Works as you would hope, in large part because of how well pint implements siunitx strings. Hat off.

Looking for contributors

I don't know python very well. This package works, but if you have ideas for how to improve it, or you spot some python faux pas, feel free to make a PR or get in touch!