Abstract
LaTeX2Solver is an interactive system designed to automate the translation of mathematical optimization models from LaTeX documents into executable solver code. By integrating deep learning-based information extraction with grammar-based math parsing, the system bridges the gap between theoretical formulation and practical implementation. This paper describes a hierarchical pipeline that segments documents, extracts entities, and generates symbolic models, allowing Operations Research practitioners to maintain synchronization between documentation and code while reducing cognitive burden through a human-in-the-loop interface.
Introduction
In Operations Research (OR), practitioners frequently encounter a "double-work" bottleneck. Complex optimization problems, such as supply chain logistics or energy grid management, are first formulated in LaTeX for documentation and academic reporting. Subsequently, these formulas must be manually translated into solver-specific programming languages like Python, Gurobi, or CPLEX.
This manual translation is not only time-consuming but also carries a high cognitive risk; a single typo in a constraint can lead to infeasible models or incorrect optimal solutions. Furthermore, maintaining synchronization between LaTeX documentation and production code is a persistent challenge. While Large Language Models (LLMs) show promise, they often struggle with mathematical logic hallucinations and the unstructured nature of scientific documents. LaTeX2Solver addresses these issues by providing an automated, verifiable pipeline.
Methodology
The LaTeX2Solver system employs a hierarchical pipeline that decomposes the translation process into three distinct stages:
- Hierarchical Declaration Extraction: The system segments the LaTeX document into "declarations"—blocks of text defining specific model elements like sets, parameters, or constraints. This stage utilizes a SciBERT sentence encoder with a Bi-LSTM layer to predict segment boundaries and labels.
- Entity and Relation Extraction: Within each declaration, the system identifies key entities, including math spans, metadata tags, and semantic descriptions. This is framed as a Machine Reading Comprehension (MRC) task, where the model extracts specific entity types from the text.
- Symbolic Model Parsing & Code Generation: The extracted math is processed by a grammar-based parser (ANTLR4) to create a symbolic parse tree. This tree is then converted into a Symbolic Model, a unified intermediate representation of the problem logic. Finally, a code generator uses Python metaprogramming to instantiate this model with user-provided data for the solver API.
Key Insights
Decoupling Logic from Data
A core innovation of LaTeX2Solver is the use of a "Symbolic Model." By separating mathematical structure from specific data parameters, the system allows users to define a problem template once and swap data files to test various scenarios without re-coding the logic.
Hybrid Parsing Approach
To ensure reliability, the authors avoid relying solely on neural networks for math translation. Instead, they use neural models for the "messy" natural language components (segmentation and entity recognition) and strict, grammar-based parsers for the precise mathematical logic. This hybrid approach significantly mitigates the risk of logical errors common in pure neural architectures.
System Demonstration and Results
As a system demonstration, the primary result is the functional software that transforms unstructured LaTeX documents into structured, editable graphs. The use of SciBERT with a custom rule-based symbol tokenizer proved essential for handling the specific syntactic structures of scientific LaTeX.
The system features a graphical interface where the symbolic model is displayed as a series of "cards." Users can interactively edit extracted logic before code generation, ensuring 100% accuracy through a human-in-the-loop verification process. This reduces mental overhead for OR experts, allowing them to focus on design rather than syntax debugging.
Limitations and Future Work
Despite its successes, the system faces challenges regarding information density; it currently assumes each declaration contains all necessary information for a model element. If definitions are scattered across multiple paragraphs, the parser may struggle. Additionally, the system is sensitive to the quality of the LaTeX source. Future work may involve integrating general-purpose LLMs to handle more complex unstructured descriptions while retaining the symbolic safety checks of the current architecture.
Summary updated