This set of notes (taken from an e-mail) covers Thanh's approach as implemented in a prototype
version of pdfTeX.
-------------------------------------------------------------------------
- snapping: support for grid typesetting. New primitives:
- \pdfsnaprefpoint: insert a whatsit node representing a reference point
- \pdfsnapy: insert a whatsit node that cause the position of the ``drawing pen'' to be
moved onto a grid. This happens only during shipping phase.
Example: after a display math it is difficult to get the next line to be on the grid. With snapping
it might look like following:
,--------
| <text before displayed math>
| $$ <some math> $$
| \vadjust pre{\pdfsnapy \snapunit plus .8\snapunit minus .2\snapunit}
| <text after displayed math>
`--------
\snapunit is a dimen, typically it would be \baselineskip. To make it work, there is one thing
more: \pdfsnaprefpoint must be inserted into each page, typically in header. Let's call the y-
position of this whatsit node Y1. The above example says roughly this: when pdftex reachs
the \pdfsnapy node, it can move the drawing pen up and down in range (-
.2\snapunit,.8\snapunit) to snap to a point with y-position Y2 so that (Y2- Y1) is a multiple
of \snapunit. The \pdfsnapy node must be inserted before the text line following the
displayed math, so we use \vadjust pre{...} to insert it (\vajdust with "pre" is an extension of
pdftex).
- \pdfsnapycomp: insert a whatsit node for snapping compensation
The problem with the previous example is that sometimes the space after math is changed
too much, while the space before math remains unchanged. Hence the result may look
ugly, because the spaces around the math are not proportional. So it is better that the
movement after math is somehow compensated into the space before math too.
\pdfsnapycomp is for this purpose. The previous example with \pdfsnapycomp will look like:
,--------
| <text before displayed math>
| \vadjust{\pdfsnapycomp 500}
| $$ <some math> $$
| \vadjust pre{\pdfsnapy \snapunit plus .8\snapunit minus .2\snapunit}
| <text after displayed math>
`--------
So the skip at \pdfsnapy will be distributed to 50% at \pdfcompsnap and 50% at \pdfsnapy.
\pdfsnapy and \pdfsnapycomp are whatsit nodes, with an exception that they are
discardable after a break.
When a page break occurs between \pdfcompsnap and \pdfsnapy, then \pdfcompsnap has
no effect, e.g., the extra space is inserted at \pdfsnapy only.
-----------------------------------------------------------------
Below is the summary of what I have done in 0.14h:
Node types:
- pdf_snap_ref_point_node: a whatsit node representing a reference point for snapping; no
associated data
- pdf_snap_x_node: a whatsit node representing a node that can be snapped in x-direction; has
a glue specifying:
- the basic unit of the ``grid''
- how much it can be moved left/right
Example: 5pt plus 4pt minus 3pt -- grid of 5pt for each cell, snap nodes can be moved as much
as 4pt forward (right) and 3pt backward (left). Any 'fill' or higher order means that the movement
amount is unlimited.
- pdf_snap_y_node: similar, but for y-direction
New primitives:
\pdfsnaprefpoint: insert a reference point
\pdfsnapx: insert a whatsit node that can be snapped in x- direction
\pdfsnapy: similar, but for y-direction
\pdflinesnapx: specify a snap_x node that will be automatically prepended to each line after line-
breaking=20
\pdflinesnapy: similar, but for y-direction
Example:
- have a \pdfsnaprefpoint in each page (e.g., in header)
- let's assume \baselineskip=10pt; saying somewhere in the beginning
\pdflinesnapy 10pt plus 5pt minus 4pt
would have the effect to snap every line to a grid with the reference at the location of
\pdfsnaprefpoint to the nearest multiple of 10pt, given that the movement amount is in range (-4pt,
5pt).
- to snap the reference of a box, insert a \pdfsnapy somewhere inside the box so that it ends up
at the baseline of the box.