#latex #matrix #nalgebra #linear-algebra

no-std nalgebra_latex

A library with several robust formatters for nalgebra::Matrix, LaTeX environments, and more

23 releases

0.1.22 Jul 20, 2022
0.1.21 Jul 19, 2022
0.1.4 Jun 26, 2022

#384 in Math

Download history 1/week @ 2024-02-20 3/week @ 2024-02-27 1/week @ 2024-03-12 30/week @ 2024-03-26 117/week @ 2024-04-02

73 downloads per month



crates.io crates.io

nalgebra extension for LaTeX

The crate provides several robust formatters for nalgebra::Matrix as well as several LaTeX environments for customization.

On top of that, the crate offers feature-gated support for nalgebra_linsys and evcxr.


use nalgebra::matrix;
use nalgebra_latex::{
	fmt::{write_latex, PlainMatrixFormatter, LatexFormatter},
	latex_modes::{InlineMathMode, DisplayMathMode, InnerParagraphMode},

let mut s = String::new();
let m = matrix!(

write_latex::<PlainMatrixFormatter,InnerParagraphMode,InlineMathMode,_,_>(&mut s, &m).unwrap();
assert_eq!(s, r"$\begin{matrix}1&2&3&4\\5&6&7&8\\9&10&11&12\end{matrix}$");
write_latex::<PlainMatrixFormatter,InnerParagraphMode,DisplayMathMode,_,_>(&mut s, &m).unwrap();
assert_eq!(s, r"$$\begin{matrix}1&2&3&4\\5&6&7&8\\9&10&11&12\end{matrix}$$");

What is nalgebra?

nalgebra is a general-purpose linear algebra library with transformations and statically-sized or dynamically-sized matrices.

What is LaTeX?

LaTeX is a language for typesetting documents, especially scientific papers, and a document preparation system.

Example of .tex code

% ...
	\glossaryentry{hadamard_product}{Hadamard product}
		\textbf{Field of study}: \textit{Mathematics. Linear Algebra. Matrix theory.} \\
		\textbf{Distinct meanings in other fields of study}: \textit{unspecified.} \\
		\begin{adjustwidth}{1em}{} \leavevmode
				For two \hyperlink{matrix}{\textit{matrices}} $A$ and $B$ of the same \hyperlink{dimension_of_matrix}{\textit{dimension}} $m \times n$, the \beingdefined{Hadamard product} $A \circ B$ (or $A \odot B$) is a \hyperlink{matrix}{\textit{matrix}} of the same \hyperlink{dimension_of_matrix}{\textit{dimension}} as the operands, with elements given by
					(A \circ B)_{ij} = (A \odot B)_{ij} = (A)_{ij}(B)_{ij}.
				Source: \cite{wiki_hadamard_product_matrices}.
				Let $A$ and $B$ be $m \times n$ \hyperlink{matrix}{\textit{matrices}} with entries in $C$. The \beingdefined{Hadamard product} is defined by $[A \circ B]_{ij}=[A]_{ij}[B]_{ij}$ for all $1 \leq i \leq m$, $1 \leq j \leq n$. \\ \vspace{1em}
				Source: \cite{emillion}.
	\end{adjustwidth} \vspace{1em}
% ...


tex output


The library is overhauled. It changes frequently and the documentation is not always available. Doc tests (examples in the documentation) generally show working code.

Resources on LaTeX


Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~93K SLoC