用LaTeX源码构建AI可读知识库,提升数学技术问答准确率
AI-Friendly LaTeX: Using LaTeX Code as a Knowledge Source for Retrieval-Augmented Generation

- 将LaTeX源码与辅助文件转化为结构化Markdown和JSONL
- 保留交叉引用、宏定义和章节结构等关键信息
- 适合需要高精度数学技术内容的AI问答系统
大语言模型在回答教科书、讲义和编程习题问题时,若答案基于显式知识源会更可靠。检索增强生成(RAG)是一种常见方法:在生成答案前,先检索文档相关片段并插入模型上下文。对于数学和技术内容,原始LaTeX源码比PDF更适合作为起点,因为它包含结构信息、标签、章节命令、宏定义和作者意图,这些在PDF提取中常丢失或失真。但LaTeX源码本身并不天然适合AI使用:交叉引用需解析,自定义宏需解释,练习题和示例需识别,可能还需作者提供的语义元数据。本文提出一种聚焦的预处理方法,将LaTeX源码及其编译辅助文件和可选作者注释,转化为适合向量数据库索引的Markdown和JSONL块。
原文摘要 · Abstract (English)
Large language models can answer questions about textbooks, lecture notes, and programming exercises more reliably when their answers are grounded in an explicit knowledge source. Retrieval-augmented generation (RAG) is a common approach: relevant fragments of a document are retrieved and inserted into the model context before answering. For mathematical and technical material, the original LaTeX source can be a better starting point than a PDF, because it contains structural information, labels, sectioning commands, macros, and authorial intent that are often lost or distorted in PDF extraction. However, LaTeX source is not automatically AI-friendly. Cross-references must be resolved, custom macros must be interpreted, exercises and examples must be identified, and author-supplied semantic metadata may be needed. This article describes a focused preprocessing approach for turning LaTeX source, together with its compiled auxiliary files and optional author annotations, into Markdown and JSONL chunks suitable for indexing in a vector database.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。