Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

nzbr/pandocode

Open more actions menu

Repository files navigation

Pandocode

pandocode is a pandoc filter that converts Python (-like) code to LaTeX-Pseudocode.
It can also be used as a standalone program.

Usage

Standalone

Outputs the resulting LaTeX code to console

Run:
./pandocode.pyz <file>
or
pandocode <file>

Filter

Converts every code-block of type pseudo to LaTeX

Run:
pandoc --filter /path/to/pandocode.pyz <infile.md> -o <outfile>
or
pandoc --filter pandocode <infile.md> -o <outfile>

Building

  • Install dependencies from requirements.txt and make-requirements.txt
    • pip3 install -r requirements.txt -r make-requirements.txt
    • or pip3 install --user -r requirements.txt -r make-requirements.txt
  • Run make
  • Optional: Run sudo make install
    • This will install pandocode.pyz to /usr/bin/pandocode

Use PyPy3 instead of CPython

  • Use pypy3 -m pip instead of pip3
    • If pip is missing, install it with pypy3 -m ensurepip or pypy3 -m ensurepip --user
  • Run make PY=pypy3 instead of make

Without PyLint:

If you want to build without running pylint:

  • Don't install make-requirements.txt
  • Run make PYLINT=$(which true) instead of make

Examples

There is an example in the demo directory

Control sequences

Pandocode allows the use of the following control sequences inside the code:

Begin/End

Syntax:

  • #$begin
  • #$end

If a begin sequence is found, Pandocode ignores any code that is outside of a pair of begin/end control sequences.
If the end of the code is reached and no end sequence is encountered, all code from the begin sequence on is included.

Add

Syntax:

  • #$+ <text>

Includes <text> as a line in the code before code processing.

Remove

Syntax:

  • #$-

Removes the next line before code processing.

Replace

Syntax:

  • #$= <text>

Replaces the next line by <text> before code processing.

Raw

Syntax:

  • :: <LaTeX>

When encountered during processing, instead of processing this line, :: gets removed and <LaTeX> is appended to the output.
This can be used as <text> in any control sequence that is processed before code processing.

Example:
#$= :: <LaTeX>
Replaces the next line by raw LaTeX

External Code

Pandocode is tested to be working with pandoc-include-code

---
header-includes:
  - \usepackage[noend]{algpseudocode}
---

```{.pseudo include=code.py}
```

About

Pandocode is a program/pandoc-filter that converts Python(-like) code to LaTeX Pseudocode

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.