-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbreaking boxes.jl
1849 lines (1537 loc) · 51.9 KB
/
breaking boxes.jl
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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.9
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ cf0eb30e-f299-43d7-ab31-8a48ebc647ed
using PlutoUI
# ╔═╡ d1696d25-1f3c-4a4a-b287-7f0035c897c7
using HypertextLiteral
# ╔═╡ 0bdfd444-f783-4707-ac69-3851dfaa61c2
using Plots
# ╔═╡ d5e2a7f1-5d44-4e58-91ef-df12e0d007c2
using PlutoTest
# ╔═╡ ad4f807a-ad18-422f-816b-ac75edfbcc60
overflow(x) = @htl("""
<div style="max-height: 500px; overflow-y: auto;">
$(x)
</div>
""")
# ╔═╡ eb0f1ea4-7e07-4670-8fe4-e531aa918ba3
jl(str) = Markdown.MD(Markdown.Code("julia", str))
# ╔═╡ 85920cbd-bad3-45d1-99ad-fe9acfab9a02
br = html"<br>"
# ╔═╡ 0c7a5125-302b-4239-a6bb-5475695c1e68
@htl("""
<h1 style="text-align: center;">✨ Pluto 1.0 ✨ <span style="opacity: .7;">in Fall 2021</span></h1>
""")
# ╔═╡ 4c019753-a360-4d69-86b2-a92710c5ffad
# ╔═╡ ed6d9e33-2a59-439b-9490-b8c996d257ea
@htl("""
<h1><code>github.com/fonsp/Pluto.jl</code></h1>
""")
# ╔═╡ 0e46ef73-60db-4ce6-8752-97f501ebe62f
names = split("""
Fons van der Plas
Nicholas Bochenski
Παναγιώτης Γεωργακόπουλος
Michiel Dral
Paul Berg
Benjamin Lungwitz
Connor Burns
Rogerluo
Eric Zhang
Felipe S. S. Schneider
Luka van der Plas
Glen Hertz
Eric Hanson
Shuhei Kadowaki
Jerry Ling
Jelmar Gerritsen
Rok Novosel
Supanat
Zachary Moon
pupuis
Michael Abbott
Nicholas Bauer
Patrick Bouffard
Shashank Polasa
TheCedarPrince
fghzxm
karlwessel
Ciarán O'Mara
Rik Huijzer
Aayush Joglekar
Alexis
Chris Foster
Dhruva Sambrani
Diego Javier Zea
Felix Cremer
Fredrik Ekre
Gautam Mishra
Iagoba Apellaniz
Ian Butterworth
Immortalin
Jeremiah
Jonas Jonker
János Veres
Leo
Logan Kilpatrick
Marius Millea
Matt Helm
Musab Kılıç
Philip D Loewen
Robert Moss
Rémi Vezy
Satoshi Terasaki
Sebastian Stabinger
Sergey Konoplich
Chebro
Syx Pek
Tobias Skarhed
Troels Arnfred Bojesen
Utkarsh Shah
zuckberj
Vlad
Zhixing Wang
Zlatan Vasović
contradict
disberd
elliotsayes
gregod
heetbeet
holomorphism
romaindegivry
Ömür Özkir
""", "\n"; keepempty=false)
# ╔═╡ b684b0d3-609a-431f-a1ce-08a87d3d4fab
@htl("""
<h4 style="text-align: center;">Thank you ❤️</h4>
<br>
<p style="background: #fff;">
$(map(enumerate(names[2:end])) do (i,n)
@htl("<span style=$(Dict(
"font-weight" => 700 - i*20,
"margin-right" => "$(max(5,20 - i))px",
"font-size" => string(max(13, 20-.2i), "px"),
"line-height" => string(max(10, 20-.5i), "px"),
"background" => "#f5f5f5",
"border-radius" => "6px",
"padding" => "4px",
"display" => "inline-block",
))>$(n)$(i < length(names) - 1 ? "" : "") </span>")
end)
</p>
""")
# ╔═╡ 48c1443e-9656-4a97-a42b-4f8db332c7cc
podcast = html"<iframe src='https://omny.fm/shows/future-of-coding/37-de-nerding-programming-jonathan-edwards/embed' width='100%' height='150' frameborder='0'></iframe>";
# ╔═╡ 0fbcf962-f8f4-471d-b2ed-38ec020df877
bigbreak = html"
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
"
# ╔═╡ 363429f1-d456-4195-9fbe-142ca7f62824
bigbreak
# ╔═╡ a4c1a119-0b52-4576-9d85-597726892b20
bigbreak
# ╔═╡ 54d2de83-e336-41fd-923f-76b0a67a094d
1 + 1
# ╔═╡ 7ec0f50b-937e-4f68-ab0e-af70937757fa
bigbreak
# ╔═╡ 1819c538-7ef2-419c-a81f-ee9807292aa1
md"""
# Programming is too difficult!
$(podcast)
$(br)
$(br)
$(br)
"""
# ╔═╡ 08f9dfa2-28f9-4cda-a888-7068153de44c
show_on_hover(x) = @htl("""
<span class="show_on_hover">$(x)</span>
<style>
.show_on_hover {
opacity: .1;
display: block;
transition: opacity .5s ease-out;
-moz-transition: opacity .5s ease-out;
-webkit-transition: opacity .5s ease-out;
-o-transition: opacity .5s ease-out;
}
.show_on_hover:hover {
opacity: 100%;
}
</style>
""");
# ╔═╡ 399229b6-94d3-429f-9e36-eb49a1ca595f
md"""
> "(...) those of us who are good at abstraction are the ones that flourish in programming, yet, even we don't have the power enough to pull it off. **We're constantly failing and making mistakes and unable to comprehend what it is that we've just done.**"
>
> -- _**Jonathan Edwards**, Future of Coding #37_
""" |> show_on_hover
# ╔═╡ e889bddb-fe84-40a0-87c9-badc32beafc9
md"""
> "If we could only just **minimize this intense intellectual burden** of programming, then regular people would be able to do it, but we'd also be able to do more."
>
> -- _**Jonathan Edwards**, Future of Coding #37_
""" |> show_on_hover
# ╔═╡ c6f6f8e8-483a-489f-84c2-e179a5b9de4d
md"""
# Visual programming?
"""
# ╔═╡ 35d6d38c-6795-4608-a046-5025b015eadd
md"""
_How to get the column sums of a matrix:_
"""
# ╔═╡ cb3a2807-038c-4637-a886-83f49d6d9a6a
bigbreak
# ╔═╡ c0d1f009-2690-44ea-98d8-7124a7b0b646
(a=1, b=[2,3], c=Ref(5))
# ╔═╡ 4462eaa4-dfb4-4dbb-bf68-d26c909b072a
# ╔═╡ fe8bd5ea-8190-43a8-9998-1e8ad74c60e2
(a = 123, b = rand(4), c = jl("""
function f(x)
y = rand(x)
end
"""))
# ╔═╡ 7606d86e-9d13-4b40-86b1-8766a2a19bb4
# ╔═╡ 5420f5c8-bcd9-4316-886c-c55955d523fd
# ╔═╡ 33931c2d-a63f-4bc1-9e6c-af12f49357df
md"""
### Used in PlutoTest.jl:
"""
# ╔═╡ f11d2ede-522c-4281-abdb-9002257d6191
@test sqrt(12 + 12) > 3
# ╔═╡ fabef496-0ba4-4ed8-b0ee-669b3a841f5b
@test 5 ∈ filter(iseven, [x^2 for x in 1:6])
# ╔═╡ a81d7ed8-cf2a-4082-b2e1-6b27348c4d33
hello
# ╔═╡ 00bc0ea3-bdd0-45bc-8890-2f31d99d9989
@test left == right
# ╔═╡ 9030f04b-09cd-42dd-bc62-d2fcbf5629e2
bigbreak
# ╔═╡ d250b611-6f42-4e43-886e-5c0550cda037
md"""
## Code and LaTeX
"""
# ╔═╡ 6a97635a-a6fa-4cae-bbe7-50c4db2ace99
# ╔═╡ 3159c138-3146-4572-956c-d49708714b07
bigbreak
# ╔═╡ 74c53f70-a993-4759-b31c-33d1708af27f
md"""
## Widgets and code
"""
# ╔═╡ 99c3580b-a22e-4df0-869f-d73303c087ff
@bind hi TextField(default="asdfasdfasdf")
# ╔═╡ 24776638-d84f-4438-8a8d-278e3f89b542
hi
# ╔═╡ b18fabaf-4f79-414c-9cb5-e63bbea84c41
br
# ╔═╡ cdbd6980-747c-4936-b5ee-597bd49b041c
# ╔═╡ 950faf39-8e9b-4cdd-afed-0f2aecfb4ef0
function TextField2(; default="")
@htl("""
<script>
const init = $(default)
const el = html`<input>`
el.value = init
const cm = currentScript.closest("pluto-cell").querySelector(".CodeMirror").CodeMirror
el.addEventListener("input", () => {
const old_value = cm.getValue()
const new_command = `TextField2(default=\${JSON.stringify(el.value)})`
cm.setValue(old_value.replace(/TextField2\\(.*default\\=\\".*\\"\\)/, new_command))
})
return el
</script>
""")
end
# ╔═╡ e3654826-c3e0-4473-ac0a-e750cd2677c9
@bind howdy TextField2(default="asdfasdfasdfasdf")
# ╔═╡ d7e02ef6-9c17-4c90-ac9b-4d6fca88cbea
howdy
# ╔═╡ 1c4d7d9a-3492-4018-bab3-62f49bf522e0
bigbreak
# ╔═╡ 32665c5c-39d8-472c-b4a0-2595dac8afaa
md"""
## Visual _and_ textual programming?
"""
# ╔═╡ fca45d57-e5d8-4cbe-bb09-3572870281a8
bigbreak
# ╔═╡ 7196aaff-78f2-460d-9b84-9e02f7036be3
bigbreak
# ╔═╡ 8629e702-7d21-49a3-a82d-99ae608a7077
macro widget(expr)
esc(expr)
end
# ╔═╡ b8138809-cc22-4ee2-89b0-4801775bd32e
slider(x) = x
# ╔═╡ 2e51c19e-dfaa-44bb-9fdf-8bfa444353eb
x = [
@widget(slider(95)) @widget(slider(44))
@widget(slider(40)) @widget(slider(21))
]
# ╔═╡ e4cbfda6-9c10-41db-977f-82948b3b542d
x
# ╔═╡ 8eade898-fc7a-4ea6-9bff-98726b2e7b09
checkbox(x) = x
# ╔═╡ e38b1738-38d1-4822-a699-a72f57ab4b42
plot([1,4,5];
linewidth = @widget(slider(16)),
legend = @widget(checkbox(false)),
)
# ╔═╡ 87206d83-5aea-4c88-b3ce-45b570cd15df
@widget(slider(28)), @widget(checkbox(true))
# ╔═╡ fee84fce-9c36-470e-ae6b-a682e4fc5a5a
stackrows(x) = permutedims(hcat(x...),(2,1))
# ╔═╡ 3115cec1-55fa-423d-8d85-6b74e040cca3
begin
Base.@kwdef struct Div
contents
style=Dict()
end
Div(x) = Div(contents=x)
function Base.show(io::IO, m::MIME"text/html", d::Div)
h = @htl("""
<div style=$(d.style)>
$(d.contents)
</div>
""")
show(io, m, h)
end
Div
end
# ╔═╡ 868e7ecc-908a-4c55-9a47-40bf00a5389e
outline(x) = Div(x, Dict(
"border" => "3px solid rgba(0,0,0,.3)",
"border-radius" => "3px",
"padding" => "5px",
))
# ╔═╡ f1a969cd-d7f7-4517-898f-23e772ffffb1
Div(
[md"""
```julia
function height(p)
c1 * sqrt(p * c2)
end
```
""",
md"to",
md"""
```julia
function height(p)
c1 * log(p * c2)
end
```
"""],
Dict(
"display" => "flex",
"justify-content" => "space-evenly",
"align-items" => "center",
))
# ╔═╡ e5a4b22c-bbb4-4c81-9f52-3d327bca00cf
flex(x::Union{AbstractVector,Base.Generator}; kwargs...) = flex(x...; kwargs...)
# ╔═╡ 1df0fc0c-21e4-498d-abf1-8e5924d31a28
function flex(args...; kwargs...)
Div(;
contents=collect(args),
style=Dict("display" => "flex", ("flex-" * String(k) => string(v) for (k,v) in kwargs)...)
)
end
# ╔═╡ f14424b0-8a3f-4892-aa46-9b37571ce8cb
flex([
html"""
<div>
<h4>Scratch</h4>
<p><img src="https://user-images.githubusercontent.com/6933510/124468203-1d862f00-dd99-11eb-8677-7f6b7b5c8989.png" width="80%"></p>
</div>
"""
html"<div>"
md"""
#### LabVIEW
![image](https://user-images.githubusercontent.com/6933510/124467529-40641380-dd98-11eb-8719-077965de1ea6.png)
"""
])
# ╔═╡ c84cf597-2bec-4d6f-b757-c7e986d8be67
function grid(items::AbstractMatrix; fill_width::Bool=true)
Div(
contents=Div.(vec(permutedims(items, [2,1]))),
style=Dict(
"display" => fill_width ? "grid" : "inline-grid",
"grid-template-columns" => "repeat($(size(items,2)), auto)",
"column-gap" => "1em",
),
)
end
# ╔═╡ 30c6024a-9a71-4058-acb0-dff147af4469
function aside(x)
@htl("""
<style>
@media (min-width: calc(700px + 30px + 300px)) {
aside.plutoui-aside-wrapper {
position: absolute;
right: -11px;
width: 0px;
transform: translate(0, -40%);
}
aside.plutoui-aside-wrapper > div {
width: 300px;
}
}
</style>
<aside class="plutoui-aside-wrapper">
<div>
$(x)
</div>
</aside>
""")
end
# ╔═╡ 69faf33d-ac2d-4050-a874-55a0fac77d23
cpp_ex = md"""
#### C++
```js
vector <int> result;
result.resize(cols);
for(size_t j = 0; j < cols; ++j)
{
int sum = 0;
for(size_t i = 0; i < rows; ++i)
{
sum += A[i][j];
}
result[j] = sum;
}
```
""";
# ╔═╡ b58207ea-3797-4b7d-af0b-74cb1f5a107f
x86_ex = md"""
#### Assembly
```js
main:
push rbp
mov rbp, rsp
push rbx
sub rsp, 104
lea rax, [rbp-80]
mov rdi, rax
call std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::vector() [complete object constructor]
mov QWORD PTR [rbp-48], 2
mov QWORD PTR [rbp-56], 2
mov rdx, QWORD PTR [rbp-48]
lea rax, [rbp-80]
mov rsi, rdx
mov rdi, rax
call std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::resize(unsigned long)
lea rax, [rbp-112]
mov rdi, rax
call std::vector<int, std::allocator<int> >::vector() [complete object constructor]
mov rdx, QWORD PTR [rbp-56]
lea rax, [rbp-112]
mov rsi, rdx
mov rdi, rax
call std::vector<int, std::allocator<int> >::resize(unsigned long)
mov QWORD PTR [rbp-24], 0
jmp .L12
.L15:
mov DWORD PTR [rbp-28], 0
mov QWORD PTR [rbp-40], 0
jmp .L13
.L14:
mov rdx, QWORD PTR [rbp-40]
lea rax, [rbp-80]
mov rsi, rdx
mov rdi, rax
call std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::operator[](unsigned long)
mov rdx, rax
mov rax, QWORD PTR [rbp-24]
mov rsi, rax
mov rdi, rdx
call std::vector<int, std::allocator<int> >::operator[](unsigned long)
mov eax, DWORD PTR [rax]
add DWORD PTR [rbp-28], eax
add QWORD PTR [rbp-40], 1
.L13:
mov rax, QWORD PTR [rbp-40]
cmp rax, QWORD PTR [rbp-48]
jb .L14
mov ebx, DWORD PTR [rbp-28]
mov rdx, QWORD PTR [rbp-24]
lea rax, [rbp-112]
mov rsi, rdx
mov rdi, rax
call std::vector<int, std::allocator<int> >::operator[](unsigned long)
mov DWORD PTR [rax], ebx
add QWORD PTR [rbp-24], 1
.L12:
mov rax, QWORD PTR [rbp-24]
cmp rax, QWORD PTR [rbp-56]
jb .L15
lea rax, [rbp-112]
mov rdi, rax
call std::vector<int, std::allocator<int> >::~vector() [complete object destructor]
lea rax, [rbp-80]
mov rdi, rax
call std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~vector() [complete object destructor]
mov eax, 0
jmp .L21
mov rbx, rax
lea rax, [rbp-112]
mov rdi, rax
call std::vector<int, std::allocator<int> >::~vector() [complete object destructor]
jmp .L18
mov rbx, rax
.L18:
lea rax, [rbp-80]
mov rdi, rax
call std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~vector() [complete object destructor]
mov rax, rbx
mov rdi, rax
call _Unwind_Resume
.L21:
mov rbx, QWORD PTR [rbp-8]
leave
ret
.LC0:
.string "vector::_M_default_append"
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L245
cmp DWORD PTR [rbp-8], 65535
jne .L245
mov edi, OFFSET FLAT:_ZStL8__ioinit
call std::ios_base::Init::Init() [complete object constructor]
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:_ZStL8__ioinit
mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
call __cxa_atexit
.L245:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
```
""";
# ╔═╡ d43d73a5-6dfc-441f-b298-2ed70cfbe6d7
Div(
[
Div(
x86_ex
,
Dict(
"max-width" => "200px",
"max-height" => "400px",
"overflow" => "auto",
)),
md"👉",
Div(
cpp_ex
,
Dict(
"max-width" => "200px",
)),
md"👉",
md"""
#### Julia
```julia
sum(A; dims=1)
```
"""],
Dict(
"display" => "flex",
"justify-content" => "space-evenly",
"align-items" => "center",
))
# ╔═╡ 99bdcfab-14ce-428d-997f-01038b863d69
import PlutoTest: @visual_debug
# ╔═╡ 3d1b0b7b-3231-4f90-be92-90124caa7594
@visual_debug begin
(1+2) + (7-6)
miniplot(2000 .+ 30 .* rand(2+2))
4+5
sqrt(sqrt(sqrt(5)))
md"# Wow"
end
# ╔═╡ 9690aace-803f-41a1-894b-bafbb1476335
@visual_debug begin
tex_example
miniplot(2000 .+ 30 .* rand(2+2))
4+5
sqrt(sqrt(sqrt(5)))
md"# Wow"
end
# ╔═╡ 95aa341e-f845-4500-a21b-27ec0bab9c4a
miniplot(x...; kwargs...) = Plots.plot(x...; kwargs..., size=(200,100))
# ╔═╡ c955769b-06cf-4bac-9ac9-59c3c7a0dcf0
begin
Base.@kwdef struct SlottedLaTeX
parts::Vector{String}
slots::Vector{Any}
# displaymode::Bool=true
end
function Base.show(io::IO, m::MIME"text/html", sl::SlottedLaTeX)
h = @htl("""
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css" integrity="sha384-Um5gpz1odJg5Z4HAmzPtgZKdTBHZdw8S29IecapCSB31ligYPhHQZMIlWLYQGVoc" crossorigin="anonymous">
<style>
.katex .base,
.katex .strut {
/*display: inline-flex !important;*/
pointer-events: none;
}
.SlottedLaTeX {
font-size: .75em;
}
.SlottedLaTeX .slot {
pointer-events: initial;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.js" integrity="sha384-YNHdsYkH6gMx9y3mRkmcJ2mFUjTd0qNQQvY9VYZgQd7DcN7env35GzlmFaZ23JGp" crossorigin="anonymous"></script>
<span class="SlottedLaTeX-slots" style="display: none;">
$(
map(sl.slots) do s
@htl("<span class='slot'>$(s)</span>")
end
)
</span>
<script>
// https://unicode-table.com/en/#2800
const braille_start = 10240
// https://unicode-table.com/en/#03B1
const greek_start = 945
const placeholder = (i) => String.fromCodePoint(braille_start + i)
const placeholder_index = (s) => s.codePointAt(0) - braille_start
const k = (segments, ...slots) => {
const mock = [...slots.flatMap((_, i) => [segments[i], placeholder(i)]), segments[segments.length-1]].join("")
const el = html`<span class='SlottedLaTeX'></span>`
katex.render(mock, el, {
displayMode: currentScript.closest("p") == null,
})
Array.from(el.querySelectorAll("span")).forEach(span => {
const t = span.innerText
if(t.length === 1) {
const i = placeholder_index(t)
if(0 <= i && i < slots.length) {
span.replaceWith(slots[i])
}
}
})
return el
}
const parts = $(sl.parts)
console.log(parts)
const slots = Array.from(currentScript.previousElementSibling.children)
console.log(slots)
return k(parts, ...slots)
</script>
""")
Base.show(io, m, h)
end
end
# ╔═╡ 70557b20-88e3-4346-a5fd-3382f68e0590
begin
macro tex(x)
tex(x)
end
# `_str` macros with interpolation are not reactive in pluto 🙈 until https://github.com/fonsp/Pluto.jl/pull/1032 is fixed. :((
#macro tex_str(_x::String)
# x = Meta.parse("\"" * _x * "\"")
# tex(x)
#end
function tex(ex::Expr)
@assert ex.head === :string
if ex.args[1] isa String
parts = String[ex.args[1]]
slots = Any[]
else
parts = ["\\hspace{0pt}"]
slots = [ex.args[1]]
end
for x in ex.args[2:end]
if x isa String
all(==(' '), x) ? push!(parts, "\\hspace{0pt}") : push!(parts, x)
else
length(parts) != length(slots) + 1 && push!(parts, "\\hspace{0pt}")
push!(slots, x)
end
end
if length(slots) == length(parts)
push!(parts, "\\hspace{0pt}")
end
quote
SlottedLaTeX(
parts = $parts,
slots = [$(esc.(slots)...)],
)
end
end
function tex(x::String)
SlottedLaTeX(
parts=[x],
slots=[],
)
end
end
# ╔═╡ dbfa3b38-ccd3-48cb-add5-8ad3962a976c
tex_example = @tex("""
f(x) =
\\oint_{
x \\in \\mathbb{R}
}
\\frac{
1 + $(Slider(1:100))
}{
$(embed_display([1,2,23])) + x
}
""")
# ╔═╡ ac065b33-f9fd-41d3-a9a8-f3579bd5f31b
smalldog = html"""
<img src='https://user-images.githubusercontent.com/6933510/116753174-fa40ab80-aa06-11eb-94d7-88f4171970b2.jpeg' height=30px>"""
# ╔═╡ 45e5c62b-40df-4f6a-8a22-ae093a2fcb12
@tex("""
f(x) =
\\oint_{
x \\in \\mathbb{R}
}
\\frac{
1 + $(smalldog)
}{
$(@bind z Scrubbable(5)) + x
}
""")
# ╔═╡ fc4ea0a9-cfc9-42a0-ac03-63afaaaab117
z
# ╔═╡ 7d93e8bb-4305-4942-8fd9-a7c6757237a2
bigbreak
# ╔═╡ d2183a30-f1cd-4262-b51e-16e1e21ade38
bigbreak
# ╔═╡ 61277f1a-72b3-46f5-a2bd-5d9ca7c0f172
hello = 123
# ╔═╡ b2fbe633-21d9-4211-88ba-8dad66823d3b
@bind hello Slider(1:10)
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
HypertextLiteral = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoTest = "cb4044da-4d16-4ffa-a6a3-8cad7f73ebdc"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
[compat]
HypertextLiteral = "~0.8.0"
Plots = "~1.16.6"
PlutoTest = "~0.1.0"
PlutoUI = "~0.7.9"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.1"
[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c3598e525718abcc440f69cc6d5f60dda0a1b61e"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.6+5"
[[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "e2f47f6d8337369411569fd45ae5753ca10394c6"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.0+6"
[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"]
git-tree-sha1 = "c8fd01e4b736013bc61b704871d20503b33ea402"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.12.1"
[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.0"
[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.8"
[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "dc7dedc2c2aa9faf59a55c622760a25cbefbe941"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.31.0"
[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "0.5.2+0"
[[Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.7"
[[DataAPI]]
git-tree-sha1 = "ee400abb2298bd13bfc3df1c412ed228061a2385"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.7.0"
[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "4437b64df1e0adccc3e5d1adbc3ac741095e4677"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.9"
[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]