1 | initial version |

- the sage REPL or command-line-interface
- launch Sage in a terminal, wait for the
`sage:`

prompt - type a command then hit the ENTER or RETURN key, get output

- launch Sage in a terminal, wait for the
- the Jupyter Notebook with the Sage kernel
- ways to launch it
- in a terminal, type
`sage -n jupyter`

- or use a launcher such as
- the macOS "Sage app"
- the Windows launcher
- a desktop launcher for Linux

- in a terminal, type

- ways to launch it
- JupyterLab
- install using
`sage --pip install jupyterlab`

- then in the terminal run
`sage -n jupyterlab`

- install using
- the legacy SageNB notebook
- ways to launch it
- in a terminal, type
`sage -n sagenb`

- or in the Sage REPL, type
`notebook()`

- or use a launcher

- in a terminal, type

- ways to launch it
- run a command with
`sage -c`

- example: in a terminal, run
`sage -c "print(2 + 2)"`

- example: in a terminal, run
- run a file with extension
`.py`

or`.sage`

- put the commands in a file such as
`myfile.sage`

or`myfile.py`

- in the terminal, run
`sage myfile.sage`

or`sage myfile.py`

- difference between
`.sage`

and`.py`

files- for
`.sage`

files, the Sage preparser will be used - for
`.py`

files, the Sage preparser will not be used

- for

- put the commands in a file such as
- use external files
- commands
`load`

,`runfile`

,`attach`

,`%load`

,`%runfile`

,`%attach`

- examples
- suppose the file
`myfile.sage`

contains`def sq(a): return a*a`

- in the terminal, run
`sage -c "load('myfile.sage'); print(sq(2))"`

- suppose the file

- commands
- from another program
- SageTeX, a LaTeX package to use Sage within TeX/LaTeX documents
- PreTeXt
- Cantor
- TeXmacs
- see also Interfaces to SageMath in other software

- use OpenMath and SCSCP to exchange mathematical objects with other mathematics software; work in progress, see

- SageCell
- one-off computations on SageCell page
- use it to include compute cells in a webpage
- use it with PreTeXt

- CoCalc
- see dedicated item below

- JupyterHub
- there are some deployments of JupyterHub which offer the Sage kernel

- mybinder
- there are some mybinder instances that include Sage

- Sage Notebook servers
- there some deployments of the SageNB notebook; the one formerly at sagenb.org is no longer active

- in a CoCalc terminal, run
`sage`

for the Sage REPL - use
`sage_select`

to select which version of Sage to use by default - CoCalc Sage worksheets (
`.sagews`

) - Jupyter Notebook worksheets (
`.ipynb`

)- using CoCalc's version of the Jupyter Notebook
- using the Classic Jupyter Notebook
- go to Project preferences and launch Classic Jupyter Notebook; this will open a separate browser tab which will connect to your project using the classic Jupyter Notebook protocol;
- allows to use Jupyter Notebook extensions that are not yet implemented in "CoCalc Jupyter", such as widgets, RISE, ...

- common file extensions
- .py, .sage, .pyx, .spyx, ...
- .sobj
- SageNB notebook worksheets: .sws
- CoCalc Sage worksheets: .sagews
- .rst, .txt, .html

- converters
`rst2ipynb`

, ...

- viewing, saving, copying, transferring worksheets

- any command starting with
`!`

is executed as a shell command - many basic shell commands are available in IPython without
`!`

:`ls`

,`cd`

,`pwd`

... - see also the Python modules
`os`

and`sys`

- this uses standard Python functionality
- 'r' for read, 'w' for write (overwriting file), 'a' for append
read from file, all at once or line by line

`with open('/path/to/file.txt', 'r') as f: s = f.read() with open('/path/to/file.txt', 'r') as f: for line in f: <do something with line>`

write to file, bit by bit or line by line

`with open('/path/to/file.txt', 'a') as f: f.write('blah') f.writelines(['haha', 'hehe', 'hihi'])`

see also the

`csv`

module for "comma-separated-values" data files

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.