Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
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
19namespace 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
45
46 class TeXArea : public Gtk::DrawingArea {
47 public:
48 TeXArea(bool use_microtex, TeXView *owner_);
49 ~TeXArea();
50
51 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
52
56
57 void update_image(std::shared_ptr<TeXEngine::TeXRequest>, double scale);
58
62
63 Glib::RefPtr<Gdk::Pixbuf> pixbuf;
64 double scale_;
66
70 void set_latex(const std::string& latex);
71
74 void layout_latex() const;
75
77
78 int need_height(int width) const;
79 protected:
80 Gtk::SizeRequestMode get_request_mode_vfunc() const override;
82 int& natural_height) const override;
84 int& natural_width) const override;
85 void on_size_allocate(Gtk::Allocation& allocation) override;
86
87 private:
89 mutable int rendering_width;
91
92 // MicroTeX
93 mutable microtex::Render* _render;
94 std::string unfixed, fixed;
95
96 // Return a string in which backslashes, curly braces,
97 // underscores and tildes are properly backslashed, so they
98 // typeset as if we are in a verbatim environment.
99 std::string verbatimise(const std::string&) const;
100 };
101
103
105 void update_image();
106
109
110 void dim(bool);
111
112 sigc::signal1<bool, std::string> tex_error;
113
114 protected:
115 virtual bool on_button_release_event(GdkEventButton *) override;
116 virtual void on_show() override;
117
118 void convert();
119
120 private:
123
124 float text_size() const;
125 };
126
127 }
128
TeXEngine is used to convert LaTeX strings into PNG images.
Definition TeXEngine.hh:23
Definition TeXView.hh:46
std::string fixed
Definition TeXView.hh:94
std::string unfixed
Definition TeXView.hh:94
void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition TeXView.cc:133
TeXView * owner
Definition TeXView.hh:88
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:365
int padding_x
Definition TeXView.hh:90
void layout_latex() const
MicroTeX: just run the LaTeX layout algorithms, do not draw.
Definition TeXView.cc:260
double scale_
Definition TeXView.hh:64
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
Definition TeXView.cc:302
std::string verbatimise(const std::string &) const
Definition TeXView.cc:354
microtex::Render * _render
Definition TeXView.hh:93
bool use_microtex
Definition TeXView.hh:76
Glib::RefPtr< Gdk::Pixbuf > pixbuf
The actual image is stored in the image referenced by pixbuf.
Definition TeXView.hh:63
float _text_size
Definition TeXView.hh:65
int need_height(int width) const
Definition TeXView.cc:126
int padding_y
Definition TeXView.hh:90
int rendering_width
Definition TeXView.hh:89
Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition TeXView.cc:86
~TeXArea()
Definition TeXView.cc:513
void on_size_allocate(Gtk::Allocation &allocation) override
Definition TeXView.cc:150
void get_preferred_height_for_width_vfunc(int width, int &minimum_height, int &natural_height) const override
Definition TeXView.cc:91
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:210
TeXEngine & engine
Definition TeXView.hh:121
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:204
Gtk::Revealer rbox
Definition TeXView.hh:40
virtual ~TeXView()
Definition TeXView.cc:49
float text_size() const
Definition TeXView.cc:63
TeXArea image
Definition TeXView.hh:102
DTree::iterator datacell
Definition TeXView.hh:39
void update_image()
Update the TeX image.
Definition TeXView.cc:216
virtual void on_show() override
Definition TeXView.cc:79
std::shared_ptr< TeXEngine::TeXRequest > content
Definition TeXView.hh:33
Gtk::HBox hbox
Definition TeXView.hh:42
int window_width
Definition TeXView.hh:44
bool use_microtex
Definition TeXView.hh:122
void set_use_microtex(bool)
Definition TeXView.cc:54
void convert()
Definition TeXView.cc:181
sigc::signal1< bool, DTree::iterator > show_hide_requested
Definition TeXView.hh:35
sigc::signal1< bool, std::string > tex_error
Definition TeXView.hh:112
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1063