Functional METAPOST for L A TEX

Similar documents
EMP: Encapsulated METAPOST for L A TEX

Producing graphs with MetaPost

Introduction to L A TEX

ConTEXt. TPIC Conversion. category: ConTEXt Support Macros. version: date: March 19, author: Hans Hagen

Latex Tutorial. CIS400 Senior Design 9/5/2013

L A TEX: Online module 6

Introduction to L A TEX

A brief introduction to L A TEX

The mpostinl Package

srcltx.sty srctex.sty

L A TEX for psychological researchers

Getting ready for L A TEX. Alexis Dimitriadis. Version: March 28, 2013

mylatexformat Use mylatexformat to make a format based on the preamble of any LaTeX file 2011/02/12 version 3.4

An Introduction to. Rado Ivanov CIS400 Senior Design Tutorial September 18, 2014

troff and friends this talk historical background my troff history history and background theory practical usage

L A TEX Tutorial. 1 Introduction. 2 Running L A TEX. J. E. Rice. May 2010

Package epsdice a scalable dice font

The ohio-etd template for Electronic Theses and Dissertations at Ohio University

Some NT S thoughts. Hans Hagen. The next stage. Some NT S thoughts 1

Intro to LATEX I. Aaron Erlich POLS/CSSS 510, Why LATEX? Programming Document Structure Floats Tables Lists Math

Introduction to Scientific Typesetting Lesson 1: Getting Started

An Introduction to. Andrew G. West, Jian Chang CIS400 Senior Design Tutorial September 15, 2009

L A TEX: Eh? What is it, what isn t it, who cares? Andy Caird. LATEX: Eh? p.1/13

Math 235: Introduction to LaTeX

Detailed Contents for TEX Unbound: Strategies for Font, Graphics, and More

Including Graphics in L A TEX Files

LaTeX. Information Literacy II EN(IL2) Course

DANTE So, it was just five characters for which the META- FONT source had to be made suitable to be processed. TUGboat, Volume 28 (2007), No.

Will Robertson. Abstract

L A T E X Week 11, Other Document Classes

How to use abdnthesis.cls

makempy Including text as graphics is far from trivial. First it has to be typeset, and of course we want to use

Introduction to Latex. A workshop by Dr. Ala Eshmawi

Square cells: an array cooking lesson

EXP FOR WINDOWS, VERSION 5.1

Part of the adjustbox bundle. Martin Scharrer Version v /04/08. Abstract

Absolute L A TEX Beginner

Lab1: Communicating science

Trivial Experiments with pstricks manipulation

Thesis in a Box. Mark Andrew Paskin. B.A. Hon. (Cornell University) 1998 M.S. (University of California, Berkeley) 2000

Compressed Images in PostScript and PDF with L A TEX HOWTO

Trivial Experiments with pstricks manipulation

FOR NUMERICAL POSTPROCESSING AND RESULT VISUALIZATION USING PGFPLOTS AND PGFPLOTSTABLE. Christian Feuersänger

Learning L A TEX. Patrick Lam

VERY VERY SHORT GUIDE TO LATEX

What is T E X? T E X and L A T E X Document preparation tools. Setting and casting type. What Knuth was setting. Setting and casting type

Introduction to L A TEX

Introduction to L A TEX for MCS-236

The Honours Dissertation Class for L A TEX2e. Cara MacNish

M. R. C. van Dongen. ucc. LaTEX and Friends. Commands and Environments. Marc van Dongen

The AES Convention Paper LATEX class Adam H. Lewenberg (October 18, 2008) 1

Help with PDF Files Is there a way someone else can do this for me? What Software Do I Need to Create PDF Files?

Began as TeX, in 1982 (Knuth). Purely a typesetting tool. LaTeX added macros, maintaining TeX as it s typesetting engine (Lamport).

Functions and text files

Wide range METAPOST tutorial

Helen Cameron. A Brief Overview of LATEX

During my health situation, I spent

The auto-pst-pdf package

Installing a Custom AutoCAD Toolbar (CUI interface)

The vc bundle. June 11, 2018

Hello, world! 206 TUGboat, Volume 31 (2010), No. 2. resulting in: Drawing structured diagrams with SDDL Mathieu Bourgeois and Roger Villemaire

Getting to Grips with L A T E X. Andrew Roberts

LaTeX Workshop. While you re waiting, please make an account at

nomencl A Package to Create a Nomenclature

SLDNF-Draw user s manual Chapter 1: static trees

A Short L A TEX Introduction

In another markup scheme it will be like as given hereunder:

Functions and text files

Typesetting lettrines in L A TEX 2ε documents Daniel Flipo

Com S 541. Programming Languages I

L A TEX. COMPSCI 111 / 111G Mastering Cyberspace: An introduction to practical computing. LaTeX. Development. Why?

1. Welcome. (1) Hello. My name is Dr. Christopher Raridan (Dr. R). (3) In this tutorial I will introduce you to the amsart documentclass.

Pimp your thesis: a minimal introduction to L A T E X.

Getting Started with L A T E X for a Technical Document or Thesis

