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.2.0.tar.gz (15.0 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.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for json2tex-1.2.0.tar.gz
Algorithm Hash digest
SHA256 14da72a1ce4948f8d776447fc6cafa605a1e51426795b4fffcc2c9c5fc7a896d
MD5 71d1932fe27f9e3beba1b01da0632783
BLAKE2b-256 12576ca724cec615a72f645138f352116c608910bd2e7263bcf849d2a4575835

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for json2tex-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2caa70596d903df14ae52a6db12be4eb053e02264c83d495c11e1f42cb9a11a
MD5 50c38e44449d25738d7e039bc912c201
BLAKE2b-256 7b75a045a0499a88fb10b326b2bd9b360377cf89f396ad4b99e69663cffdab3c

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