{"id":15021251,"url":"https://github.com/alvinwan/tex2py","last_synced_at":"2025-08-27T11:10:57.330Z","repository":{"id":49334659,"uuid":"55278374","full_name":"alvinwan/tex2py","owner":"alvinwan","description":"converts LaTeX into a Python parse tree, allowing navigation using the default or a custom hierarchy","archived":false,"fork":false,"pushed_at":"2018-11-30T01:38:08.000Z","size":60,"stargazers_count":92,"open_issues_count":1,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T08:01:39.214Z","etag":null,"topics":["document-tree","latex","texsoup"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alvinwan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-02T04:53:38.000Z","updated_at":"2025-01-09T20:55:44.000Z","dependencies_parsed_at":"2022-09-03T08:52:09.142Z","dependency_job_id":null,"html_url":"https://github.com/alvinwan/tex2py","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Ftex2py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Ftex2py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Ftex2py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Ftex2py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alvinwan","download_url":"https://codeload.github.com/alvinwan/tex2py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238552970,"owners_count":19491351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["document-tree","latex","texsoup"],"created_at":"2024-09-24T19:56:21.296Z","updated_at":"2025-02-12T21:30:42.416Z","avatar_url":"https://github.com/alvinwan.png","language":"Python","readme":"# LaTeX2Python (tex2py)\n\n[![Build Status](https://travis-ci.org/alvinwan/tex2py.svg?branch=master)](https://travis-ci.org/alvinwan/tex2py)\n[![Coverage Status](https://coveralls.io/repos/github/alvinwan/tex2py/badge.svg?branch=master)](https://coveralls.io/github/alvinwan/tex2py?branch=master)\n\nTex2py converts LaTeX into a Python parse tree, using [TexSoup](http://github.com/alvinwan/texsoup). This allows you to\nnavigate latex files as trees, using either the default or a custom hierarchy. See [md2py](https://github.com/alvinwan/md2py) for a markdown parse tree.\n\n\u003e Note `tex2py` currently only supports Python3.\n\ncreated by [Alvin Wan](http://alvinwan.com)\n\n# Installation\n\nInstall via pip.\n\n```\npip install tex2py\n```\n\n# Usage\n\nLaTeX2Python offers only one function `tex2py`, which generates a Python\nparse tree from Latex. This object is a navigable, \"Tree of Contents\"\nabstraction for the latex file.\n\nTake, for example, the following latex file. ([See pdf](https://github.com/alvinwan/tex2py/blob/master/tests/samples/chikin.pdf))\n\n**chikin.tex**\n\n```\n\\documentclass[a4paper]{article}\n\\begin{document}\n\n\\section{Chikin Tales}\n\n\\subsection{Chikin Fly}\n\nChickens don't fly. They do only the following:\n\n\\begin{itemize}\n\\item waddle\n\\item plop\n\\end{itemize}\n\n\\section{Chikin Scream}\n\n\\subsection{Plopping}\n\nPlopping involves three steps:\n\n\\begin{enumerate}\n\\item squawk\n\\item plop\n\\item repeat, unless ordered to squat\n\\end{enumerate}\n\n\\subsection{I Scream}\n\n\\end{document}\n```\n\nAkin to a navigation bar, the `TreeOfContents` object allows you to expand a\nlatex file one level at a time. Running `tex2py` on the above latex file\nwill generate a tree, abstracting the below structure.\n\n```\n          \u003cDocument\u003e\n          /        \\\n  Chikin Tales   Chikin Scream\n      /            /     \\\n Chikin Fly  Plopping   I Scream\n```\n\nAt the global level, we can access the title.\n\n```\n\u003e\u003e\u003e from tex2py import tex2py\n\u003e\u003e\u003e with open('chikin.tex') as f: data = f.read()\n\u003e\u003e\u003e toc = tex2py(data)\n\u003e\u003e\u003e toc.section\nChikin Tales\n\u003e\u003e\u003e str(toc.section)\n'Chikin Tales'\n```\n\nNotice that at this level, there are no `subsection`s.\n\n```\n\u003e\u003e\u003e list(toc.subsections)\n[]\n```\n\nThe main `section` has two `subsection`s beneath it. We can access both.\n\n```\n\u003e\u003e\u003e list(toc.section.subsections)\n[Chikin Fly, Chikin Scream]\n\u003e\u003e\u003e toc.section.subsection\nChikin Fly\n```\n\nThe `TreeOfContents` class also has a few more conveniences defined. Among them\nis support for indexing. To access the `i`th child of an `\u003celement\u003e` - instead of `\u003celement\u003e.branches[i]` - use `\u003celement\u003e[i]`.\n\nSee below for example usage.\n\n```\n\u003e\u003e\u003e toc.section.branches[0] == toc.section[0] == toc.section.subsection\nTrue\n\u003e\u003e\u003e list(toc.section.subsections)[1] == toc.section[1]\nTrue\n\u003e\u003e\u003e toc.section[1]\nChikin Scream\n```\n\nYou can now print the document tree. (There is some weirdness with branches beyond titles, so for only titles, we have the following:\n\n```\n           ┌Chikin Tales┐\n           │            └Chikin Fly\n [document]┤\n           │             ┌Plopping\n           └Chikin Scream┤\n                         │        \n                         │        \n                         └I Scream\n```\n\n# Additional Notes\n\n- Behind the scenes, tex2py uses [`TexSoup`](https://github.com/alvinwan/TexSoup). All tex2py objects have a\n`source` attribute containing a [TexSoup](https://github.com/alvinwan/TexSoup) object.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvinwan%2Ftex2py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falvinwan%2Ftex2py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvinwan%2Ftex2py/lists"}