#!python

import argparse, json2latex, json
from os import path

parser = argparse.ArgumentParser(description="Convert a JSON file to a format accessible using LaTeX.")
parser.add_argument('json', type=str, help="The JSON file to convert.")
parser.add_argument('name', type=str, help="The LaTeX command name to save the JSON data to.")
parser.add_argument('tex', type=str, nargs="?", help="The latex file to save the output to.")

args = parser.parse_args()

with open(args.json) as json_file:
    if args.tex is None:
        args.tex = path.splitext(args.json)[0] + '.tex'
    with open(args.tex, 'w') as tex_file:
        json2latex.dump(args.name, json.load(json_file), tex_file)
