/
TeXout.h
62 lines (50 loc) · 1.64 KB
/
TeXout.h
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
#ifndef TEXOUT_H
#define TEXOUT_H
#include <iosfwd>
#include <string> // forward-declared in iosfwd, for gcc
#include <set>
class TeXout {
std::string doc_class;
std::set<std::string> classopts;
std::set<std::string> packages;
std::set<std::string> tikzlibraries;
std::string preamble;
std::string doc;
public:
TeXout(std::string docuclass = "standalone") : doc_class{docuclass} {}
void documentclass(std::string doc_class);
void classopt(std::string opt);
void usepackage(std::string package);
void usetikzlibrary(std::string lib);
void addtopreamble(std::string pre);
TeXout& operator<<(std::string s);
TeXout& operator<<(char c);
TeXout& operator<<(double d); // fixed precision, 1 digit after decimal point
TeXout& operator<<(int i);
TeXout& operator<<(unsigned u);
TeXout& operator<<(long unsigned u);
// TeXout& operator<<(boost::dynamic_bitset<> b); // wrong-endian hex
std::ostream& tostream(std::ostream&);
};
inline std::ostream& operator<<(std::ostream& os, TeXout& t) {
return t.tostream(os);
}
/* env_wrap manipulator, wraps the next input in a LaTeX environment */
/* Use: tex << "La la" << env_wrap{"displaymath"} << object << "whee"; */
struct EnvironmentWrapper {
TeXout& t;
std::string env;
};
struct env_wrap {
std::string env;
};
inline EnvironmentWrapper operator<<(TeXout& t, const env_wrap& e) {
return {t, e.env};
}
template<typename T>
TeXout& operator<<(EnvironmentWrapper&& ew, const T& data) {
return ew.t << ("\\begin{" + ew.env + "}\n")
<< data
<< ("\\end{" + ew.env + "}\n");
}
#endif //TEXOUT_H