Math 291: Lecture 2. Justin A James. Minnesota State University Moorhead web.mnstate.edu/jamesju/

The basics of LaTeX. Cédric Buron. April 25, 2016

Effective Programming Practices for Economists

An Introduction to LATEX

COMP496/901: Academic Presentation and Writing Skills Using LaTeX

TeXnicCenter v1 Beta Frank Van Puyvlde ICT for Research K.U.Leuven

Introduction to Computer Science E15 Lab Week 37

My favorite LaTex distribution is TexLive. You can download TexLive free TUG, the Tex Users Group, at

L A TEX minicourse. dstowell, mag, sar, scannell,... September Typeset by FoilTEX

unitn-bimrep Installation Instructions

APPM 2460 PLOTTING IN MATLAB

altfont: Using alternative fonts

qstest, a L A TEX package for unit tests

An Introduction to L A T E X

Instructions for the Use of a General L A TEX Template for LSU Theses and Dissertations

Helen Cameron. A Brief Overview of LATEX

Excellent support for mathematical formatting. Automatically downloads/installs missing components as needed Updates somewhat frequently

A LAT E X Tutorial. Evangelos Milios. March 15, 2004

The listofsymbols.sty package (v0.2)

v2.1, dated 2014/03/04.

Export of PSTricks environments

INSTALLING AND USING L A TEX

ECE112 - Lab 6. Purpose. Parts/tools needed: Make sure we have a properly working environment

inside TEX Documents Vít Novotný

An anecdote about ML type inference

Become a L A TEX Guru

Transcription:

Functional METAPOST for L A TEX Marco Kuhlmann 2001/11/19 Abstract Functional METAPOST (fmp) is a powerful frontend to the METAPOST language. This package adds basic fmp support to L A TEX, enabling users to keep fmp source code within their documents and, by a two-run mechanism, including automatically generated fmp figures. 1 Introduction Functional METAPOST by Joachim Korittky ([Kor98]) adds a high-level interface to the METAPOST language ([Hob89], [Hob92]), enabling the user to program their graphics using the Haskell language. Impressive examples of Functional META- POST can be found in Korittky s diploma thesis; some of them will be given below. The system and the documentation can be downloaded from http://www.informatik.uni-bonn.de/~ralf/software.html Using Functional METAPOST as my standard graphics developing tool, I felt a need to write a L A TEX package which smoothly integrates fmp into daily work, similar to the emp package by Thorsten Ohl ([Ohl97]); this is how fmp came to being. The earliest version supported only the possibility to automatically produce shell-scripts for graphics generation. Since then, I have added the possibility to encapsulate fmp code though I still ask myself if this way of maintaining code is as natural for fmp as it is for pure METAPOST in emp. In case you have any questions or comments on this package, feel free to send me an email. May fmp help fmp to spread around the world. :-) 1.1 Examples of Functional METAPOST Before I start to present the fmp package, let me first give you two mouth-watering examples of fmp (the Haskell code for them can be found at the end of this document): figure 1 gives a binominal tree of rank 5, figure 2 shows a simple Venn diagram. Among other things, these examples exhibit two features in which fmp is superior to many other graphics drawing packages around: This file has version number v1.1a. E-Mail: marco.kuhlmann@gmx.net 1

Figure 1: A binominal tree of rank 5 By embedding METAPOST into the Haskell programming language, fmp gives the user (and especially users who have previous experience in functional programming) a great tool to program graphics on a very high-level level of abstraction. This not only helps you to focus on the logical structure rather than on layout questions, but also is especially important if you want to scale and re-use old material. fmp can be easily extended. For example, for figure 1, the core language has been augmented by tree drawing features, using much better algorithms than those of any other tree drawing package around. This is especially good news for computer scientists, who need trees very often, but did not yet have a package to draw them on such a level of abstraction. To be able to use fmp, you need a Haskell interpreter, such as hugs, and the METAPOST program, which should be part of any somewhat complete distribution of L A TEX. Having produced a Haskell source, you feed it into hugs and issue the generate command provided by fmp. This will translate your code into low-level METAPOST commands, and finally produce a ready-to use PostScript file. 1.2 How this package works Calling hugs and typing in the generation commands is a tedious job if you keep more than but a few illustrations around. This package offers the \fmpfigure B U A Figure 2: A Venn diagram (cf. figure 22 in [Hob92]) 2

