Command.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 namespace boca
7 {
8 
13 namespace latex
14 {
15 
16 class Optional
17 {
18 public:
19 
20  Optional(std::string const& option);
21 
22  std::string Get() const;
23 
24 private:
25 
26  std::string option_;
27 
28 };
29 
30 std::string Macro(std::string const& string);
31 
32 class Command
33 {
34 
35 public:
36 
37  template <typename... Arguments_>
38  Command(std::string const& command, Arguments_... arguments) {
39  command_ = command;
40  Argument(arguments...);
41  }
42 
43  template <typename... Arguments_>
44  void Argument(std::string const& argument, Arguments_... arguments) {
45  options_.emplace_back(argument);
46  Argument(arguments...);
47  }
48 
49  template <typename... Arguments_>
50  void Argument(char const* argument, Arguments_... arguments) {
51  options_.emplace_back(argument);
52  Argument(arguments...);
53  }
54 
55  template <typename... Arguments_>
56  void Argument(int argument, Arguments_... arguments) {
57  options_.emplace_back(std::to_string(argument));
58  Argument(arguments...);
59  }
60 
61  template <typename... Arguments_>
62  void Argument(Optional const& option, Arguments_... arguments) {
63  optional_.emplace_back(option.Get());
64  Argument(arguments...);
65  }
66 
67  template <typename... Arguments_>
68  void Argument(bool add_line, Arguments_... arguments) {
69  add_line_ = add_line;
70  Argument(arguments...);
71  }
72 
73  template <typename... Arguments_>
74  void Optional(std::string const& argument, Arguments_... arguments) {
75  optional_.emplace_back(argument);
76  Optional(arguments...);
77  }
78 
79  std::string str() const;
80 
81  operator std::string() {
82  return str();
83  }
84 
85  friend std::ostream& operator<<(std::ostream& stream, Command const& tex);
86 
87  void Argument() {}
88 
89 private:
90 
91  void Optional() {}
92 
93  std::vector<std::string> options_;
94 
95  std::vector<std::string> optional_;
96 
97  std::string command_;
98 
99  bool add_line_ = false;
100 
101 };
102 
103 std::ostream& operator<<(std::ostream& stream, Command const& tex);
104 
105 class UsePackage : public Command
106 {
107 
108 public:
109 
110  template <typename... Arguments_>
111  UsePackage(std::string const& package, Arguments_ ... arguments) :
112  Command("usepackage", package) {
113  Argument(arguments...);
114  }
115 
116 };
117 
118 class SetCounter : public Command
119 {
120 
121 public:
122 
123  SetCounter(const std::string& counter, int number);
124 
125 };
126 
127 class RenewCommand : public Command
128 {
129 
130 public:
131 
132  template <typename Value>
133  RenewCommand(std::string const& command, Value value):
134  Command("renewcommand", Command(command).str(), value) {}
135 
136 };
137 
138 class DocumentClass : public Command
139 {
140 
141 public:
142 
143  template <typename... Arguments_>
144  DocumentClass(const std::string& document_class, Arguments_ ... arguments):
145  Command("documentclass", document_class, true) {
146  Optional(arguments...);
147  }
148 };
149 
150 class Article : public DocumentClass
151 {
152 
153 public:
154 
155  template <typename... Arguments_>
156  Article(Arguments_ ... arguments) :
157  DocumentClass("article", arguments...) {}
158 };
159 
160 class Caption: public Command
161 {
162 
163 public:
164 
165  Caption(const std::string& caption) : Command("caption", caption + ".") {}
166 
167 };
168 
170 {
171 
172 public:
173 
174  Environment(std::string const& name, bool new_line = true);
175 
176  template <typename... Arguments_>
177  std::string Begin(Arguments_... arguments) {
178  return (new_line_ ? '\n' : '\0') + Command("begin", name_, true, arguments...).str();
179  }
180 
181  std::string End() const;
182 
183 private:
184 
185  std::string name_;
186 
187  bool new_line_;
188 
189 
190 };
191 
192 class Unit : public Command
193 {
194 
195 public :
196 
197  Unit(std::string const& unit) :
198  Command("unit", unit) {}
199 
200  template <typename Value_>
201  Unit(std::string const& unit, Value_ value) :
202  Command("unit", unit, boca::latex::Optional(std::to_string(value))) {}
203 };
204 
205 class MultiColumn : public Command
206 {
207 
208 public:
209 
210  MultiColumn(std::string const& name, int number, std::string const& alignment = "c") :
211  Command("multicolumn", number, alignment, name) {}
212 
213 };
214 
215 }
216 
217 }
std::string Macro(std::string const &string)
Definition: Command.cpp:21
void Argument(int argument, Arguments_...arguments)
Definition: Command.hh:56
RenewCommand(std::string const &command, Value value)
Definition: Command.hh:133
void Argument(Optional const &option, Arguments_...arguments)
Definition: Command.hh:62
MultiColumn(std::string const &name, int number, std::string const &alignment="c")
Definition: Command.hh:210
Article(Arguments_...arguments)
Definition: Command.hh:156
void Argument()
Definition: Command.hh:87
DocumentClass(const std::string &document_class, Arguments_...arguments)
Definition: Command.hh:144
Definition: Command.hh:105
void Argument(std::string const &argument, Arguments_...arguments)
Definition: Command.hh:44
STL namespace.
void Argument(char const *argument, Arguments_...arguments)
Definition: Command.hh:50
UsePackage(std::string const &package, Arguments_...arguments)
Definition: Command.hh:111
void Argument(bool add_line, Arguments_...arguments)
Definition: Command.hh:68
std::string Begin(Arguments_...arguments)
Definition: Command.hh:177
Unit(std::string const &unit)
Definition: Command.hh:197
Definition: Command.hh:16
Definition: Command.hh:138
Caption(const std::string &caption)
Definition: Command.hh:165
std::ostream & operator<<(std::ostream &stream, Command const &tex)
Definition: Command.cpp:38
std::string str() const
Definition: Command.cpp:26
Boosted Collider Analysis.
Definition: Analysis.hh:15
std::string Get() const
Definition: Command.cpp:16
Definition: Command.hh:192
Definition: Command.hh:32
cmake CMakeConfig cmake option(BUILD_TESTING"Build testing"OFF) if(BUILD_TESTING) enable_testing() find_package(Boost 1.56 COMPONENTS unit_test_framework REQUIRED) add_libraries($
Definition: CMakeLists.txt:18
Definition: Command.hh:169
Definition: Command.hh:127
Command(std::string const &command, Arguments_...arguments)
Definition: Command.hh:38
Definition: Command.hh:205
void Optional(std::string const &argument, Arguments_...arguments)
Definition: Command.hh:74
Definition: Command.hh:118
Definition: Command.hh:160
Definition: Command.hh:150
Unit(std::string const &unit, Value_ value)
Definition: Command.hh:201
Optional(std::string const &option)
Definition: Command.cpp:11