Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/editor-button-bar.ts
1678 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/* Definition and control logic behind the various button bars.
7
//
8
There is a level of separation between the button bar's and the actual content what they insert/modify.
9
This is motivated by editing text, where various markups have different realizations ("B"old button -> **abc** or <b>abc</b>)
10
11
There are less/none overlaps for programming languages.
12
13
FUTURE:
14
* think about creating a dedicated dialog for more elaborate examples,
15
which should also have a client/server communication to avoid bloat
16
(think of a repository of hundrets of full examples with explanatory text)
17
* work out how codemirror should react if there is a text selected or multiple
18
cursors active (just the primary one!?)
19
20
CONSIDERATIONS:
21
* buttons should insert code which immediately works:
22
it's easier for users to delete lines than to end up with some partial broken fragments
23
*/
24
25
import $ from "jquery";
26
27
export const FONT_SIZES = [
28
"xx-small",
29
"x-small",
30
"small",
31
"medium",
32
"large",
33
"x-large",
34
"xx-large",
35
] as const;
36
37
export const FONT_FACES = [
38
"Serif",
39
"Sans",
40
"Arial",
41
"Arial Black",
42
"Courier",
43
"Courier New",
44
"Comic Sans MS",
45
"Cursive",
46
"Georgia",
47
"Helvetica",
48
"Impact",
49
"Lucida Grande",
50
"Lucida Sans",
51
"Monaco",
52
"Palatino",
53
"Tahoma",
54
"Times New Roman",
55
"Ubuntu",
56
"Verdana",
57
] as const;
58
59
let i, j, k;
60
61
export const commands = {
62
shell: {
63
comment: {
64
wrap: {
65
left: "#",
66
right: "",
67
multi: true,
68
space: true,
69
},
70
},
71
set_name_and_email: {
72
insert: `\
73
git config --global user.name ""
74
git config --global user.email ""\
75
`,
76
},
77
initalize_git: {
78
insert: `\
79
git init\
80
`,
81
},
82
create_gitignore: {
83
insert: `\
84
# See examples of .gitignore files at https://github.com/github/gitignore
85
echo "
86
# For CoCalc files like .sage-chat etc
87
*.sage-chat
88
*.sage-history
89
*.term
90
*.py[cod]" >> .gitignore\
91
`,
92
},
93
clone_local_repo: {
94
insert: `\
95
git clone ~/local_dir/\
96
`,
97
},
98
clone_remote_repo: {
99
insert: `\
100
git clone https://github.com/sagemathinc/cocalc.git\
101
`,
102
},
103
add_file_to_repo: {
104
insert: `\
105
git add afile.py\
106
`,
107
},
108
add_all_to_repo: {
109
insert: `\
110
git add *\
111
`,
112
},
113
diff: {
114
insert: `\
115
git diff\
116
`,
117
},
118
commit: {
119
insert: `\
120
git commit -a -m "commit message"\
121
`,
122
},
123
setup_ssh_for_github: {
124
insert: `\
125
set -e
126
mkdir -p ~/.ssh/
127
SSHFILE=~/.ssh/id_rsa
128
ssh-keygen -t rsa -b 4096 -N "" -C "[email protected]" -f $SSHFILE
129
eval $(ssh-agent -s)
130
ssh-add ~/.ssh/id_rsa
131
echo "Below this line is your public SSH key"
132
cat ~/.ssh/id_rsa.pub
133
# Copy your public key below and follow the instructions at https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/#platform-linux\
134
`,
135
},
136
push_origin_master: {
137
insert: `\
138
git push origin master\
139
`,
140
},
141
142
status: {
143
insert: `\
144
git status\
145
`,
146
},
147
148
add_remote_repo: {
149
insert: `\
150
git remote add origin <server>\
151
`,
152
},
153
154
list_remote_repos: {
155
insert: `\
156
git remote -v\
157
`,
158
},
159
160
create_new_branch: {
161
insert: `\
162
git checkout -b <branchname>\
163
`,
164
},
165
166
switch_branches: {
167
insert: `\
168
git checkout <branchname>\
169
`,
170
},
171
172
list_branches: {
173
insert: `\
174
git branch\
175
`,
176
},
177
178
delete_the_feature_branch: {
179
insert: `\
180
git branch -d <branchname>\
181
`,
182
},
183
184
push_branch: {
185
insert: `\
186
git push origin <branchname>\
187
`,
188
},
189
190
push_all_branches: {
191
insert: `\
192
git push --all origin\
193
`,
194
},
195
196
delete_remote_branch: {
197
insert: `\
198
git push origin --delete <branchName>\
199
`,
200
},
201
202
pull: {
203
insert: `\
204
git pull\
205
`,
206
},
207
208
merge_branch: {
209
insert: `\
210
git merge <branchname>
211
git diff
212
git diff --base <filename>
213
git diff <sourcebranch> <targetbranch>
214
git add <filename>\
215
`,
216
},
217
218
show_history: {
219
insert: `\
220
git log\
221
`,
222
},
223
224
undo_local_changes: {
225
insert: `\
226
git checkout -- <filename>\
227
`,
228
},
229
230
get_rid_of_local_changes: {
231
insert: `\
232
git fetch origin
233
git reset --hard origin/master\
234
`,
235
},
236
237
search_for: {
238
insert: `\
239
git grep "foo()"\
240
`,
241
},
242
},
243
tex: {
244
integral: {
245
insert: "$int_{0}^{infty} \frac{1}{1+x^2},mathrm{d}x$",
246
},
247
cases: {
248
insert: `\
249
$$
250
f(n) =
251
\begin{cases}
252
2 (n+1) & \text{if} n \equiv 0 \\
253
(3n+1)/2 & \text{if} n \equiv 1.
254
\end{cases}
255
$$\
256
`,
257
},
258
bold: {
259
wrap: {
260
left: "\\textbf{",
261
right: "}",
262
},
263
},
264
italic: {
265
wrap: {
266
left: "\\textit{",
267
right: "}",
268
},
269
},
270
underline: {
271
wrap: {
272
left: "\\underline{",
273
right: "}",
274
},
275
},
276
strikethrough: {
277
// requires the soul package
278
wrap: {
279
left: "\\st{",
280
right: "}",
281
},
282
},
283
equation: {
284
default: "x^2",
285
wrap: {
286
left: "$",
287
right: "$",
288
},
289
},
290
display_equation: {
291
default: "x^2",
292
wrap: {
293
left: "$$",
294
right: "$$",
295
},
296
},
297
insertunorderedlist: {
298
wrap: {
299
left: "\\begin{itemize}\n \\item\n",
300
right: "\\end{itemize}",
301
},
302
},
303
insertorderedlist: {
304
wrap: {
305
left: "\\begin{enumerate}\n \\item\n",
306
right: "\\end{enumerate}",
307
},
308
},
309
format_heading_0: {
310
strip: [
311
"format_heading_1",
312
"format_heading_2",
313
"format_heading_3",
314
"format_heading_4",
315
],
316
wrap: { left: "", right: "" },
317
},
318
format_heading_1: {
319
strip: ["format_heading_2", "format_heading_3", "format_heading_4"],
320
wrap: {
321
left: "\\section{",
322
right: "}",
323
},
324
},
325
format_heading_2: {
326
strip: ["format_heading_1", "format_heading_3", "format_heading_4"],
327
wrap: {
328
left: "\\subsection{",
329
right: "}",
330
},
331
},
332
format_heading_3: {
333
strip: ["format_heading_1", "format_heading_2", "format_heading_4"],
334
wrap: {
335
left: "\\subsubsection{",
336
right: "}",
337
},
338
},
339
format_heading_4: {
340
strip: ["format_heading_1", "format_heading_2", "format_heading_4"],
341
wrap: {
342
left: "\\subsubsubsection{",
343
right: "}",
344
},
345
},
346
format_code: {
347
wrap: {
348
left: "\n\\begin{verbatim}\n",
349
right: "\n\\end{verbatim}\n",
350
},
351
},
352
indent: {
353
wrap: {
354
left: "\n\\begin{quote}\n",
355
right: "\n\\end{quote}\n",
356
},
357
},
358
quote: {
359
wrap: {
360
left: "\n\\begin{quote}\n",
361
right: "\n\\end{quote}\n",
362
},
363
},
364
table: {
365
wrap: {
366
left: "\n\\begin{center}\\begin{tabular}{|c|c|}\n\\hline\ncell1 & cell2 \\\\\ncell3 & cell4 \\\\\n\\hline",
367
right: "\n\\end{tabular}\\end{center}\n",
368
},
369
},
370
subscript: {
371
wrap: {
372
left: "_{",
373
right: "}",
374
},
375
},
376
superscript: {
377
wrap: {
378
left: "^{",
379
right: "}",
380
},
381
},
382
comment: {
383
wrap: {
384
left: "%",
385
right: "",
386
multi: true,
387
space: true,
388
},
389
},
390
horizontalRule: {
391
wrap: {
392
left: "\\hrulefill",
393
//left : "\n\\noindent\\makebox[\\linewidth]{\\rule{\\paperwidth}{0.4pt}}\n"
394
right: "",
395
},
396
},
397
justifyleft: {
398
wrap: {
399
left: "\n\\begin{flushleft}\n",
400
right: "\n\\end{flushleft}\n",
401
},
402
},
403
justifyright: {
404
wrap: {
405
left: "\n\\begin{flushright}\n",
406
right: "\n\\end{flushright}\n",
407
},
408
},
409
justifycenter: {
410
wrap: {
411
left: "\n\\begin{center}\n",
412
right: "\n\\end{center}\n",
413
},
414
},
415
},
416
417
md: {
418
bold: {
419
wrap: {
420
left: "**",
421
right: "**",
422
},
423
},
424
italic: {
425
wrap: {
426
left: "_",
427
right: "_",
428
},
429
},
430
underline: {
431
wrap: {
432
left: "<u>",
433
right: "</u>",
434
},
435
},
436
strikethrough: {
437
wrap: {
438
left: "~~",
439
right: "~~",
440
},
441
},
442
code: {
443
wrap: {
444
left: "`",
445
right: "`",
446
},
447
},
448
insertunorderedlist: {
449
wrap: {
450
left: " - first\n - second\n",
451
right: "",
452
multi: true,
453
space: false,
454
newline: true,
455
trim: false,
456
},
457
},
458
insertorderedlist: {
459
wrap: {
460
left: "1. first\n2. second\n",
461
right: "",
462
multi: true,
463
space: false,
464
newline: true,
465
trim: false,
466
},
467
},
468
format_code: {
469
wrap: {
470
left: " ",
471
right: "",
472
multi: true,
473
space: false,
474
newline: true,
475
trim: false,
476
},
477
},
478
format_heading_0: {
479
strip: [
480
"format_heading_1",
481
"format_heading_2",
482
"format_heading_3",
483
"format_heading_4",
484
"format_heading_5",
485
"format_heading_6",
486
],
487
wrap: { left: "", right: "" },
488
},
489
indent: {
490
wrap: {
491
left: "> ",
492
right: "",
493
multi: true,
494
space: false,
495
newline: true,
496
trim: false,
497
},
498
},
499
quote: {
500
wrap: {
501
left: "> ",
502
right: "",
503
multi: true,
504
space: false,
505
newline: true,
506
trim: false,
507
},
508
},
509
horizontalRule: {
510
wrap: {
511
left: "\n---\n",
512
right: "",
513
},
514
},
515
table: {
516
wrap: {
517
left: `\
518
| Left-Aligned | Center Aligned | Right Aligned |
519
| :------------ |:---------------:| -------------:|
520
| col 3 is | some wordy text | 1600 |
521
| col 2 is | centered | 12 |
522
| zebra stripes | and math | $\\pi^3$ |\
523
`,
524
right: "",
525
},
526
},
527
},
528
529
html: {
530
italic: {
531
wrap: {
532
left: "<em>",
533
right: "</em>",
534
},
535
},
536
bold: {
537
wrap: {
538
left: "<strong>",
539
right: "</strong>",
540
},
541
},
542
underline: {
543
wrap: {
544
left: "<u>",
545
right: "</u>",
546
},
547
},
548
strikethrough: {
549
wrap: {
550
left: "<strike>",
551
right: "</strike>",
552
},
553
},
554
subscript: {
555
wrap: {
556
left: "<sub>",
557
right: "</sub>",
558
},
559
},
560
superscript: {
561
wrap: {
562
left: "<sup>",
563
right: "</sup>",
564
},
565
},
566
comment: {
567
wrap: {
568
left: "<!--",
569
right: " -->",
570
space: true,
571
},
572
},
573
insertunorderedlist: {
574
wrap: {
575
left: "\n<ul>\n <li> ",
576
right: "</li>\n</ul>\n",
577
},
578
},
579
insertorderedlist: {
580
wrap: {
581
left: "\n<ol>\n <li> ",
582
right: "</li>\n</ol>\n",
583
},
584
},
585
justifyleft: {
586
// FUTURE -- define via for loop below
587
strip: ["justifycenter", "justifyright", "justifyfull"],
588
wrap: {
589
left: "",
590
right: "",
591
},
592
},
593
justifycenter: {
594
strip: ["justifycenter", "justifyright", "justifyleft"],
595
wrap: {
596
left: "<div style='text-align:center'>",
597
right: "</div>",
598
},
599
},
600
justifyright: {
601
strip: ["justifycenter", "justifyright", "justifyleft"],
602
wrap: {
603
left: "<div style='text-align:right'>",
604
right: "</div>",
605
},
606
},
607
justifyfull: {
608
strip: ["justifycenter", "justifyright", "justifyleft"],
609
wrap: {
610
left: "<div style='text-align:justify'>",
611
right: "</div>",
612
},
613
},
614
indent: {
615
wrap: {
616
left: "<blockquote>",
617
right: "</blockquote>",
618
},
619
},
620
format_heading_0: {
621
strip: [
622
"format_heading_1",
623
"format_heading_2",
624
"format_heading_3",
625
"format_heading_4",
626
],
627
wrap: { left: "", right: "" },
628
},
629
format_heading_1: {
630
// FUTURE -- define via for loop below
631
strip: ["format_heading_2", "format_heading_3", "format_heading_4"],
632
wrap: {
633
left: "<h1>",
634
right: "</h1>",
635
},
636
},
637
format_heading_2: {
638
strip: ["format_heading_1", "format_heading_3", "format_heading_4"],
639
wrap: {
640
left: "<h2>",
641
right: "</h2>",
642
},
643
},
644
format_heading_3: {
645
strip: ["format_heading_1", "format_heading_2", "format_heading_4"],
646
wrap: {
647
left: "<h3>",
648
right: "</h3>",
649
},
650
},
651
format_heading_4: {
652
strip: ["format_heading_1", "format_heading_2", "format_heading_3"],
653
wrap: {
654
left: "<h4>",
655
right: "</h4>",
656
},
657
},
658
format_code: {
659
wrap: {
660
left: "<pre>",
661
right: "</pre>",
662
},
663
},
664
equation: {
665
default: "x^2",
666
wrap: {
667
left: "$",
668
right: "$",
669
},
670
},
671
display_equation: {
672
default: "x^2",
673
wrap: {
674
left: "$$",
675
right: "$$",
676
},
677
},
678
table: {
679
wrap: {
680
left: `\
681
<table>
682
<tr>
683
<th>Header 1</th>
684
<th>Header 2</th>
685
</tr>
686
<tr>
687
<td>Cell 1</td>
688
<td>Cell 2</td>
689
</tr>
690
<tr>
691
<td>Cell 3</td>
692
<td>Cell 4</td>
693
</tr>
694
</table>\
695
`,
696
right: "\n",
697
},
698
},
699
horizontalRule: {
700
wrap: {
701
left: "\n<hr size='1'/>\n",
702
right: "",
703
},
704
},
705
},
706
707
rst: {
708
// there is intentionally no underline or strikethough in rst
709
italic: {
710
wrap: {
711
left: "*",
712
right: "*",
713
},
714
},
715
bold: {
716
wrap: {
717
left: "**",
718
right: "**",
719
},
720
},
721
subscript: {
722
wrap: {
723
left: " :sub:`",
724
right: "` ",
725
},
726
},
727
superscript: {
728
wrap: {
729
left: " :sup:`",
730
right: "` ",
731
},
732
},
733
comment: {
734
wrap: {
735
left: "\n..",
736
right: "",
737
multi: true,
738
space: true,
739
},
740
},
741
insertunorderedlist: {
742
wrap: {
743
left: "\n - ",
744
right: "",
745
},
746
},
747
insertorderedlist: {
748
wrap: {
749
left: "\n 1. ",
750
right: "",
751
},
752
},
753
justifyleft: {
754
// FUTURE -- define via for loop below
755
strip: ["justifycenter", "justifyright", "justifyfull"],
756
wrap: {
757
left: "",
758
right: "",
759
},
760
},
761
justifycenter: {
762
strip: ["justifycenter", "justifyright", "justifyleft"],
763
wrap: {
764
left: "\n.. class:: center\n\n",
765
right: "",
766
},
767
},
768
justifyright: {
769
strip: ["justifycenter", "justifyright", "justifyleft"],
770
wrap: {
771
left: "\n.. class:: right\n\n",
772
right: "",
773
},
774
},
775
justifyfull: {
776
strip: ["justifycenter", "justifyright", "justifyleft"],
777
wrap: {
778
left: "\n.. class:: justify\n\n",
779
right: "",
780
},
781
},
782
indent: {
783
wrap: {
784
left: "\n ",
785
right: "",
786
},
787
},
788
format_heading_0: {
789
strip: [
790
"format_heading_1",
791
"format_heading_2",
792
"format_heading_3",
793
"format_heading_4",
794
],
795
wrap: { left: "", right: "" },
796
},
797
format_heading_1: {
798
// FUTURE -- define via for loop below
799
strip: ["format_heading_2", "format_heading_3", "format_heading_4"],
800
wrap: {
801
left: "\n===============\n",
802
right: "\n===============\n",
803
},
804
},
805
format_heading_2: {
806
strip: ["format_heading_1", "format_heading_3", "format_heading_4"],
807
wrap: {
808
left: "\n---------------\n",
809
right: "\n---------------\n",
810
},
811
},
812
format_heading_3: {
813
strip: ["format_heading_1", "format_heading_2", "format_heading_4"],
814
wrap: {
815
left: "\n",
816
right: "\n=============\n",
817
},
818
},
819
format_heading_4: {
820
strip: ["format_heading_1", "format_heading_2", "format_heading_3"],
821
wrap: {
822
left: "\n",
823
right: "\n-------------\n",
824
},
825
},
826
format_code: {
827
wrap: {
828
left: `\
829
.. code:: python
830
831
def f(x):
832
return 2*x\
833
`,
834
right: "\n",
835
},
836
},
837
equation: {
838
default: "x^2",
839
wrap: {
840
left: " :math:`",
841
right: "` ",
842
},
843
},
844
display_equation: {
845
default: "x^2",
846
wrap: {
847
left: "\n.. math::\n\n ",
848
right: "\n",
849
},
850
},
851
table: {
852
// the first is the more complex grid table, the second one is a "simple" table
853
insert: `\
854
+------------+------------+-----------+
855
| Header 1 | Header 2 | Header 3 |
856
+============+============+===========+
857
| body row 1 | column 2 | column 3 |
858
+------------+------------+-----------+
859
| body row 2 | Cells may span columns.|
860
+------------+------------+-----------+
861
| body row 3 | Cells may | - Cells |
862
+------------+ span rows. | - contain |
863
| body row 4 | | - blocks. |
864
+------------+------------+-----------+
865
\
866
`,
867
},
868
/*
869
insert: """
870
===== ===== ======
871
Inputs Output
872
------------ ------
873
A B A or B
874
===== ===== ======
875
False False False
876
True False True
877
False True True
878
True True True
879
===== ===== ======
880
"""
881
*/
882
horizontalRule: {
883
insert: "\n------------------\n",
884
},
885
},
886
887
mediawiki: {
888
// https://www.mediawiki.org/wiki/Help:Formatting
889
bold: {
890
wrap: {
891
left: "'''",
892
right: "'''",
893
},
894
},
895
italic: {
896
wrap: {
897
left: "''",
898
right: "''",
899
},
900
},
901
underline: {
902
wrap: {
903
left: "<u>",
904
right: "</u>",
905
},
906
},
907
strikethrough: {
908
wrap: {
909
left: "<strike>",
910
right: "</strike>",
911
},
912
},
913
insertunorderedlist: {
914
wrap: {
915
left: "\n* item1\n* item2\n* ",
916
right: "\n",
917
},
918
},
919
insertorderedlist: {
920
wrap: {
921
left: "\n# one\n# two\n# ",
922
right: "\n",
923
},
924
},
925
comment: {
926
wrap: {
927
left: "\n<!--",
928
right: " -->\n",
929
space: true,
930
},
931
},
932
indent: {
933
// pre tag is more for code, but makes more sense than a dysfunctional ":"
934
wrap: {
935
left: "\n<pre>",
936
right: "</pre>\n",
937
},
938
},
939
format_heading_0: {
940
// FUTURE -- define via for loop below
941
strip: [
942
"format_heading_1",
943
"format_heading_2",
944
"format_heading_3",
945
"format_heading_4",
946
],
947
wrap: { left: "", right: "" },
948
},
949
format_heading_1: {
950
// FUTURE -- define via for loop below
951
strip: ["format_heading_2", "format_heading_3", "format_heading_4"],
952
wrap: {
953
left: "\n== ",
954
right: " ==\n",
955
},
956
},
957
format_heading_2: {
958
strip: ["format_heading_1", "format_heading_3", "format_heading_4"],
959
wrap: {
960
left: "\n=== ",
961
right: " ===\n",
962
},
963
},
964
format_heading_3: {
965
strip: ["format_heading_1", "format_heading_2", "format_heading_4"],
966
wrap: {
967
left: "\n==== ",
968
right: " ====\n",
969
},
970
},
971
format_heading_4: {
972
strip: ["format_heading_1", "format_heading_2", "format_heading_3"],
973
wrap: {
974
left: "\n===== ",
975
right: " =====\n",
976
},
977
},
978
format_code: {
979
wrap: {
980
left: " <code>",
981
right: "</code> ",
982
},
983
},
984
horizontalRule: {
985
wrap: {
986
left: "\n----\n",
987
right: "",
988
},
989
},
990
table: {
991
// https://www.mediawiki.org/wiki/Help:Tables
992
insert: `\n
993
{| class="table"
994
|+Table Caption
995
! Column 1
996
! Column 2
997
|-
998
|Integral
999
|Derivative
1000
|-
1001
|Sin
1002
|Cos
1003
|-
1004
|Tan
1005
|Sec
1006
|}\
1007
`,
1008
},
1009
},
1010
1011
python: {
1012
comment: {
1013
wrap: {
1014
left: "#",
1015
right: "",
1016
multi: true,
1017
space: true,
1018
},
1019
},
1020
len: {
1021
insert: "len([1, 2, 5, 6, 10])",
1022
},
1023
list: {
1024
insert: "[1, 2, 5, 6, 10]",
1025
},
1026
list_comprehension: {
1027
insert: "[n+1 for n in range(10) if n%2==0]",
1028
},
1029
read_csv_file: {
1030
insert: `\
1031
import csv
1032
import sys
1033
1034
f = open('example.csv', 'rt')
1035
try:
1036
reader = csv.reader(f)
1037
for row in reader:
1038
print(row)
1039
finally:
1040
f.close()\
1041
`,
1042
},
1043
write_csv_file: {
1044
insert: `\
1045
import csv
1046
import sys
1047
1048
f = open('example.csv', 'wt')
1049
try:
1050
writer = csv.writer(f)
1051
writer.writerow( ('Title 1', 'Title 2', 'Title 3') )
1052
for i in range(10):
1053
writer.writerow( (i+1, chr(ord('a') + i), '08/%02d/07' % (i+1)) )
1054
finally:
1055
f.close()
1056
1057
print(open('example.csv', 'rt').read())\
1058
`,
1059
},
1060
dict: {
1061
insert: "{'sage':'math', 3:7}",
1062
},
1063
set: {
1064
insert: "{7, 3, 2}",
1065
},
1066
tuple: {
1067
insert: "(2, 3, 7)",
1068
},
1069
forloop: {
1070
insert: `\
1071
for i in range(5):
1072
print(i)\
1073
`,
1074
},
1075
forlistloop: {
1076
insert: `\
1077
l = [1, 2, 5, 8, 10]
1078
for i in l:
1079
print(i)\
1080
`,
1081
},
1082
forelseloop: {
1083
insert: `\
1084
for k in [1, 2, 5, 10]:
1085
if k == 3:
1086
print("found k, returning")
1087
break
1088
else:
1089
print("Haven't found k == 3")\
1090
`,
1091
},
1092
whileloop: {
1093
insert: `\
1094
n = 0
1095
while n < 5:
1096
print(n)
1097
n += 1\
1098
`,
1099
},
1100
if: {
1101
insert: `\
1102
if i == 1:
1103
print('i equals 1')\
1104
`,
1105
},
1106
ifelse: {
1107
insert: `\
1108
if i == 1:
1109
print('i equals 1')
1110
else:
1111
print('i is not 1')\
1112
`,
1113
},
1114
cases: {
1115
insert: `\
1116
if i == 0:
1117
print("i is zero")
1118
elif i == 1:
1119
print("i is one")
1120
else:
1121
print("i is neither zero or one")\
1122
`,
1123
},
1124
function: {
1125
insert: `\
1126
def f(a, b=0):
1127
\"\"\"
1128
This function returns the sum of a and b.
1129
\"\"\"
1130
return a + b\
1131
`,
1132
},
1133
lambda: {
1134
insert: "f = lambda a, b: a + b",
1135
},
1136
simple_class: {
1137
insert: `\
1138
class MyClass(object):
1139
\"\"\"
1140
This is a simple class.
1141
\"\"\"
1142
def __init__(self, a):
1143
self.a = a
1144
def __repr__(self):
1145
return "Instance of MyClass with a = %s"%self.a
1146
1147
print(MyClass(5))\
1148
`,
1149
},
1150
class_inheritance: {
1151
insert: `\
1152
class A(object):
1153
def __repr__(self):
1154
return "instance of A"
1155
def foo(self):
1156
return "foo"
1157
1158
class B(object):
1159
def __repr__(self):
1160
return "instance of B"
1161
def bar(self):
1162
return "bar"
1163
1164
class C(A, B):
1165
\"\"\"
1166
This is a class that inherits from classes A and B.
1167
\"\"\"
1168
def __repr__(self):
1169
return "instance of C"
1170
1171
# Both foo and bar are defined on instances of C.
1172
c = C()
1173
print(c.foo(), c.bar())\
1174
`,
1175
},
1176
},
1177
cython: {
1178
cython_class: {
1179
insert: `\
1180
cdef class MyClass:
1181
\"\"\"
1182
This is a Cython class.
1183
\"\"\"
1184
cdef int a
1185
def __init__(self, int a):
1186
self.a = a
1187
def __repr__(self):
1188
return "Instance of MyClass with a = %s"%self.a
1189
1190
print(MyClass(5))\
1191
`,
1192
},
1193
},
1194
sage: {
1195
sagemathdoc: {
1196
url: "http://doc.sagemath.org/",
1197
},
1198
sagemathtutorial: {
1199
url: "http://doc.sagemath.org/html/en/tutorial/index.html",
1200
},
1201
sagemathreference: {
1202
url: "http://doc.sagemath.org/html/en/reference/index.html",
1203
},
1204
sagemathkeyboardshortcuts: {
1205
url: "https://github.com/sagemathinc/cocalc/wiki/Keyboard-Shortcuts",
1206
},
1207
sagesyntaxerrors: {
1208
url: "https://github.com/sagemathinc/cocalc/wiki/MathematicalSyntaxErrors",
1209
},
1210
cocalcwiki: {
1211
url: "https://doc.cocalc.com/sagews.html",
1212
},
1213
sagequestion: {
1214
url: "https://github.com/sagemathinc/cocalc/wiki/SageQuestion",
1215
},
1216
help: {
1217
wrap: {
1218
left: "help(",
1219
right: ")",
1220
},
1221
},
1222
differentiate: {
1223
insert: "diff(1 + x + x^2, x)",
1224
},
1225
integrate: {
1226
insert: "integrate(1 + x + x^2, x)",
1227
},
1228
nintegrate: {
1229
insert:
1230
"numerical_integral(1 + x + x^2, 0, 3)[0] # [1] gives error bound",
1231
},
1232
symbolic_function: {
1233
insert: "f(x,y) = x * sin(y)",
1234
},
1235
matrix: {
1236
insert: "matrix(2, 3, [1,pi,3, e,5,6])",
1237
},
1238
vector: {
1239
insert: "vector([pi, 2, 3, e])",
1240
},
1241
plot2d: {
1242
insert: "plot(x * sin(x), (x, -2, 10))",
1243
},
1244
plot_line: {
1245
insert:
1246
"line([(0,0), (1,2), (1/2,pi), (1/2,pi/2)], color='darkgreen', thickness=3)",
1247
},
1248
plot_polygon: {
1249
insert: `\
1250
a = polygon2d([(0,0), (1,2), (1/2,pi), (1/2,pi/2)], color='orange')
1251
b = polygon2d([(0,0), (1,2), (1/2,pi), (1/2,pi/2)], color='black', fill=False, thickness=3)
1252
show(a + b)\
1253
`,
1254
},
1255
plot_parametric: {
1256
insert:
1257
"parametric_plot([cos(x) + 2*cos(x/4), sin(x) - 2*sin(x/4)], (x,0,8*pi), color='green', thickness=3, fill = True)",
1258
},
1259
plot_random_walk: {
1260
insert: "stats.TimeSeries(1000).randomize('normal').sums().plot()",
1261
},
1262
plot_text: {
1263
insert:
1264
'text(r"Text and LaTeX: $\\alpha^3 + 1$", (1,1), color="black", fontsize=15, rotation=30)',
1265
},
1266
plot_points: {
1267
insert:
1268
"show(points([(1,0), (sqrt(2)/2,sqrt(2)/2), (0,1), (1/2,1/2)], color='darkgreen', pointsize=50), aspect_ratio=1)",
1269
},
1270
plot3d: {
1271
insert: `\
1272
%var x y
1273
plot3d(x * sin(y), (x, -5, 5), (y, -5, 5))\
1274
`,
1275
},
1276
plot_torus: {
1277
insert: `\
1278
from sage.plot.plot3d.shapes import Torus
1279
inner_radius = .3; outer_radius = 1
1280
show(Torus(outer_radius, inner_radius, color='orange'), aspect_ratio=1, spin=3)\
1281
`,
1282
},
1283
parametric_curve3d: {
1284
insert: `\
1285
%var u
1286
parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20), thickness=5, color='green', plot_points=100)\
1287
`,
1288
},
1289
parametric_surface: {
1290
insert: `\
1291
%var u, v
1292
fx = (3*(1+sin(v)) + 2*(1-cos(v)/2)*cos(u))*cos(v)
1293
fy = (4+2*(1-cos(v)/2)*cos(u))*sin(v)
1294
fz = -2*(1-cos(v)/2) * sin(u)
1295
parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), color="green", opacity=.7, mesh=1, spin=5)\
1296
`,
1297
},
1298
implicit_plot3d: {
1299
insert: `\
1300
%var x y z
1301
g = golden_ratio; r = 4.77
1302
p = 2 - (cos(x + g*y) + cos(x - g*y) + cos(y + g*z) +
1303
cos(y - g*z) + cos(z - g*x) + cos(z + g*x))
1304
show(implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r),
1305
plot_points=30, color='orange', mesh=1, opacity=.7), spin=1)\
1306
`,
1307
},
1308
1309
random_walk_3d: {
1310
insert: `\
1311
v = [(0,0,0)]
1312
for i in range(1000):
1313
v.append([a+random()-.5 for a in v[-1]])
1314
line3d(v, color='red', thickness=3, spin=3)\
1315
`,
1316
},
1317
polytope: {
1318
insert: `\
1319
points = [(2,0,0), (0,2,0), (0,0,2), (-1,0,0), (0,-1,0), (0,0,-1)]
1320
show(LatticePolytope(points).plot3d(), spin=5)\
1321
`,
1322
},
1323
icosahedron: {
1324
insert: "show(icosahedron(color='green', opacity=.5, mesh=3), spin=1)",
1325
},
1326
tetrahedron: {
1327
insert: "show(tetrahedron(color='lime', opacity=.5, mesh=3), spin=1)",
1328
},
1329
cube: {
1330
insert: `\
1331
show(cube(color=['red', 'blue', 'green'], frame_thickness=2,
1332
frame_color='brown', opacity=0.8), frame=False)\
1333
`,
1334
},
1335
plot_text3d: {
1336
insert: 'text3d("Text in 3D", (1,1, 1), color="darkred", fontsize=20)',
1337
},
1338
graphs: {
1339
insert:
1340
"# Press the TAB key after 'graphs.' to see a list of predefined graphs.\ngraphs.",
1341
},
1342
petersen: {
1343
insert: "graphs.PetersenGraph()",
1344
},
1345
random_graph: {
1346
insert:
1347
"g = graphs.RandomGNM(15, 20) # 15 vertices and 20 edges\nshow(g)\ng.incidence_matrix()",
1348
},
1349
chromatic_number: {
1350
insert: "g = graphs.PetersenGraph().chromatic_number()\nshow(g)",
1351
},
1352
auto_group_graph: {
1353
insert: "graphs.PetersenGraph().automorphism_group()",
1354
},
1355
graph_2dplot: {
1356
insert: "show(graphs.PetersenGraph())",
1357
},
1358
graph_3dplot: {
1359
insert: "show(graphs.PetersenGraph().plot3d())",
1360
},
1361
factor: {
1362
insert: "factor(2015)",
1363
},
1364
primes: {
1365
insert: "prime_range(100)",
1366
},
1367
prime_pi: {
1368
insert: "prime_pi(10^6)",
1369
},
1370
mod: {
1371
insert: "Mod(5, 12)",
1372
},
1373
contfrac: {
1374
insert: "continued_fraction(e)",
1375
},
1376
binary_quadform: {
1377
insert: "BinaryQF([1,2,3])",
1378
},
1379
ellcurve: {
1380
insert: "EllipticCurve([1,2,3,4,5])",
1381
},
1382
var: {
1383
insert: "%var x, theta",
1384
},
1385
det: {
1386
insert: "matrix(2, 2, [1,2, 3,4]).det()",
1387
},
1388
charpoly: {
1389
insert: "matrix(2, 2, [1,2, 3,4]).charpoly()",
1390
},
1391
eigen: {
1392
insert: "matrix(3,[1,2,3, 4,5,6, 7,8,9]).right_eigenvectors()",
1393
},
1394
svd: {
1395
insert: "matrix(CDF, 3, [1,2,3, 4,5,6, 7,8,9]).SVD()",
1396
},
1397
numpy_array: {
1398
insert: "import numpy\nnumpy.array([[1,2,3], [4,5,6]], dtype=float)",
1399
},
1400
1401
ring_AA: {
1402
insert: "AA",
1403
},
1404
ring_CC: {
1405
insert: "CC",
1406
},
1407
ring_CDF: {
1408
insert: "CDF",
1409
},
1410
ring_CIF: {
1411
insert: "CIF",
1412
},
1413
ring_CLF: {
1414
insert: "CLF",
1415
},
1416
ring_FF_p: {
1417
insert: "GF(7)",
1418
},
1419
ring_FF_pr: {
1420
insert: "GF(7^3,'a')",
1421
},
1422
ring_QQ: {
1423
insert: "QQ",
1424
},
1425
ring_QQbar: {
1426
insert: "QQbar",
1427
},
1428
ring_QQp: {
1429
insert: "Qp(7)",
1430
},
1431
ring_RR: {
1432
insert: "RR",
1433
},
1434
ring_RDF: {
1435
insert: "RDF",
1436
},
1437
ring_RIF: {
1438
insert: "RIF",
1439
},
1440
ring_RLF: {
1441
insert: "RLF",
1442
},
1443
ring_ZZ: {
1444
insert: "ZZ",
1445
},
1446
ring_ZZp: {
1447
insert: "Zp(7)",
1448
},
1449
ring_QQx: {
1450
insert: "R.<x> = QQ[]",
1451
},
1452
ring_QQxyz: {
1453
insert: "R.<x,y,z> = QQ[]",
1454
},
1455
ring_ZZxp: {
1456
insert:
1457
"R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)])\nR.inject_variables()",
1458
},
1459
ring_QQ_quo: {
1460
insert: "R.<x,y> = QQ[]\nR.<xx, yy> = R.quo([y^2 - x^3 - x])",
1461
},
1462
interact_fx: {
1463
insert: `\
1464
@interact
1465
def interactive_function(a = slider(0, 10, .05, default=4),
1466
b = (-3, 3, .1)):
1467
f(x) = b * x + sin(a * x)
1468
plot(f, (x, -5, 5)).show()\
1469
`,
1470
},
1471
modes: {
1472
insert: "print('\\n'.join(modes()))",
1473
},
1474
jupyterkernels: {
1475
insert: "print(jupyter.available_kernels())",
1476
},
1477
mode_typeset: {
1478
insert: "%typeset_mode True\n",
1479
},
1480
mode_auto: {
1481
insert: "%auto",
1482
},
1483
mode_cython: {
1484
insert: "%cython\n",
1485
},
1486
mode_default_mode: {
1487
insert: "%default_mode r # change r to any mode\n",
1488
},
1489
mode_exercise: {
1490
insert: "%exercise\n",
1491
},
1492
mode_gap: {
1493
insert: "%gap\n",
1494
},
1495
mode_gp: {
1496
insert: "%gp\n",
1497
},
1498
mode_hide: {
1499
insert: "%hide\n",
1500
},
1501
mode_html: {
1502
insert: "%html\n",
1503
},
1504
mode_julia: {
1505
insert: "%julia\n",
1506
},
1507
mode_javascript: {
1508
insert: "%javascript\n/* Use print(...) for output */",
1509
},
1510
mode_jupyter_bridge: {
1511
insert: `\
1512
a5 = jupyter("anaconda5")
1513
# start new cells with %a5
1514
# or set %default_mode a5\
1515
`,
1516
},
1517
mode_md: {
1518
insert: "%md\n",
1519
},
1520
mode_octave: {
1521
insert: "%octave\n",
1522
},
1523
mode_python: {
1524
insert: "%python\n",
1525
},
1526
mode_python3: {
1527
insert: "%python3\n",
1528
},
1529
mode_anaconda: {
1530
insert: "%anaconda\n",
1531
},
1532
mode_r: {
1533
insert: "%r\n",
1534
},
1535
mode_scilab: {
1536
insert: "%scilab\n",
1537
},
1538
mode_sh: {
1539
insert: "%sh\n",
1540
},
1541
mode_time: {
1542
wrap: {
1543
left: "%time ",
1544
right: "",
1545
},
1546
},
1547
mode_timeit: {
1548
wrap: {
1549
left: "%timeit ",
1550
right: "",
1551
},
1552
},
1553
comment: {
1554
wrap: {
1555
left: "# ",
1556
right: "",
1557
multi: true,
1558
space: true,
1559
},
1560
},
1561
assign: {
1562
insert: "a = 5",
1563
},
1564
forloop: {
1565
insert: `\
1566
for animal in ["dog", "cat", "mouse"]
1567
println("$animal is a mammal")
1568
end\
1569
`,
1570
},
1571
function: {
1572
insert: `\
1573
function add(x, y)
1574
println("x is $x and y is $y")
1575
# Functions return the value of their last statement
1576
x + y
1577
end
1578
1579
println(add(2000, 15))\
1580
`,
1581
},
1582
ifelse: {
1583
insert: `\
1584
a = 10
1585
if a > 10
1586
println("a is bigger than 10.")
1587
elseif a < 10 # This elseif clause is optional.
1588
println("a is smaller than 10.")
1589
else # The else clause is optional too.
1590
println("a is indeed 10.")
1591
end\
1592
`,
1593
},
1594
},
1595
1596
r: {
1597
// http://cran.r-project.org/doc/manuals/r-release/R-intro.html
1598
comment: {
1599
wrap: {
1600
left: "#",
1601
right: "",
1602
multi: true,
1603
space: true,
1604
},
1605
},
1606
vector: {
1607
insert: "v <- c(1,1,2,3,5,8,13)",
1608
},
1609
forloop: {
1610
insert: `\
1611
for (i in seq(1, 10, by=2)) {
1612
print(sprintf("i = %s", i));
1613
}\
1614
`,
1615
},
1616
ifelse: {
1617
insert: `\
1618
k <- 10
1619
if (k > 5) {
1620
print("k greater than 5")
1621
} else {
1622
print("k less or equal than 5")
1623
}\
1624
`,
1625
},
1626
summary: {
1627
wrap: {
1628
left: "summary(",
1629
right: ")",
1630
},
1631
},
1632
plot: {
1633
insert: 'plot(c(1,2,4,8,16,32,64), c(1,1,2,3,5,8,13), type="l")',
1634
},
1635
seq: {
1636
insert: "-5:5",
1637
},
1638
seq_by: {
1639
insert: "seq(-5, 5, by=.2)",
1640
},
1641
seq_length: {
1642
insert: "seq(length=51, from=-5, by=.2)",
1643
},
1644
rep1: {
1645
insert: "rep(c(5,1,3), times = 3)",
1646
},
1647
rep2: {
1648
insert: "rep(c(5,1,3), each = 3)",
1649
},
1650
charvec: {
1651
insert: 'paste(c("X","Y"), 1:10, sep="")',
1652
},
1653
mean: {
1654
insert: "mean(c(4,3,4,2,-1,3,2,3,2))",
1655
},
1656
matrix: {
1657
insert: "array(1:20, dim=c(4,5))",
1658
},
1659
assign: {
1660
insert: `\
1661
x <- "hello"
1662
print(x)\
1663
`,
1664
},
1665
outer: {
1666
insert: "c(1,2) %o% c(4,4)",
1667
},
1668
matrixmult: {
1669
insert: `\
1670
x <- c(1,2,3,4)
1671
A <- array(seq(1:20), dim=c(5,4))
1672
A %*% x\
1673
`,
1674
},
1675
function: {
1676
insert: `\
1677
f <- function(x, y) {
1678
y <- 2 * x + y
1679
return(y + cos(x))
1680
}
1681
f(1,2)\
1682
`,
1683
},
1684
inverse: {
1685
insert: "solve(array(c(2,1,-4,1), dim=c(2,2)))",
1686
},
1687
solvelin: {
1688
insert: "solve(array(c(2,1,-4,1), dim=c(2,2)), c(6,7))",
1689
},
1690
svd: {
1691
insert: "svd(array(-9:6, dim=c(4,4)))",
1692
},
1693
list1: {
1694
insert: `\
1695
# index into a list via [[idx]]
1696
l <- list(1,"fred", c(1,2,3))
1697
print(l[[1]])
1698
print(l[[2]])
1699
print(l[[3]])\
1700
`,
1701
},
1702
list2: {
1703
insert: `\
1704
# assoziated list of names and objects
1705
l <- list(a = 1, b = c(1,2,3))
1706
print(l$a) # access a in l
1707
print(l$b)\
1708
`,
1709
},
1710
arrayselect: {
1711
insert: "x <- c(4,7,3,2,9)\nx[x > 4]",
1712
},
1713
dataframe: {
1714
insert: `\
1715
a <- c(1,2,1)
1716
b <- c("Fred", "Susan", "Joe")
1717
c <- seq(1, by=.01, length=3)
1718
df <- data.frame(sex = a, name = b, result = c)
1719
df
1720
# for more information: help(data.frame)\
1721
`,
1722
},
1723
normal: {
1724
insert: "rnorm(10, mean = 100, sd = 1)",
1725
},
1726
stem: {
1727
insert:
1728
"# condensed overview of all numbers in the given list\nstem(rnorm(1000, mean = 5, sd = 10))",
1729
},
1730
defaultsize: {
1731
insert: "%sage r.set_plot_options(height=4, width=10)",
1732
},
1733
attach: {
1734
insert:
1735
"# attach loads internal datasets\nattach(faithful)\nprint(summary(faithful))\nprint(head(faithful))",
1736
},
1737
histdensity: {
1738
insert: `\
1739
attach(faithful)
1740
hist(eruptions, seq(1.6, 5.2, 0.2), prob=TRUE)
1741
lines(density(eruptions, bw=0.1))
1742
rug(eruptions)\
1743
`,
1744
},
1745
qqplot: {
1746
insert: `\
1747
attach(faithful)
1748
long <- eruptions[eruptions > 3]
1749
par(pty="s") # square figure
1750
qqnorm(long)
1751
qqline(long)\
1752
`,
1753
},
1754
boxplot: {
1755
insert: `\
1756
a <- rnorm(10)
1757
b <- rnorm(10, mean=2)
1758
boxplot(a, b)\
1759
`,
1760
},
1761
contour: {
1762
insert: `\
1763
x <- seq(-pi, pi, len=50)
1764
y <- x
1765
f <- outer(x, y, function(x, y) cos(y)/(1 + x^2))
1766
contour(x, y, f, nlevels=15)\
1767
`,
1768
},
1769
lm: {
1770
insert: `\
1771
y <- c(0,3,2,2,4,5,8,9,7,6,2,0)
1772
x1 <- c(1,2,3,4,3,4,5,7,5,7,8,9)
1773
x2 <- c(1,1,1,1,2,2,2,3,3,3,4,4)
1774
df <- data.frame(x1=x1, x2=x2)
1775
model <-lm(y ~ x1 + x2, data=df)
1776
model
1777
summary(model)
1778
anova(model)\
1779
`,
1780
},
1781
nlm: {
1782
insert: `\
1783
x <- c(0.02, 0.02, 0.06, 0.06, 0.11, 0.11, 0.22, 0.22, 0.56, 0.56, 1.10, 1.10)
1784
y <- c(76, 47, 97, 107, 123, 139, 159, 152, 191, 201, 207, 200)
1785
# function to be fitted
1786
fn <- function(p) sum((y - (p[1] * x)/(p[2] + x))^2)
1787
# supplying nlm with starting varlues
1788
nlm(fn, p = c(200, 0.1), hessian = TRUE)\
1789
`,
1790
},
1791
},
1792
} as const;
1793
1794
/*
1795
fricas:
1796
help:
1797
wrap:
1798
insert : ")summary"
1799
explain:
1800
wrap:
1801
left : ")display operation "
1802
right : ""
1803
differentiate:
1804
insert : 'differentiate(1 + x + x^2, x)'
1805
integrate:
1806
insert : 'integrate(1 + x + x^2, x)'
1807
nintegrate:
1808
insert : 'aromberg(sin, -%pi, %pi, 0.0001, 0.001, 2, 5, 20) -- aromberg(fn, a, b, epsrel, epsabs, nmin, nmax, nint)'
1809
'one-line function':
1810
insert : 'f(x,y) == x * sin(y)'
1811
matrix:
1812
insert : "matrix [[1,%pi],[3, %e],[5,6]]"
1813
vector:
1814
insert : "vector [%pi, 2, 3, %e]"
1815
factor:
1816
insert : "factor 2015"
1817
primes:
1818
insert : "primes(1,100)"
1819
mod:
1820
insert : "12::IntegerMod(5)"
1821
contfrac:
1822
insert : "continuedFraction(%e::Expression Float)$NumericContinuedFraction(Float)"
1823
determinant:
1824
insert : "determinant matrix [[1,2], [3,4]]"
1825
charpoly:
1826
insert : "characteristicPolynomial matrix [[1,2], [3,4]]"
1827
eigen:
1828
insert : "eigenvectors matrix [[1,2, 3], [4,5,6], [7,8,9]]"
1829
1830
ring_CC:
1831
insert : "Polynomial Complex Float"
1832
ring_QQ:
1833
insert : "Polynomial Fraction Integer"
1834
ring_RR:
1835
insert : "Polynomial Float"
1836
ring_ZZ:
1837
insert : "Polynomial Integer"
1838
comment:
1839
wrap:
1840
left : "--"
1841
right: ""
1842
multi : true
1843
space : true
1844
assign:
1845
insert : "a: = 5"
1846
forloop:
1847
insert : """
1848
for animal in ["dog", "cat", "mouse"] repeat
1849
output("Mammal: ",animal)
1850
"""
1851
function :
1852
insert : """
1853
plus(x, y) ==
1854
output("x is ",x)
1855
output("and y is ",y)
1856
-- Functions return the value of their last statement
1857
return x + y
1858
1859
output plus(2000, 15)
1860
"""
1861
ifelse:
1862
insert : """
1863
a := 10
1864
if a > 10 then
1865
output("a is bigger than 10.")
1866
else -- This elseif clause is optional.
1867
if a < 10 then
1868
output("a is smaller than 10.")
1869
else -- The else clause is optional too.
1870
output("a is indeed 10.")
1871
"""
1872
*/
1873
1874
/*
1875
Programmatically adding to above data structure
1876
*/
1877
1878
// 6 markdown heading levels:
1879
for (k = 1, i = k; k <= 6; k++, i = k) {
1880
const strip = (() => {
1881
const result: string[] = [];
1882
for (j = 1; j <= 6; j++) {
1883
if (j !== i) {
1884
result.push(`format_heading_${j}`);
1885
}
1886
}
1887
return result;
1888
})();
1889
const left =
1890
"\n" +
1891
(() => {
1892
let asc, end;
1893
const result1: string[] = [];
1894
for (
1895
j = 1, end = i, asc = 1 <= end;
1896
asc ? j <= end : j >= end;
1897
asc ? j++ : j--
1898
) {
1899
result1.push("#");
1900
}
1901
return result1;
1902
})().join("") +
1903
" ";
1904
commands.md[`format_heading_${i}`] = {
1905
strip,
1906
wrap: {
1907
left,
1908
right: "",
1909
},
1910
};
1911
}
1912
1913
/*
1914
Programmatically creating the menu entries and buttons
1915
*/
1916
1917
//
1918
// helper functions
1919
//
1920
1921
function make_bar(cls: string = "") {
1922
return $(`<span class='btn-group ${cls}'></span>`);
1923
}
1924
1925
// this adds the content of a dropdown menu (basically, single or triple entries)
1926
const add_menu = function (bar, entries) {
1927
const dropdown = $("<span class='btn-group'></span>");
1928
dropdown.append(
1929
$(`\
1930
<span class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="${entries[1]}">
1931
${entries[0]} <b class="caret"></b>
1932
</span>\
1933
`),
1934
);
1935
1936
const droplist = $("<ul class='dropdown-menu'></ul>");
1937
const divider = '<li class="divider"></li>';
1938
let first = true;
1939
for (let item of entries[2]) {
1940
var e;
1941
if (item.length === 1) {
1942
// new divider
1943
// don't show dividing line if it is at the very top
1944
let d = first ? "" : divider;
1945
d += `<li role="presentation" class="dropdown-header">${item[0]}</li>`;
1946
e = $(d);
1947
} else if ([2, 3].includes(item.length)) {
1948
// item in the menu
1949
let help = "";
1950
if (item.length === 3 && item[2].length > 0) {
1951
help = `data-toggle='tooltip' data-placement='right' title='${item[2]}'`;
1952
}
1953
e = $(`<li><a href='${item[1]}' ${help}>${item[0]}</a></li>`);
1954
}
1955
first = false;
1956
droplist.append(e);
1957
}
1958
1959
dropdown.append(droplist);
1960
return bar.append(dropdown);
1961
};
1962
1963
// this adds a single icon to the bar
1964
function add_icon(bar, inner: string, href: string, comment: string) {
1965
let help = "";
1966
if (comment.length > 0) {
1967
help = `data-toggle='tooltip' data-placement='bottom' title='${comment}'`;
1968
}
1969
const icon = $(`<a href='${href}' class='btn btn-default' ${help}></a>`);
1970
icon.html(inner);
1971
return bar.append(icon);
1972
}
1973
1974
//
1975
// initializing and creating the menus
1976
// this works in conjunction with editor.html
1977
//
1978
1979
// Initialize fonts for the editor
1980
const initialize_sagews_editor = function () {
1981
let item;
1982
const bar = $(".webapp-editor-codemirror-worksheet-editable-buttons");
1983
let elt = bar.find(".sagews-output-editor-font").find(".dropdown-menu");
1984
for (let font of "Serif,Sans,Arial,Arial Black,Courier,Courier New,Comic Sans MS,Georgia,Helvetica,Impact,Lucida Grande,Lucida Sans,Monaco,Palatino,Tahoma,Times New Roman,Verdana".split(
1985
",",
1986
)) {
1987
item = $(`<li><a href='#fontName' data-args='${font}'>${font}</a></li>`);
1988
item.css("font-family", font);
1989
elt.append(item);
1990
}
1991
1992
elt = bar.find(".sagews-output-editor-font-size").find(".dropdown-menu");
1993
for (let size = 1; size <= 7; size++) {
1994
item = $(
1995
`<li><a href='#fontSize' data-args='${size}'><font size=${size}>Size ${size}</font></a></li>`,
1996
);
1997
elt.append(item);
1998
}
1999
2000
elt = bar.find(".sagews-output-editor-block-type").find(".dropdown-menu");
2001
for (i = 1; i <= 6; i++) {
2002
item = $(
2003
`<li><a href='#formatBlock' data-args='<H${i}>'><H${i} style='margin:0'>Heading</H${i}></a></li>`,
2004
);
2005
elt.append(item);
2006
}
2007
2008
elt.prepend('<li role="presentation" class="divider"></li>');
2009
2010
// trick so that data is retained even when editor is cloned:
2011
const args = JSON.stringify([
2012
null,
2013
{ normalize: true, elementTagName: "code", applyToEditableOnly: true },
2014
]);
2015
item = $(
2016
`<li><a href='#ClassApplier' data-args='${args}'><i class='fa fa-code'></i> <code>Code</code></a></li>`,
2017
);
2018
elt.prepend(item);
2019
2020
elt.prepend('<li role="presentation" class="divider"></li>');
2021
item = $(`<li><a href='#removeFormat'><i class='fa fa-remove'></i> \
2022
Normal</a></li>`);
2023
return elt.prepend(item);
2024
};
2025
2026
// Initialize fonts for the editor
2027
const initialize_md_html_editor = function () {
2028
let item;
2029
const bar = $(".webapp-editor-textedit-buttonbar");
2030
let elt = bar.find(".sagews-output-editor-font-face").find(".dropdown-menu");
2031
for (let font of FONT_FACES) {
2032
item = $(`<li><a href='#font_face' data-args='${font}'>${font}</a></li>`);
2033
item.css("font-family", font);
2034
elt.append(item);
2035
}
2036
2037
elt = bar.find(".sagews-output-editor-font-size").find(".dropdown-menu");
2038
const v = [1, 2, 3, 4, 5, 6, 7];
2039
v.reverse();
2040
for (let size of v) {
2041
item = $(
2042
`<li><a href='#font_size' data-args='${size}'><font size=${size}>Size ${size} ${
2043
size === 3 ? "default" : ""
2044
}</font></a></li>`,
2045
);
2046
elt.append(item);
2047
}
2048
2049
elt = bar.find(".sagews-output-editor-block-type").find(".dropdown-menu");
2050
for (i = 1; i <= 4; i++) {
2051
elt.append(
2052
$(
2053
`<li><a href='#format_heading_${i}'><H${i} style='margin:0'>Heading ${i}</H${i}></a></li>`,
2054
),
2055
);
2056
}
2057
elt.append('<li role="presentation" class="divider"></li>');
2058
return elt.append(
2059
$(
2060
"<li><a href='#format_code'><i class='fa fa-code'></i> <code>Code</code></a></li>",
2061
),
2062
);
2063
};
2064
2065
// adding Python & Sage menu entries programmatically (editing HTML directly is too painful)
2066
// FUTURE: make a general class for menu entries and hence use these functions for all menu entries?
2067
const initialize_sage_python_r_toolbar = function () {
2068
// reference example, FUTURE: delete it
2069
`\
2070
<span class="btn-group">
2071
<span class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="Control Structures">
2072
<i class="fa">Control</i> <b class="caret"></b>
2073
</span>
2074
<ul class="dropdown-menu">
2075
<li role="presentation" class="dropdown-header">Loops</li>
2076
<li><a href='#forloop' data-toggle="tooltip" data-placement="right" title="Iterate over a range of integers">For-Loop</a></li>
2077
<li><a href="#forlistloop">For-Loop over a list</a></li>
2078
<li class="divider"></li>
2079
<li role="presentation" class="dropdown-header">Decisions</li>
2080
<li><a href='#if'>If clause</a></li>
2081
<li><a href='#ifelse'>If-else clause</a></li>
2082
<li class="divider"></li>
2083
<li role="presentation" class="dropdown-header">Advanced</li>
2084
<li><a href="#cases">Cases</a></li>
2085
<li><a href='#forelseloop'>For-Else Loop</a></li>
2086
</ul>
2087
</span>
2088
<a href='#comment' class='btn btn-default' data-toggle="tooltip" data-placement="bottom" title="Comment selected code"><i class="fa">#</i></a>
2089
</span>\
2090
`;
2091
2092
const codebar = $(".webapp-editor-codeedit-buttonbar");
2093
2094
// -- modes (this isn't really code so weird to put here)
2095
const system_bar = make_bar("webapp-editor-codeedit-buttonbar-system");
2096
2097
const help_list = [
2098
"<i class='fa fa-question-circle'></i> Help",
2099
"Sage Worksheet Help",
2100
[
2101
["SageMath help"],
2102
["Overview", "#sagemathdoc"],
2103
["Tutorial", "#sagemathtutorial"],
2104
["Reference", "#sagemathreference"],
2105
["Keyboard shortcuts", "#sagemathkeyboardshortcuts"],
2106
["Common syntax problems", "#sagesyntaxerrors"],
2107
["Sage worksheet commands"],
2108
["Worksheets in CoCalc", "#cocalcwiki"],
2109
["I have a question about Sage", "#sagequestion"],
2110
["General help", "#help"],
2111
["Mode commands", "#modes"],
2112
["Jupyter kernels", "#jupyterkernels"],
2113
],
2114
];
2115
add_menu(system_bar, help_list);
2116
2117
const mode_list = [
2118
"Modes",
2119
"Sage Worksheet Modes",
2120
[
2121
["General"],
2122
["Auto execute cell on startup", "#mode_auto"],
2123
["Hide input", "#mode_hide"],
2124
["Set default mode", "#mode_default_mode"],
2125
["Typeset output", "#mode_typeset"],
2126
["Timing"],
2127
["Benchmark code repeatedly", "#mode_timeit"],
2128
["Time code once", "#mode_time"],
2129
["Language modes"],
2130
["Anaconda", "#mode_anaconda"],
2131
["Cython", "#mode_cython"],
2132
["Gap", "#mode_gap"],
2133
["PARI/GP", "#mode_gp"],
2134
["HTML", "#mode_html"],
2135
["Javascript", "#mode_javascript"],
2136
["Julia", "#mode_julia"],
2137
["Jupyter bridge", "#mode_jupyter_bridge"],
2138
["Markdown", "#mode_md"],
2139
["Octave", "#mode_octave"],
2140
["Python", "#mode_python"],
2141
["Python 3", "#mode_python3"],
2142
["R", "#mode_r"],
2143
["Shell", "#mode_sh"],
2144
],
2145
];
2146
add_menu(system_bar, mode_list);
2147
2148
//# MAYBE ADD THESE in another menu:
2149
//axiom
2150
//capture
2151
//coffeescript
2152
//command
2153
//file
2154
//fork
2155
//fortran
2156
//fricas
2157
//gap3
2158
//giac
2159
//go
2160
//hideall
2161
//javascript
2162
//kash
2163
//lie
2164
//lisp
2165
//load
2166
//macaulay2
2167
//maxima
2168
//octave
2169
//pandoc
2170
//perl
2171
//prun
2172
//reset
2173
//ruby
2174
//runfile
2175
//sage0
2176
//script
2177
//singular
2178
//typeset_mode
2179
//var
2180
//wiki
2181
//mode_list = ["More", "More Sage Worksheet Modes",
2182
// [
2183
// ["Axiom", "#mode_axiom"],
2184
// ["Scilab", "#mode_scilab"],
2185
// ["Shell script", "#mode_sh"],
2186
// []
2187
// ]]
2188
//add_menu(system_bar, mode_list)
2189
codebar.append(system_bar);
2190
2191
// -- python specific --
2192
const pybar = make_bar("webapp-editor-codeedit-buttonbar-python");
2193
add_icon(pybar, "#", "#comment", "Comment selected text");
2194
2195
let py_control = [
2196
"Data",
2197
"Basic Data Types",
2198
[
2199
["Construction"],
2200
["Dictionary", "#dict"],
2201
["List", "#list"],
2202
["List comprehension", "#list_comprehension"],
2203
["Set", "#set"],
2204
["Tuple", "#tuple"],
2205
["Properties"],
2206
["Length", "#len"],
2207
["CSV"],
2208
["Write CSV file", "#write_csv_file"],
2209
["Read CSV file", "#read_csv_file"],
2210
],
2211
];
2212
add_menu(pybar, py_control);
2213
2214
// structured dropdown menu data: button text, title info, list of ["button, "#id", "title help (optional)"]
2215
py_control = [
2216
"Control",
2217
"Control Structures",
2218
[
2219
["Loops"],
2220
["For-Loop", "#forloop", "Iterate over a range of integers"],
2221
["For-Loop over a list", "#forlistloop", "Iterate over a list"],
2222
["While loop", "#whileloop", "Loop while a condition holds"],
2223
["Decisions"],
2224
["If", "#if"],
2225
["If-Else", "#ifelse"],
2226
["Advanced"],
2227
["Cases", "#cases", "Deciding between different cases"],
2228
[
2229
"For-Else Loop",
2230
"#forelseloop",
2231
"Searching for an item with a fallback.",
2232
],
2233
],
2234
];
2235
add_menu(pybar, py_control);
2236
2237
const py_func = [
2238
"Program",
2239
"Define Functions and Classes",
2240
[
2241
["Functions"],
2242
["Function", "#function", "Define a Python function"],
2243
["Lambda", "#lambda", "A Python lambda function"],
2244
["Classes"],
2245
["Class", "#simple_class", "Define a simple class"],
2246
[
2247
"Class with inheritance",
2248
"#class_inheritance",
2249
"A class that inherits from other classes",
2250
],
2251
],
2252
];
2253
2254
add_menu(pybar, py_func);
2255
2256
codebar.append(pybar);
2257
2258
// -- Cython specific
2259
const cythonbar = make_bar("webapp-editor-codeedit-buttonbar-cython");
2260
const cython_classes = [
2261
"Cython Classes",
2262
"Define cdef'd Classes",
2263
[["cdef Class", "#cython_class", "Define a Cython class"]],
2264
];
2265
add_menu(cythonbar, cython_classes);
2266
cythonbar.append(cythonbar);
2267
2268
// -- sage specific --
2269
// we hide this bar on smaller screens to avoid the linebreak but still show the assistant
2270
// https://github.com/sagemathinc/cocalc/issues/4068
2271
// don't worry about xs, because then the whole bar is not visible (and replaced by one for mobile)
2272
// actually not: https://github.com/sagemathinc/cocalc/issues/6416
2273
const sagebar = make_bar("webapp-editor-codeedit-buttonbar-sage hidden-xs");
2274
2275
const sage_calculus = [
2276
"Calculus",
2277
"Calculus",
2278
[
2279
["&part; Differentiate", "#differentiate", "Differentiate a function"],
2280
[
2281
"&int; Numerical integral",
2282
"#nintegrate",
2283
"Numerically integrate a function",
2284
],
2285
[
2286
"$f(x,y) = \\cdots $ - Symbolic Function",
2287
"#symbolic_function",
2288
"Define a symbolic function",
2289
],
2290
["&int; Symbolic integral", "#integrate", "Integrate a function"],
2291
["Interact plots"],
2292
["Interactive f(x)", "#interact_fx"],
2293
],
2294
];
2295
const sage_linalg = [
2296
"Linear",
2297
"Linear Algebra",
2298
[
2299
["Matrix $M$", "#matrix", "Define a matrix"],
2300
["Vector $\\vec v$", "#vector", "Define a vector"],
2301
["Functions"],
2302
["Characteristic polynomial", "#charpoly"],
2303
["Determinant", "#det"],
2304
["Eigenvectors", "#eigen", "Eigenvalues and eigenvectors of matrix"],
2305
["SVD", "#svd", "Singular value decomposition of matrix"],
2306
2307
["Numpy"],
2308
["Array", "#numpy_array"],
2309
],
2310
];
2311
const sage_plotting = [
2312
"Plots",
2313
"Plotting Graphics",
2314
[
2315
["2D plotting"],
2316
["Function", "#plot2d", "Plot f(x)"],
2317
["Line", "#plot_line", "Sequence of line segments"],
2318
["Parametric", "#plot_parametric", "Parematric plot"],
2319
["Points", "#plot_points", "Plot many points"],
2320
["Polygon", "#plot_polygon"],
2321
["Random walk", "#plot_random_walk", "A random walk"],
2322
["Text", "#plot_text", "Draw text"],
2323
["3D plotting"],
2324
["Cube", "#cube", "Show a colored cube"],
2325
["Function", "#plot3d", "Plot f(x, y)"],
2326
["Icosahedron", "#icosahedron"],
2327
["Implicit plot", "#implicit_plot3d", "Create an implicit 3D plot"],
2328
["Parametric curve", "#parametric_curve3d"],
2329
["Parametric surface", "#parametric_surface"],
2330
["Polytope", "#polytope"],
2331
["Random walk", "#random_walk_3d", "A 3d Random Walk"],
2332
["Tetrahedron", "#tetrahedron"],
2333
["Text", "#plot_text3d", "Draw text"],
2334
["Torus", "#plot_torus"],
2335
],
2336
];
2337
const sage_graphs = [
2338
"Graphs",
2339
"Graph theory",
2340
[
2341
["graphs.&lt;tab&gt;", "#graphs"],
2342
["Petersen graph", "#petersen", "Define the Peterson graph"],
2343
["Random graph", "#random_graph"],
2344
["Invariants"],
2345
[
2346
"Automorphism group",
2347
"#auto_group_graph",
2348
"Automorphism group of a graph",
2349
],
2350
["Chromatic number", "#chromatic_number", "Chromatic number of a graph"],
2351
["Visualization"],
2352
["2D plot", "#graph_2dplot"],
2353
["3D plot", "#graph_3dplot"],
2354
],
2355
];
2356
const sage_nt = [
2357
"Numbers",
2358
"Number theory",
2359
[
2360
[
2361
"Binary quadratic form",
2362
"#binary_quadform",
2363
"Define a binary quadratic form",
2364
],
2365
["Continued fraction", "#contfrac", "Compute a continued fraction"],
2366
["Elliptic curve", "#ellcurve", "Define an elliptic curve"],
2367
["Factor", "#factor", "Factorization of something"],
2368
["Mod $n$", "#mod", "Number modulo n"],
2369
["List prime numbers", "#primes", "Enumerate prime numbers"],
2370
["Count prime numbers", "#prime_pi", "Count prime numbers"],
2371
],
2372
];
2373
2374
const sage_rings = [
2375
"Rings",
2376
"Rings and fields",
2377
[
2378
["$\\CC$ - Complex numbers", "#ring_CC"],
2379
["$\\QQ$ - Rational numbers", "#ring_QQ"],
2380
["$\\RR$ - Real numbers", "#ring_RR"],
2381
["$\\ZZ$ - Integers", "#ring_ZZ"],
2382
["Polynomial rings"],
2383
["$\\QQ[x, y, z]$", "#ring_QQxyz"],
2384
["$\\QQ[x, y]/(y^2-x^3-x)$", "#ring_QQ_quo"],
2385
["$\\ZZ[x_2, x_3, \\ldots, x_{97}]$", "#ring_ZZxp"],
2386
["Advanced rings"],
2387
["$\\mathbb{A}$ - Algebraic reals", "#ring_AA"],
2388
["$\\CDF$ - Complex double", "#ring_CDF"],
2389
["$\\CC$ - Complex interval", "#ring_CIF"],
2390
["$\\CLF$ - Complex lazy", "#ring_CLF"],
2391
["$\\FF_p$ - Prime finite field", "#ring_FF_p"],
2392
["$\\FF_{p^r}$ - finite field", "#ring_FF_pr"],
2393
["$\\overline{\\QQ}$ - Algebraic closure", "#ring_QQbar"],
2394
["$\\QQ_p$ - $p$-adic numbers", "#ring_QQp"],
2395
["$\\RDF$ - Real double", "#ring_RDF"],
2396
["$\\RR$ - Real interval", "#ring_RIF"],
2397
["$\\RLF$ - Real lazy", "#ring_RLF"],
2398
["$\\ZZ_p$ - $p$-adic integers", "#ring_ZZp"],
2399
],
2400
];
2401
2402
add_icon(sagebar, "$x$", "#var", "Define a symbolic variable");
2403
add_menu(sagebar, sage_plotting);
2404
add_menu(sagebar, sage_calculus);
2405
add_menu(sagebar, sage_linalg);
2406
add_menu(sagebar, sage_graphs);
2407
add_menu(sagebar, sage_nt);
2408
add_menu(sagebar, sage_rings);
2409
2410
codebar.append(sagebar);
2411
2412
// -- r specific --
2413
const rbar = $(".webapp-editor-redit-buttonbar");
2414
2415
const r_basic = make_bar();
2416
add_icon(r_basic, "#", "#comment", "Comment selected text");
2417
add_icon(r_basic, "$\\vec v$", "#vector", "Insert a vector");
2418
2419
const r_control = make_bar();
2420
const r_control_entries = [
2421
"Control",
2422
"Control structures",
2423
[
2424
["Assignment", "#assign", "Give an object a (variable)name"],
2425
["For-Loop", "#forloop", "Insert a for loop"],
2426
["Function definition", "#function", "Define a function"],
2427
["If-Else", "#ifelse"],
2428
],
2429
];
2430
add_menu(r_control, r_control_entries);
2431
2432
const r_data = make_bar();
2433
const r_data_entries = [
2434
"Data",
2435
"Data structures",
2436
[
2437
["List, indexed", "#list1"],
2438
["List, associative", "#list2"],
2439
["Array selection", "#arrayselect"],
2440
["Data frame", "#dataframe"],
2441
["Attach", "#attach"],
2442
],
2443
];
2444
add_menu(r_data, r_data_entries);
2445
2446
const r_funcs = make_bar();
2447
const r_funcs_entries = [
2448
"Functions",
2449
"Some selected functions",
2450
[
2451
["Sequence simple", "#seq"],
2452
["Sequence stepsize", "#seq_by"],
2453
["Sequence length", "#seq_length"],
2454
["Repetitions (times)", "rep1"],
2455
["Repetitions (each)", "rep2"],
2456
["Character vector", "#charvec"],
2457
["Matrix array", "#matrix"],
2458
["Matrix multipliation", "#matrixmult"],
2459
["Outer product", "#outer"],
2460
["Inverse matrix", "#inverse"],
2461
["Solve A*x=b", "#solvelin"],
2462
["SVD", "#svd"],
2463
],
2464
];
2465
add_menu(r_funcs, r_funcs_entries);
2466
2467
const r_stats = make_bar();
2468
const r_stats_entries = [
2469
"Stats",
2470
"Basic statistical functions",
2471
[
2472
["Statistical summary", "#summary"],
2473
["Mean", "#mean"],
2474
["Normal distribution", "#normal"],
2475
["Linear model", "#lm"],
2476
["Nonlinear model", "#nlm"],
2477
],
2478
];
2479
add_menu(r_stats, r_stats_entries);
2480
2481
const r_plot = make_bar();
2482
const r_plot_entries = [
2483
"Plots",
2484
"Basic plots",
2485
[
2486
["Plot x/y pairs", "#plot"],
2487
["Stem plot", "#stem"],
2488
["Histogram + Density + Rug", "#histdensity"],
2489
["QQ-Plot", "#qqplot", "Quantile-quantile plot"],
2490
["Boxplot", "#boxplot"],
2491
["Contour plot", "#contour"],
2492
["Change default plot size", "#defaultsize"],
2493
],
2494
];
2495
add_menu(r_plot, r_plot_entries);
2496
2497
rbar.append(r_basic);
2498
rbar.append(r_control);
2499
rbar.append(r_data);
2500
rbar.append(r_funcs);
2501
rbar.append(r_stats);
2502
rbar.append(r_plot);
2503
2504
// -- Julia specific --
2505
const julia_bar = $(".webapp-editor-julia-edit-buttonbar");
2506
2507
const julia_basic = make_bar();
2508
add_icon(julia_basic, "#", "#comment", "Comment selected text");
2509
2510
const julia_control = make_bar();
2511
const julia_control_entries = [
2512
"Control",
2513
"Control structures",
2514
[
2515
["Assignment", "#assign", "Give an object a (variable)name"],
2516
["For-Loop", "#forloop", "Insert a for loop"],
2517
["Function definition", "#function", "Define a function"],
2518
["If-Else", "#ifelse"],
2519
],
2520
];
2521
add_menu(julia_control, julia_control_entries);
2522
julia_bar.append(julia_basic);
2523
julia_bar.append(julia_control);
2524
2525
// -- sh specific --
2526
const sh_bar = $(".webapp-editor-sh-edit-buttonbar");
2527
2528
const sh_git = make_bar();
2529
const sh_git_entries = [
2530
"Git",
2531
"Basic Git commands",
2532
[
2533
["Set name and email", "#set_name_and_email", "Set name and email"],
2534
["Initalize Git", "#initalize_git", "Initalize Git"],
2535
["Create an ignore file", "#create_gitignore", "Create an ignore file"],
2536
["Clone a local repo", "#clone_local_repo", "Clone local repo"],
2537
["Clone a remote repo", "#clone_remote_repo", "Clone remote repo"],
2538
["Add a file to repo", "#add_file_to_repo", "Add file to the repo"],
2539
[
2540
"Add all files to repo",
2541
"#add_all_to_repo",
2542
"Add all not ignored files to the repo",
2543
],
2544
[
2545
"See changes before committing",
2546
"#diff",
2547
"See changes before committing",
2548
],
2549
["Commit your changes", "#commit", "Commit all your changes"],
2550
["Setup SSH for Github", "#setup_ssh_for_github", "Setup SSH for Github"],
2551
[
2552
"Push changes",
2553
"#push_origin_master",
2554
"Push changes to the master branch of your remote repository",
2555
],
2556
["Status", "#status", "Status"],
2557
["Add remote repo", "#add_remote_repo", "Connect to a remote repository"],
2558
[
2559
"List remote repos",
2560
"#list_remote_repos",
2561
"List all currently configured remote repositories",
2562
],
2563
[
2564
"Create a new branch",
2565
"#create_new_branch",
2566
"Create a new branch and switch to it",
2567
],
2568
[
2569
"Switch branches",
2570
"#switch_branches",
2571
"Switch from one branch to another",
2572
],
2573
[
2574
"List branches",
2575
"#list_branches",
2576
"List all the branches in your repo, and also tell you what branch you're currently in",
2577
],
2578
[
2579
"Delete the feature branch",
2580
"#delete_the_feature_branch",
2581
"Delete the feature branch",
2582
],
2583
[
2584
"Push branch",
2585
"#push_branch",
2586
"Push the branch to your remote repository, so others can use it",
2587
],
2588
[
2589
"Push all branches",
2590
"#push_all_branches",
2591
"Push all branches to your remote repository",
2592
],
2593
[
2594
"Delete remote branch",
2595
"#delete_remote_branch",
2596
"Delete a branch on your remote repository",
2597
],
2598
[
2599
"Update repo",
2600
"#pull",
2601
"Update from the remote repository Fetch and merge changes on the remote server to your working directory",
2602
],
2603
[
2604
"Merge a branch",
2605
"#merge_branch",
2606
"To merge a different branch into your active branch",
2607
],
2608
["Show history", "#show_history", "Show the history of previous commits"],
2609
["Undo local changes", "#undo_local_changes", "Undo local changes"],
2610
[
2611
"Get rid of local changes",
2612
"#get_rid_of_local_changes",
2613
"Drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it",
2614
],
2615
[
2616
"Search the working directory for foo()",
2617
"#search_for",
2618
"Search the working directory for foo()",
2619
],
2620
],
2621
];
2622
add_menu(sh_git, sh_git_entries);
2623
return sh_bar.append(sh_git);
2624
};
2625
2626
// error since not yet used.
2627
// @ts-expect-error
2628
function initialize_latex_buttonbar() {
2629
const latexbar = make_bar();
2630
add_icon(
2631
latexbar,
2632
"<i class='fa fa-comment'></i>",
2633
"#comment",
2634
"Comment selected text",
2635
);
2636
2637
const templates = [
2638
"Templates",
2639
"These templates come exclusively on top",
2640
[
2641
["Article", "#article"],
2642
["KOMA Script"],
2643
["Article", "#scrartcl"],
2644
["Report", "#scrreprt"],
2645
],
2646
];
2647
add_menu(latexbar, templates);
2648
2649
// FUTURE: merge this with the usual text formatting toolbar, such that its list of actions is inserted here
2650
// IDEA: maybe, clicking on the "Format" dropdown shows the cloned formatting toolbar?
2651
//text = ["Format", "Text formatting",[]]
2652
//add_menu(latexbar, text)
2653
const formatting = $("<span class='btn-group'></span>");
2654
formatting.append(
2655
$(`\
2656
<span class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="Text Formatting">
2657
<i class="fa">Format</i> <b class="caret"></b>
2658
</span>\
2659
`),
2660
);
2661
const format_buttons = $(
2662
".webapp-editor-codemirror-worksheet-editable-buttons",
2663
).clone();
2664
format_buttons.addClass("dropdown-menu");
2665
format_buttons.removeClass("hide");
2666
format_buttons.css("min-width", 300);
2667
formatting.append(format_buttons);
2668
latexbar.append(formatting);
2669
// end format button idea
2670
2671
const formulas = [
2672
"Formula",
2673
"These are some standard formuas",
2674
[
2675
["$x^2$", "#xsquare"],
2676
["$\\int$", "#integral"],
2677
["Environment"],
2678
["Cases", "#cases"],
2679
],
2680
];
2681
add_menu(latexbar, formulas);
2682
2683
const bb = $(".webapp-editor-latex-buttonbar");
2684
return bb.append(latexbar);
2685
}
2686
2687
// NOT READY YET.
2688
//initialize_latex_buttonbar()
2689
2690
// must get called before using the button bars.
2691
export function init_buttonbars() {
2692
initialize_sagews_editor();
2693
initialize_md_html_editor();
2694
return initialize_sage_python_r_toolbar();
2695
}
2696
2697