Module latex_printer

Module latex_printer 

Source
Expand description

LaTeX renderer for converting Markdown AST to LaTeX.

Render AST to LaTeX using render_latex. LaTeX printer for Markdown AST

This module provides functionality to render a Markdown Abstract Syntax Tree (AST) into LaTeX format. The printer supports full CommonMark + GitHub Flavored Markdown features and offers configurable output styles.

§Features

  • Full AST coverage: All block and inline elements from CommonMark + GFM
  • Configurable table styles: tabular, longtabu, booktabs
  • Configurable code styles: verbatim, listings, minted
  • Proper LaTeX escaping: All special characters are properly escaped
  • GitHub extensions: Alerts, task lists, footnotes, strikethrough
  • Width control: Configurable line width for pretty-printing

§Basic Usage

use markdown_ppp::ast::*;
use markdown_ppp::latex_printer::{render_latex, config::Config};

let doc = Document {
    blocks: vec![
        Block::Heading(Heading {
            kind: HeadingKind::Atx(1),
            content: vec![Inline::Text("Hello LaTeX".to_string())],
        }),
        Block::Paragraph(vec![
            Inline::Text("This is ".to_string()),
            Inline::Strong(vec![Inline::Text("bold".to_string())]),
            Inline::Text(" and ".to_string()),
            Inline::Emphasis(vec![Inline::Text("italic".to_string())]),
            Inline::Text(" text with special chars: $100 & 50%.".to_string()),
        ]),
    ],
};

let latex = render_latex(&doc, Config::default());
// Produces:
// \section{Hello LaTeX}
//
// This is \textbf{bold} and \textit{italic} text with special chars: \$100 \& 50\%.

§Advanced Configuration

let config = Config::default()
    .with_width(120)
    .with_table_style(TableStyle::Booktabs)
    .with_code_block_style(CodeBlockStyle::Minted);

let latex = render_latex(&doc, config);

§LaTeX Element Mappings

MarkdownLaTeX
# Heading\section{Heading}
**bold**\textbf{bold}
*italic*\textit{italic}
~~strike~~\sout{strike}
`code`\texttt{code}
> quote\begin{quote}...\end{quote}
- list\begin{itemize}...\end{itemize}
1. ordered\begin{enumerate}...\end{enumerate}
[link](url)\href{url}{link}
![img](url)\includegraphics{url}
Tables\begin{tabular}... (configurable)
Code blocks\begin{verbatim}... (configurable)

Modules§

config
Configuration for LaTeX rendering
util
Utility functions for LaTeX rendering

Functions§

render_latex
Render the given Markdown AST to LaTeX