-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzetotex.cpp
163 lines (128 loc) · 4.18 KB
/
zetotex.cpp
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
//++++++++++++++++++++++++++++++++++++++++++++++++++
// ZetoTex Latex Assistant
// Version 1.0
// Written by: Carl Schaffer
// Mail: [email protected]
// ZetoTex is free software: you can redistribute it
// and/or modify it under the terms of the GNU
// General Public License as published by the Free
// Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General
// Public License along with this program. If not,
// see <http://www.gnu.org/licenses/>.
//++++++++++++++++++++++++++++++++++++++++++++++++++
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstring>
#include <sstream>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <vector>
#include "zetotex.hpp"
//++++++++++++++++++++++++++++++++++++++++++++++++++
// Useful Functions
//++++++++++++++++++++++++++++++++++++++++++++++++++
std::string array_to_str(std::vector<std::string> array,unsigned int index){
if( index < array.size()){
std::stringstream ss;
ss.clear();
ss << array[index];
return ss.str();
}
else{
return " ";
};
};
std::string array_to_str(std::vector<float> array,unsigned int index){
if( index < array.size()){
std::stringstream ss;
ss.clear();
ss << array[index];
return ss.str();
}
else{
return " ";
};
};
//++++++++++++++++++++++++++++++++++++++++++++++++++
// tex_assistant and methods
//++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++Constructor++++++++++++++++++++
tex_assistant::tex_assistant(std::string tex_file_path){
tex_file=tex_file_path;
std::fstream myfile;
std::time_t t = time(0);// get time now
struct tm * now = localtime( & t );
myfile.open(tex_file.c_str(), std::ofstream::out | std::ofstream::trunc);
myfile << "%TexAssistant file written by Tex Assistant"<<"\n";
myfile << "%Written on: "
<< std::setw(2)<< std::setfill('0')<<now->tm_mday << "."
<< std::setw(2)<< std::setfill('0')<<now->tm_mon + 1 << "."
<< std::setw(4)<< std::setfill('0')<<now->tm_year + 1900 << " at "
<< std::setw(2)<< std::setfill('0')<<now->tm_hour <<":"
<< std::setw(2)<< std::setfill('0')<<now->tm_min
<<"\n"<<"\n"<<"\n";
myfile.close();
};//end constructor
//+++++++++++++++++++Write to File++++++++++++++++++
void tex_assistant::write_to_file(std::string toAppend){
std::fstream myfile;
myfile.open (tex_file.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
myfile << toAppend;
myfile.close();
};
//++++++++++++++++++Command Methods+++++++++++++++++
void tex_assistant::ncmdValue(std::string name, float value){
std::stringstream ss;
ss<<value;
ncmdStr(name,ss.str());
};
void tex_assistant::ncmdStr(std::string name, std::string value){
std::ostringstream oss;
oss << "\\newcommand{";
oss << "\\"+name;
oss << "}{";
oss << value;
oss << "}\n\n";
write_to_file(oss.str());
};
void tex_assistant::ncmdArray(std::string name,
std::vector <std::string> header,
std::vector<std::vector< float> > data){
if(not header.size() == data.size()){
std::cout <<"Header and data not of compatible size! \n appending empty spaces where necessary ";
}
int ncols=std::max(header.size(),data[0].size());
std::ostringstream oss;
oss << "\n\t\\begin{tabular}{";
for(int i=0;i<ncols-1;i++){
oss<< "|c";
}
oss <<"|}\n" << "\t\\hline ";
for(int i=0;i<ncols-1;i++){
oss <<array_to_str(header,i);
if(!(i==ncols-2)) oss << " & ";
else oss << " \\\\\n";
}
int nlines = (int) data.size();
for(int j=0;j< nlines-1;j++){
oss <<"\t\\hline ";
for(int i=0;i<ncols-1;i++){
if(!(i >(int) data[0].size())){
oss << array_to_str(data[j],i);
}
if(!(i==ncols-2)) oss<< " & ";
else oss << " \\\\\n";
}
}
oss<<"\t\\hline\n \t\\end{tabular}\n";
ncmdStr(name,oss.str());
}