Skip to content

Commit fcdd62e

Browse files
committed
xyz
1 parent 58108d0 commit fcdd62e

File tree

1 file changed

+117
-68
lines changed

1 file changed

+117
-68
lines changed

latex.html

Lines changed: 117 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@
104104
editor.selection.setRange({start, end})
105105

106106
editor.renderer.scrollCursorIntoView(null, 0.5)
107+
108+
lastRe = eqreg
109+
110+
return !match.fake;
111+
}
107112

113+
function updateSearch(eqreg) {
114+
if (!eqreg) eqreg = lastRe
108115
if (searchValue != eqreg.source) {
109116
searchValue = eqreg.source
110117
}
@@ -113,11 +120,9 @@
113120
editor.searchBox.searchInput.value = eqreg.source
114121
editor.searchBox.regExpOption.checked = true;
115122
editor.searchBox.$syncOptions()
116-
})
117-
118-
return !match.fake;
123+
})
119124
}
120-
125+
var lastRe
121126
var searchValue
122127
var searchTimeout
123128

@@ -210,16 +215,57 @@
210215

211216
initialize()
212217
}}, "initialize"],
213-
// " ",
218+
214219

215-
// ["button", {
216-
// style: "float: right",
217-
// onclick: function() {
218-
// sidePanel.remove()
219-
// editor.focus()
220-
// }
221-
// }, "x"],
222-
["hr"],
220+
["hr"], // bibliography
221+
["button", {onclick: function() {
222+
bookCitation();
223+
editor.renderer.scrollCursorIntoView(null, 0.5)
224+
225+
editor.focus()
226+
}}, "cite"],
227+
228+
229+
["button", {onclick: function() {
230+
findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe)
231+
updateSearch()
232+
editor.focus()
233+
}}, "next"],
234+
235+
" \x1a \x1a \x1a ",
236+
237+
["button", {onclick: function() {
238+
editor.selection.moveTo(0, 0)
239+
var max = 10000
240+
while(findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) && max-- >0) {
241+
bookCitation();
242+
}
243+
editor.focus()
244+
}}, "all"],
245+
246+
["br"],
247+
248+
["button", {onclick: function() {
249+
250+
var text = editor.getSelectedText()
251+
252+
text = text
253+
.replace(/^\s*(References|Literature|литература)/i, "")
254+
.replace(/\n+(\d+)\.?/gm, function(_, number) {
255+
return "\n\n\\bibitem{book" + number +"}\n"
256+
});
257+
258+
var replacement = "\\begin{thebibliography}{1}\n"
259+
+ text
260+
+ "\n\\end{thebibliography}"
261+
262+
editor.insert(replacement)
263+
editor.focus()
264+
}}, "bibliography"],
265+
266+
267+
268+
["hr"], // section
223269
["button", {onclick: function() {
224270

225271
var line = editor.getSelectedText()
@@ -230,12 +276,13 @@
230276

231277
editor.insert(`\\section{ ${caption} }\n`+`\\label{part${number}}\n`)
232278
editor.renderer.scrollCursorIntoView(null, 0.5)
233-
editor.focus()
279+
editor.focus()
234280

235281
// findNext(sectionReg)
236282
}}, "section"],
237283
["button", {onclick: function() {
238284
findNext(sectionReg, eqAndBibExclusionRe)
285+
updateSearch()
239286
editor.focus()
240287
}}, "next"],
241288

@@ -255,6 +302,7 @@
255302

256303
["button", {onclick: function() {
257304
findNext(eqReg)
305+
updateSearch()
258306
editor.focus()
259307
}}, "next"],
260308
" ",
@@ -284,6 +332,7 @@
284332
["button", {onclick: function() {
285333
findNext(inlineEqReg)
286334
editor.focus()
335+
updateSearch()
287336
}}, "next"],
288337
["br"],
289338

@@ -335,6 +384,7 @@
335384
["button", {onclick: function() {
336385
findNext(eqRefReg, eqAndBibExclusionRe)
337386
editor.focus()
387+
updateSearch()
338388
}}, "next"],
339389
" \x1b \x1b \x1b \x1b ",
340390

@@ -440,6 +490,7 @@
440490
// (\\begin{tabular[\s\S]*?\\end{tabular})
441491
findNext(/(TAB(LE)|Таблица)?\s*([\d.]+)([\S\s]*?)/gi)
442492
editor.focus()
493+
updateSearch()
443494
}}, "next"],
444495
["br"],
445496

@@ -491,6 +542,7 @@
491542
["button", {onclick: function() {
492543
findNext(/(FIG(URES?|\.)?|TABLES?)\s*[\d\.]+[a-z]?(?:\s*(?:and|-|,)\s*([\d\.]+[a-z]?))?/ig)
493544
editor.focus()
545+
updateSearch()
494546
}}, "next"],
495547
["span", "\xa0\xa0\xa0\xa0\xa0\xa0"],
496548
["button", {onclick: function() {
@@ -520,75 +572,59 @@
520572
editor.focus()
521573
}}, "ref"],
522574

575+
523576
["hr"],
524577
["button", {onclick: function() {
525-
bookCitation();
526-
editor.renderer.scrollCursorIntoView(null, 0.5)
527-
528-
editor.focus()
529-
}}, "cite"],
578+
var text = editor
530579

