The Calligraphy Package: Documentation: 1 How It Works
The Calligraphy Package: Documentation: 1 How It Works
Andrew Stacey
[email protected]
\ begin { center }
\ begin { t i k z p i c t u r e }
\ pen ( − 1 3 5 : . 2 5 ) −− ( 4 5 : . 2 5 ) ;
\draw [ l i n e width =.5cm ] ( 0 , 0 ) . . c o n t r o l s + ( 4 5 : 1 ) and
+( −135:1) . . ++(3 ,0) ;
\ c a l l i g r a p h y (0 , −1) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1) . .
++(3 ,0) ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
The paths are identical in definition but the first is drawn using the standard
TikZ path with a line width of .5cm. The second is “stroked” with a calligraphic
pen of width .5cm angled at 45 degrees.
1 How It Works
To know how to use this library, it is worth knowing a little about how it works.
A “pen” is a path, as is the line that is the template for the pen stroke. The two
paths are joined together to form a region which is filled. Thus in constructing
the example given in the introduction, the following path is built.
1
original path reversed
original path
What is important to note about this is that the “pen” isn’t actually dragged
along the path, it is merely a simulation. This can be shown with the following
simple example. The first is a continuous path that goes past the angle of the
pen and thus the upstroke would involve pushing the pen. The second is how it is
meant to be done, the second line is drawn from top to bottom. However, as the
direction of the path isn’t important, the same effect can be obtained by “lifting
the nib” between the lines.
\ begin { center }
\ begin { t i k z p i c t u r e }
\ pen ( − 1 3 5 : . 1 2 5 ) −− ( 4 5 : . 1 2 5 ) ;
\ c a l l i g r a p h y ( 0 , 0 ) −− ( 1 , 0 ) −− ( 1 , 1 ) ;
\ c a l l i g r a p h y ( 2 , 0 ) −− ( 3 , 0 ) ( 3 , 1 ) −− ( 3 , 0 ) ;
\ c a l l i g r a p h y ( 4 , 0 ) −− ( 5 , 0 ) +(0 ,0) −− ( 5 , 1 ) ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
It should work as expected providing the following golden rule is not violated:
2
\ begin { center }
\ begin { t i k z p i c t u r e }
\ pen ( − 1 3 5 : . 2 5 ) −− ( − 1 3 5 : . 1 2 5 ) ( 4 5 : . 1 2 5 ) −− ( 4 5 : . 2 5 ) ;
\ c a l l i g r a p h y ( 0 , 0 ) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1) . .
+(3 ,0) ++(1.5 ,0) . . c o n t r o l s +( −135:2) and + ( 4 5 : 2 )
. . +(0 , −4) (0 , −4) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1)
. . +(3 ,0) ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
2 Copperplate
Copperplate pens are somewhat special. They are “thin” so don’t need the same
treatment as a “thick” pen, but one should be able to vary the pressure with a
copperplate pen to get a variation of thickness. Specifying a copperplate pen is
straightforward: it is a pen with no thickness.
\ begin { center }
\ b e g i n { t i k z p i c t u r e } [ l i n e width=2pt ]
\ pen ( 0 , 0 ) ;
\ c a l l i g r a p h y [ heavy ] ( 0 , 0 ) . . c o n t r o l s + ( 4 5 : 1 ) and
+( −135:1) . . +(3 ,0) ++(1.5 ,0) . . c o n t r o l s +( −135:2)
and + ( 4 5 : 2 ) . . +(0 , −3) (0 , −3) . . c o n t r o l s + ( 4 5 : 1 )
and +( −135:1) . . +(3 ,0) ;
\ c a l l i g r a p h y [ l i g h t ] ( 4 , 0 ) . . c o n t r o l s + ( 4 5 : 1 ) and
+( −135:1) . . +(3 ,0) ++(1.5 ,0) . . c o n t r o l s +( −135:2)
and + ( 4 5 : 2 ) . . +(0 , −3) (4 , −3) . . c o n t r o l s + ( 4 5 : 1 )
and +( −135:1) . . +(3 ,0) ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
3
With a copperplate pen, the segments of a path are tapered. Copperplate and
normal pens can be mixed. Any part of the pen specification that has no length
is treated as a copperplate pen.
\ begin { center }
\ b e g i n { t i k z p i c t u r e } [ l i n e width=1pt ]
\ pen ( − 1 3 5 : . 1 2 5 ) −− ( 0 , 0 ) ( 4 5 : . 1 2 5 ) ;
\ c a l l i g r a p h y ( 0 , 0 ) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1) . .
+(3 ,0) ++(1.5 ,0) . . c o n t r o l s +( −135:2) and + ( 4 5 : 2 )
. . +(0 , −3) (0 , −3) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1)
. . +(3 ,0) ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
3 Style Options
There are plenty of options for styling the paths and pens.
4
in a global macro and so can be accessed in throughout the document. However,
before being used, the pen has to be processed. At this stage, the pen is converted
from a macro in to a special object. These special objects are local and cannot
(at present) be made global. Thus whilst a pen can be defined inside a group, the
processing stage has to happen in the outermost group in which the pen is going to
be used. There is a shortcut command that (via a bit of suspicious hackery) does
all this within a tikzpicture group. However, if a pen is to be used in several
different pictures, it must be processed outside the group in which it is defined.
The following macros and keys are used to set up and use a pen.
define pen • If the define pen key is specified on a path then that path will be used
to define a pen. It can take one option which will be the pen name, if not
specified then default is assumed. The resulting path will not be counted
for bounding box considerations. When the pen is used, the origin will
correspond to the path along which it is dragged.
pen name • The key pen name=name sets the name for the current pen. This can be used
either when defining or using a pen.
\pen • The macros \pen and \definepen are analogous to the TikZ commands
\definepen \draw or \fill in that they act like a path command but store the path as
a pen. The difference between them is that \definepen is to be used outside
a TikZ picture (it contains its own \tikz command) and \pen inside.
use pen • The key use pen=name on a path means that that path should be “stroked”
with the pen (default if no name is given, or none specified via the pen name
key).
5
template path at the relevant part. The style is saved and applied to that
segment of the template path.
taper • The tapering of copperplate paths can be controled by the taper option. It
takes arguments none, both, start, and end.
weight • Copperplate paths come in two “weights”: heavy and light. The weight also
heavy affects the tapering: by default a light path is tapered to nothing whilst
light a heavy path is tapered to the width of a light path. Weights can be
specified by either weight=weight or just heavy and light. It is pos-
sible to change the weight for different components of a path using the
stroke style key. With tapering, this means that one can easily vary from
a light stroke to a heavy one. The relevant widths are controlled by the keys
heavy line width heavy line width and the light line width. The taper line width,
light line width is set automatically by the weight but can be altered afterwards using the
taper line width taper line width key.
\ begin { center }
\ begin { t i k z p i c t u r e }
\ c a l l i g r a p h y [ pen c o l o u r=green , n i b s t y l e ={2}{ c o l o r=r e d } ]
( 0 , 0 ) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1) . . +(3 ,0)
++(1.5 ,0) . . c o n t r o l s +( −135:2) and + ( 4 5 : 2 ) . .
+(0 , −3) (0 , −3) . . c o n t r o l s + ( 4 5 : 1 ) and +( −135:1) . .
+(3 ,0) ;
\ c a l l i g r a p h y [ l i n e width=1pt ] (0 , −4) . . c o n t r o l s + ( 4 5 : 1 )
and +( −135:1) . . +(3 ,0) ++(1.5 ,0) . . c o n t r o l s
+( −135:2) and + ( 4 5 : 2 ) . . +(0 , −3) (0 , −7) . . c o n t r o l s
+ ( 4 5 : 1 ) and +( −135:1) . . +(3 ,0) ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
6
4 Decorations
If a TikZ/PGF decorations library is loaded prior to this library, then the
calligraphy library defines some decorations that use the calligraphic paths,
specifically with the copperplate nib. The current decorations are:
calligraphic brace • calligraphic brace for a brace.
calligraphic straight • calligraphic straight parenthesis for a parenthesis with straight mid-
parenthesis dle component.
calligraphic curved • calligraphic curved parenthesis for a parenthesis with a curved middle
parenthesis component.
All the above use the amplitude option to specify their size. The following is an
example of their use, together with the standard brace and the delimiter key
from the matrix library for comparison.
7
\ begin { center }
\ begin { t i k z p i c t u r e }
\draw [ d e c o r a t e , d e c o r a t i o n ={ c a l l i g r a p h i c
brace , a m p l i t u d e=4mm} , u l t r a t h i c k ] ( 0 , 0 ) −− ( 0 , 8 ) ;
\draw [ l i n e
width=2pt , d e c o r a t e , d e c o r a t i o n ={brace , a m p l i t u d e =10} , l i n e
cap=round ] ( 1 , 0 ) −− ++(0 ,8) ;
\ node [ anchor=s o u t h west , minimum h e i g h t =8cm , o u t e r
s e p=0pt , l e f t d e l i m i t e r =\{] ( a ) a t ( 2 , 0 ) { } ;
\draw [ d e c o r a t e , d e c o r a t i o n ={ c a l l i g r a p h i c s t r a i g h t
p a r e n t h e s i s , a m p l i t u d e=4mm} , u l t r a t h i c k ] ( 3 , 0 ) −−
++(0 ,8) ;
\draw [ d e c o r a t e , d e c o r a t i o n ={ c a l l i g r a p h i c curved
p a r e n t h e s i s , a m p l i t u d e=4mm} , u l t r a t h i c k ] ( 4 , 0 ) −−
++(0 ,8) ;
\ node [ anchor=s o u t h west , minimum h e i g h t =8cm , o u t e r
s e p=0pt , l e f t d e l i m i t e r =(] ( a ) a t ( 5 , 0 ) { } ;
\end{ t i k z p i c t u r e }
\end{ c e n t e r }
5 Pre-Defined Pens
The following pens are predefined:
copperplate • copperplate:
8
\ begin { center }
\ tikz \ calligraphy [ copperplate ] (0 ,0) . . controls
+(1 , −1) and +( −1 ,1) . . ++(3 ,0) [ t h i s s t r o k e
s t y l e ={ l i g h t , t a p e r=s t a r t } ] +(0 ,0) . . c o n t r o l s
+(1 , −1) and +( −1 ,1) . . ++(3 ,0) [ t h i s s t r o k e
s t y l e ={heavy } ] +(0 ,0) . . c o n t r o l s +(1 , −1) and
+( −1 ,1) . . ++(3 ,0) [ t h i s s t r o k e
s t y l e ={ l i g h t , t a p e r=end } ] ;
\end{ c e n t e r }