Prev Up Top Next Contents
7.2 The "code" command
The
code
command lets you affect the way
therion
processes your
data. It can be used with one of the following arguments
- "metapost" or "mpost", to define code for MetaPost;
- "tex-map", to define code for TeX, generating maps;
- "tex-atlas", to define code for TeX, generating atlases.
The content of the command is passed to the specified processing command.
You may want to read the file "thmpost.cxx" from the therion
sources.
Notice that you can replace only existing symbols. The symbols
types (and subtypes) are defined in the files thpoint,
thline, and tharea. The metapost files contain only the symbol
visualization commands. To define a new symbol one should add both the
metapost command and the therion symbol definition and handling.
fonts
7.2.1 Fonts size
The size of the fonts can be set with a simple MetaPost command,
layout fontsize
code metapost
fontsetup( 6, 8, 10, 12, 16 );
endcode
endlayout
The five specified sizes are referred to as
tiny, small, normal, large, and huge.
The normal size is used for labels ("label" point and line).
The small one for remarks ("remark" point).
The -scale
option overrides the default size.
The actual font sizes used depends on the scale of the output map:
- 1:100 and larger: 8,10,12,16,24
- from 1:200 to 1:100: 7,8,10,12,14
- from 1:500 to 1:200: 6,7,8,10,14
- smaller than 1:500: 5,6,7,8,10
7.2.2 Replacing a symbol
The following piece of code tells
therion
to insert the specified
command in the input to MetaPost. In particular this command replaces the
symbol "p_gradient" with the UIS symbol for the entrance: not very
useful indeed.
code metapost
let p_gradient = p_entrance_UIS;
endcode
7.2.3 Hiding labels
A map prepared for a publication might need to have the lettering removed
so that the image can be scaled to fit the publication page size, and
the lettering overlaid with suitable font and size so to make them
legible.
The lettering in mostly done by the "p_lebel" metapost variable.
It takes four arguments: the text, the position, the rotation, and the
label mode. The mode is a nunmeric code for the type of the label:
- 0: entrance station (maybe ?)
- 1: altitude (drawn near a dot mark)
- 2,3,4: passage height
- 5: date, station name (drawn within a circle)
- 6: debug scrap names (drawn within a box)
- 7: debug station names, pit line, chimney line, height
- altro: label, remark
To hide the relavant writings you can modify the metapost code p_label
inserting a redefinition of "lab" with an empty string:
code metapost
vardef p_label@#(expr txt,pos,rot,mode) =
if (mode=1) or (mode=7): interim labeloffset:=(u/8) fi;
lab:=thelabel@#(txt, pos);
if mode>1: pickup PenD fi;
if mode=1:
pickup pencircle scaled (u/6);
drawdot(pos);
process_label(pos,0);
elseif mode=2: process_uplabel;
elseif mode=3: process_downlabel;
elseif mode=4: process_updownlabel;
elseif mode=5: process_circledlabel;
elseif mode=6: process_boxedlabel;
elseif mode=7: process_label(pos,rot); % station name
elseif mode=8: process_filledlabel(pos, rot);
else:
lab:=thelabel@#("", pos);
process_label(pos,rot); fi;
enddef;
endcode
7.2.4 Lines thickness
You can change the thickness of the lines in the drawing by redefining the
unit (which is called "u" in therion):
code metapost
u:=50pt;
endcode
We saw that
therion
has five pre-defined pens: "PenA" (thick),
"PenB", "PenC", "PenD", and "PenE" (thin).
You can redefine only one of the pens used by
therion
:
code metapost
def PenA =
pencircle scaled (0.001);
enddef;
endcode
You can redefine a symbol. You can start from the metapost code in
therion (files with extension ".mp" in the directory "mpost").
For example [adapted from S. Mudrak 20060621],
def l_floorstep (expr P) =
T:=identity;
pickup PenD; % thin pen
len := arclength P; % arclength of the path
ds := adjust_step(len, 0.25u); % compute step between ticks
for s=0 step ds until len:
t := arctime s of P; % path time coordinate
mark_ ( P, t, 0.2u ); % draw a tick at "point t of P"
endfor;
pickup PenC; % normal pen
thdraw P; % draw P
enddef;
endcode
The commands "thdraw" and "thfill" are Therion extentions of the metapost
commands "draw" and "fill", that apply also the transform T.
The function "mark_()" could be defined as follows:
code metapost
def mark_( expr P, t, s ) =
pair q[];
q1 := point t of P; % point P[t]
q2 := direction t ot P rotated 90; % tangent to P at P[t] rotated 90 deg
thdraw q1 -- q2;
enddef
endcode
7.2.5 Centerline color
The following code replaces the color of the centerline, and uses
a continuous line instead of only the ticks at the stations
[thexample 2]:
code metapost
def l_survey_cave (expr p) =
draw p withpen PenD withcolor (1.0, 0.0, 0.0);
enddef;
endcode
7.2.6 Map comment
Certain symbols are not handled by therionin map comments.
For example the "degree" symbol (which is renderd in TeX as
the math $^{
Therion doesn't allow TeX to interpret macros in map comment,
but you can redefine the map-comment in a
code
section of the
layout. For example (S. Mudrak 2006.20.12):
code tex-map
\comment={\vbox{\halign{#\hfil\cr\thfa Coordinates: $30\,^{\circ}$ \cr
Line 2 of map comment.\cr}}{}}
endcode
Another TeX command is
cavename
. You can specify the name of the cave
on the map with the following code (S. Mudrak 2007.03.13):
code tex-map
\cavename{My cave title}
endcode
Fig. 85. Degrees
7.2.7 Legend size
The size of the legend usually scales with the size of the
map. It becomes very tiny when the map scale is large.
You can set the attributes of the legend by adding a piece of TeX
to your layout, as shown below.
The color is specified in RGB values (each between 0 and 100).
layout mylegend
code tex-map
\legendwidth=10cm
\legendtextcolor={\color[0 0 100]} % RGB values 0--100
\legendtextsize={\size[14]}
\legendtextheadersize={\size[24]}
endcode
endlayout
The north arrow macro is also customizable.
For example the following code produces the arrow for the magnetic
north (the default arrow being the geografic north),
def s_northarrow (expr rot) =
T:=identity scaled 0.4 rotated -rot;
thdraw (.5cm,-1cm)--(-.5cm,-1cm)--(0,1.5cm)--(0,-1.5cm);
thfill (-.5cm,-1cm)--(0,1.5cm)--(0,-1cm)--cycle;
enddef;
Fig. 86. Magnetic north arrow
The north arrow is one of the special symbols
defined in the file mpost/thSpecial.mp:
northarrow
, scalebar
, hgrid
and vgrid
.
7.2.8 Grid size
The layout grid is drawn by default with crosses spaced by the amount
specified on the option command line. You can redefine the way the
grid is drawn by adding a replacement metapost code. For example,
layout my_grid
code metapost
def s_hgrid (expr xpos, ypos, xsize, ysize) =
pickup PenD;
if ( xpos >= -xsize ) and ( ypos >= -ysize ):
draw ( -xsize/2, 0) -- ( xsize/2, 0);
draw ( 0, -ysize/2) -- ( 0, ysize/2);
fi
enddef;
endcode
endlayout
The result is shown in the figure below. On the left is the default
grid layout, on the right that with the MetaPost code above.
Fig. 87. Grid layouts
7.2.9 Scale legend
It is customary to write the scale in the legend of a map and to
draw a scale bar. By default
therion draws only the scalebar.
Here is a Metapost code to have it write the scale as well
[S. Mudrak, 2008.01.29]
layout scale
code metapost
def s_scalebar (expr l, units, txt) =
begingroup
interim warningcheck:=0;
tmpl:=l / Scale * cm * units / 2;
endgroup;
pickup PenC;
draw (-tmpl,0)--(tmpl,0);
draw (-tmpl,0)--(-tmpl,2bp);
draw (tmpl,0)--(tmpl,2bp);
draw (-tmpl,2bp)--(tmpl,2bp);
fill (0,0)--(tmpl,0)--(tmpl,2bp)--(0,2bp)--cycle;
begingroup
# interim labeloffset:=2bp;
label.top(thTEX("Scale"),origin+(-tmpl,-18bp));
label.top(thTEX(decimal (l) & "\thinspace" & txt),origin+(tmpl,5bp));
label.top(thTEX("1\thinspace:\thinspace" & decimal (Scale) & "00"), origin + (-tmpl+30bp,-18bp));
endgroup
enddef;
endcode
endlayout
The variable tmlp
is the half-size of the scale bar that is going to
be drawn. The five commands after pickup PenC;
draw the scale bar.
The following begingroup
draws the label of the bar and the legend
underneat it. The outcome is shown in the figure below.
Fig. 88. Scale bar
7.2.10 Controlling the printout
With the custom attributes you can control the way each symbol
is rendered on the output map.
Suppose you want to display only certain label points.
You add an attribute, say "visibility", to your label points
and specify a value, say "on", for those you want to draw on the map.
Then you include a MetaPost code that override the
p_label
symbol.
You must allow for a default case in which the attribute is not specified,
so that you can avoi adding "-attr visibility off" to all the points
you do not want to draw.
vardef p_label@#(expr txt,pos,rot,mode) =
if known ATTR_visibility:
if ATTR_visibility="on": % ADDED CONDITIONS
if (mode=1) or (mode=7):
interim labeloffset:=(u/8)
fi;
lab:=thelabel@#(txt, pos);
if mode>1: pickup PenD fi;
if mode=1: % altitude
pickup pencircle scaled (u/6);
drawdot(pos);
process_label(pos,0);
elseif mode=2: process_uplabel; % passage height positive
elseif mode=3: process_downlabel; % passage height negative
elseif mode=4: process_updownlabel; % passage height both
elseif mode=5: process_circledlabel; % passage height unsigned
elseif mode=6: process_boxedlabel;
elseif mode=7: process_label(pos,rot); % station name
elseif mode=8: process_filledlabel(pos, rot);
else: % mode=0 date
process_label(pos,rot);
fi;
fi;
fi; % END OF CONDITIONS
enddef;
Several useful pieces of metapost code can be found on the
Therion wiki pages: using colors, new symbol definitions,
North arrows and scale bars, and others.
7.2.11 The examples
therion users - Mon Apr 2 08:35:45 2012
Prev Up Top Next Contents
This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 2.5 License.