{"id":19345139,"url":"https://github.com/alphaharrius/texmd","last_synced_at":"2026-01-29T11:39:45.744Z","repository":{"id":260509292,"uuid":"881496653","full_name":"Alphaharrius/texmd","owner":"Alphaharrius","description":"A small library that converts LaTeX to Markdown.","archived":false,"fork":false,"pushed_at":"2024-11-26T09:22:10.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T23:48:15.285Z","etag":null,"topics":["latex","markdown","python-package","python3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/texmd/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alphaharrius.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-31T17:30:39.000Z","updated_at":"2024-11-26T09:22:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"56707b11-0437-4f41-addd-3c7abd1a39df","html_url":"https://github.com/Alphaharrius/texmd","commit_stats":null,"previous_names":["alphaharrius/texmd"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alphaharrius%2Ftexmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alphaharrius%2Ftexmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alphaharrius%2Ftexmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alphaharrius%2Ftexmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alphaharrius","download_url":"https://codeload.github.com/Alphaharrius/texmd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250372460,"owners_count":21419719,"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":["latex","markdown","python-package","python3"],"created_at":"2024-11-10T04:05:05.456Z","updated_at":"2026-01-29T11:39:43.991Z","avatar_url":"https://github.com/Alphaharrius.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# texmd\nA small library that converts LaTeX to Markdown.\nThis package uses `pylatexenc` to parse the LaTeX expressions.\n\nCurrently, it supports converting inlined mathematical equations `$...$`, \nequation blocks (`equation`, `equation*`, `align`, `align*`, `array`, `matrix`, `eqnarray`, `multline`), \ntitle `\\title`, sections (`\\section`, `\\subsection`, `subsubsection`); abstract content `\\abstract{...}` \n(supported by Markdown block quote); in-text quotations ``` ``...'' ```; equation numbered labels are also supported.\nMore will be introduced in later versions.\n\n## Installation\nRun ```pip install texmd``` in the terminal.\n\n## Usage\nThis package allows you to load a `.tex` file directly.\n```python\nfrom texmd import tex # Import the package\n\nparser = tex.TexParser()\nfile_path = \"\u003cPATH_TO_TEX_FILE\u003e\"\ntex_file = parser.load_file(file_path) # Load the file\n```\nThe loaded file ```tex_file``` is type of ```texmd.texmd.TexDocument```.\n\nIf you want to parse the LaTeX string directly you can also do\n```python\ntex_expr = \"\u003cTEX_EXPR\u003e\"\ntex_file = parser.parse(tex_expr)\n```\n\nWe can convert then it to Markdown by\n```python\ndocument = parser.to_md(tex_file)\n```\nThe output `document` is type of ```texmd.md.MdDocument```.\nTo output the `document` as Markdown syntax we can do\n```python\nmd = document.to_str()\n```\nand you can write it to a `.md` file.\n\n## Add BibTeX support\nIn order for the package to also process BibTeX we will have to load the `.bib` file.\n```python\nparser.load_citations(\"\u003cBIB_FILE_PATH\u003e\")\n```\n\n## Customization\nIf you don't like the way the package write the Markdown, or you want to support custom LaTeX expressions,\nyou can use the API ```parser.set_converter``` with a specific sub-type of `texmd.tex.TexNode`.\n\nFor example you want to set a new converter for text node.\n```python\nclass TextNodeConverter(Converter):\n    \"\"\" A converter for LaTeX text nodes. \"\"\"\n\n    def __init__(self):\n        super().__init__(None)\n\n    def convert(self, node: TexTextNode) -\u003e Generator[MdNode]:\n        def _():\n            yield MdText(text=node.text)\n        return _()\n\nconverter = TextNodeConverter()\nparser.set_converter(TexTextNode, '', converter)\n```\n\nThe default Citation converter is implemented as follows,\n```python\nclass CiteConverter(Converter):\n    \"\"\" A converter for LaTeX cite nodes. \"\"\"\n\n    def __init__(self, parser: 'TexParser'):\n        super().__init__(parser)\n\n    def convert(self, node: TexMacroNode) -\u003e Generator[MdNode]:\n        def write_author(author: bib.Author) -\u003e str:\n            first_abbr = author.first_name[0] + '.' if author.first_name else ''\n            middle_abbr = author.middle_name[0] + '.' if author.middle_name else ''\n            return f\"{first_abbr} {middle_abbr} {author.last_name}\"\n        \n        def write_entry(entry: bib.Entry) -\u003e str:\n            content: List[str] = [*(write_author(author) for author in entry.authors), entry.title, entry.year]\n            return \", \".join(content)\n\n        def _():\n            chars: TexTextNode = node.children[0].children[0]\n            cite_names = chars.text.replace(' ', '').split(',')\n            citations = (self.parser._get_citation(name) for name in cite_names)\n            citations = (write_entry(entry) for entry in citations if entry)\n            yield MdText(text=\"(*\" + \", \".join(citations) + \"*)\")\n        return _()\n```\nIf you want a different style you can implement a new one and load it via\n```python\nclass YourCiteConverter(Converter)\n    ...\n\nconverter = YourCiteConverter(parser)\nparser.set_converter(TexMacroNode, 'cite', converter)\n```\nAnd you can obtain the citation entries via ```texmd.tex.TexParser._get_citation```\nin the format of ```texmd.bib.Entry```.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphaharrius%2Ftexmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphaharrius%2Ftexmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphaharrius%2Ftexmd/lists"}