Cadabra
Computer algebra system for field theory problems
TeXView.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <gtkmm/eventbox.h>
5 #include <gtkmm/box.h>
6 #include <gtkmm/drawingarea.h>
7 #if GTKMM_MINOR_VERSION>=10
8 #include <gtkmm/revealer.h>
9 #endif
10 
11 #include "Config.hh"
12 #include "DataCell.hh"
13 #include "../common/TeXEngine.hh"
14 
15 // MicroTeX
16 #include "microtex.h"
17 #include "utils/utf.h"
18 
19 namespace cadabra {
20 
24  //
27 
28  class TeXView : public Gtk::EventBox {
29  public:
30  TeXView(TeXEngine&, DTree::iterator, bool use_microtex_, int hmargin=25);
31  virtual ~TeXView();
32 
33  std::shared_ptr<TeXEngine::TeXRequest> content;
34 
35  sigc::signal1<bool, DTree::iterator> show_hide_requested;
36 
37  void set_use_microtex(bool);
38 
39  DTree::iterator datacell;
40  Gtk::Revealer rbox;
41  Gtk::VBox vbox;
42  Gtk::HBox hbox;
43 
44  class TeXArea : public Gtk::DrawingArea {
45  public:
46  TeXArea(bool use_microtex);
47  ~TeXArea();
48 
49  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
50 
54 
55  void update_image(std::shared_ptr<TeXEngine::TeXRequest>, double scale);
56 
60 
61  Glib::RefPtr<Gdk::Pixbuf> pixbuf;
62  double scale_;
63  float _text_size;
64 
68  void set_latex(const std::string& latex);
69 
72  void layout_latex() const;
73 
75  protected:
76  Gtk::SizeRequestMode get_request_mode_vfunc() const override;
77  void get_preferred_height_for_width_vfunc(int width, int& minimum_height,
78  int& natural_height) const override;
79  void get_preferred_width_for_height_vfunc(int height, int& minimum_width,
80  int& natural_width) const override;
81  void on_size_allocate(Gtk::Allocation& allocation) override;
82 
83  private:
84  mutable int rendering_width;
86 
87  // MicroTeX
88  mutable microtex::Render* _render;
89  std::string unfixed, fixed;
90  };
91 
93 
95  void update_image();
96 
99 
100  void dim(bool);
101 
102  sigc::signal1<bool, std::string> tex_error;
103 
104  protected:
105  virtual bool on_button_release_event(GdkEventButton *) override;
106  virtual void on_show() override;
107 
108  void convert();
109 
110  private:
113 
114  float text_size() const;
115  };
116 
117  }
118 
TeXEngine is used to convert LaTeX strings into PNG images.
Definition: TeXEngine.hh:23
Definition: TeXView.hh:44
std::string fixed
Definition: TeXView.hh:89
std::string unfixed
Definition: TeXView.hh:89
void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition: TeXView.cc:107
void set_latex(const std::string &latex)
MicroTeX: set the LaTeX string and replace/substitute so that MicroTeX can render it (but do not actu...
Definition: TeXView.cc:290
int padding_x
Definition: TeXView.hh:85
void layout_latex() const
MicroTeX: just run the LaTeX layout algorithms, do not draw.
Definition: TeXView.cc:226
double scale_
Definition: TeXView.hh:62
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
Definition: TeXView.cc:240
microtex::Render * _render
Definition: TeXView.hh:88
TeXArea(bool use_microtex)
Definition: TeXView.cc:404
bool use_microtex
Definition: TeXView.hh:74
Glib::RefPtr< Gdk::Pixbuf > pixbuf
The actual image is stored in the image referenced by pixbuf.
Definition: TeXView.hh:61
float _text_size
Definition: TeXView.hh:63
int padding_y
Definition: TeXView.hh:85
void update_image(std::shared_ptr< TeXEngine::TeXRequest >, double scale)
Update the visible image from the pixbuf.
Definition: TeXView.cc:193
int rendering_width
Definition: TeXView.hh:84
Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition: TeXView.cc:76
~TeXArea()
Definition: TeXView.cc:412
void on_size_allocate(Gtk::Allocation &allocation) override
Definition: TeXView.cc:124
void get_preferred_height_for_width_vfunc(int width, int &minimum_height, int &natural_height) const override
Definition: TeXView.cc:81
TeXView is a widget which knows how to turn a string into a LaTeX-rendered image and display that.
Definition: TeXView.hh:28
Gtk::VBox vbox
Definition: TeXView.hh:41
virtual bool on_button_release_event(GdkEventButton *) override
Definition: TeXView.cc:176
TeXEngine & engine
Definition: TeXView.hh:111
void dim(bool)
Dim the output to indicate that the result is no longer guaranteed to be correlated with the input ce...
Definition: TeXView.cc:170
Gtk::Revealer rbox
Definition: TeXView.hh:40
virtual ~TeXView()
Definition: TeXView.cc:42
float text_size() const
Definition: TeXView.cc:56
TeXArea image
Definition: TeXView.hh:92
DTree::iterator datacell
Definition: TeXView.hh:39
void update_image()
Update the TeX image.
Definition: TeXView.cc:182
virtual void on_show() override
Definition: TeXView.cc:69
std::shared_ptr< TeXEngine::TeXRequest > content
Definition: TeXView.hh:33
TeXView(TeXEngine &, DTree::iterator, bool use_microtex_, int hmargin=25)
Definition: TeXView.cc:15
Gtk::HBox hbox
Definition: TeXView.hh:42
bool use_microtex
Definition: TeXView.hh:112
void set_use_microtex(bool)
Definition: TeXView.cc:47
void convert()
Definition: TeXView.cc:147
sigc::signal1< bool, DTree::iterator > show_hide_requested
Definition: TeXView.hh:35
sigc::signal1< bool, std::string > tex_error
Definition: TeXView.hh:102
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83