Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
mat_latex.H File Reference

Matrix to LaTeX table conversion utilities. More...

#include <fstream>
#include <ostream>
#include <string>
Include dependency graph for mat_latex.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::Default_Row_Formatter< Mat >
 Default row index formatter. More...
 
struct  Aleph::Default_Col_Formatter< Mat >
 Default column index formatter. More...
 
struct  Aleph::Default_Entry_Formatter< Mat >
 Default entry formatter. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Functions

template<typename Mat , class RowIndexFormatter , class ColIndexFormatter , class EntryFormatter >
void Aleph::mat_to_latex (Mat &mat, long n, long m, std::ostream &out, const std::string &prefix="", const std::string &suffix="")
 Generate LaTeX tabular representation of a matrix.
 
template<typename Mat , class RowIndexFormatter , class ColIndexFormatter , class EntryFormatter >
void Aleph::mat_to_latex (Mat &mat, long n, long m, std::ofstream &out, const std::string &prefix="", const std::string &suffix="")
 Overload for std::ofstream output.
 
template<typename Mat >
void Aleph::mat_to_latex_simple (Mat &mat, long n, long m, std::ostream &out, const std::string &prefix="", const std::string &suffix="")
 Generate LaTeX table with default formatters.
 

Detailed Description

Matrix to LaTeX table conversion utilities.

This file provides utilities for generating LaTeX tabular representations of matrices. It is particularly useful for visualizing adjacency matrices, distance matrices from Floyd-Warshall, and path matrices.

Features

  • Customizable row and column index formatting
  • Customizable cell content formatting
  • Support for prefix and suffix LaTeX content
  • Works with any matrix-like container

Usage Example

#include <mat_latex.H>
#include <fstream>
// Formatter for row indices
struct RowFormatter {
std::string operator()(const MyMatrix& m, long i) const {
return std::to_string(i);
}
};
// Formatter for column indices
struct ColFormatter {
std::string operator()(const MyMatrix& m, long j) const {
return std::to_string(j);
}
};
// Formatter for matrix entries
struct EntryFormatter {
std::string operator()(const MyMatrix& m, long i, long j) const {
return std::to_string(m(i, j));
}
};
std::ofstream out("matrix.tex");
mat_to_latex<MyMatrix, RowFormatter, ColFormatter, EntryFormatter>(
matrix, n, m, out, "\\begin{center}\n", "\\end{center}\n");
Matrix to LaTeX table conversion utilities.

Generated LaTeX Format

The function generates a tabular environment with:

  • Column headers from the column formatter
  • Row headers from the row formatter
  • Cell contents from the entry formatter
  • Horizontal lines at top and bottom
See also
latex_floyd.H For Floyd-Warshall specific LaTeX output
tpl_matgraph.H For matrix-based graph representations
Author
Leandro Rabindranath León

Definition in file mat_latex.H.