markdown_ppp/latex_printer/
config.rs

1//! Configuration for LaTeX rendering
2//!
3//! This module provides configuration options to customize the LaTeX output
4//! style and format. The main configuration struct [`Config`] allows you to
5//! control table styles, code block formatting, and output width.
6
7/// Table rendering style
8///
9/// Controls how Markdown tables are converted to LaTeX table environments.
10/// Each style has different capabilities and LaTeX package requirements.
11#[derive(Debug, Clone, PartialEq)]
12pub enum TableStyle {
13    /// Basic `tabular` environment
14    ///
15    /// Uses the standard LaTeX `tabular` environment with `\hline` for borders.
16    /// This is the most compatible option and works without additional packages.
17    ///
18    /// **Requirements:** None (built into LaTeX)
19    ///
20    /// **Example output:**
21    /// ```latex
22    /// \begin{tabular}[lc]
23    /// Header 1 & Header 2 \\
24    /// \hline
25    /// Cell 1 & Cell 2 \\
26    /// \end{tabular}
27    /// ```
28    Tabular,
29
30    /// Long tables with page breaks using `longtabu`
31    ///
32    /// Uses the `longtabu` environment which can automatically break across pages.
33    /// Useful for very long tables that exceed page length.
34    ///
35    /// **Requirements:** `longtabu` package
36    ///
37    /// **Example output:**
38    /// ```latex
39    /// \begin{longtabu}[X[l] to \textwidth {lc}]
40    /// Header 1 & Header 2 \\
41    /// \\ \hline
42    /// Cell 1 & Cell 2 \\
43    /// \end{longtabu}
44    /// ```
45    Longtabu,
46
47    /// Beautiful tables using `booktabs` package
48    ///
49    /// Uses professional typography rules from the `booktabs` package.
50    /// Produces the most aesthetically pleasing tables with proper spacing
51    /// and rule weights.
52    ///
53    /// **Requirements:** `booktabs` package
54    ///
55    /// **Example output:**
56    /// ```latex
57    /// \begin{tabular}[lc]
58    /// \toprule
59    /// Header 1 & Header 2 \\
60    /// \midrule
61    /// Cell 1 & Cell 2 \\
62    /// \bottomrule
63    /// \end{tabular}
64    /// ```
65    Booktabs,
66}
67
68/// Code block rendering style
69///
70/// Controls how Markdown fenced and indented code blocks are converted
71/// to LaTeX environments. Each style offers different features for
72/// syntax highlighting and formatting.
73#[derive(Debug, Clone, PartialEq)]
74pub enum CodeBlockStyle {
75    /// Basic `verbatim` environment
76    ///
77    /// Uses the standard LaTeX `verbatim` environment. No syntax highlighting
78    /// but maximum compatibility. Language information is ignored.
79    ///
80    /// **Requirements:** None (built into LaTeX)
81    ///
82    /// **Example output:**
83    /// ```latex
84    /// \begin{verbatim}
85    /// fn main() {
86    ///     println!("Hello");
87    /// }
88    /// \end{verbatim}
89    /// ```
90    Verbatim,
91
92    /// Syntax highlighting with `listings` package
93    ///
94    /// Uses the `listings` package for syntax highlighting. Supports many
95    /// programming languages and offers extensive customization options.
96    /// Language is taken from the fenced code block info string.
97    ///
98    /// **Requirements:** `listings` package
99    ///
100    /// **Example output:**
101    /// ```latex
102    /// \begin{lstlisting}[language=rust]
103    /// fn main() {
104    ///     println!("Hello");
105    /// }
106    /// \end{lstlisting}
107    /// ```
108    Listings,
109
110    /// Advanced syntax highlighting with `minted` package
111    ///
112    /// Uses the `minted` package which leverages Pygments for superior
113    /// syntax highlighting. Requires Python and Pygments to be installed.
114    /// Supports more languages and produces better highlighting than `listings`.
115    ///
116    /// **Requirements:** `minted` package, Python, Pygments
117    ///
118    /// **Example output:**
119    /// ```latex
120    /// \begin{minted}{rust}
121    /// fn main() {
122    ///     println!("Hello");
123    /// }
124    /// \end{minted}
125    /// ```
126    Minted,
127}
128
129/// Configuration for LaTeX rendering
130///
131/// This struct controls various aspects of how the Markdown AST is converted
132/// to LaTeX. Use the builder methods to customize the output style.
133///
134/// # Examples
135///
136/// ```rust
137/// use markdown_ppp::latex_printer::config::*;
138///
139/// // Default configuration
140/// let config = Config::default();
141///
142/// // Custom configuration
143/// let config = Config::default()
144///     .with_width(120)
145///     .with_table_style(TableStyle::Booktabs)
146///     .with_code_block_style(CodeBlockStyle::Minted);
147/// ```
148pub struct Config {
149    pub(crate) width: usize,
150    pub(crate) table_style: TableStyle,
151    pub(crate) code_block_style: CodeBlockStyle,
152}
153
154impl Default for Config {
155    /// Create a default configuration
156    ///
157    /// Default settings:
158    /// - Width: 80 characters
159    /// - Table style: [`TableStyle::Tabular`]
160    /// - Code block style: [`CodeBlockStyle::Verbatim`]
161    fn default() -> Self {
162        Self {
163            width: 80,
164            table_style: TableStyle::Tabular,
165            code_block_style: CodeBlockStyle::Verbatim,
166        }
167    }
168}
169
170impl Config {
171    /// Set the line width for pretty-printing
172    ///
173    /// Controls how the pretty-printer wraps long lines. This affects the
174    /// formatting of the generated LaTeX, not the content itself.
175    ///
176    /// # Arguments
177    ///
178    /// * `width` - Maximum line width in characters
179    ///
180    /// # Examples
181    ///
182    /// ```rust
183    /// use markdown_ppp::latex_printer::config::Config;
184    ///
185    /// let config = Config::default().with_width(120);
186    /// ```
187    pub fn with_width(self, width: usize) -> Self {
188        Self { width, ..self }
189    }
190
191    /// Set the table rendering style
192    ///
193    /// Controls which LaTeX environment is used for tables and what
194    /// styling rules are applied.
195    ///
196    /// # Arguments
197    ///
198    /// * `table_style` - The desired table style
199    ///
200    /// # Examples
201    ///
202    /// ```rust
203    /// use markdown_ppp::latex_printer::config::*;
204    ///
205    /// let config = Config::default()
206    ///     .with_table_style(TableStyle::Booktabs);
207    /// ```
208    pub fn with_table_style(self, table_style: TableStyle) -> Self {
209        Self {
210            table_style,
211            ..self
212        }
213    }
214
215    /// Set the code block rendering style
216    ///
217    /// Controls which LaTeX environment is used for code blocks and
218    /// whether syntax highlighting is applied.
219    ///
220    /// # Arguments
221    ///
222    /// * `code_block_style` - The desired code block style
223    ///
224    /// # Examples
225    ///
226    /// ```rust
227    /// use markdown_ppp::latex_printer::config::*;
228    ///
229    /// let config = Config::default()
230    ///     .with_code_block_style(CodeBlockStyle::Minted);
231    /// ```
232    pub fn with_code_block_style(self, code_block_style: CodeBlockStyle) -> Self {
233        Self {
234            code_block_style,
235            ..self
236        }
237    }
238}