Programming

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.

4 answers 1 view

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

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:

  1. Coq/Rocq: The theorem prover that contains your proofs
  2. Coq-serapi: The Standard Engine API for Coq, required for Alectryon to interface with Coq
  3. Alectryon: The documentation generation tool
  4. 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:

  1. Prepare your Coq proof: Save your proof in a file with the .v extension (Coq’s standard file format)

  2. Generate reStructuredText with Alectryon:

bash
alectryon --frontend coq+rst --backend latex proof.v -o proof.rst
  1. Convert reStructuredText to LaTeX:
bash
alectryon --frontend coq+rst --backend latex proof.rst -o proof.tex
  1. Compile the LaTeX document to PDF:
bash
pdflatex proof.tex

For optimal results with mathematical symbols, especially those requiring special fonts, use XeLaTeX instead of pdfLaTeX:

bash
xelatex proof.tex

Handling Multiple Proofs

When working with multiple proofs in a single document, you can batch-process them:

bash
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:

  1. Install the Alectryon Sphinx extension:
bash
pip install alectryon.sphinx
  1. Configure your Sphinx project with the Alectryon extension:
python
extensions = [
'alectryon.sphinx',
'sphinx.ext.mathjax',
# other extensions
]
  1. Use Alectryon directives in your reStructuredText files:
rst
.. alectryon::

.. coq::

Theorem forall n m : nat, n + m = m + n.
Proof.
intros; induction n; simpl; auto.
Qed.
  1. Build your documentation:
bash
sphinx-build -b html . _build
sphinx-build -b latex . _build/latex
  1. Compile to PDF:
bash
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:

  1. For Lean proofs, use the appropriate frontend:
bash
alectryon --frontend lean+rst --backend latex proof.lean -o proof.tex
  1. 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:

  1. Style customization through CSS or LaTeX templates
  2. Symbol rendering options for different mathematical contexts
  3. Proof display preferences (show/hide certain parts, customize proof styles)
  4. 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:

  1. Structure your proofs carefully: Well-organized proofs with clear comments translate better to readable mathematical notation.

  2. Use proper Coq notation: Standard mathematical notation in Coq (like instead of forall) often produces better results.

  3. Batch processing: For large projects, process multiple proofs together to ensure consistent formatting across the document.

  4. Font considerations: Use XeLaTeX with appropriate math fonts (like STIX or Latin Modern Math) for optimal symbol rendering.

  5. 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

  1. Missing symbols: If certain mathematical symbols don’t render properly, ensure you’re using XeLaTeX and have the required math fonts installed.

  2. Compilation errors: Check that all required packages are included in your LaTeX preamble and that dependencies are properly resolved.

  3. Layout issues: Adjust Alectryon’s styling options or customize LaTeX templates to address spacing or formatting problems.

  4. 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

  1. Alectryon GitHub Repository — Documentation and source code for proof assistant documentation generation: https://github.com/cpitclaudel/alectryon
  2. Rocq Official Documentation — Comprehensive guide to the Rocq theorem prover and its documentation: https://coq.inria.fr/
  3. Coq Development Repository — Source code and documentation for the Coq/Rocq project: https://github.com/coq/coq
  4. Clément Pit-Claudel’s Profile — Developer information and contact details for Alectryon’s creator: https://github.com/cpitclaudel
  5. 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.

Clément Pit-Claudel / Assistant Professor

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 / Documentation Portal

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.

GitHub / Developer Tools

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.

Authors
Clément Pit-Claudel / Assistant Professor
Assistant Professor
Sources
GitHub / Developer Tools
Developer Tools
Rocq / Documentation Portal
Documentation Portal
Verified by moderation
NeuroAnswers
Moderation
Convert Coq/Rocq Proofs to PDF with Mathematical Symbols