Search manual:

- Main page
- Introduction
- Hello, world!
- Basics
  - How to write the layout
  - Structure of the data file and the layout rules
  - Outputting objects
  - Grid
  - Areas on the page (PositioningArea)
  - File organization
  - Hyphenation / language settings
  - Using fonts
  - Text formats
  - Text formatting
  - Colors
- Programming
- Image inclusion
- Tables
- Advanced topics
  - Bookmarks
  - Creation of XML structures
  - Print output / crop marks
  - Using CSS with the speedata Publisher
  - Groups (virtual objects)
  - Virtual pages
  - Rotation of contents
  - Sorting data
  - Wrap around images
  - Page types
  - Starting the Publisher via the Hotfolder
  - Lua-Filter / pre-processing
  - Schema validation
  - Quality assurance and PDF comparison
  - Troubleshooting / Debugging
  - Server mode (REST API)
  - Control of the layout when calling the Publisher
  - Create and use images with MetaPost
- Cookbook
  - Thumb index
  - Embed multipage PDF files
  - Layout optimization using groups
  - Imitate bulleted lists
  - Automatically generated directories
  - Create table of contents in one go
  - Page numbers: Page x of y
- Installation instructions
- File name in the Publisher
- speedata Publisher defaults
- Running the speedata publisher on the command line
- How to configure the speedata publisher
- Lenghts and units
- XPath- and Layoutfunctions
- Internal variables
- Associate XML editor with schema
  - Visual Studio Code
  - OxygenXML
  - Atom
- Changelog
- Glossary
- Compatibility with other software
- Command reference
  - A
  - Action
  - AddSearchpath
  - AtPageCreation
  - AtPageShipout
  - AttachFile
  - Attribute
  - B
  - Barcode
  - Bold
  - BoldItalic
  - Bookmark
  - Box
  - Br
  - Case
  - Circle
  - ClearPage
  - Color
  - Column
  - Columns
  - Compatibility
  - Contents
  - Copy-of
  - DefineColor
  - DefineColorprofile
  - DefineFontalias
  - DefineFontfamily
  - DefineGraphic
  - DefineMatter
  - DefineTextformat
  - Element
  - Fallback
  - Fontface
  - ForAll
  - Frame
  - Grid
  - Group
  - Groupcontents
  - HSpace
  - Hyphenation
  - I
  - Image
  - Include
  - Initial
  - InsertPages
  - Italic
  - Layout
  - Li
  - LoadDataset
  - LoadFontfile
  - Loop
  - Makeindex
  - Margin
  - Mark
  - Message
  - NewPage
  - NextFrame
  - NextRow
  - NoBreak
  - Ol
  - Options
  - Otherwise
  - Output
  - Overlay
  - Pageformat
  - Pagetype
  - Paragraph
  - PDFOptions
  - PlaceObject
  - Position
  - PositioningArea
  - PositioningFrame
  - ProcessNode
  - Record
  - Regular
  - Rule
  - SaveDataset
  - SavePages
  - SetGrid
  - SetVariable
  - SortSequence
  - Stylesheet
  - Span
  - Sub
  - Sup
  - Switch
  - Table
  - TableNewPage
  - Tablefoot
  - Tablehead
  - Tablerule
  - Td
  - Text
  - Textblock
  - Tr
  - Trace
  - Transformation
  - U
  - Ul
  - Until
  - URL
  - Value
  - VSpace
  - While

Version 4.8.0
Search manual

- Main page
- Introduction
- Hello, world!
- Basics
  - How to write the layout
  - Structure of the data file and the layout rules
  - Outputting objects
  - Grid
  - Areas on the page (PositioningArea)
  - File organization
  - Hyphenation / language settings
  - Using fonts
  - Text formats
  - Text formatting
  - Colors
- Programming
- Image inclusion
- Tables
- Advanced topics
  - Bookmarks
  - Creation of XML structures
  - Print output / crop marks
  - Using CSS with the speedata Publisher
  - Groups (virtual objects)
  - Virtual pages
  - Rotation of contents
  - Sorting data
  - Wrap around images
  - Page types
  - Starting the Publisher via the Hotfolder
  - Lua-Filter / pre-processing
  - Schema validation
  - Quality assurance and PDF comparison
  - Troubleshooting / Debugging
  - Server mode (REST API)
  - Control of the layout when calling the Publisher
  - Create and use images with MetaPost
- Cookbook
  - Thumb index
  - Embed multipage PDF files
  - Layout optimization using groups
  - Imitate bulleted lists
  - Automatically generated directories
  - Create table of contents in one go
  - Page numbers: Page x of y
- Installation instructions
- File name in the Publisher
- speedata Publisher defaults
- Running the speedata publisher on the command line
- How to configure the speedata publisher
- Lenghts and units
- XPath- and Layoutfunctions
- Internal variables
- Associate XML editor with schema
  - Visual Studio Code
  - OxygenXML
  - Atom
