File: customizing.rstw

package info (click to toggle)
python-pweave 0.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,064 kB
  • sloc: python: 30,281; makefile: 167
file content (53 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

Customizing output
==================

.. index:: customizing

.. currentmodule:: pweave

Pweave has several output formats and you can customize the output
with chunk options. However you may want to customize the output for
different purposes.

The simplest form of customization is to update the *format dictionary*
of an existing format. It sets chunk delimiters, output extension and
figure format and width.

You can do this easily with :py:class:`Pweb` class. Below
is a small demonstration using ReST Pweave document `ma.mdw <_static/ma.mdw>`_.

Let's start by creating an instance of :py:class:`Pweb` class with markdown document:

<<term=True>>=
from pweave import *
from pprint import pprint
doc = Pweb('ma.mdw', doctype = "pandoc")
@

Have a look at what the format dictionary contains:

<<term=True>>=
pprint(doc.getformat())
@

The names of the dictionary elements are hopefully self
explanatory. You'll notice that you can specify start and end tag for
code, results and term as well as block indent.

You can change the formats using :py:meth:`Pweb.updateformat` method. Let's set the
default figure width to 10cm and figure format to pdf and
:py:attr:`figfmt` specifies what format is used in the output.

<<term=True>>=
doc.updateformat({'width' : '10cm', 'figfmt' : '.pdf'})
@

And after setting options weave and tangle the document:

<<term=True>>=
doc.weave()
doc.tangle()
@

View this page as `Pweave document <_static/customizing.rstw>`_ .