Giter Club home page Giter Club logo

diagrams-pgf's Introduction

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.

Usage

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
square

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
\begin{pgfpicture}
  \pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{22.0000px}{22.0000px}}
  \pgfusepath{use as bounding box}
  \begin{pgfscope}
    \begin{pgfscope}
      \pgfpathmoveto{\pgfqpoint{21.0000px}{1.0000px}}
      \pgfpathlineto{\pgfqpoint{21.0000px}{21.0000px}}
      \pgfpathlineto{\pgfqpoint{1.0000px}{21.0000px}}
      \pgfpathlineto{\pgfqpoint{1.0000px}{1.0000px}}
      \pgfpathlineto{\pgfqpoint{21.0000px}{1.0000px}}
      \pgfpathclose
      \definecolor{sc}{rgb}{0.0000,0.0000,0.0000}
      \pgfsetstrokecolor{sc}
      \pgfsetlinewidth{0.0132mm}
      \pgfusepath{stroke}
    \end{pgfscope}
  \end{pgfscope}
\end{pgfpicture}

Typesetting

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

hbox

Missing features

The following features are not currently supported:

  • selecting fonts (italic and bold work)
  • gradients

diagrams-pgf's People

Contributors

cchalmers avatar byorgey avatar chris-martin avatar bergey avatar jeffreyrosenbluth avatar ggreif avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.