Skip to main content

Convert a JSON document to LaTeX commands

Project description

📝 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}

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

json2tex-1.3.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

json2tex-1.3.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file json2tex-1.3.0.tar.gz.

File metadata

  • Download URL: json2tex-1.3.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for json2tex-1.3.0.tar.gz
Algorithm Hash digest
SHA256 ed46a7bb53a46014984cea2320a6d439fddefc668f66b8e8e882eeb0f403aa40
MD5 f64a9e5ab63497242a97462a287fb133
BLAKE2b-256 a40d27f4b6153895b668d880a0f9ac57ed6884393887e20a2e0466409c2260f2

See more details on using hashes here.

File details

Details for the file json2tex-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: json2tex-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for json2tex-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c623342009b8e5c6b199aa3ff3da483a51d877aaa197ff45b8a93e05e54705
MD5 ac0d061b6bf635c6b4654778abc878de
BLAKE2b-256 658f96c1ea8a395d03b70a8f5e5f37b2e4a3d9667b8776db4203ddd3c4fc3d16

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