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.
Running your code
Code blocks are executable. Use the status bar above the code area to run and monitor your code.
Click Run all to execute every code block in the document. The session indicator shows the kernel state as it starts up: grey when idle, pulsing yellow while starting, and green when ready. Output appears directly beneath each block and can include text, tables, images, audio, and video.
Output is saved with the document and reloads when you reopen it, so you see results before re-running. On a shared document, output syncs live to everyone.
Installing libraries
Import any supported package in your code and Corca installs it into the document's environment on first run. Installed packages persist across sessions, so you don't reinstall them each time. Because every document has its own isolated environment, variables and installed packages never leak between documents.
Monitoring resources
Hover the chip icon in the status bar to see live CPU and memory usage for the current session. Stop the kernel from the status bar's menu when you're finished.
Appearance
You can set the font size of a code block from
Letting the AI write and run code
Ask the AI Helper to write code for a task. It can insert a code block, run it, and install any libraries it needs, then explain the result. See AI Helper.
Previous: Graphs and Visualizations | Next: Copying Expressions |