malachite_nz/integer/conversion/string/latex.rs
1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::integer::Integer;
10use core::fmt::{Display, Formatter, Result};
11use malachite_base::strings::latex::ToLatex;
12
13impl ToLatex for Integer {
14 /// Writes a [`Integer`] as a LaTeX math-mode fragment.
15 ///
16 /// The fragment is the number's decimal digits, preceded by a minus sign if it is negative,
17 /// which is what LaTeX math mode already writes a number as, and what [`Display`] gives.
18 ///
19 /// # Worst-case complexity
20 /// $T(n) = O(n (\log n)^2 \log\log n)$
21 ///
22 /// $M(n) = O(n \log n)$
23 ///
24 /// where $T$ is time, $M$ is additional memory, and $n$ is `self.significant_bits()`.
25 ///
26 /// # Examples
27 /// ```
28 /// use malachite_base::strings::latex::ToLatex;
29 /// use malachite_nz::integer::Integer;
30 ///
31 /// assert_eq!(Integer::from(0).to_latex_string(), "0");
32 /// assert_eq!(Integer::from(123).to_latex_string(), "123");
33 /// assert_eq!(Integer::from(-123).to_latex_string(), "-123");
34 /// ```
35 ///
36 /// | value | fragment | renders as |
37 /// |-----------------------|----------|------------|
38 /// | `Integer::from(123)` | `123` | $123$ |
39 /// | `Integer::from(-123)` | `-123` | $-123$ |
40 #[inline]
41 fn fmt_latex(&self, f: &mut Formatter) -> Result {
42 Display::fmt(self, f)
43 }
44}