-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjulia.cbmd
123 lines (72 loc) · 2.64 KB
/
julia.cbmd
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
---
title: "Codebraid with Julia"
---
## Inline code
### Run
Inline code with `.cb-run` gives raw stdout.
`println(1 + 2)`{.julia .cb-run example=true}
### Expression and inline notebook
Inline code with `.cb-expr` evaluates an expression and then inserts the raw
output into the document, where it is interpreted as Markdown. Inline code
with `.cb-nb` (`nb` is short for `notebook`) is similar, except output is
shown verbatim.
`"\$\\sin(30^\\circ) = $(sind(30))\$"`{.julia .cb-expr example=true}
`"\$e^{\\pi/4} = $(exp(pi/4))\$"`{.julia .cb-expr example=true}
`"\$e^{\\pi/4} = $(exp(pi/4))\$"`{.julia .cb-nb example=true}
### Stderr
In the event of an error, inline code automatically shows stderr by default.
This code is executed in its own session, `inline_error`, so that it does
not impact other examples.
`1 + "a"`{.julia .cb-run session=inline_error example=true}
### Source errors
A message is also displayed for errors in the Markdown source. This usually
includes the name of the document source and the approximate line number.
`println(1 + 2)`{.jlia .cb-run session=inline_source_error example=true}
## Block code
### Run
Code blocks with `.cb-run` give raw stdout. There is continuity between code
blocks so long as they are in the same session; variables persist.
```{.julia .cb-run session=hello example=true}
x = "Hello from *Julia!*"
```
```{.julia .cb-run session=hello example=true}
println(x)
```
### Notebook
Code blocks with `.cb-nb` show the code and also the verbatim stdout.
```{.julia .cb-nb session=random example=true}
using Random
using Statistics
Random.seed!(1)
rnums = rand(1:100, 10)
println("Random numbers: $(rnums)")
println("Median: $(median(rnums))")
println("Mean: $(mean(rnums))")
```
### Stderr
Code blocks automatically show stderr by default.
```{.julia .cb-nb .line_numbers session=block_error example=true}
var = 123
println(var)
flush(stdout)
var += "a"
```
### Source errors
A message is also displayed for errors in the Markdown source. This usually
includes the name of the document source and the approximate line number.
```{.julia .cb-ruuun session=block_source_error example=true}
println(1 + 2)
```
## Other options
By default, stdout and stderr are only shown if they are non-empty. In some
situations, it may be useful to represent empty output visually as
confirmation that there indeed was none.
```{.julia .cb-run show=code+stdout+stderr:verbatim_or_empty example=true}
x = 1 + 2
```
It is also possible to selectively hide output from a code chunk.
```{.julia .cb-nb hide=stdout example=true}
println(x)
```
`hide` takes any combination of `code`, `stderr`, and `stdout`, or simply
`all`.