Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
mat_latex.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
94#ifndef MAT_LATEX_H
95#define MAT_LATEX_H
96
97#include <fstream>
98#include <ostream>
99#include <string>
100
101namespace Aleph
102{
103
139template <typename Mat,
140 class RowIndexFormatter,
141 class ColIndexFormatter,
142 class EntryFormatter>
143void mat_to_latex(Mat & mat,
144 long n,
145 long m,
146 std::ostream & out,
147 const std::string & prefix = "",
148 const std::string & suffix = "")
149{
150 out << prefix;
151 out << "\\begin{tabular}{|c|";
152
153 for (long j = 0; j < m; ++j)
154 out << "p{1mm}";
155
156 out << "|} \\hline\n& ";
157
158 // Column headers
159 for (long j = 0; j < m; ++j)
160 {
161 out << ColIndexFormatter()(mat, j);
162 if (j < m - 1)
163 out << " & ";
164 else
165 out << "\\\\ \\hline\n";
166 }
167
168 // Matrix rows
169 for (long i = 0; i < n; ++i)
170 {
171 out << RowIndexFormatter()(mat, i) << " & ";
172
173 for (long j = 0; j < m; ++j)
174 {
175 out << EntryFormatter()(mat, i, j);
176 if (j < m - 1)
177 out << " & ";
178 }
179
180 out << "\\\\\n";
181 }
182
183 out << "\\hline\\end{tabular}\n" << suffix;
184}
185
193template <typename Mat,
194 class RowIndexFormatter,
195 class ColIndexFormatter,
196 class EntryFormatter>
197void mat_to_latex(Mat & mat,
198 long n,
199 long m,
200 std::ofstream & out,
201 const std::string & prefix = "",
202 const std::string & suffix = "")
203{
205 mat, n, m, static_cast<std::ostream&>(out), prefix, suffix);
206}
207
215template <typename Mat>
217{
218 std::string operator()(Mat &, long i) const
219 {
220 return std::to_string(i);
221 }
222};
223
231template <typename Mat>
233{
234 std::string operator()(Mat &, long j) const
235 {
236 return std::to_string(j);
237 }
238};
239
248template <typename Mat>
250{
251 std::string operator()(Mat & mat, long i, long j) const
252 {
253 std::ostringstream ss;
254 ss << mat(i, j);
255 return ss.str();
256 }
257};
258
274template <typename Mat>
276 long n,
277 long m,
278 std::ostream & out,
279 const std::string & prefix = "",
280 const std::string & suffix = "")
281{
286}
287
288} // namespace Aleph
289
290// Global namespace compatibility
296
297#endif // MAT_LATEX_H
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
void 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.
Definition mat_latex.H:143
void 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.
Definition mat_latex.H:275
static void suffix(Node *root, DynList< Node * > &acc)
static void prefix(Node *root, DynList< Node * > &acc)
DynList< T > maps(const C &c, Op op)
Classic map operation.
Default column index formatter.
Definition mat_latex.H:233
std::string operator()(Mat &, long j) const
Definition mat_latex.H:234
Default entry formatter.
Definition mat_latex.H:250
std::string operator()(Mat &mat, long i, long j) const
Definition mat_latex.H:251
Default row index formatter.
Definition mat_latex.H:217
std::string operator()(Mat &, long i) const
Definition mat_latex.H:218