- Changelog
- Glossary
- Compatibility with other software
- Command reference
  - A
  - Action
  - AddSearchpath
  - AtPageCreation
  - AtPageShipout
  - AttachFile
  - Attribute
  - B
  - Barcode
  - Bold
  - BoldItalic
  - Bookmark
  - Box
  - Br
  - Case
  - Circle
  - ClearPage
  - Color
  - Column
  - Columns
  - Compatibility
  - Contents
  - Copy-of
  - DefineColor
  - DefineColorprofile
  - DefineFontalias
  - DefineFontfamily
  - DefineGraphic
  - DefineMatter
  - DefineTextformat
  - Element
  - Fallback
  - Fontface
  - ForAll
  - Frame
  - Grid
  - Group
  - Groupcontents
  - HSpace
  - Hyphenation
  - I
  - Image
  - Include
  - Initial
  - InsertPages
  - Italic
  - Layout
  - Li
  - LoadDataset
  - LoadFontfile
  - Loop
  - Makeindex
  - Margin
  - Mark
  - Message
  - NewPage
  - NextFrame
  - NextRow
  - NoBreak
  - Ol
  - Options
  - Otherwise
  - Output
  - Overlay
  - Pageformat
  - Pagetype
  - Paragraph
  - PDFOptions
  - PlaceObject
  - Position
  - PositioningArea
  - PositioningFrame
  - ProcessNode
  - Record
  - Regular
  - Rule
  - SaveDataset
  - SavePages
  - SetGrid
  - SetVariable
  - SortSequence
  - Stylesheet
  - Span
  - Sub
  - Sup
  - Switch
  - Table
  - TableNewPage
  - Tablefoot
  - Tablehead
  - Tablerule
  - Td
  - Text
  - Textblock
  - Tr
  - Trace
  - Transformation
  - U
  - Ul
  - Until
  - URL
  - Value
  - VSpace
  - While

- Dieses Handbuch auf Deutsch

# Create and use images with MetaPost

| The functionality to create and embed MetaPost graphics is still very new and experimental. The interface may still change or disappear altogether. In this respect, it should be used with caution.

MetaPost is a programming language that can be used to create graphics.

For example, one creates from the following program code:

    beginfig(1)
        for a=0 upto 9:
          draw (0,0){dir 45}..{dir -10a}(6cm,0);
        endfor
    endfig;

a graphic:

## MetaPost and the speedata Publisher

The idea now is to be able to use these images in the speedata Publisher as well. To do this, you first define a graphic and then use it later in the box command:

    <Layout
        xmlns="urn:speedata.de:2009/publisher/en"
        xmlns:sd="urn:speedata:2009/publisher/functions/en">

        <!-- no beginfig() ... endfig necessary -->
        <DefineGraphic name="dottedbox">
          pickup pencircle scaled 1mm;
          draw (0,0) -- (box.width,0) -- (box.width, box.height) --
            (box.width, box.height) -- (0, box.height ) -- cycle
            dashed withdots withcolor 0.7red ;
        </DefineGraphic>

        <!-- same, but uses predefined path box: -->
        <DefineGraphic name="dottedboxsimple">
            pickup pencircle scaled 1mm;
            draw box dashed withdots withcolor 0.7red ;
        </DefineGraphic>

        <Record element="data">
            <PlaceObject row="1" column="1">
                <Box height="2" width="5" graphic="dottedbox" />
            </PlaceObject>
        </Record>
    </Layout>

The width of the box and the height of the box are defined with the variables `box.width` and `box.height` in MetaPost. This allows you to adjust the graphic to the defaults in the Publisher.

The dotted lines correspond to the specifications of the box. Raster display has been turned on to make this visible.

## Coordinates

The origin of the coordinate system is in the lower left corner of the box, so positive values go in the right and up direction.

## Variables

Variables for MetaPost can be set with `<SetVariable>`.

    <SetVariable
        variable="curcol"
        type="mp:rgbcolor"
        select="'colors_mycolor'"/>

The assignment is evaluated at the beginning of the MetaPost context. Thus `curcol` is available at the beginning of the graphics.

## Predefined values

- All colors defined in the layout can be used in MetaPost with the prefix `colors.`:

      <DefineColor name="mycolor" value="#FF4E00"/>

      <DefineGraphic name="dots">
          pickup pencircle scaled 3mm;
          for i=0 upto 3:
              draw (i * 1cm, i * 1cm) withcolor colors.mycolor ;
          endfor;
      </DefineGraphic>

      <Record element="data">
          <PlaceObject row="1" column="1">
              <Box height="5" width="1" graphic="dots" />
          </PlaceObject>
      </Record>

- CSS level 3 colors are defined in RGB colorspace.
- The width and height of a box can be accessed via `box.width` and `box.height`
- The box' path is saved in the variable `box` (see the example above).
- Hans Hagen’s MetaFun macro package is included (parts of it).
- In page types you can also access these variables:

  Variable | Description
  --- | ---
  `page.width` | Page width
  `page.height` | Page height
  `page.margin.left` | Margin left
  `page.margin.right` | Margin right
  `page.margin.top` | Margin top
  `page.margin.bottom` | Margin bottom
  `page.trim` | Bleed

## MetaPost resources

There are a number of manuals and tutorials for MetaPost:

- The MetaPost manual (mpman) can be obtained from CTAN: http://mirrors.ctan.org/systems/doc/metapost/mpman.pdf
- Learning MetaPost by doing by André Heck: https://staff.fnwi.uva.nl/a.j.p.heck/Courses/mptut.pdf
- MetaPost examples: http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html
- A Beginner’s Guide to MetaPost for Creating High-Quality Graphics http://www.tug.org/pracjourn/2006-4/henderson/henderson.pdf
- Puzzling graphics in MetaPost https://www.pragma-ade.com/articles/art-puzz.pdf
- MetaFun (a macro package that is based on MetaPost - not all commands are supported by the speedata Publisher) https://www.pragma-ade.com/general/manuals/metafun-p.pdf

- Control of the layout when calling the Publisher
- Cookbook