-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlatex_daniel.cpp
More file actions
159 lines (138 loc) · 2.93 KB
/
latex_daniel.cpp
File metadata and controls
159 lines (138 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "./BB/latex_daniel.h"
#include <vector>
#include <sstream>
LatexTable::LatexTable()
{
latexText = "";
caption = "__insert_caption__";
label = "__insert_label__";
}
LatexTable::LatexTable(std::vector<std::string> header_, std::vector<std::vector <std::string> > fields_)
{
header = header_;
fields = fields_;
}
LatexTable::~LatexTable()
{
}
std::string LatexTable::printLineSeparator()
{
return "\t\\midrule\n";
}
std::string LatexTable::print(bool printHeader = true, bool printFormat = true)
{
if (printFormat)
{
latexText = "\\begin{longtable} {l|";
for (int i = 1; i < header.size(); i++)
{
latexText += "r";
}
latexText += "}\n";
latexText += "\t\\caption{"+ caption +"} \\label{table:" + label + "} \\\\\n";
latexText += "\t\\toprule\n";
}
if (printHeader)
{
latexText += "\t\t";
for (int i = 0; i < header.size(); i++)
{
if (i > 0)
{
latexText += " & ";
}
latexText += header[i];
}
latexText += "\\\\\n";
}
if (printFormat) {
latexText += "\t\\midrule\n";
latexText += "\t\\endfirsthead\n";
latexText += "\t\\midrule\n";
latexText += "\t\\caption*{Table \\ref{table:"+ label +"} Continued: " + caption + "} \\\\\n";
latexText += "\t\\midrule\n";
latexText += "\t\\endhead\n";
}
for (int i = 0; i < fields.size(); i++)
{
latexText += "\t\t";
for (int j = 0; j < fields[i].size(); j++)
{
if (j > 0)
{
latexText += " & ";
}
latexText += fields[i][j];
}
latexText += "\\\\\n";
}
if (printFormat)
{
latexText += "\t\\bottomrule\n";
latexText += "\\end{longtable}\n";
}
return latexText;
}
void LatexTable::appendHeader(std::string textToAppend)
{
header.push_back(textToAppend);
}
//fazer template para appendField
void LatexTable::appendField(std::string stringTextToAppend)
{
//std::replace( stringTextToAppend.begin(), stringTextToAppend.end(), '_', '\\_'); // replace all 'x' to 'y'
fields[fields.size()-1].push_back(stringTextToAppend);
}
void LatexTable::appendField(int intTextToAppend)
{
std::stringstream strs;
strs << intTextToAppend;
fields[fields.size()-1].push_back(strs.str() );
}
void LatexTable::appendField(double doubleTextToAppend)
{
std::stringstream strs;
strs << doubleTextToAppend;
fields[fields.size()-1].push_back(strs.str() );
}
void LatexTable::newLine()
{
std::vector<std::string> emptyvector;
fields.push_back(emptyvector);
}
void LatexTable::setCaption(std::string stringCaption)
{
caption = stringCaption;
}
void LatexTable::setLabel(std::string stringLabel)
{
label = stringLabel;
}
std::string LatexTable::printExcel(bool printHeader = true)
{
if (printHeader)
{
for (int i = 0; i < header.size(); i++)
{
if (i > 0)
{
xlText += "\t";
}
xlText += header[i];
}
xlText += "\n";
}
for (int i = 0; i < fields.size(); i++)
{
for (int j = 0; j < fields[i].size(); j++)
{
if (j > 0)
{
xlText += "\t";
}
xlText += fields[i][j];
}
xlText += "\n";
}
return xlText;
}