Copyright | (c) 2015 Christopher Chalmers |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | diagrams-discuss@googlegroups.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A full-featured PGF backend for diagrams producing PGF code suitable for LaTeX, ConTeXt or plain TeX consumption.
To invoke the PGF backend, you have a number of options.
- You can use
renderPGF
orrenderPGF'
to render aDiagram
to a ".tex" or ".pdf" file; - You can use the most flexible
renderDia
function to access the resulting PGF code directly in memory as a bytestringBuilder
. - Use
mainWith
ordefaultMain
to make a command line application. SeeCmdLine
for more info.
The Surface
provides the necessary information for rendering PGF code and
building a PDF using "texrunner". See Surface
for more info.
Synopsis
- data PGF = PGF
- type B = PGF
- renderPGF :: (TypeableFloat n, Monoid' m) => FilePath -> SizeSpec V2 n -> QDiagram PGF V2 n m -> IO ()
- renderPGF' :: (TypeableFloat n, Monoid' m) => FilePath -> Options PGF V2 n -> QDiagram PGF V2 n m -> IO ()
- renderPGFSurf :: (TypeableFloat n, Monoid' m) => FilePath -> SizeSpec V2 n -> Surface -> QDiagram PGF V2 n m -> IO ()
- readable :: Lens' (Options PGF V2 n) Bool
- sizeSpec :: Lens' (Options PGF V2 n) (SizeSpec V2 n)
- surface :: Lens' (Options PGF V2 n) Surface
- standalone :: Lens' (Options PGF V2 n) Bool
- data Surface
- surfOnlineTex :: Surface -> OnlineTex a -> a
- latexSurface :: Surface
- contextSurface :: Surface
- plaintexSurface :: Surface
- command :: Lens' Surface String
- arguments :: Lens' Surface [String]
- preamble :: Lens' Surface String
- data OnlineTex a
- renderOnlinePGF :: (TypeableFloat n, Monoid' m) => FilePath -> SizeSpec V2 n -> OnlineTex (QDiagram PGF V2 n m) -> IO ()
- renderOnlinePGF' :: (TypeableFloat n, Monoid' m) => FilePath -> Options PGF V2 n -> OnlineTex (QDiagram PGF V2 n m) -> IO ()
- data Hbox n
- hboxOnline :: (TypeableFloat n, Renderable (Hbox n) b) => String -> OnlineTex (QDiagram b V2 n Any)
- hboxPoint :: (OrderedField n, Typeable n, Renderable (Hbox n) b) => String -> QDiagram b V2 n Any
- hboxSurf :: (TypeableFloat n, Renderable (Hbox n) b) => Surface -> String -> QDiagram b V2 n Any
Rendering token & options
This data declaration is simply used as a token to distinguish this rendering engine.
Instances
Rendering functions
:: (TypeableFloat n, Monoid' m) | |
=> FilePath | path to output |
-> SizeSpec V2 n | size of output |
-> QDiagram PGF V2 n m |
|
-> IO () |
Render a pgf diagram and write it to the given filepath. Same as
renderPGF'
but uses the default options.
renderPGF' :: (TypeableFloat n, Monoid' m) => FilePath -> Options PGF V2 n -> QDiagram PGF V2 n m -> IO () Source #
Render a pgf diagram and write it to the given filepath. If the file has
the extension .pdf
, a PDF is generated in a temporary directory using
options from the given surface, otherwise, the tex output is saved
using the surface's TexFormat
.
Options
Options for changing how the diagram is rendered. Options
PGF
is an instance of Default
:
def = PGFOptions { _surface =latexSurface
_sizeSpec =absolute
_readable =True
_standalone =False
}
You can edit the default options using lenses.
readable :: Lens' (Options PGF V2 n) Bool Source #
Lens onto whether the lines of the TeX output are indented.
standalone :: Lens' (Options PGF V2 n) Bool Source #
Lens onto whether a standalone TeX document should be produced.
Surfaces
These surfaces should be suitable for basic diagrams. For more
complicated options see Surface
.
Instances
Default Surface Source # | Latex is the default surface. |
Defined in Diagrams.Backend.PGF.Surface | |
Eq Surface Source # | |
Hashable Surface Source # | |
Defined in Diagrams.Backend.PGF.Surface | |
TypeableFloat n => Mainable (Surface, QDiagram PGF V2 n Any) Source # | |
Defined in Diagrams.Backend.PGF.CmdLine | |
TypeableFloat n => Mainable (Surface, OnlineTex (QDiagram PGF V2 n Any)) Source # | |
Defined in Diagrams.Backend.PGF.CmdLine mainArgs :: Parseable (MainOpts (Surface, OnlineTex (QDiagram PGF V2 n Any))) => proxy (Surface, OnlineTex (QDiagram PGF V2 n Any)) -> IO (MainOpts (Surface, OnlineTex (QDiagram PGF V2 n Any))) # mainRender :: MainOpts (Surface, OnlineTex (QDiagram PGF V2 n Any)) -> (Surface, OnlineTex (QDiagram PGF V2 n Any)) -> IO () # mainWith :: (Surface, OnlineTex (QDiagram PGF V2 n Any)) -> IO () # | |
type MainOpts (Surface, QDiagram PGF V2 n Any) Source # | |
type MainOpts (Surface, OnlineTex (QDiagram PGF V2 n Any)) Source # | |
surfOnlineTex :: Surface -> OnlineTex a -> a Source #
Get the result of an OnlineTex using the given surface.
Predefined surfaces
latexSurface :: Surface Source #
Default surface for latex files by calling pdflatex
.
Sample output
contextSurface :: Surface Source #
Default surface for latex files by calling pdflatex
.
Sample output
command
: context --pipe --once %preamble
usemodule[pgf] setuppagenumbering[location=] %pageSize
definepapersize[diagram][width=100bp,height=80bp] setuppapersize[diagram][diagram] setuplayout [ topspace=0bp , backspace=0bp , header=0bp , footer=0bp , width=100bp , height=80bp ] %beginDoc
starttext <Context pgf code> %endDoc
stoptext
plaintexSurface :: Surface Source #
Default surface for latex files by calling pdflatex
.
Sample output
Lenses
preamble :: Lens' Surface String Source #
Preamble for the tex document. This should at least import
pgfcore
.
Online TeX
By using OnlineTex
, diagrams is able to query tex for sizes
of hboxs and give them the corresponding envelopes. These can
then be used as any other diagram with the correct size.
Online diagrams use the Surface
to run tex in online mode and
get feedback for hbox sizes. To run it you can use
renderOnlinePGF
, renderOnlinePGF'
or onlineMain
from
CmdLine
.
See https://github.com/diagrams/diagrams-pgf/tree/master/examples for examples.
Type for dealing with Tex's piping interface; the current streams
are available though the MonadReader
instance.
Instances
renderOnlinePGF :: (TypeableFloat n, Monoid' m) => FilePath -> SizeSpec V2 n -> OnlineTex (QDiagram PGF V2 n m) -> IO () Source #
Render an online PGF
diagram and save it. Same as
renderOnlinePGF'
using default options.
renderOnlinePGF' :: (TypeableFloat n, Monoid' m) => FilePath -> Options PGF V2 n -> OnlineTex (QDiagram PGF V2 n m) -> IO () Source #
Hbox
Primitive for placing raw Tex commands in a hbox.
Instances
Fractional n => Transformable (Hbox n) Source # | |
Defined in Diagrams.Backend.PGF.Hbox | |
Fractional n => Renderable (Hbox n) NullBackend Source # | |
Defined in Diagrams.Backend.PGF.Hbox render :: NullBackend -> Hbox n -> Render NullBackend (V (Hbox n)) (N (Hbox n)) # | |
TypeableFloat n => Renderable (Hbox n) PGF Source # | |
type N (Hbox n) Source # | |
Defined in Diagrams.Backend.PGF.Hbox | |
type V (Hbox n) Source # | |
Defined in Diagrams.Backend.PGF.Hbox |
hboxOnline :: (TypeableFloat n, Renderable (Hbox n) b) => String -> OnlineTex (QDiagram b V2 n Any) Source #
Hbox with bounding box envelope.
hboxPoint :: (OrderedField n, Typeable n, Renderable (Hbox n) b) => String -> QDiagram b V2 n Any Source #
Raw Tex commands in a hbox with no envelope. Transformations are
applied normally. This primitive ignores
FontSize
.
hboxSurf :: (TypeableFloat n, Renderable (Hbox n) b) => Surface -> String -> QDiagram b V2 n Any Source #
Hbox with bounding box envelope. Note that each box requires a call to
Tex. For multiple boxes consider using hboxOnline
to get multiple boxes
from a single call. (uses unsafePerformIO)