Convert Coq/Rocq Proofs to PDF with Mathematical Symbols
Learn how to convert Coq/Rocq proofs to PDF with proper mathematical symbols using Alectryon and LaTeX. Step-by-step guide for professional documentation.
How can I convert mathematical proofs from Rocq/Coq or similar interactive theorem proving tools into PDF documents with proper mathematical symbols instead of code syntax? What combination of theorem proving tool and automatic documentation generation software should I use, and what are the specific steps to implement this workflow?
The primary solution for converting Coq/Rocq proofs to PDF documents with proper mathematical symbols involves using Alectryon, a specialized tool that transforms code syntax into professionally formatted mathematical notation. This workflow combines the theorem proving power of Coq/Rocq with Alectryon’s documentation generation capabilities and LaTeX’s typesetting to create publication-ready PDFs with correct mathematical symbols and formatting.
Contents
- Understanding Coq/Rocq and Proof Documentation Needs
- Alectryon: The Primary Tool for Converting Coq Proofs to PDF
- Step-by-Step Workflow: Coq to PDF with Mathematical Symbols
- Advanced Options: Sphinx Integration and Multi-Assistant Support
- Best Practices and Troubleshooting
Understanding Coq/Rocq and Proof Documentation Needs
Coq (recently renamed to Rocq) is an industrial-strength interactive theorem prover that provides a formal language for writing mathematical definitions, executable algorithms, and machine-checked proofs. When working with formal verification or mathematical proof development, you often need to share your work in a format that’s accessible to mathematicians and scientists who may not be familiar with proof assistant syntax. The challenge lies in converting the code-like notation of Coq/Rocq into conventional mathematical notation that can be easily read and understood in PDF documents.
Rocq’s documentation sources are located in the doc directory of the repository, and while the tool itself focuses on proof development rather than document generation, it forms the foundation for various documentation solutions. When working with mathematical proofs, proper symbol rendering is essential for clarity and professional presentation. This is where specialized conversion tools like Alectryon become invaluable, as they bridge the gap between the interactive proof environment and traditional mathematical publishing.
Alectryon: The Primary Tool for Converting Coq Proofs to PDF
Alectryon is the specialized tool designed specifically for converting Coq or Lean snippets into properly formatted mathematical documents. Developed by Clément Pit-Claudel, an Assistant Professor heading the SYSTEMF lab at EPFL, Alectryon transforms code syntax into rendered mathematical symbols in PDF output, addressing the core challenge of making formal proofs accessible to a broader audience.
The tool works by parsing Coq proof fragments and converting them into LaTeX representations that include proper mathematical notation, typesetting, and formatting. This process ensures that logical operators, quantifiers, variables, and other mathematical elements appear in their standard mathematical forms rather than as programming constructs. Alectryon supports various output formats including LaTeX, HTML, and reStructuredText, making it versatile for different documentation needs. For PDF generation specifically, LaTeX integration provides the highest quality mathematical typesetting, complete with proper symbol rendering, spacing, and layout.
The tool’s architecture allows it to handle both simple standalone proofs and complex document structures containing multiple proof assistants. This flexibility makes it suitable not just for individual researchers but also for teams working on large formalization projects that require polished documentation.
Step-by-Step Workflow: Coq to PDF with Mathematical Symbols
Prerequisites
Before you begin the conversion process, ensure you have the following components installed:
- Coq/Rocq: The theorem prover that contains your proofs
- Coq-serapi: The Standard Engine API for Coq, required for Alectryon to interface with Coq
- Alectryon: The documentation generation tool
- LaTeX distribution: Such as TeX Live, MiKTeX, or MacTeX (for PDF compilation)
Basic Conversion Process
The fundamental workflow involves processing your Coq proofs through Alectryon to generate LaTeX files, which can then be compiled into PDFs. Here’s the step-by-step implementation:
-
Prepare your Coq proof: Save your proof in a file with the
.vextension (Coq’s standard file format) -
Generate reStructuredText with Alectryon:
alectryon --frontend coq+rst --backend latex proof.v -o proof.rst
- Convert reStructuredText to LaTeX:
alectryon --frontend coq+rst --backend latex proof.rst -o proof.tex
- Compile the LaTeX document to PDF:
pdflatex proof.tex
For optimal results with mathematical symbols, especially those requiring special fonts, use XeLaTeX instead of pdfLaTeX:
xelatex proof.tex
Handling Multiple Proofs
When working with multiple proofs in a single document, you can batch-process them:
alectryon --frontend coq+rst --backend latex *.v -o combined.tex xelatex combined.tex
This approach efficiently combines multiple Coq proofs into a single LaTeX document that can be compiled into a cohesive PDF with consistent formatting and proper mathematical symbols throughout.
Advanced Options: Sphinx Integration and Multi-Assistant Support
Sphinx Integration
For more complex documentation projects, Alectryon integrates seamlessly with Sphinx, the popular documentation generator. This integration allows for automated processing of multiple proofs within a structured documentation framework:
- Install the Alectryon Sphinx extension:
pip install alectryon.sphinx
- Configure your Sphinx project with the Alectryon extension:
extensions = [
'alectryon.sphinx',
'sphinx.ext.mathjax',
# other extensions
]
- Use Alectryon directives in your reStructuredText files:
.. alectryon::
.. coq::
Theorem forall n m : nat, n + m = m + n.
Proof.
intros; induction n; simpl; auto.
Qed.
- Build your documentation:
sphinx-build -b html . _build sphinx-build -b latex . _build/latex
- Compile to PDF:
cd _build/latex
xelatex main.tex
Multi-Assistant Support
Alectryon’s versatility extends beyond Coq, supporting other proof assistants such as Lean. This multi-assistant capability is particularly valuable for projects that involve multiple verification tools:
- For Lean proofs, use the appropriate frontend:
alectryon --frontend lean+rst --backend latex proof.lean -o proof.tex
- Mixed assistant documentation can be processed by specifying the appropriate frontend for each file type.
Customizing Output
Alectryon offers extensive customization options to tailor the appearance of your mathematical proofs:
- Style customization through CSS or LaTeX templates
- Symbol rendering options for different mathematical contexts
- Proof display preferences (show/hide certain parts, customize proof styles)
- Cross-references and navigation elements in larger documents
These customization features ensure that your final PDF documents not only contain proper mathematical symbols but also maintain a professional appearance consistent with your publication standards.
Best Practices and Troubleshooting
Optimization Tips
To achieve the best results when converting Coq/Rocq proofs to PDF with mathematical symbols:
-
Structure your proofs carefully: Well-organized proofs with clear comments translate better to readable mathematical notation.
-
Use proper Coq notation: Standard mathematical notation in Coq (like
∀instead offorall) often produces better results. -
Batch processing: For large projects, process multiple proofs together to ensure consistent formatting across the document.
-
Font considerations: Use XeLaTeX with appropriate math fonts (like STIX or Latin Modern Math) for optimal symbol rendering.
-
Version management: Be aware that different Coq/Rocq versions might affect proof export workflows, as noted in the Recent changes chapter of the reference manual.
Common Issues and Solutions
-
Missing symbols: If certain mathematical symbols don’t render properly, ensure you’re using XeLaTeX and have the required math fonts installed.
-
Compilation errors: Check that all required packages are included in your LaTeX preamble and that dependencies are properly resolved.
-
Layout issues: Adjust Alectryon’s styling options or customize LaTeX templates to address spacing or formatting problems.
-
Complex proofs: For very long or intricate proofs, consider breaking them into smaller, more manageable sections.
Community Resources
When you encounter challenges, leverage the vibrant formal methods community:
- Rocq/Zulip chat: Real-time discussions with other Rocq users
- Discourse forum: Asynchronous discussions and problem-solving
- GitHub issues: Report bugs or request features for Alectryon
- Documentation: Comprehensive guides available through Rocq’s official documentation portal
By following these best practices and utilizing community resources, you can efficiently convert your Coq/Rocq proofs into polished PDF documents that showcase your mathematical work with proper symbols and professional presentation.
Sources
- Alectryon GitHub Repository — Documentation and source code for proof assistant documentation generation: https://github.com/cpitclaudel/alectryon
- Rocq Official Documentation — Comprehensive guide to the Rocq theorem prover and its documentation: https://coq.inria.fr/
- Coq Development Repository — Source code and documentation for the Coq/Rocq project: https://github.com/coq/coq
- Clément Pit-Claudel’s Profile — Developer information and contact details for Alectryon’s creator: https://github.com/cpitclaudel
- Rocq Installation Guide — Instructions for installing Coq/Rocq and related tools: https://rocq-prover.org/install
Conclusion
Converting mathematical proofs from Coq/Rocq to PDF with proper mathematical symbols is efficiently accomplished using Alectryon in combination with LaTeX. This workflow transforms code-like proof notation into professionally typeset mathematical documents that are accessible to a broader audience of mathematicians and scientists. The process requires installing Coq-serapi and Alectryon, then using commands like alectryon --frontend coq+rst --backend latex proof.rst -o proof.tex to generate LaTeX files that can be compiled with XeLaTeX for optimal symbol rendering. For larger documentation projects, Alectryon integrates with Sphinx, providing automated processing and consistent formatting across multiple proofs. By following the outlined steps and best practices, researchers and formal verification specialists can create polished PDF documentation that accurately represents their mathematical work with proper symbols and professional presentation.
Alectryon is the specialized tool that converts Coq or Lean snippets into properly formatted mathematical documents. It transforms code syntax into rendered mathematical symbols in PDF output. The process requires installing Coq-serapi and Alectryon, then using commands like alectryon --frontend coq+rst --backend latex proof.rst -o proof.tex to generate LaTeX files. These LaTeX files can be compiled with pdflatex or xelatex to create PDFs with correct mathematical symbols. For complex documentation, Alectryon integrates with Sphinx through the alectryon.sphinx extension, allowing automated processing of multiple proofs in a single document.
Rocq (formerly Coq) is an industrial-strength interactive theorem prover that provides a formal language for writing mathematical definitions, executable algorithms, and machine-checked proofs. The documentation sources are located in the doc directory of the repository. While Rocq itself focuses on proof development rather than document generation, it forms the foundation for tools like Alectryon that convert proofs into publication-ready formats with proper mathematical symbols. The project maintains comprehensive documentation including reference manuals, standard library documentation, and ML API documentation, which can serve as examples of properly formatted mathematical content.

The Coq/Rocq prover is an interactive proof assistant that allows users to write mathematical definitions, algorithms, and theorems with machine-checked proofs. Installation instructions are available at rocq-prover.org/install, and documentation sources are in the doc directory. The project provides continuous documentation builds including reference manuals, standard library documentation, and ML API documentation. The Recent changes chapter in the reference manual explains version differences and incompatibilities, which is important when upgrading versions that might affect proof export workflows. The community offers support through Zulip chat, Discourse forum, and other platforms.