Special objects - Sketch
Description: Sketch

Next: Object transforms, Previous: Drawing a solid, Up: Introduction by example

### 2.4 Special objects

We can add labels to a drawing by using `special` objects, which provide a way to embed raw LaTeX and `PSTricks` code. Adding this to the tetrahedron does the trick.

      special |\footnotesize
               \uput{2pt}[ur]#1{$P1$}
               \uput[r]#2{$P2$}
               \uput[u]#3{$P3$}
               \uput[d]#4{$P4$}|
        (p1)(p2)(p3)(p4)

Here is the result.

There are several details to note here. First, the quoting convention for the raw code is similar to the LaTeX `\verb` command. The first non-white space character following `special` is understood to be the quote character, in this case |. The raw text continues until this character recurs.

Second, the argument references `#1`, `#2`, `#3`, and `#4` refer to point, vector, or scalar values in the list that follow. This is similar to TeX macro syntax. The transformed and two-dimensional projections of these three-dimensional points are substituted in the final output. An argument reference of the form `#1-2` is replaced with the angle in degrees of the two-dimensional vector that connects the projections of the two respective argument points, here `#1` and `#2`. The substituted angle is enclosed in curly braces `{ }`. When `TikZ/PGF` output is being generated, the angle is rounded to the nearest degree because non-integer angles are not allowed by `TikZ/PGF` primitives.

As of Version 0.3 of `sketch`, special arguments may be scalars or vectors in addition to points. References to scalar arguments are merely replaced with a number formatted just as any point coordinate. References to vectors become two-dimensional points. The tick operator that selects individual components of points and vectors elsewhere in `sketch` (see for example Affine arithmetic) can also be applied to point and vector argument references. All three dimensions of a transformed point or vector can also be substitued with `'3`. See Specials for details.

By default, `special` objects are printed last, overlaying all other objects in the scene. If you specify the internal option `lay=in`, the hidden surface algorithm considers the entire special object to be the first point (`#1`) in the argument list. If that point is behind (of smaller z-component than) any drawable, then the entire special object is drawn before that drawable, so the drawable obscures parts of the special object that overlaps it. In our example, `p1` is the front-most point in the scene (has the largest z-component), so adding `lay=in` has no effect.

With option `lay=under`, a special is drawn before, hence appears under any of the objects handled by the hidden surface algorithm. This is how the light gray axes were added to the “hello world” example Hello world.

`Special` objects are powerful, with many possible uses.