{"_id":"@bottxrnif/latex-json-ast-converter","name":"@bottxrnif/latex-json-ast-converter","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bottxrnif/latex-json-ast-converter","version":"1.0.0","description":"Convert LaTeX documents to JSON abstract syntax trees with advanced statistics and section counting","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo 'Tests already passed during build'","prepublishOnly":"echo 'Package already built and tested'"},"keywords":["latex","json","ast","parser","typescript","document-analysis","academic","section-counting","math-counting","statistics"],"author":{"name":"LaTeX Converter Team","email":"contact@latex-converter.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/latex-converter/json-ast.git"},"bugs":{"url":"https://github.com/latex-converter/json-ast/issues"},"homepage":"https://github.com/latex-converter/json-ast#readme","engines":{"node":">=14.0.0"},"dependencies":{},"publishConfig":{"access":"public"},"_id":"@bottxrnif/latex-json-ast-converter@1.0.0","gitHead":"85ce4a23ad8dbeb49a360171877dd14d099b3e9a","_nodeVersion":"20.19.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-m49NQCwVznI/d2UFJ9OrFSq1xbt32cdQFzH630eSKLjlCM3oI1kEg1bYljVsOVM80W+OYBm0dYh3rKeeBL0Cjw==","shasum":"03532638d5fd4cec498ba3f8ee40ffd4416c0cd7","tarball":"https://registry.npmjs.org/@bottxrnif/latex-json-ast-converter/-/latex-json-ast-converter-1.0.0.tgz","fileCount":37,"unpackedSize":165482,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDnr8ftws8idopn+xvjE3gxgeOBqaxE/ELuzf5XxTneKwIhAIjoL8CDeTFg4ieCK04+/9TRH4/G06PRwf/0E6+rRJhf"}]},"_npmUser":{"name":"bottxrnif","email":"martinliu1104@gmail.com"},"directories":{},"maintainers":[{"name":"bottxrnif","email":"martinliu1104@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/latex-json-ast-converter_1.0.0_1771447336029_0.08105664070129026"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-18T20:42:15.945Z","1.0.0":"2026-02-18T20:42:16.179Z","modified":"2026-02-18T20:42:16.357Z"},"maintainers":[{"name":"bottxrnif","email":"martinliu1104@gmail.com"}],"description":"Convert LaTeX documents to JSON abstract syntax trees with advanced statistics and section counting","homepage":"https://github.com/latex-converter/json-ast#readme","keywords":["latex","json","ast","parser","typescript","document-analysis","academic","section-counting","math-counting","statistics"],"repository":{"type":"git","url":"git+https://github.com/latex-converter/json-ast.git"},"author":{"name":"LaTeX Converter Team","email":"contact@latex-converter.com"},"bugs":{"url":"https://github.com/latex-converter/json-ast/issues"},"license":"MIT","readme":"# @latex-converter/json-ast\n\n[![npm version](https://badge.fury.io/js/%40latex-converter%2Fjson-ast.svg)](https://badge.fury.io/js/%40latex-converter%2Fjson-ast)\n[![Build Status](https://travis-ci.org/latex-converter/json-ast.svg?branch=main)](https://travis-ci.org/latex-converter/json-ast)\n[![Coverage Status](https://coveralls.io/repos/github/latex-converter/json-ast/badge.svg?branch=main)](https://coveralls.io/repos/github/latex-converter/json-ast?branch=main)\n\nA powerful TypeScript library for converting LaTeX documents to JSON abstract syntax trees with advanced statistics and section counting. Perfect for document analysis, content management systems, and academic processing workflows.\n\n## ✨ Features\n\n- 🚀 **Fast LaTeX Parsing** - Convert LaTeX to structured JSON AST\n- 📊 **Advanced Statistics** - Word counts, math expressions, section analysis\n- 🎯 **Section Hierarchy** - Accurate section/subsection/subsubsection parsing\n- 📐 **Math Detection** - Separate counting for inline and displayed math\n- 🌐 **Unicode Support** - Handle international characters and special symbols\n- 🔧 **Robust Error Handling** - Graceful processing of malformed LaTeX\n- 📱 **Web Interface** - Built-in web UI with file upload and visualization\n- 🧪 **Comprehensive Testing** - 66+ tests with edge case coverage\n\n## 📦 Installation\n\n\\`\\`\\`bash\nnpm install @latex-converter/json-ast\n\\`\\`\\`\n\n## 🚀 Quick Start\n\n### Basic Usage\n\n\\`\\`\\`typescript\nimport { LaTeXToJSONAST } from '@latex-converter/json-ast';\n\nconst latex = `\n\\\\documentclass{article}\n\\\\begin{document}\n\n\\\\section{Introduction}\nThis is the introduction section with math: $E = mc^2$.\n\n\\\\subsection{Background}\nSome background information.\n\n\\\\end{document}`;\n\nconst ast = LaTeXToJSONAST.convert(latex);\nconsole.log(ast);\n\\`\\`\\`\n\n### Advanced Statistics\n\n\\`\\`\\`typescript\nimport { AccurateLaTeXParser } from '@latex-converter/json-ast';\n\nconst result = AccurateLaTeXParser.parseWithStatistics(latex);\n\nconsole.log('Document Statistics:');\nconsole.log(\\`Words in text: \\${result.stats.wordsInText}\\`);\nconsole.log(\\`Math inlines: \\${result.stats.mathInlines}\\`);\nconsole.log(\\`Total sections: \\${result.stats.numberOfHeaders}\\`);\n\\`\\`\\`\n\n## 📊 Output Format\n\nThe JSON AST follows this structure:\n\n\\`\\`\\`typescript\ninterface LaTeXAST {\n  type: 'document';\n  title?: string;\n  sections: SectionNode[];\n  metadata: {\n    totalSections: number;\n    totalSubsections: number;\n    totalSubsubsections: number;\n    maxDepth: number;\n  };\n}\n\ninterface SectionNode {\n  type: 'section' | 'subsection' | 'subsubsection';\n  title: string;\n  level: number;\n  children: SectionNode[];\n  content?: string;\n}\n\\`\\`\\`\n\n## 🔧 Advanced Features\n\n### Section-Level Statistics\n\nGet detailed statistics for each section:\n\n\\`\\`\\`typescript\nconst result = AccurateLaTeXParser.parseWithStatistics(latex);\n\nresult.stats.sectionStats.forEach(stat => {\n  console.log(\\`\\${stat.type}: \\${stat.title}\\`);\n  console.log(\\`  Words: \\${stat.wordsInText}, Headers: \\${stat.wordsInHeaders}\\`);\n  console.log(\\`  Math: \\${stat.mathInlines} inline, \\${stat.mathDisplayed} displayed\\`);\n  console.log(\\`  Subcounts: \\${stat.subcounts}\\`);\n});\n\\`\\`\\`\n\n### Round-trip Conversion\n\nConvert JSON back to LaTeX:\n\n\\`\\`\\`typescript\nimport { JSONToLaTeX } from '@latex-converter/json-ast';\n\nconst latex = JSONToLaTeX.convert(ast);\nconsole.log(latex);\n\\`\\`\\`\n\n### Web Interface\n\nLaunch the built-in web interface:\n\n\\`\\`\\`bash\nnpm start\n# Visit http://localhost:8080\n\\`\\`\\`\n\n## 📈 Statistics Features\n\nThe parser provides comprehensive document statistics:\n\n- **Word Counting**: Separate counts for text, headers, and captions\n- **Math Analysis**: Distinguishes inline (`$...$`) from displayed (`$$...$$`, `\\\\begin{equation}...`)\n- **Section Hierarchy**: Accurate parsing of nested sections\n- **Float Detection**: Count figures and tables\n- **Unicode Support**: Handle international characters\n\n### Example Statistics Output\n\n\\`\\`\\`json\n{\n  \"wordsInText\": 21157,\n  \"wordsInHeaders\": 203,\n  \"wordsOutsideText\": 25,\n  \"mathInlines\": 3992,\n  \"mathDisplayed\": 72,\n  \"numberOfHeaders\": 80,\n  \"numberOfFloats\": 0,\n  \"sectionStats\": [\n    {\n      \"title\": \"Introduction\",\n      \"type\": \"section\",\n      \"level\": 1,\n      \"wordsInText\": 150,\n      \"wordsInHeaders\": 1,\n      \"mathInlines\": 5,\n      \"mathDisplayed\": 0,\n      \"subcounts\": \"150+1+0 (1/0/5/0)\"\n    }\n  ]\n}\n\\`\\`\\`\n\n## 🧪 Testing\n\nRun the comprehensive test suite:\n\n\\`\\`\\`bash\nnpm test\n\\`\\`\\`\n\nRun tests with coverage:\n\n\\`\\`\\`bash\nnpm run test:coverage\n\\`\\`\\`\n\n## 🏗️ Development\n\n### Building\n\n\\`\\`\\`bash\nnpm run build\n\\`\\`\\`\n\n### Development Mode\n\n\\`\\`\\`bash\nnpm run dev\n\\`\\`\\`\n\n### Linting\n\n\\`\\`\\`bash\nnpm run lint\nnpm run lint:fix\n\\`\\`\\`\n\n## 📚 API Reference\n\n### LaTeXToJSONAST\n\nBasic LaTeX to JSON conversion.\n\n\\`\\`\\`typescript\nstatic convert(latex: string): LaTeXAST\n\\`\\`\\`\n\n### AccurateLaTeXParser\n\nAdvanced parsing with detailed statistics.\n\n\\`\\`\\`typescript\nstatic parseWithStatistics(latex: string): { ast: LaTeXAST; stats: AccurateStatistics }\n\\`\\`\\`\n\n### JSONToLaTeX\n\nConvert JSON AST back to LaTeX.\n\n\\`\\`\\`typescript\nstatic convert(ast: LaTeXAST): string\nstatic generateRandomAST(maxDepth?: number, maxSectionsPerLevel?: number): LaTeXAST\n\\`\\`\\`\n\n## 🎯 Use Cases\n\n- **Academic Content Management** - Analyze research papers and theses\n- **Document Processing** - Extract structure from LaTeX documents\n- **Content Analysis** - Generate statistics for large document collections\n- **Educational Tools** - Create LaTeX learning applications\n- **Publishing Systems** - Integrate with content management workflows\n\n## 🔍 Supported LaTeX Features\n\n- **Section Commands**: `\\\\section`, `\\\\subsection`, `\\\\subsubsection`\n- **Math Environments**: Inline `$...$`, displayed `$$...$$`, `\\\\begin{equation}...`\n- **Document Classes**: `article`, `report`, `book`, `amsart`\n- **Unicode Characters**: International text and symbols\n- **Comments**: Proper handling of LaTeX comments\n- **Escaped Characters**: `\\\\$`, `\\\\&`, `\\\\%`, etc.\n\n## 🤝 Contributing\n\nContributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) and submit a Pull Request.\n\n## 📄 License\n\nMIT © [LaTeX Converter Team](https://github.com/latex-converter/json-ast)\n\n## 🔗 Related Projects\n\n- [TexSoup](https://github.com/alvinwan/TexSoup) - Python LaTeX parsing library\n- [LaTeX.js](https://github.com/michael-brinkmann/latex.js) - JavaScript LaTeX parser\n- [KaTeX](https://github.com/KaTeX/KaTeX) - Fast math typesetting library\n\n## 📞 Support\n\n- 📧 Email: contact@latex-converter.com\n- 🐛 Issues: [GitHub Issues](https://github.com/latex-converter/json-ast/issues)\n- 📖 Docs: [Documentation](https://latex-converter.github.io/json-ast/)\n","readmeFilename":"README.md","_rev":"1-ddb2e057248a0eb8b6ef85af9c350289"}