Skip to main content

📝 json2tex - Convert JSON to LaTeX

pipeline status coverage report documentation

This Python script can read multiple JSON files, merge them and outputs LaTeX-\newcommand-definitions to access all elements.

Installation

# from PyPI
pip install json2tex
# or directly from GitLab
pip install git+https://gitlab.com/nobodyinperson/json2tex

Usage

JSON file → TeX file

With a JSON file values.json like this:

[
  {
    "_id": "5f1570db9d5aa0b6df3823f8",
    "index": 0,
    "guid": "0fdfb3c5-1f0a-4c2a-8fed-75861742b588",
    "isActive": true,
    "balance": "$1,652.14",
    "picture": "http://placehold.it/32x32",
    "age": 22,
    "eyeColor": "blue",
    "name": {
      "first": "Harrington",
      "last": "Emerson"
    },
    "company": "ISOSURE"
  }
]

(generated with JSONGenerator btw.)

You can then convert that JSON to TeX-definitions like this:

json2tex -i values.json -o values.tex

... which generates the following values.tex file:

\newcommand{\FirstId}{5f1570db9d5aa0b6df3823f8}
\newcommand{\FirstIndex}{0}
\newcommand{\FirstGuid}{0fdfb3c5-1f0a-4c2a-8fed-75861742b588}
\newcommand{\FirstIsactive}{True}
\newcommand{\FirstBalance}{\$1,652.14}
\newcommand{\FirstPicture}{http://placehold.it/32x32}
\newcommand{\FirstAge}{22}
\newcommand{\FirstEyecolor}{blue}
\newcommand{\FirstNameFirst}{Harrington}
\newcommand{\FirstNameLast}{Emerson}
\newcommand{\FirstCompany}{ISOSURE}

Python dict/list → TeX file

import json2tex json2texfile
json2tex.json2texfile({
    "experiment": "Free Fall",
    "g": 9.81,
    "duration_s": 3,
    "equation": r"h(t) = \frac{1}{2}gt^2",
    "results": [0.0, 4.9, 19.6],
    "valid": True
},"experiment.tex")
# produces experiment.tex:
# \newcommand{\Experiment}{Free Fall}
# \newcommand{\G}{9.81}
# \newcommand{\Duration_S}{3}
# \newcommand{\Equation}{h(t) = \textbackslash frac\{1\}\{2\}gt\textasciicircum 2}
# \newcommand{\ResultsFirst}{0.0}
# \newcommand{\ResultsSecond}{4.9}
# \newcommand{\ResultsThird}{19.6}
# \newcommand{\Valid}{True}

Metadata

Release files for json2tex 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json2tex 1.3.0
File Size Uploaded Provenance
json2tex-1.3.0.tar.gz 15.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for json2tex 1.3.0
File Interpreter ABI Platform
json2tex-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 kB

Release files / json2tex-1.3.0.tar.gz

Download URL json2tex-1.3.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ed46a7bb53a46014984cea2320a6d439fddefc668f66b8e8e882eeb0f403aa40
BLAKE2b-256 checksum
How to use checksums
a40d27f4b6153895b668d880a0f9ac57ed6884393887e20a2e0466409c2260f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Release files / json2tex-1.3.0-py3-none-any.whl

Download URL json2tex-1.3.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0c623342009b8e5c6b199aa3ff3da483a51d877aaa197ff45b8a93e05e54705
BLAKE2b-256 checksum
How to use checksums
658f96c1ea8a395d03b70a8f5e5f37b2e4a3d9667b8776db4203ddd3c4fc3d16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Security for json2tex 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page