diagrams-pgf: PGF backend for diagrams drawing EDSL.

[ bsd3, graphics, library ] [ Propose Tags ]

This package provides a modular backend for rendering diagrams created with the diagrams EDSL using the TeX library PGF.

Support for rendering LaTeX, ConTeXt and plain TeX files.

[Skip to Readme]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,,,,, 1.4, 1.4.1,, 1.4.2,
Dependencies base (>=4.4 && <4.20), bytestring (>=0.9 && <1.1), bytestring-builder (<1.1), colour, containers (>=0.3 && <0.7), diagrams-core (>=1.4 && <1.6), diagrams-lib (>=1.4 && <1.5), directory (>=1.0 && <1.4), filepath (>=1.2 && <1.5), hashable (>=1.1 && <1.5), JuicyPixels, mtl (>=2.1 && <3.0), optparse-applicative (>=0.13 && <0.19), process (>=1.0 && <1.7), split (>=0.1.2 && <0.3), texrunner (<=0.0.2), time (>=1.2 && <1.14), vector, zlib [details]
License BSD-3-Clause
Author Christopher Chalmers
Maintainer c.chalmers@me.com
Revised Revision 1 made by BrentYorgey at 2024-01-29T20:10:54Z
Category Graphics
Home page http://github.com/cchalmers/diagrams-pgf
Bug tracker http://github.com/cchalmers/diagrams-pgf/issues
Source repo head: git clone http://github.com/cchalmers/diagrams-pgf
Uploaded by BrentYorgey at 2023-07-10T17:17:20Z
Distributions NixOS:
Reverse Dependencies 2 direct, 25 indirect [details]
Downloads 6829 total (29 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-07-10 [all 1 reports]

Readme for diagrams-pgf-

[back to package description]

PGF diagrams backend

diagrams-pgf is a PGF backend for diagrams. Diagrams is a powerful, flexible, declarative domain-specific language for creating vector graphics, using the Haskell programming language.

PGF is a TeX macro package for generating graphics. It is platform- and format-independent and works together with the most important TeX backend drivers, including pdftex and dvips.

diagrams-pgf is a work in progress, it supports the basic features of diagrams with the following features:

  • LaTeX, ConTeXt and plain TeX support
  • direct PDF generation using a TeX distribution (e.g. texlive) via texrunner.


A simple example that uses diagrams-pgf to draw a square.

import Diagrams.Prelude
import Diagrams.Backend.PGF.CmdLine

b1 = square 20 # lwG 0.05

main = defaultMain (pad 1.1 b1)

Save this to file named square.hs and compile this program:

ghc --make square.hs

This will generate an executable which, when run produces a TeX (or PDF) file. Run the executable with the --help option to find out more about how to call it.

$ ./square --help

Usage: square [-?|--help] [-w|--width WIDTH] [-h|--height HEIGHT]
              [-o|--output OUTPUT] [-f|--format FORMAT] [-a|--standalone]
              [-r|--readable] [-l|--loop] [-s|--src ARG]
              [-i|--interval INTERVAL]
  Command-line diagram generation.

Available options:
  -?,--help                Show this help text
  -w,--width WIDTH         Desired WIDTH of the output image
  -h,--height HEIGHT       Desired HEIGHT of the output image
  -o,--output OUTPUT       OUTPUT file
  -f,--format FORMAT       l for LaTeX, c for ConTeXt, p for plain
                           TeX (default: LaTeX)
  -a,--standalone          Produce standalone .tex output
  -r,--readable            Indent lines
  -l,--loop                Run in a self-recompiling loop
  -s,--src ARG             Source file to watch
  -i,--interval INTERVAL   When running in a loop, check for changes every
                           INTERVAL seconds.

If no output file is given, output is send to stdout. Supported outputs are .tex and .pdf. PDF generation is done using texrunner.

$ ./Square -o square.tex
$ cat ./square.tex
  \pgfusepath{use as bounding box}


pgf-diagrams allows typesetting TeX commands and can calculate the corresponding envelope. See the hbox example to see how get envelopes of text:


Missing features

The following features are not currently supported:

  • selecting fonts (italic and bold work)
  • gradients