Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TeXEngine.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <stdexcept>
5 #include <vector>
6 #include <set>
7 #include <string>
8 #include <memory>
9 
12 
13 namespace cadabra {
14 
25 
26  class TeXEngine {
27  public:
28  class TeXException : public std::logic_error {
29  public:
30  TeXException(const std::string&);
31  };
32 
33  class TeXRequest {
34  public:
35  TeXRequest();
36  friend class TeXEngine;
37 
38  unsigned width() const;
39  unsigned height() const;
40  const std::vector<unsigned char>& image() const;
41 
42  private:
43  std::string latex_string;
44  std::string start_wrap, end_wrap;
46  std::vector<unsigned char> image_;
47  unsigned width_, height_;
48  };
49 
50  TeXEngine();
51  ~TeXEngine();
52 
53  // Set the width and font size for all images to be generated.
54  void set_geometry(int horizontal_pixels);
55  void set_scale(double);
56  void set_font_size(int font_size);
57  std::vector<std::string> latex_packages;
58 
59  // All checkin/checkout conversion routines. TeXEngine keeps
60  // track of all TeXRequests in order to be able to convert
61  // all of them in one shot (with one LaTeX run), which you can
62  // do with 'convert_all'.
63 
64  // You can share the result in a TeXRequest in multiple
65  // widgets, but you need to call checkout if a widget no
66  // longer needs it. TeXEngine will then run a cleanup on all
67  // TeXRequests that are no longer referenced except by
68  // itself.
69 
70  std::shared_ptr<TeXRequest> checkin(const std::string&,
71  const std::string& startwrap, const std::string& endwrap);
72  std::shared_ptr<TeXRequest> modify(std::shared_ptr<TeXRequest>, const std::string&);
73 
75  void convert_all();
76 
79  void invalidate_all();
80 
82  void checkout(std::shared_ptr<TeXRequest>);
83  void checkout_all();
84 
85  private:
86  std::string convert_unicode_to_tex(const std::string&) const;
87 
88  static double millimeter_per_inch;
89 
90  std::set<std::shared_ptr<TeXRequest> > requests;
91 
92  std::string preamble_string;
95  double scale_;
96 
97  void erase_file(const std::string&) const;
98  void convert_one(std::shared_ptr<TeXRequest>);
99  void convert_set(std::set<std::shared_ptr<TeXRequest> >&);
100 
101  std::string handle_latex_errors(const std::string&, int exit_code) const;
102  };
103 
104 }
std::string handle_latex_errors(const std::string &, int exit_code) const
Definition: TeXEngine.cc:112
unsigned width() const
Definition: TeXEngine.cc:92
std::string convert_unicode_to_tex(const std::string &) const
Definition: TeXEngine.cc:27
double scale_
Definition: TeXEngine.hh:95
std::string preamble_string
Definition: TeXEngine.hh:92
std::string end_wrap
Definition: TeXEngine.hh:44
std::shared_ptr< TeXRequest > checkin(const std::string &, const std::string &startwrap, const std::string &endwrap)
Definition: TeXEngine.cc:227
const std::vector< unsigned char > & image() const
Definition: TeXEngine.cc:102
Definition: TeXEngine.hh:28
~TeXEngine()
Definition: TeXEngine.cc:163
void convert_all()
Generate images for all TeXRequests which are labelled as needing conversion.
Definition: TeXEngine.cc:267
void erase_file(const std::string &) const
Definition: TeXEngine.cc:107
void set_scale(double)
Definition: TeXEngine.cc:209
TeXRequest()
Definition: TeXEngine.cc:222
bool needs_generating
Definition: TeXEngine.hh:45
void checkout_all()
Definition: TeXEngine.cc:246
void convert_one(std::shared_ptr< TeXRequest >)
Definition: TeXEngine.cc:283
Definition: TeXEngine.hh:33
int font_size_
Definition: TeXEngine.hh:94
std::set< std::shared_ptr< TeXRequest > > requests
Definition: TeXEngine.hh:90
TeXEngine is used to convert LaTeX strings into PNG images.
Definition: TeXEngine.hh:26
void convert_set(std::set< std::shared_ptr< TeXRequest > > &)
Definition: TeXEngine.cc:291
std::vector< unsigned char > image_
Definition: TeXEngine.hh:46
int horizontal_pixels_
Definition: TeXEngine.hh:93
std::vector< std::string > latex_packages
Definition: TeXEngine.hh:57
void set_geometry(int horizontal_pixels)
Definition: TeXEngine.cc:183
void invalidate_all()
Mark all TeXRequests as needing re-generating.
Definition: TeXEngine.cc:251
TeXException(const std::string &)
Definition: TeXEngine.cc:22
unsigned width_
Definition: TeXEngine.hh:47
unsigned height_
Definition: TeXEngine.hh:47
std::shared_ptr< TeXRequest > modify(std::shared_ptr< TeXRequest >, const std::string &)
Definition: TeXEngine.cc:260
void set_font_size(int font_size)
Definition: TeXEngine.cc:196
static double millimeter_per_inch
Definition: TeXEngine.hh:88
std::string start_wrap
Definition: TeXEngine.hh:44
unsigned height() const
Definition: TeXEngine.cc:97
void checkout(std::shared_ptr< TeXRequest >)
Mark a TeXRequest as no longer being needed.
Definition: TeXEngine.cc:239
TeXEngine()
Definition: TeXEngine.cc:167
std::string latex_string
Definition: TeXEngine.hh:43