pandoc-plot-0.3.0.0: A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice.

Copyright(c) Laurent P René de Cotret 2020
LicenseGNU GPL, version 2 or above
Maintainerlaurent.decotret@outlook.com
Stabilityunstable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Text.Pandoc.Filter.Plot

Contents

Description

This module defines a Pandoc filter makePlot and related functions that can be used to walk over a Pandoc document and generate figures from code blocks using a multitude of plotting toolkits.

The syntax for code blocks is simple, Code blocks with the appropriate class attribute will trigger the filter:

  • matplotlib for matplotlib-based Python plots;
  • plotly_python for Plotly-based Python plots;
  • matlabplot for MATLAB plots;
  • mathplot for Mathematica plots;
  • octaveplot for GNU Octave plots;
  • ggplot2 for ggplot2-based R plots;
  • gnuplot for gnuplot plots;

The code block will be reworked into a script and the output figure will be captured. Optionally, the source code used to generate the figure will be linked in the caption.

Here are the possible attributes what pandoc-plot understands for ALL toolkits:

  • directory=... : Directory where to save the figure.
  • source=true|false : Whether or not to link the source code of this figure in the caption. Ideal for web pages, for example. Default is false.
  • format=...: Format of the generated figure. This can be an extension or an acronym, e.g. format=PNG.
  • caption="...": Specify a plot caption (or alternate text). Captions should be formatted in Markdown, with LaTeX math.
  • dpi=...: Specify a value for figure resolution, or dots-per-inch. Certain toolkits ignore this.
  • preamble=...: Path to a file to include before the code block. Ideal to avoid repetition over many figures.

Default values for the above attributes are stored in the Configuration datatype. These can be specified in a YAML file which must be named ".pandoc-plot.yml".

Here is an example code block which will render a figure using gnuplot, in Markdown:

    ```{.gnuplot format=png caption="Sinusoidal function"}
    sin(x)

    set xlabel "x"
    set ylabel "y"
    ```
Synopsis

Operating on single Pandoc blocks

makePlot Source #

Arguments

:: Configuration

Configuration for default values

-> Block 
-> IO Block 

Highest-level function that can be walked over a Pandoc tree. All code blocks that have the .plot / .plotly class will be considered figures.

The target document format determines how the figure captions should be parsed. By default (i.e. if Nothing), captions will be parsed as Markdown with LaTeX math $...$,

Operating on whole Pandoc documents

plotTransform Source #

Arguments

:: Configuration

Configuration for default values

-> Pandoc

Input document

-> IO Pandoc 

Walk over an entire Pandoc document, changing appropriate code blocks into figures. Default configuration is used.

Runtime configuration

configuration :: FilePath -> IO Configuration Source #

Read configuration from a YAML file. The keys are exactly the same as for code blocks.

If a key is either not present, its value will be set to the default value. Parsing errors result in thrown exceptions.

data Configuration Source #

The Configuration type holds the default values to use when running pandoc-plot. These values can be overridden in code blocks.

Constructors

Configuration 

Fields

data SaveFormat Source #

Generated figure file format supported by pandoc-plot. Note that not all formats are supported by all toolkits.

Constructors

PNG 
PDF 
SVG 
JPG 
EPS 
GIF 
TIF 
WEBP 
Instances
Bounded SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

Enum SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

Eq SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

Show SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

IsString SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

Generic SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

Associated Types

type Rep SaveFormat :: Type -> Type #

Hashable SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

ToJSON SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

FromJSON SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

type Rep SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Types

type Rep SaveFormat = D1 (MetaData "SaveFormat" "Text.Pandoc.Filter.Plot.Types" "pandoc-plot-0.3.0.0-A3xd1bMePguH2iZU4iRhSf" False) (((C1 (MetaCons "PNG" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "PDF" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "SVG" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "JPG" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "EPS" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "GIF" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "TIF" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "WEBP" PrefixI False) (U1 :: Type -> Type))))

For testing purposes ONLY

make Source #

Arguments

:: Toolkit

Plotting toolkit.

-> Configuration

Configuration for default values.

-> Block 
-> IO Block 

Force to use a particular toolkit to render appropriate code blocks.

Failing to render a figure does not stop the filter, so that you may run the filter on documents without having all necessary toolkits installed. In this case, error messages are printed to stderr, and blocks are left unchanged.

availableToolkits :: Configuration -> IO [Toolkit] Source #

List of toolkits available on this machine. The executables to look for are taken from the configuration.

unavailableToolkits :: Configuration -> IO [Toolkit] Source #

List of toolkits not available on this machine. The executables to look for are taken from the configuration.