-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathquill_template2.html
213 lines (202 loc) · 7.49 KB
/
mathquill_template2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MathQuill in PyQt6</title>
<link rel="stylesheet" href="resources/mathquill.min.css" />
<style>
body::-webkit-scrollbar {
display: none;
}
body {
scrollbar-width: none;
overflow: auto;
}
body, html {
height: 100%;
width: 100%;
margin: 0px;
padding: 1px;
display: flex;
justify-content: center;
align-items: center;
}
.container {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;
padding: 0 0px;
}
.scroll-container {
overflow: auto;
height: 100%;
width: 100%;
}
#mathquill-input {
flex-grow: 1;
height: 60px;
border: 2px solid #ccc;
display: flex;
align-items: center;
justify-content: flex-end;
padding: 5px;
overflow-y: auto;
}
#mathquill-input:focus {
border-color: #ffa500;
border-width: 2px;
}
#result {
padding: 0px 5px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
background: #fff;
white-space: nowrap;
overflow: visible;
line-height: 1.0; /* Adjusting line height */
}
#result-value {
font-size: 16px;
color: green;
padding: 5px;
max-height: none;
max-width: none;
overflow: visible;
text-align: center;
}
#latex-output {
display: none;
}
.result-box {
display: inline-block;
padding: 3px 3px;
background-color: #d9f2e6;
border: 2px solid #5cb85c;
border-radius: 2px;
}
</style>
<!-- MathJax Configuration -->
<script type="text/javascript">
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$', '$$'], ['\\[', '\\]']]
},
svg: { fontCache: 'global' },
startup: {
ready() {
MathJax.startup.defaultReady();
console.log('MathJax is ready, version', MathJax.version);
}
}
};
</script>
<script src="qwebchannel.js"></script>
<script src="resources/jquery-3.6.0.min.js"></script>
<script src="resources/mathquill.min.js"></script>
<script src="resources/qwebchannel.js"></script>
<script src="resources/MathJax/es5/tex-mml-chtml.js"></script>
<script type="text/javascript">
function initializeBridge() {
new QWebChannel(qt.webChannelTransport, function(channel) {
window.bridge = channel.objects.bridge;
document.body.onclick = function() {
window.bridge.clickedSignal();
};
});
}
</script>
</head>
<body onload="initializeBridge()">
<div class="container">
<div id="mathquill-input" class="mathquill-editable"></div>
<div id="result"><br>
result: <div style="padding-left: 10px;"><br><span id="result-value"></span></div>
</div>
</div>
<div id="latex-output">
LaTeX Output:
<span id="latex"></span>
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var MQ = MathQuill.getInterface(2);
var mathField = MQ.MathField(document.getElementById('mathquill-input'), {
spaceBehavesLikeTab: true,
handlers: {
edit: function() {
var latex = mathField.latex();
document.getElementById('latex').textContent = latex;
if (window.bridge) {
window.bridge.latexUpdated(latex);
}
},
enter: function() { submitLatex(latex); }
}
});
window.mathField = mathField;
// Setup QWebChannel communication
new QWebChannel(qt.webChannelTransport, function(channel) {
window.bridge = channel.objects.bridge;
});
// Function to update MathQuill content from PyQt6
window.updateMathQuill = function(latex) {
mathField.latex(latex);
};
// Function to insert a result box into MathQuill
window.insertResultBox = function(result) {
var resultLatex = `\\class{result-box}{\\text{${result}}}`;
mathField.write(resultLatex);
};
// Function to update the result with LaTeX and render it
window.updateResultWithLatex = function(latex) {
var resultElement = document.getElementById('result-value');
// Update the result element with LaTeX
resultElement.innerHTML = `$${latex}$$`;
MathJax.typesetPromise([resultElement]).then(() => {
});
};
// Slow down the scroll speed
let scrollSpeed = 0.20; // Adjust this value for slower or faster scrolling
window.addEventListener('wheel', function(event) {
event.preventDefault(); // Prevent the default scroll behavior
var delta = event.deltaY * scrollSpeed; // Apply the scroll speed factor
document.documentElement.scrollTop += delta;
document.body.scrollTop += delta; // For Safari compatibility
}, { passive: false });
var resultValue = document.getElementById('result-value');
resultValue.addEventListener('click', function() {
// Communication bridge to the PyQt app
if (window.bridge) {
window.bridge.openMathJaxWindow();
}
});
// Function to focus on MathQuill and move cursor left
window.focusAndMoveLeft = function() {
// Focus on the MathQuill field
window.mathField.focus();
// Simulate a mouse click into the MathQuill field
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
document.getElementById('mathquill-input').dispatchEvent(clickEvent);
// Simulate left arrow key press
const leftArrowEvent = new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
key: 'ArrowLeft',
code: 'ArrowLeft',
keyCode: 37 // Left arrow key code
});
document.getElementById('mathquill-input').dispatchEvent(leftArrowEvent);
};
});
</script>
</body>
</html>