diff --git a/README.md b/README.md index 66e4732..bb38d9d 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,7 @@ The Python scientific visualisation landscape is huge. It is composed of a myria ### Read the book -You can read the book **[PDF](https://hal.inria.fr/hal-03427242/document)** (95Mo) that is open access and hosted on -[HAL](https://hal.archives-ouvertes.fr/) which is a French open -archive for academics. -Sources for the book (including code examples) +You can read the book **[PDF](pdf/book.pdf)** (95Mo) that is open access and hosted on GitHub. Sources for the book (including code examples) are available at [github.com/rougier/scientific-visualization-book](https://github.com/rougier/scientific-visualization-book). @@ -46,8 +43,8 @@ future work on Python (and - - + + diff --git a/pdf/book.pdf b/pdf/book.pdf new file mode 100644 index 0000000..412ccbd Binary files /dev/null and b/pdf/book.pdf differ diff --git a/rst/anatomy.rst b/rst/anatomy.rst index 2fe63d2..356551d 100644 --- a/rst/anatomy.rst +++ b/rst/anatomy.rst @@ -50,7 +50,7 @@ In many cases, this can be further compacted using the subplots_ method. .. code:: python fig, ax = plt.subplots(figsize=(6,6), - subplot_kw={"aspect"=1}) + subplot_kw={"aspect": 1}) ax.plot(range(10)) plt.show() diff --git a/rst2latex.py b/rst2latex.py new file mode 100755 index 0000000..cc38abb --- /dev/null +++ b/rst2latex.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + + +""" +A customized front end to the Docutils Publisher, producing LaTeX with valid codeblocks using the listings package. +""" + +try: + import locale + locale.setlocale(locale.LC_ALL, '') +except: + pass + +from docutils.core import publish_cmdline +from docutils.parsers.rst import directives, Directive +from docutils import nodes + + +class CodeBlock(Directive): + required_arguments = 1 + optional_arguments = 0 + final_argument_whitespace = False + option_spec = {} + has_content = True + + rstlang_to_listingslang = { + 'text': '{}' + } + + def run(self): + language = self.rstlang_to_listingslang.get(self.arguments[0], self.arguments[0]) + content = '\n'.join(self.content) + latex = '\\begin{{lstlisting}}[language={}]\n{}\n\\end{{lstlisting}}'.format(language, content) + return [nodes.raw('', latex, format='latex')] + + +description = ('Generates LaTeX documents from standalone reStructuredText ' + 'sources. ' + 'Reads from (default is stdin) and writes to ' + ' (default is stdout). See ' + ' for ' + 'the full reference.') + + +for directive_name in ('code', 'code-block'): + directives.register_directive(directive_name, CodeBlock) +publish_cmdline(writer_name='latex', description=description)