command, which generates a shell script (at present, this only works for n x), which you then can execute to have all the graphics files generated at once. At the next run of L A TEX, these graphic files will appear at their proper positions. Besides, fmp enables you to store Haskell code within a L A TEX file, in case you want to have all the code for one document at one place. 2 Usage \fmpfigure fmp \fmpsourcefilename \fmpscriptfilename \fmpfigurebasename 2.1 Including graphics Using fmp to include graphics from some fmp source is straightforward. Let us assume that you keep two fmp figures (Haskell values) example1 and example2 in a file called fmp-doc.hs. A minimal document using the package to include these two figures would then look like this: \documentclass{article} \usepackage{fmp} \fmpsourcefilename{fmp-doc} \begin{document} \fmpfigure{example1} \fmpfigure{example2} \end{document} \end{verbatim} You include a figure into your L A TEX document by using the \fmpfigure macro. It takes, as its mandatory argument, the string identifying the figure in the Haskell source, and creates a shell script containing all the hugs calls needed for the actual generation. After the shell script has been written, you can execute it and run L A TEX again; if everything went right, the graphics file will appear at the place where you issued the \fmpfigure command. Any optional arguments to \fmpfigure will be passed to the graphicx package and interpreted as if they appeared together with a \includegraphics command. This allows you to change the visual appearance of the included figure (e. g., the size to which the figure shall be scaled). Refer to [Car99] for more information about possible paramters. 2.2 Including code You can also store your fmp code in the same file than your L A TEX source, included within the fmp environment. During compilation, the contents of this environment are written to an external file (see below). 2.3 Changing file names You can control the names of three different files: the Haskell source (\fmpsourcefilename, defaults to jobname.hs), 3

the shell script (\fmpscriptfilename, defaults to fmpgenerate.sh) and the graphics file base name (\fmpfigurebasename, defaults to fmpfigure), which is the base file name of the graphics files that will be generated by hugs. (An index number specifying their order in the document will be appended to this name.) You can modify all three file names by calling the respective macros, each of which takes the new name as its argument. \fmpsourcepreamble \fmpaddtosourcepreamble \fmpscriptpreamble \fmpaddtoscriptpreamble \fmpsourcepostamble \fmpaddtosourcepostamble \fmpscriptpostamble \fmpaddtoscriptpostamble 2.4 Preamble and postamble Before something is written to the source file or the shell script file, the package will output a preamble to that file. The source code preamble could contain everything from comments to Haskell module identifications and basic imports, while the shell script preamble should probably contain the line that calls hugs and tells it to input the rest of the file as comment. Have a sample run to see the default contents of the preamble. If you wish to change the text: you can set a new preamble by the \fmpsourcepreamble command, and you can append a new line to the current preamble calling \fmpaddtosourcepreamble. (Similar commands are available for the shell script preamble.) There is also a postamble, which is written as the very last thing to the source code or shell script. METAPOST uses the environment variable $TEX to determine which TEX it has to call when generating labels etc. On many systems, this variable defaults to tex, which is certainly not what you want in conjunction with fmp. One common usage for the preamble therefore is to include a line like export TEX=latex (or something similar, depending on your shell) into the generation script. 2.5 Graphics file formats The graphicx package is used to handle the inclusion of generated fmp figures. If fmp is called from within pdflatex, graphicx is loaded with the pdftex driver option. In this case, the fall-back behaviour when encountering an \fmpfigure command is to read the corresponding graphics file as mps (METAPOST output); it will then internally be converted to pdf by graphicx. When called from within normal latex, graphics files are handled as eps (encapsulated PostScript). You probably need to load a specific PostScript driver for graphicx in this case do so by supplying fmp with the same package option that you would use for graphicx (see the graphicx user manual for further information on that). Acknowledgements The help of Ralf Hinze and the suggestions of Peter Bartke and Ferenc Wagner are gratefully acknowledged. 4

Source code for the examples This is file fmp-doc.hs, generated with the docstrip utility. The original source files were: fmp.dtx (with options: examples ) Example source code for the FMP package module FMPDoc where import FMP import FMPTree example1 = binom 5 where ce = circle empty binom 0 = node ce [] binom n = node ce [edge (binom i) i <- [(n-1),(n-2)..0]] #setalign AlignRight example2 = box (math "U" ooalign [topicture [carea a 0.7, carea b 0.7, carea ab 0.4], bovera]) where carea a c bovera = toarea a #setcolor c = column [math "B" #setbgcolor white, vspace 50, math "A" #setbgcolor white] a = transformpath (scaled 30) fullcircle b = transformpath (scaled 30 & shifted (0,-30)) fullcircle ab = buildcycle a b References [Hob89] [Hob92] John D. Hobby: A METAFONT-like System with PostScript Output. TUGboat vol. 10, no. 2, pp. 505 512, 1989 John D. Hobby: A User s manual for METAPOST. Computing Science Technical Report no. 162, AT&T Bell Laboratories, Murray Hill, New Jersey, 1992 5

[Kor98] [Ohl97] [Car99] Joachim Korittky: functional METAPOST. Eine Beschreibungssprache für Grafiken. Diplomarbeit an der Rheinischen Friedrich-Wilhelms- Universität Bonn, 1998 Thorsten Ohl: EMP: Encapsulated METAPOST for L A TEX. Technische Hochschule Darmstadt, 1998 David Carlisle: Packages in the graphics bundle. User documentation, 1999 Change History v1.0a General: Initial release......... 1 v1.0b General: Documentation: Improvements as suggested by Peter Bartke................... 2 v1.1a General: Added to bibliography: Reference to graphicx package user documentation......... 5 Documentation: Optional arguments to \fmpfigure are now passed to the graphicx package..................... 3 6