Skip to main content

pandoc_pyrun

pipeline status License

Pandoc_pyrun is a pandoc filter used to execute Python code embedded in Markdown CodeBlocks.
The result of the execution of the Python code is displayed in the produced documents, for example in PDF or HTML format. Images produced by the turtle and mathplotlib Python libraries can also be included.
Options allow to display the Python code and / or the result of its execution.

\

Usage

An interactive alive console takes the input code, compiles it and displays it to the specific type given, like PDF or Markdown. It can also manage turtle or mathplotlib codes by generating the images, saving them in the current directory and adding the markdow line to incorporate them in the final file. Code has to be trusted ; which means that the code is not verified before any execution, the role of this filter is just to execute the code, not to make sure that it is safe to execute it.
To use this filter, you can execute this command template :

pandoc INPUT_FILE -o OUTPUT_FILE -t OUTPUT_FORMAT  -F pandoc_pyrun

Example :

pandoc hello.md -F pandoc_pyrun -t pdf -o hello_converted.pdf
  • This can be used to convert into any text pandoc supported format.
  • The only expected source is Markdown language.


\

Installation

pandoc_pyrun requires Python language.
To install the filter, follow the instructions below :

  1. Install Pandoc on your device with this link
  2. (Optional) Install LaTeX to transform your markdown into pdf with this link
  3. Install Ghostscript for plot and turtle figures with this link
    • NOTE : In your PATH variable, make sure you have the bin/ folder of Ghostscript added, otherwise it won't work.
  4. Update your pip with python -m pip install --upgrade pip
  5. Install this filter with pip install pandoc-pyrun


\

How to use it

On the top of your document, you'll be able to define global variables for the pandoc_pyrun filter.
NOTE : the classes' names and values can be written in both ways : lower case and upper case.

---
title: Running your Python CodeBlocks
author: Thomas D'HULST, Ajwad TAYEBI
date: March 29, 2021
pandoc_pyrun_out: OUT
pandoc_pyrun_mode: MODE
pandoc_pyrun_type: TYPE
---

Here is a sample of how a CodeBlock has to be written ; you can also put values (other than defined above) for any pandoc_pyrun classes in the {}.
Instead of .py or .python, you can also write .pandocPyrun.

    ```{.py[thon] out=OUT type=TYPE scope=SCOPE file=FILE}
    #Here you enter your code
    ```

\

The list of possible values for the above parameters can be found in the overview table of the reference_manual.
A complete use of this filter is available in the tutorial.

\

NB :

  • Only CodeBlock can be read with this filter.
  • If you don't want to let the filter compile your code, add a .pyrunPass between the {} explained below.
  • The main goal of its utilisation is to produce, for a code block, its text and/or its execution's result by a Python interpreter.


\

Examples

Let's take the following document content input.md.

    ```{.python out=NONE}
    def for_all(lst):
        return not False in lst
    ```

    ```{.python out=ALL}
    for_all([])
    for_all((True, True, True))
    for_all((True, False, True))
    ```

Here we have forced the out values but the others are set as [default] as indicated in the table above.
Now just execute pandoc -o output.md input.md -F pandoc_pyrun and then you'll get :

    ::: {.pyrun}
    ::: {.in}
    ``` {.python .pyrunPass}
    for_all([])
    for_all((True, True, True))
    for_all((True, False, True))
    ```
    :::

    ::: {.out}
    ``` {.python .pyrunPass}
    True
    True
    False
    ```
    :::
    :::


\

Wanna see more ?

Check the folder samples/ which contains multiple other examples.

Use the command make to generate all examples.

Use the command make [filename].pdf to generate the chosen example in pdf.

Use the command make [filename]-out.md to generate the chosen example in markdown.

Use the command make clean to clean all generated files.
\

Help

Any trouble with our filter ? File an issue or contact us !

Metadata

Release files for pandoc-pyrun 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandoc-pyrun 1.0.2
File Size Uploaded
pandoc_pyrun-1.0.2.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pandoc-pyrun 1.0.2
File Interpreter ABI Platform
pandoc_pyrun-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / pandoc_pyrun-1.0.2.tar.gz

Download URL pandoc_pyrun-1.0.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f37bd7fe94220ced7cc64797ab667994aa6b6f6f6989662fefeec85cb72d1919
BLAKE2b-256 checksum
How to use checksums
023e419472829f55adb50029d5682c8b90b1f96e5e9e94081b66e233da6cb6cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.10

Release files / pandoc_pyrun-1.0.2-py3-none-any.whl

Download URL pandoc_pyrun-1.0.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a23b057f9e073ecf8d98bba9e1b309cfa421e4a6ea56a6cda1055776dd5eb34
BLAKE2b-256 checksum
How to use checksums
a665b6ff0e614589ef3ad817b38b288a39fa19ae976a982423f906e507eecd60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page