| 1 |
.\" grdemo-doc.ms |
| 2 |
.\" |
| 3 |
. |
| 4 |
.nr PS 11 |
| 5 |
.nr VS 13 |
| 6 |
. |
| 7 |
.TL |
| 8 |
MetaPost with groff |
| 9 |
. |
| 10 |
.LP |
| 11 |
John Hobby's MetaPost program had an \f[I]AT&T troff\/\f[P]interface which |
| 12 |
have been changed to use \f[I]GNU troff\/\f[P] instead. |
| 13 |
. |
| 14 |
. |
| 15 |
.SH |
| 16 |
Usage |
| 17 |
. |
| 18 |
.LP |
| 19 |
Since MetaPost is a picture-drawing language that outputs PostScript, it is |
| 20 |
necessary to use the \f[CW]\%-mpspic\f[P] macro package, which is |
| 21 |
automatically included when \f[I]groff\/\f[P](1) is invoked with the |
| 22 |
\f[CW]\%-Tps\f[P] option to prepare output for PostScript printers or |
| 23 |
previewers. |
| 24 |
. |
| 25 |
.PP |
| 26 |
Suppose you have written some figures in MetaPost and placed the input in a |
| 27 |
file \f[CW]\%figures.mp\f[P]. |
| 28 |
Running |
| 29 |
. |
| 30 |
.DS I |
| 31 |
.ft CW |
| 32 |
mp -T figures |
| 33 |
.ft |
| 34 |
.DE |
| 35 |
. |
| 36 |
to invoke the MetaPost interpreter produces output files |
| 37 |
\f[CW]\%figures.1\f[P], \f[CW]\%figures.2\f[P], \&.\|.\|. |
| 38 |
. |
| 39 |
.PP |
| 40 |
Standalone EPS pictures can be produced from such files by |
| 41 |
\f[CW]\%fixgrofffonts\f[P], that fixes comments according to |
| 42 |
Adobe Document Structuring Conventions (DSC), embeds |
| 43 |
font reencoding commands and non-standard fonts. |
| 44 |
. |
| 45 |
.DS I |
| 46 |
.nf |
| 47 |
.ft CW |
| 48 |
fixgrofffonts < figures.1 > figures1.eps |
| 49 |
fixgrofffonts < figures.2 > figures2.eps |
| 50 |
\&... |
| 51 |
.ft |
| 52 |
.fi |
| 53 |
.DE |
| 54 |
. |
| 55 |
.PP |
| 56 |
Before these figures can be included into \f[I]groff\/\f[P], they have to |
| 57 |
be processed with the \f[CW]\%fixmp\f[P] script: |
| 58 |
It adds an encoding vector for all text fonts back to the file (which |
| 59 |
MetaPost can't add itself) and changes the Adobe Document Structuring |
| 60 |
Conventions (DSC) comments to something \f[I]groff\/\f[P] can handle. |
| 61 |
. |
| 62 |
.DS I |
| 63 |
.nf |
| 64 |
.ft CW |
| 65 |
fixmp < figures.1 > figures.1ps |
| 66 |
fixmp < figures.2 > figures.2ps |
| 67 |
\&... |
| 68 |
.ft |
| 69 |
.fi |
| 70 |
.DE |
| 71 |
. |
| 72 |
Now the converted files can be included in a \f[I]groff\/\f[P] document via |
| 73 |
macro calls such as |
| 74 |
. |
| 75 |
.DS I |
| 76 |
.ft CW |
| 77 |
\&.PSPIC figures.1ps [width [height]] |
| 78 |
.ft |
| 79 |
.DE |
| 80 |
. |
| 81 |
as explained in the \f[I]grops\/\f[P](1) documentation. |
| 82 |
Note that the picture gets rescaled if the height and width in the |
| 83 |
\f[CW]\%.PSPIC\f[P] command don't match \f[I]mp\/\f[P]'s idea of the |
| 84 |
picture dimensions. |
| 85 |
. |
| 86 |
. |
| 87 |
.SH |
| 88 |
An example |
| 89 |
. |
| 90 |
.PSPIC grdemo.1ps |
| 91 |
. |
| 92 |
.LP |
| 93 |
This figure was derived from a file \f[CW]\%grdemo.mp\f[P] and included at |
| 94 |
this point by invoking the \f[CW]\%.PSPIC\f[P] macro (omitting the height |
| 95 |
and width parameters to avoid rescaling). |
| 96 |
. |
| 97 |
.PP |
| 98 |
The file \f[CW]\%grdemo.mp\f[P] looks like this: |
| 99 |
. |
| 100 |
.DS I |
| 101 |
.nf |
| 102 |
.ft CW |
| 103 |
.ps 9 |
| 104 |
.vs 11 |
| 105 |
verbatimtex |
| 106 |
\&.EQ |
| 107 |
delim $$ |
| 108 |
\&.EN |
| 109 |
\e# etex |
| 110 |
|
| 111 |
input boxes |
| 112 |
|
| 113 |
beginfig(1); |
| 114 |
pair shadowshift; |
| 115 |
shadowshift = (1, -1) * bp; |
| 116 |
|
| 117 |
def drawshadowed(text t) = |
| 118 |
forsuffixes $=t: |
| 119 |
fill bpath$ shifted shadowshift; |
| 120 |
unfill bpath$; |
| 121 |
drawboxed($); |
| 122 |
endfor |
| 123 |
enddef; |
| 124 |
|
| 125 |
boxit.a(btex \e[12] \es8A\es+2 \e[lh] a etex); |
| 126 |
circleit.b(btex $e sup {i omega t}$ etex rotated 20); |
| 127 |
|
| 128 |
b.w - a.e = (10bp, 0); |
| 129 |
|
| 130 |
drawshadowed(a, b); |
| 131 |
draw a.e .. b.w; |
| 132 |
|
| 133 |
label.top(btex \e[Cs] \e[Po] \e[Eu] etex, a.n); |
| 134 |
label.llft(btex \e[Fn] etex, a.s); |
| 135 |
|
| 136 |
draw bbox currentpicture dashed evenly; |
| 137 |
endfig; |
| 138 |
|
| 139 |
end |
| 140 |
.ps 11 |
| 141 |
.vs 13 |
| 142 |
.ft |
| 143 |
.fi |
| 144 |
.DE |
| 145 |
. |
| 146 |
. |
| 147 |
.SH |
| 148 |
Changing GNU troff pipeline |
| 149 |
.PP |
| 150 |
Note that, by default, the typesetting commands in the \f[CW]\%btex\f[P] |
| 151 |
\&.\|.\|.\& \f[CW]\%etex\f[P] blocks in the above example |
| 152 |
are processed by |
| 153 |
. |
| 154 |
.DS I |
| 155 |
.ft CW |
| 156 |
eqn -Tps -d\e$\e$ | troff -Tps |
| 157 |
.ft |
| 158 |
.DE |
| 159 |
. |
| 160 |
If a different \f[I]troff\/\f[P] pipeline must be used it can be |
| 161 |
specified via the \f[CW]\%TROFF\f[P] environment variable. |
| 162 |
For \f[I]groff\f[P], the following is recommended: |
| 163 |
. |
| 164 |
.DS I |
| 165 |
.ft CW |
| 166 |
TROFF='groff -teZ' |
| 167 |
.ft |
| 168 |
.DE |
| 169 |
. |
| 170 |
It adds \f[I]tbl\/\f[P] to the pipeline in addition to \f[I]eqn\f[P], |
| 171 |
producing output for \f[I]groff\/\f[P]'s default `ps' device. Note that |
| 172 |
you then have to specify the left and right delimiters of \f[I]eqn\/\f[P]'s |
| 173 |
in-line equations within the document (which is good practice anyway). |
| 174 |
. |
| 175 |
.PP |
| 176 |
Macro definitions and such can be added via the standard |
| 177 |
\f[CW]\%verbatimtex\f[P] \&.\|.\|.\& \f[CW]\%etex\f[P] mechanism that adds |
| 178 |
the given material to the \f[I]troff\/\f[P] input. |
| 179 |
Such material should not generate any output since this would get mixed up |
| 180 |
with the next \f[CW]\%btex\f[P] .\|.\|.\& \f[CW]\%etex\f[P] block. |
| 181 |
Note the comment escape right before the first \f[CW]\%etex\f[P] command in |
| 182 |
the above example to avoid an empty line. |
| 183 |
. |
| 184 |
.\" eof |