Code Blocks
Code blocks allow you to write, display, and run code directly inside your document.
Code blocks behave as independent blocks. They preserve formatting, support syntax highlighting, and can execute code.
Creating a code block
Open the right sidebar.
Click the Add Code Block icon:
A new code block will be inserted.
If the current line already contains text, the code block is created on the next line.
Writing code
You can type or paste code directly into the block.
print("Hello, world!")Code is stored exactly as written. Math symbols remain plain text.
a = 5
b = 3
result = a + b
print(result)Syntax highlighting
Code blocks automatically highlight syntax. You can select the programming language from the Code panel (it appears when you click inside the code block):
Code in Python:
for i in range(5):
print(i)Code JavaScript:
const numbers = [1, 2, 3];
numbers.forEach(n => {
console.log(n);
});The selected language determines highlighting behavior.
Navigation inside a code block
Key | Action |
|---|---|
Enter | New line |
Tab | Insert tab character |
Arrow keys | Move cursor |
Cmd | Select code |
Cmd | Select document |
Navigation stays inside the block until you exit.
Exiting a code block
Action | Result |
|---|---|
Arrow key at boundary | Move outside block |
Cmd | Add paragraph below |
Shift | Add paragraph above |
Triple Enter | Exit block |
Multiple code blocks
Documents can contain multiple code blocks. Each block runs independently.
Installing packages
You can install libraries inside the document environment.
For example:
pip install numpyInstalled packages remain available in the current document.
Previous: Graphs and Visualizations | Next: Copying Expressions |