-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatex.html
798 lines (619 loc) · 20.7 KB
/
latex.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
<script src="https://ace.c9.io/build/src/ace.js"></script>
<div id="container">
<div id="sidePanel"></div>
<div id='example'>
Example
\[{{\gamma }_{1}}=\frac{1}{2\pi }\arg ,\] (1.1)
Fig. 1. some text \[\int_L dL\]
Figure. 2 more text
paragraph \[\int_L dL\] 1 \[\int_L dL\] (1.2)
paragraph 2 $eq$ (1.2) [1-2] and [2]
Fig. 3 description
see (Fig.1) for explanation
${{\gamma }_{1}}=\frac{1}{2\pi }\arg ,$ (1.2)
References
1. Galin L.A. Contact problems of the theory of elasticity and viscoelasticity.-M.: Nauka, 1980.- 304 p. (In Russian)
2. Shtaerman I.Ya. Contact problem of elasticity theory. - M.-L.: Gostekhteorizdat, 1947 - 270 p. (In Russian)
</div>
</div>
<style>
#container {
display: flex;
height: 100%;
align-items: stretch;
}
#example {
flex: 1;
}
#sidePanel {
background: rebeccapurple;
overflow: auto;
color: white;
}
button {
margin-top: 5px;
}
</style>
<script>
var editor = ace.edit("example", {
theme: "ace/theme/textmate",
mode: "ace/mode/latex",
wrap: true
});
ace.config.loadModule("ace/ext/searchbox", function (e) {
e.Search(editor);
editor.searchBox.searchInput.value = ""
});
if (localStorage.lastValue) {
editor.setValue(localStorage.lastValue, -1);
if (localStorage.lastSelection) {
try {
let sel = JSON.parse(localStorage.lastSelection)
editor.selection.fromJSON(sel)
} catch(e) {
console.error(e)
}
}
editor.session.setScrollTop(localStorage.scrollTop || 0)
}
function findNext(eqreg, excludeRe) {
value = editor.getValue()
if (excludeRe) {
value = value.replace(excludeRe, function(_) {
return " ".repeat(_.length)
})
}
lastIndex = editor.session.doc.positionToIndex(editor.selection.getRange().end)
eqreg.lastIndex = lastIndex
match = eqreg.exec(value)
lastIndex = eqreg.lastIndex
if (!match) match = {index: 0, 0: "", fake: true};
start = editor.session.doc.indexToPosition(match.index)
end = editor.session.doc.indexToPosition(match.index + match[0].length)
editor.selection.setRange({start, end})
editor.renderer.scrollCursorIntoView(null, 0.5)
lastRe = eqreg
return !match.fake;
}
function updateSearch(eqreg) {
if (!eqreg) eqreg = lastRe
if (searchValue != eqreg.source) {
searchValue = eqreg.source
}
searchTimeout = searchTimeout || setTimeout(function() {
searchTimeout = null;
editor.searchBox.searchInput.value = eqreg.source
editor.searchBox.regExpOption.checked = true;
editor.searchBox.$syncOptions()
})
}
var lastRe
var searchValue
var searchTimeout
var eqReg = / *(\\\[(?:[^\\]|\\[^\]])+\\\]|\$[^$]+\$)([\s,.;]*)(\(\d+(?:\.[\d.]*)?\w*\))/g
var eqRegStrict = /^[ \t]*(\\\[(?:[^\\]|\\[^\]])+\\\]|\$[^$]+\$)([\s,.;]*)(\(\d+(?:\.[\d.]*)?\w*\))[ \t]*$/gm
var sectionReg = /^(\d+(?:\.[\d.]*)?)(.*)/gm
var numberReg =/(\(\d+(?:\.[\d.]*)?\w*\))/g
var numberRegUnStrict = /(\(\s*\d+(?:\.[\d.]*)?\w*\)\s*)/g
var inlineEqReg=/ *(\\\[(?:[^\\]|\\[^\]])+\\\]|\$[^$]+\$)([ ;,.]*)/g
var inlineEqStartReg=/^\s*(\$[^$]+\$)|\\\[(?:[^\\]|\\[^\]])+\\\](?= *\w)|(?<=\w +)\\\[(?:[^\\]|\\[^\]])+\\\]/gm
var eqAndBibExclusionRe = /\\begin{(equation|tabular|figure)[\s\S]*?\\end{\1|\$[^$]+\$|\\begin{thebibliography}[\s\S]*/g
var displayEqReg=/^\s*(\$[^$]+\$)\s*$/gm
var sidePanel = document.getElementById("sidePanel")
if (!sidePanel) {
sidePanel = document.createElement("div")
sidePanel.id="sidePanel"
document.body.appendChild(sidePanel)
sidePanel.style.cssText=" position: absolute; background: beige;"
}
sidePanel.innerHTML = ""
if (!window.dom) dom = ace.require("ace/lib/dom")
//editor = document.querySelector(".ace_editor").env.editor
function formatRefNumber(str) {
return str.trim().replace(/\.+$/, "").replace(/\./g, "_").trim()
}
function replaceNumberedEquation() {
var line = editor.getSelectedText()
eqReg.lastIndex = 0
var match = eqReg.exec(line)
var number = "eq" + match[3].replace(/[()]/g, "") .replace(/[\.]/g, "_")
var punct = match[2].trim()
var eq = match[1].trim().replace(/^(\\\[|\$)/, "").replace(/(\\\]|\$)$/, "").trim()
var replacement = `\\begin{equation} \\label{${number}}\n${eq + punct}\n\\end{equation}`
editor.insert(replacement)
}
function convertToInline() {
var line = editor.getSelectedText()
inlineEqReg.lastIndex = 0
var match = inlineEqReg.exec(line)
var punct = match[2].trim()
var eq = match[1].trim().replace(/^(\\\[|\$)/, "").replace(/(\\\]|\$)$/, "").trim()
var replacement = ` $${eq}$` + punct + " "
editor.insert(replacement)
}
function convertToDisplay() {
var line = editor.getSelectedText()
inlineEqReg.lastIndex = 0
var match = inlineEqReg.exec(line)
var punct = match[2].trim()
var eq = match[1].trim().replace(/^(\\\[|\$)/, "").replace(/(\\\]|\$)$/, "").trim()
var replacement = `\\begin{equation*}\n${eq + punct}\n\\end{equation*}`
editor.insert(replacement)
}
function bookCitation() {
var line = editor.getSelectedText()
var match = /\[([\d\,\-\s]*)\]/g.exec(line)
var books = match[1].replace(/\s+/g, "").replace(/(\d+)-(\d+)/g, function(_, a, b) {
a = parseInt(a)
b = parseInt(b)
if (a > b) throw a
var r = []
for (var i = a; i <= b; i++) {
r.push(i)
}
return r.join(",")
} ).replace(/\d+/g, x=>"book" + x)
var replacement = "\\cite{" + books +"}"
editor.insert(replacement)
}
dom.buildDom([
"div", {onclick: ()=> editor.focus()},
["button", {onclick: function() {
initialize()
}}, "initialize"],
["hr"], // bibliography
["button", {onclick: function() {
bookCitation();
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "cite"],
["button", {onclick: function() {
findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe)
updateSearch()
editor.focus()
}}, "next"],
" \x1a \x1a \x1a ",
["button", {onclick: function() {
editor.selection.moveTo(0, 0)
var max = 10000
while(findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) && max-- >0) {
bookCitation();
}
editor.focus()
}}, "all"],
["br"],
["button", {onclick: function() {
var text = editor.getSelectedText()
text = text
.replace(/^\s*(References|Literature|литература)/i, "")
.replace(/\n+(\d+)\.?/gm, function(_, number) {
return "\n\n\\bibitem{book" + number +"}\n"
});
var replacement = "\\begin{thebibliography}{1}\n"
+ text
+ "\n\\end{thebibliography}"
editor.insert(replacement)
editor.focus()
}}, "bibliography"],
["hr"], // section
["button", {onclick: function() {
var line = editor.getSelectedText()
sectionReg.lastIndex = 0
var match = sectionReg.exec(line)
var number = match[1]
var caption = match[2].trim()
editor.insert(`\\section{ ${caption} }\n`+`\\label{part${number}}\n`)
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
// findNext(sectionReg)
}}, "section"],
["button", {onclick: function() {
findNext(sectionReg, eqAndBibExclusionRe)
updateSearch()
editor.focus()
}}, "next"],
["hr"],
"Equations",
["br"],
["button", {onclick: function() {
replaceNumberedEquation()
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "numbered equation"],
["button", {onclick: function() {
findNext(eqReg)
updateSearch()
editor.focus()
}}, "next"],
" ",
["button", {onclick: function() {
editor.selection.moveTo(0, 0)
var max = 10000
while(findNext(eqRegStrict) && max-- >0) {
replaceNumberedEquation()
}
}}, "all"],
["br"],
["button", {onclick: function() {
convertToDisplay();
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus();
}}, "display"],
["button", {onclick: function() {
convertToInline()
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "inline"],
["button", {onclick: function() {
findNext(inlineEqReg)
editor.focus()
updateSearch()
}}, "next"],
["br"],
["button", {onclick: function() {
editor.selection.moveTo(0, 0)
var max = 10000
while(findNext(inlineEqReg) && max-- >0) {
convertToInline()
}
editor.focus()
}}, "all inline"],
["br"],
["hr"],
["button", {onclick: function() {
findNext(inlineEqStartReg)
editor.focus()
}}, "next broken"],
["button", {onclick: function() {
findNext(/^\s*\(\d+\.\d+\.\d+\w*\)\s*$/gmi)
editor.focus()
}}, "next empty"],
["br"],
["button", {onclick: function() {
editor.selection.moveTo(0, 0)
var max = 10000
while(findNext(displayEqReg) && max-- >0) {
convertToDisplay()
}
editor.focus()
}}, "all display"],
["br"],
// ["button", {onclick: function() {
// convertNumbers()
// editor.focus()
// }}, "convert numbers to refs"],
["button", {onclick: function() {
replaceEqRef()
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "eq ref"],
["button", {onclick: function() {
findNext(eqRefReg, eqAndBibExclusionRe)
editor.focus()
updateSearch()
}}, "next"],
" \x1b \x1b \x1b \x1b ",
["button", {onclick: function() {
editor.selection.moveTo(0, 0)
var max = 10000
var data = {}
while(findNext(eqRefReg, eqAndBibExclusionRe) && max-- >0) {
replaceEqRef(data)
}
console.log(max)
}}, "all"],
["br"],
["hr"],
// ["button", {onclick: function() {
// var line = editor.getSelectedText()
// var replacement = `\\begin{subequations}\n${line}\n\\end{subequations}`
// console.log(replacement)
// editor.insert(replacement)
// editor.renderer.scrollCursorIntoView(null, 0.5)
// editor.focus()
// }}, "subequations"],
// ["button", {onclick: function() {
// findNext(/eq\d+_\d+_\d+[^\d\}]+/g, /\\begin{subequations[\s\S]*?\\end{subequations/g)
// editor.focus()
// }}, "next"],
["br"],
// ["button", {onclick: function() {
// var figureRe = /(?<!\\)\b(sh|ch|exp)\b/g
// var line = editor.getSelectedText()
// var match = figureRe.exec(line)
// var figName = match[1]
// var replacement = "\\" + figName
// editor.insert(replacement)
// editor.renderer.scrollCursorIntoView(null, 0.5)
// editor.focus()
// editor.focus()
// }}, "sh|ch"],
// ["button", {onclick: function() {
// findNext(/(?<!(?:\\|\\operatorname\{))\b(sh|ch|exp)\b/g)
// editor.focus()
// }}, "next"],
// ["br"],
// ["button", {onclick: function() {
// findNext(inlineEqStartReg)
// editor.focus()
// }}, "check eq refs"],
["br"],
["button", {onclick: function() {
findNext(/[^\x00-\xff\s]/g)
editor.focus()
}}, "next non-english"],
["br"],
["button", {onclick: function() {
do {
findNext(/(\\\[(?:[^\\]|\\[^\]])+\\\]|\$[^$]+\$|\\begin{equation[\s\S]*?\\end{equation)|(\. *\n)(?=[ \t]*\S)/g)
var text = editor.getSelectedText()
} while(text && !/^(\. *\n)/.test(text))
editor.focus()
}}, "next paragraph"],
["br"],
["button", {onclick: function() {
var line = editor.getSelectedText()
var match = /[^\d]*([\d.]+)(.*)([\s\S]*)/g.exec(line)
var number = formatRefNumber(match[1])
var caption = match[2].trim().replace(/^}|\\textbf{}/g, "")
var tabular = match[3]
var rows = tabular.trim().split("\n");
var l
rows.forEach(function(x) {
if (l == null) l = x.split("\t").length
})
tabular = "\\begin{tabular}{|" + "c| ".repeat(l) + "}\\hline \n"
+ rows.map(x=>x.replace(/\t/g, " & ")).join("\\\\ \\hline \n")
+ "\\\\ \\hline \n \\end{tabular}"
var replacement = `\\begin{table}[!h]
\\centering
\\caption{
${caption}
}
\\label{tab:${number}}
${tabular}
\\end{table}`
editor.insert(replacement)
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "table"],
["button", {onclick: function() {
// (\\begin{tabular[\s\S]*?\\end{tabular})
findNext(/(TAB(LE)|Таблица)?\s*([\d.]+)([\S\s]*?)/gi)
editor.focus()
updateSearch()
}}, "next"],
["br"],
["button", {onclick: function() {
var figureRe = /(?:FIGURE|Fig|фиг)?\.?\s*([\d.]+\w?)(.*)/i
var line = editor.getSelectedText().replace(/\n/g, " ")
var match = figureRe.exec(line)
var number = formatRefNumber(match[1])
var caption = match[2].trim().replace(/^}|\\textbf{}/g, "").trim()
if (figureRe.test(caption)) {
var match2 = figureRe.exec(caption)
var number2 = formatRefNumber(match2[1])
var caption2 = match2[2].trim().replace(/^}|\\textbf{}/g, "").trim()
caption = caption.slice(0, match2.index).trim()
var pageType = /[^\d]$/.test(number) ? "subfigure" : "minipage"
var replacement = `\\begin{figure}[h]
\\centering
\\begin{${pageType}}{.45\\textwidth}
\\centering
\\includegraphics[width=.9\\linewidth]{fig_${number}.eps}
\\caption{ ${caption} }
\\label{fig_${number}}
\\end{${pageType}}
\\begin{${pageType}}{.45\\textwidth}
\\centering
\\includegraphics[width=.9\\linewidth]{fig_${number2}.eps}
\\caption{ ${caption2} }
\\label{fig_${number2}}
\\end{${pageType}}
\\end{figure}`
} else {
var replacement = `\\begin{figure}[h]
\\centering
\\includegraphics[scale=.4]{fig_${number}.eps}
\\caption{ ${caption} }
\\label{fig_${number}}
\\end{figure}`
}
editor.insert(replacement)
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "figure"],
["button", {onclick: function() {
findNext(/(FIG(URES?|\.)?|TABLES?)\s*[\d\.]+[a-z]?(?:\s*(?:and|-|,)\s*([\d\.]+[a-z]?))?/ig)
editor.focus()
updateSearch()
}}, "next"],
["span", "\xa0\xa0\xa0\xa0\xa0\xa0"],
["button", {onclick: function() {
var figureRe = /(FIG(?:URES?|\.)?|TABLES?)\s*([\d\.]+[a-z]?)(?:\s*(and|-|,)\s*([\d\.]+[a-z]?))?/i
var line = editor.getSelectedText().replace(/\n/g, " ")
if (line.slice(-1) == ".") {
line = line.slice(0,-1)
var r = editor.selection.getRange(); r.end.column--; editor.selection.setRange(r)
}
var match = figureRe.exec(line)
var figName = match[1]
var number = formatRefNumber(match[2])
var link = match[3]
var number2 = formatRefNumber(match[4] || "")
var replacement = figName + " \\ref{fig_" + number + "}"
if (number2) replacement += (link == "-" ? "-" : link == ","? ", " : " " + link + " ") + "\\ref{fig_" + number2 + "}"
editor.insert(replacement)
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
editor.focus()
}}, "ref"],
["hr"],
["button", {onclick: function() {
var text = editor
var line = editor.getSelectedText()
expRe.lastIndex=0
var m = expRe.exec(line)
console.log(m)
var contents = (m[1] || m[2])
if (!contents) return;
var replacement = "e^{" + contents + "}"
var sel = editor.selection.toJSON();
var reg = ace.require("ace/lib/lang").escapeRegExp(line);
var reg = new RegExp(reg)
editor.selection.moveTo(0, 0)
var max = 10000
var data = {}
while(findNext(reg) && max-- >0) {
editor.insert(replacement)
}
editor.selection.fromJSON(sel);
// sectionReg.lastIndex = 0
// var match = sectionReg.exec(line)
// var number = match[1]
// var caption = match[2].trim()
// editor.insert(`\\section{ ${caption} }\n`+`\\label{part${number}}\n`)
editor.renderer.scrollCursorIntoView(null, 0.5)
editor.focus()
}}, "exp to e"],
["button", {onclick: function() {
findNext(expRe)
editor.focus()
updateSearch()
}}, "next"],
], sidePanel)
var expRe = /\\exp\s*(?:\(([^)]*)\)|\\left\(([^)]*)\\right\))/g
function replaceBibItem() {
var line = editor.getSelectedText()
var replacement = line.replace(/\n+(\d+)\.?/gm, function(_, number) {
return "\n\n\\bibitem{book" + number +"}\n"
});
editor.insert(replacement)
}
function initialize() {
var v=editor.getValue();
var v1=v.replace(/’/g, "'").replace(/β/g, '$\beta$')
v1 = v1.replace(/(\\\[(?:[^\\]|\\[^\]])+\\\]|\$[^$]+\$|\\begin{equation[\s\S]*?\\end{equation)|(\. *\n)(?=[ \t]*[^\s}\])$])/g, function(a,_,b) { if(b) return b + "\n"; return a })
v1 = v1.replace(/{align}/g, "{aligned}")
v1 = v1.replace(/а/g, "a")
v1 = v1.replace(/–/g, "--")
v1 = v1.replace(/[“”]/g, '"')
if (!/begin\{document}/.test(v1)) {
v1=`\\documentclass[12pt,a4paper]{article}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{amssymb}
\\usepackage{graphicx}
% \\usepackage{diagbox}
% \\newcommand{\\Chi}{\\mathrm{X}}
% \\newcommand{\\Alpha}{\\mathrm{A}}
% \\usepackage{unicode-math}
% \\newcommand{\\sgn}{\\mathop{sgn}}
\\usepackage{caption}
\\captionsetup[figure]{font=scriptsize}
\\captionsetup[figure]{font=footnotesize}
% \\renewcommand{\\theequation}{\\thesection.{\\arabic{equation}}}
\\numberwithin{equation}{section}
\\begin{document}
\\begin{center}\\Large{\\textbf{
TITLE
} }\\end{center}
\\begin{center}
AUTHOR NAME
\\end{center}
${v1}
\\end{document}
`
}
if (v!=v1) editor.setValue(v1)
}
var eqRefReg = /\(\d+[.\d]+\w*\)/g
function replaceEqRef(data) {
if (!data) data = {}
var results = data.results;
if (!results) {
results = data.results = computeLabels()
}
var e = editor.getSelectedText();
if (!e) return
var e1 = e.slice(1, -1).replace(/\./g, "_");
if (!results[e1]) {
console.log(e1)
editor.navigateRight()
return
}
var replacement = `\\eqref{eq${e1}}`
editor.insert(replacement)
}
function computeLabels() {
var v = editor.getValue();
var re = /\\label{eq([\d_\w]*)}/g
var results = {}
var m
while ((m = re.exec(v))) {
results[m[1]] = 1
}
return results
}
function convertNumbers() {
var results = computeLabels();
var v1 = v.replace(/\(\d+\.\d+\.\d+\w*\)/g, function(e) {
var e1 = e.slice(1, -1).replace(/\./g, "_");
if (!results[e1]) {
console.log(e1)
return e
}
return `\\eqref{eq${e1}}`
})
if (v1 != v) editor.setValue(v1)
}
function fixBibliography() {
var newValue = editor.getValue() .replace(/(\\bibitem{book\d+}\s*)([^\d\\\n]+)(\d{4}\b).?\s*/g, function(_, intro, names, number) {
var newNames = names.replace(/([^\s,.]+),?\s+(\w{1,3}\.(\s*\w{1,3}\.)*)/g, function(_, x1, x2) {
return x1 + " " + x2.replace(/[\s.]/g, "")
}).trim()
console.log(newNames)
return intro + newNames + " (" + number + ") "
})
editor.setValue(newValue)
}
function randomStuff() {
value = "\\bibitem{book19}\n\
Uflyand, Ya.1968. Integral Transformations in Problems of the Elasticity Theory. Leningrad. Nauka. 402 (in Russian). \
"
value.replace(/(\\bibitem{book\d+}\s*)([^\d\\\n]+)(\d+).?\s*/g, function(_, intro, names, number) {
/* var parts = names.split(",")
var newNames = []
for (var i = 0; i< parts.length; i++) {
var lastName = parts[i].trim()
var initials = parts[i + 1].replace(/[\s\.]/g, "")
i++
newNames.push(lastName + " " + initials)
}
*/
var newNames = names.replace(/([^\s,.]+),?\s+(\w{1,3}\.(\s*\w{1,3}\.)*)/g, function(_, x1, x2) {
return x1 + " " + x2.replace(/[\s.]/g, "")
}).trim()
console.log(newNames)
return intro + newNames + " (" + number + ") "
})
}
function removeAlignement() {
v=editor.getValue().replace(/\\(begin|end){aligned}/g, "")
.replaceAll("\\right.", "").replaceAll("\\left.", "")
.replaceAll("\\right", "").replaceAll("\\left", "")
.replaceAll(/\\\\/g, "") .replaceAll(/&/g, "")
.replaceAll(/\\\\/g, "") .replaceAll(/&/g, "")
.replaceAll(/ *\+ *\n *\+/g, " +\n")
.replaceAll(/ *\- *\n *\-/g, " -\n")
.replaceAll(/ *\\times *\n *\\times/g, " \\times\n")
console.log(v)
}
window.onpagehide = function() {
localStorage.lastValue = editor.getValue();
localStorage.lastSelection = JSON.stringify(editor.selection.toJSON());
localStorage.scrollTop = editor.session.getScrollTop()
}
</script>