Text blocks/Transformations/Scaling rotating mirroring clipping text

Unofficial ConTeXt Wiki mirror

Last modified: 2025-01-10

You can use the commands for text, but also for graphics or other “building blocks”.

Scaling

The \scale command is all-purpose, you can scale by factors or to a defined size.

As a special case, you can insert symbols at a reduced size in the text flow using \getscaledglyph.

Mirroring

\mirror makes a \hbox and mirrors the contents. If you want to have a longer paragraph mirrored, you have to make a \vbox manually.

Rotating

You can \rotate something by an arbitrary angle like

The rotation angle and the location (which determines around which point the content is rotated) are optional and can also be set by

You can rotate a long paragraph as well.

Location parameter

The influence of location= at different angles:

Rotating Figures

The following code shows how the location parameter influences rotation with a frame:

\setupbodyfont[sans, 30pt]
\setuppagenumbering[location=,]
\showframe

\starttext
     \topskip4cm
        \dostepwiserecurse{0}{360}{10}{
\doloopoverlist{normal,default,depth,fit,broad,high,middle}{
\ruledhbox{\rotate[rotation=\recurselevel, location=\recursestring]{%
\framed
   [width=\textheight, height=\textwidth, rulethickness=5pt,
    depth=0cm, foregroundstyle=\bfd]
  {\recursestring, \recurselevel°}
            }
        }
    }
}
\stoptext

or, even nicer:

In a box

Depending on the usage you will sometimes probably want to include the content of what you wish to rotate into a box. Compare the following two examples:

Page dependent landscape figures

Sometimes, in a double-sided portrait document, you may wish to rotate a landscape figure so that the top is towards the spine of the book – no matter whether it’s on an odd or even page. In this case the \doifoddpageelse command can help:

\rotate[rotation=\doifoddpageelse{90}{270}]{\externalfigure[cow]}

This example is by Wolfgang, from the thread starting here. The thread contains other solutions to the problem.

Clipping

You can adjust the size of an element by cropping/clipping its borders:[1]

And here’s how to cut out a piece by measures (see also \setupclipping and \clip):

Further reading

Graphic transformations are implemented in grph-trf.mkiv and grph-trf.lua.

Footnotes

  1. Please, don’t forget that clipping only displays a part of an image. At least when this comes from a PDF document, the whole page has to be included, although only part of it is displayed.
    The PDF output from the following sample contains hans hagen, pragma ade . Depending on your PDF viewer, you may be able to search for it.
    Of course, you will have to compile the source yourself, since the wiki will only contains PNG images from compilations.
    • \setuppapersize[A5, landscape]
      \setuplayout[page]
      \starttext
      \clip[nx=3,ny=3,x=1,y=1]{\externalfigure[xml-mkiv.pdf]}
      \stoptext