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#ifndef USE_GTK4
5#include <gtkmm/eventbox.h>
6#endif
7#include <gtkmm/box.h>
8#include <gtkmm/drawingarea.h>
9#include <gtkmm/menu.h>
10#if GTKMM_MINOR_VERSION>=10
11#include <gtkmm/revealer.h>
12#endif
13
14#include "Config.hh"
15#include "DataCell.hh"
16#include "../common/TeXEngine.hh"
17
18// MicroTeX
19#include "microtex.h"
20#include "utils/utf.h"
21
22namespace cadabra {
23
27 //
30
31 class TeXView : public Gtk::EventBox {
32 public:
33 TeXView(TeXEngine&, DTree::iterator, bool use_microtex_, int hmargin=25);
34 virtual ~TeXView();
35
36 std::shared_ptr<TeXEngine::TeXRequest> content;
37
38 sigc::signal1<bool, DTree::iterator> show_hide_requested;
39
40 void set_use_microtex(bool);
41
42 void set_is_error(bool);
43
44 DTree::iterator datacell;
45 Gtk::Revealer rbox;
46 Gtk::Box vbox;
47 Gtk::Box hbox;
48
50
51 class TeXArea : public Gtk::DrawingArea {
52 public:
53 TeXArea(bool use_microtex, TeXView *owner_);
54 ~TeXArea();
55
56 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
57
61
62 void update_image(std::shared_ptr<TeXEngine::TeXRequest>, double scale);
63
67
68 Glib::RefPtr<Gdk::Pixbuf> pixbuf;
69 double scale_;
71
75 void set_latex(const std::string& latex);
76
79 void layout_latex() const;
80
82
83 int need_height(int width) const;
84 protected:
85 Gtk::SizeRequestMode get_request_mode_vfunc() const override;
87 int& natural_height) const override;
89 int& natural_width) const override;
90 void on_size_allocate(Gtk::Allocation& allocation) override;
91
92 private:
94 mutable int rendering_width;
96
97 // MicroTeX
98 mutable microtex::Render* _render;
99 std::string unfixed, fixed;
100
101 // Return a string in which backslashes, curly braces,
102 // underscores and tildes are properly backslashed, so they
103 // typeset as if we are in a verbatim environment.
104 std::string verbatimise(const std::string&) const;
105 };
106
108
110 void update_image();
111
114
115 void dim(bool);
116
117 sigc::signal1<bool, std::string> tex_error;
118 sigc::signal0<bool> signal_on_copy_as_latex;
119
120 protected:
121 virtual bool on_button_release_event(GdkEventButton *) override;
122 virtual bool on_button_press_event(GdkEventButton *event) override;
123 virtual void on_show() override;
124
125 void convert();
126
127 void on_copy_as_latex() const;
128
129 private:
133
134 Gtk::Menu context_menu;
135 Gtk::MenuItem item_copy_as_latex;
136
137 float text_size() const;
138 };
139
140 }
141
TeXEngine is used to convert LaTeX strings into PNG images.
Definition TeXEngine.hh:23
Definition TeXView.hh:51
std::string fixed
Definition TeXView.hh:99
std::string unfixed
Definition TeXView.hh:99
void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition TeXView.cc:149
TeXView * owner
Definition TeXView.hh:93
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:398
int padding_x
Definition TeXView.hh:95
void layout_latex() const
MicroTeX: just run the LaTeX layout algorithms, do not draw.
Definition TeXView.cc:290
double scale_
Definition TeXView.hh:69
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
Definition TeXView.cc:332
std::string verbatimise(const std::string &) const
Definition TeXView.cc:387
microtex::Render * _render
Definition TeXView.hh:98
bool use_microtex
Definition TeXView.hh:81
Glib::RefPtr< Gdk::Pixbuf > pixbuf
The actual image is stored in the image referenced by pixbuf.
Definition TeXView.hh:68
float _text_size
Definition TeXView.hh:70
int need_height(int width) const
Definition TeXView.cc:142
int padding_y
Definition TeXView.hh:95
int rendering_width
Definition TeXView.hh:94
Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition TeXView.cc:102
~TeXArea()
Definition TeXView.cc:565
void on_size_allocate(Gtk::Allocation &allocation) override
Definition TeXView.cc:166
void get_preferred_height_for_width_vfunc(int width, int &minimum_height, int &natural_height) const override
Definition TeXView.cc:107
TeXView is a widget which knows how to turn a string into a LaTeX-rendered image and display that.
Definition TeXView.hh:31
virtual bool on_button_release_event(GdkEventButton *) override
Definition TeXView.cc:226
TeXEngine & engine
Definition TeXView.hh:130
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:220
Gtk::Revealer rbox
Definition TeXView.hh:45
virtual ~TeXView()
Definition TeXView.cc:55
float text_size() const
Definition TeXView.cc:79
TeXArea image
Definition TeXView.hh:107
Gtk::MenuItem item_copy_as_latex
Definition TeXView.hh:135
DTree::iterator datacell
Definition TeXView.hh:44
bool is_error
Definition TeXView.hh:132
void update_image()
Update the TeX image.
Definition TeXView.cc:246
Gtk::Box hbox
Definition TeXView.hh:47
virtual void on_show() override
Definition TeXView.cc:95
std::shared_ptr< TeXEngine::TeXRequest > content
Definition TeXView.hh:36
int window_width
Definition TeXView.hh:49
bool use_microtex
Definition TeXView.hh:131
void set_use_microtex(bool)
Definition TeXView.cc:65
virtual bool on_button_press_event(GdkEventButton *event) override
Definition TeXView.cc:235
void convert()
Definition TeXView.cc:197
Gtk::Menu context_menu
Definition TeXView.hh:134
Gtk::Box vbox
Definition TeXView.hh:46
void on_copy_as_latex() const
Definition TeXView.cc:60
void set_is_error(bool)
Definition TeXView.cc:74
sigc::signal1< bool, DTree::iterator > show_hide_requested
Definition TeXView.hh:38
sigc::signal0< bool > signal_on_copy_as_latex
Definition TeXView.hh:118
sigc::signal1< bool, std::string > tex_error
Definition TeXView.hh:117
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:1179