531580

532-
["button", {onclick: function() {
533-
findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe)
534-
editor.focus()
535-
}}, "next"],
581+
582+
var line = editor.getSelectedText()
583+
expRe.lastIndex=0
584+
var m = expRe.exec(line)
585+
console.log(m)
586+
var contents = (m[1] || m[2])
587+
if (!contents) return;
536588

537-
" \x1a \x1a \x1a ",
589+
var replacement = "e^{" + contents + "}"
538590

539-
["button", {onclick: function() {
540-
editor.selection.moveTo(0, 0)
541-
var max = 10000
542-
while(findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) && max-- >0) {
543-
bookCitation();
544-
}
545-
editor.focus()
546-
}}, "all"],
591+
var sel = editor.selection.toJSON();
547592

548-
["br"],
593+
var reg = ace.require("ace/lib/lang").escapeRegExp(line);
594+
var reg = new RegExp(reg)
549595

550-
// ["button", {onclick: function() {
551-
// replaceBibItem()
552-
// editor.renderer.scrollCursorIntoView(null, 0.5)
596+
editor.selection.moveTo(0, 0)
597+
var max = 10000
598+
var data = {}
599+
while(findNext(reg) && max-- >0) {
600+
editor.insert(replacement)
601+
}
553602

554-
// editor.focus()
555-
// }}, "bibitem"],
556-
557-
// ["button", {onclick: function() {
558-
// findNext(/\n+\d+\./gm, /^[\S\s]*\\begin{thebibliography}/g)
559-
// editor.focus()
560-
// }}, "next"],
561-
// " \xa0 \xa0 \xa0 \xa0 \xa0 \xa0 ",
562-
// ["button", {onclick: function() {
563-
// while (findNext(/\n+\d+\./gm, /^[\S\s]*\\begin{thebibliography}/g)) {
564-
// replaceBibItem();
565-
// }
566-
// findNext(/n{thebibliography}/)
567-
// editor.focus();
568-
// }}, "all"],
603+
editor.selection.fromJSON(sel);
604+
// sectionReg.lastIndex = 0
605+
// var match = sectionReg.exec(line)
606+
// var number = match[1]
607+
// var caption = match[2].trim()
569608

570-
["button", {onclick: function() {
609+
// editor.insert(`\\section{ ${caption} }\n`+`\\label{part${number}}\n`)
610+
editor.renderer.scrollCursorIntoView(null, 0.5)
571611

572-
var text = editor.getSelectedText()
573-
574-
text = text
575-
.replace(/^\s*(References|Literature|литература)/i, "")
576-
.replace(/\n+(\d+)\.?/gm, function(_, number) {
577-
return "\n\n\\bibitem{book" + number +"}\n"
578-
});
612+
editor.focus()
579613

580-
var replacement = "\\begin{thebibliography}{1}\n"
581-
+ text
582-
+ "\n\\end{thebibliography}"
614+
}}, "exp to e"],
583615

584-
editor.insert(replacement)
616+
["button", {onclick: function() {
617+
findNext(expRe)
585618
editor.focus()
586-
}}, "bibliography"],
587-
588-
["hr"],
619+
updateSearch()
620+
}}, "next"],
621+
589622

590623
], sidePanel)
591624

625+
var expRe = /\\exp\s*(?:\(([^)]*)\)|\\left\(([^)]*)\\right\))/g
626+
627+
592628
function replaceBibItem() {
593629
var line = editor.getSelectedText()
594630
var replacement = line.replace(/\n+(\d+)\.?/gm, function(_, number) {
@@ -693,7 +729,6 @@
693729
return `\\eqref{eq${e1}}`
694730
})
695731
if (v1 != v) editor.setValue(v1)
696-
697732
}
698733

699734
function fixBibliography() {
@@ -711,7 +746,7 @@
711746
editor.setValue(newValue)
712747
}
713748

714-
749+
function randomStuff() {
715750

716751
value = "\\bibitem{book19}\n\
717752
Uflyand, Ya.1968. Integral Transformations in Problems of the Elasticity Theory. Leningrad. Nauka. 402 (in Russian). \
@@ -738,7 +773,21 @@
738773
return intro + newNames + " (" + number + ") "
739774

740775
})
776+
}
741777

778+
function removeAlignement() {
779+
v=editor.getValue().replace(/\\(begin|end){aligned}/g, "")
780+
.replaceAll("\\right.", "").replaceAll("\\left.", "")
781+
.replaceAll("\\right", "").replaceAll("\\left", "")
782+
783+
.replaceAll(/\\\\/g, "") .replaceAll(/&/g, "")
784+
.replaceAll(/\\\\/g, "") .replaceAll(/&/g, "")
785+
.replaceAll(/ *\+ *\n *\+/g, " +\n")
786+
.replaceAll(/ *\- *\n *\-/g, " -\n")
787+
.replaceAll(/ *\\times *\n *\\times/g, " \\times\n")
788+
console.log(v)
789+
790+
}
742791

743792
window.onpagehide = function() {
744793
localStorage.lastValue = editor.getValue();

0 commit comments

Comments
 (0)