Formatting documents

Markdown

Executable sections are verbatim sections marked with a number of tags, including "python" and "code".

``` python
W='Hello, World!'
print(W)
```

Verbatim result sections might be marked as "result" or "lresult".

``` result
Hello, World!
```

Markdown comments tagged with result/noresult (see an example below) also mark result sections. This syntax allows emitting parts of Markdown document.

<!-- result -->
Hello, World!
<!-- noresult -->

Litrepl resolves python tags into call to an actual Python interpreter using the --python-interpreter command line argument.

Latex

Litrepl treats \begin{python}\end{python} environment as code sections and \begin{result}\end{result} environment as result sections. The names are currently hardcoded into the simplified LitREPL parser. Wrapping it in other tags is not allowed.

LaTeX does not know anything about these environments by default, so we need to introduce these environments in the preamble:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}

\newenvironment{python}{\begin{texttt}}{\end{texttt}}
\newenvironment{result}{\begin{texttt}}{\end{texttt}}
\newcommand{\linline}[2]{#2}

\begin{document}
...
\end{document}

Executable sections is the document are enclosed with the python tags, results - with result tags:

\begin{python}
W='Hello, World!'
print(W)
\end{python}

\begin{result}
Hello, World!
\end{result}
%result
Hello, World!
%noresult

Additionally, LitREPL recognises linline 2-argument tags. The first argument is treated as a Python printable expression. The second argument is an immediate result section where the value of expression will be placed.

\linline{W}{Hello, World!}