Cadabra
Computer algebra system for field theory problems
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 
10 namespace cadabra {
11 
22 
23  class TeXEngine {
24  public:
25  class TeXException : public std::logic_error {
26  public:
27  TeXException(const std::string&);
28  };
29 
30  class TeXRequest {
31  public:
32  TeXRequest();
33  friend class TeXEngine;
34 
35  unsigned width() const;
36  unsigned height() const;
37  const std::vector<unsigned char>& image() const;
38 
39  private:
40  std::string latex_string;
41  std::string start_wrap, end_wrap;
43  std::vector<unsigned char> image_;
44  unsigned width_, height_;
45  };
46 
47  TeXEngine();
48  ~TeXEngine();
49 
50  // Set the width and font size for all images to be generated.
51  void set_geometry(int horizontal_pixels);
52 
53  // Set the scale factor for generating bitmaps. The total scale is
54  // the product of HiDPI scale and any text-scaling factor on top of
55  // that, so that it represents the total scale at which text renders.
56  // The device_scale is just the HiDPI factor; we need to generate
57  // bitmaps at the width times this size.
58  void set_scale(double total_scale, double device_scale);
59  double get_scale() const;
60  void set_font_size(int font_size);
61  std::vector<std::string> latex_packages;
62 
63  // All checkin/checkout conversion routines. TeXEngine keeps
64  // track of all TeXRequests in order to be able to convert
65  // all of them in one shot (with one LaTeX run), which you can
66  // do with 'convert_all'.
67 
68  // You can share the result in a TeXRequest in multiple
69  // widgets, but you need to call checkout if a widget no
70  // longer needs it. TeXEngine will then run a cleanup on all
71  // TeXRequests that are no longer referenced except by
72  // itself.
73 
74  std::shared_ptr<TeXRequest> checkin(const std::string&,
75  const std::string& startwrap, const std::string& endwrap);
76  std::shared_ptr<TeXRequest> modify(std::shared_ptr<TeXRequest>, const std::string&);
77 
79  void convert_all();
80 
83  void invalidate_all();
84 
86  void checkout(std::shared_ptr<TeXRequest>);
87  void checkout_all();
88 
89  private:
90  std::string convert_unicode_to_tex(const std::string&) const;
91 
92  static double millimeter_per_inch;
93 
94  std::set<std::shared_ptr<TeXRequest> > requests;
95 
96  std::string preamble_string;
100 
101  void erase_file(const std::string&) const;
102  void convert_one(std::shared_ptr<TeXRequest>);
103  void convert_set(std::set<std::shared_ptr<TeXRequest> >&);
104 
105  std::string handle_latex_errors(const std::string&, int exit_code) const;
106  };
107 
108  }
cadabra::TeXEngine::TeXEngine
TeXEngine()
Definition: TeXEngine.cc:182
cadabra::TeXEngine::TeXRequest::latex_string
std::string latex_string
Definition: TeXEngine.hh:40
cadabra::TeXEngine::TeXRequest::TeXRequest
TeXRequest()
Definition: TeXEngine.cc:243
cadabra::TeXEngine::TeXRequest::start_wrap
std::string start_wrap
Definition: TeXEngine.hh:41
cadabra::TeXEngine
Definition: TeXEngine.hh:23
cadabra::TeXEngine::TeXRequest::width_
unsigned width_
Definition: TeXEngine.hh:44
cadabra::TeXEngine::set_scale
void set_scale(double total_scale, double device_scale)
Definition: TeXEngine.cc:224
cadabra::TeXEngine::TeXException
Definition: TeXEngine.hh:25
cadabra::TeXEngine::TeXRequest::width
unsigned width() const
Definition: TeXEngine.cc:107
cadabra::TeXEngine::preamble_string
std::string preamble_string
Definition: TeXEngine.hh:96
cadabra::TeXEngine::TeXRequest::end_wrap
std::string end_wrap
Definition: TeXEngine.hh:41
cadabra::TeXEngine::total_scale_
double total_scale_
Definition: TeXEngine.hh:99
cadabra::TeXEngine::convert_all
void convert_all()
Generate images for all TeXRequests which are labelled as needing conversion.
Definition: TeXEngine.cc:288
cadabra::TeXEngine::convert_one
void convert_one(std::shared_ptr< TeXRequest >)
Definition: TeXEngine.cc:304
cadabra::TeXEngine::device_scale_
double device_scale_
Definition: TeXEngine.hh:99
cadabra::TeXEngine::get_scale
double get_scale() const
Definition: TeXEngine.cc:238
cadabra::TeXEngine::latex_packages
std::vector< std::string > latex_packages
Definition: TeXEngine.hh:61
cadabra::TeXEngine::TeXRequest::height_
unsigned height_
Definition: TeXEngine.hh:44
cadabra::TeXEngine::TeXRequest::image_
std::vector< unsigned char > image_
Definition: TeXEngine.hh:43
cadabra::TeXEngine::~TeXEngine
~TeXEngine()
Definition: TeXEngine.cc:178
cadabra::TeXEngine::set_geometry
void set_geometry(int horizontal_pixels)
Definition: TeXEngine.cc:198
cadabra::TeXEngine::TeXRequest::needs_generating
bool needs_generating
Definition: TeXEngine.hh:42
cadabra::TeXEngine::font_size_
int font_size_
Definition: TeXEngine.hh:98
cadabra::TeXEngine::checkout_all
void checkout_all()
Definition: TeXEngine.cc:267
cadabra::TeXEngine::TeXRequest
Definition: TeXEngine.hh:30
cadabra::TeXEngine::invalidate_all
void invalidate_all()
Mark all TeXRequests as needing re-generating.
Definition: TeXEngine.cc:272
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:82
cadabra::TeXEngine::modify
std::shared_ptr< TeXRequest > modify(std::shared_ptr< TeXRequest >, const std::string &)
Definition: TeXEngine.cc:281
cadabra::TeXEngine::horizontal_pixels_
int horizontal_pixels_
Definition: TeXEngine.hh:97
cadabra::TeXEngine::TeXRequest::height
unsigned height() const
Definition: TeXEngine.cc:112
cadabra::TeXEngine::checkout
void checkout(std::shared_ptr< TeXRequest >)
Mark a TeXRequest as no longer being needed.
Definition: TeXEngine.cc:260
cadabra::TeXEngine::requests
std::set< std::shared_ptr< TeXRequest > > requests
Definition: TeXEngine.hh:94
cadabra::TeXEngine::convert_set
void convert_set(std::set< std::shared_ptr< TeXRequest > > &)
Definition: TeXEngine.cc:312
cadabra::TeXEngine::set_font_size
void set_font_size(int font_size)
Definition: TeXEngine.cc:211
cadabra::TeXEngine::TeXRequest::image
const std::vector< unsigned char > & image() const
Definition: TeXEngine.cc:117
cadabra::TeXEngine::handle_latex_errors
std::string handle_latex_errors(const std::string &, int exit_code) const
Definition: TeXEngine.cc:127
cadabra::TeXEngine::erase_file
void erase_file(const std::string &) const
Definition: TeXEngine.cc:122
cadabra::TeXEngine::millimeter_per_inch
static double millimeter_per_inch
Definition: TeXEngine.hh:92
cadabra::TeXEngine::checkin
std::shared_ptr< TeXRequest > checkin(const std::string &, const std::string &startwrap, const std::string &endwrap)
Definition: TeXEngine.cc:248
cadabra::TeXEngine::TeXException::TeXException
TeXException(const std::string &)
Definition: TeXEngine.cc:37
cadabra::TeXEngine::convert_unicode_to_tex
std::string convert_unicode_to_tex(const std::string &) const
Definition: TeXEngine.cc:42