PDFPipe

Signing, terms and clauses / Numbered clauses

Numbered and sub-numbered clauses that renumber themselves

Hierarchical clause numbering, where 4.2.1 has to stay correct through every edit and has to be findable from a cross-reference elsewhere in the document.

Why this block is harder than it looks

The numbers are the addressing system of the document. Everything else refers to them, so they have to be right, and hand-maintained numbering in a document anyone will edit is guaranteed to go wrong the first time a clause is inserted in the middle. CSS counters solve the generation problem completely. What they do not solve is the cross-reference problem: a sentence saying subject to clause 4.2 has a number in the text that no counter is producing, and that number goes stale silently.

The decisions that make it work

Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.

  • Generate every clause number with nested counters. The markup then carries structure and no numbers at all, which is what makes insertion safe.
  • Set the numbers in a hanging indent so the clause text aligns in a column regardless of how many digits the number has.
  • Keep the number with its first line. A clause number alone at the foot of a page is a broken reference.
  • Resolve cross-references in code, not by hand. If the document format cannot do that, keep cross-references to whole sections rather than to numbered sub-clauses, so there is less to go stale.
  • Do not restart numbering per page or per column. Clause numbers address the document, not the sheet.
  • Set break-after: avoid on any clause heading so a heading and its first sentence stay together.

The fragment

Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.

html
<ol class="clauses">
  <li>
    <h3>Payment</h3>
    <ol>
      <li>Invoices are payable within thirty days of issue.</li>
      <li>Interest accrues on overdue amounts from the due date.</li>
    </ol>
  </li>
  <li><h3>Termination</h3>
    <ol><li>Either party may terminate on written notice.</li></ol>
  </li>
</ol>

<style>
  .clauses, .clauses ol { list-style: none; padding: 0; margin: 0; }
  .clauses { counter-reset: c1; }
  .clauses > li { counter-increment: c1; counter-reset: c2; margin-bottom: 8pt; }
  .clauses > li > h3 {
    break-after: avoid;
    font-size: 10pt;
    margin: 0 0 3pt 12mm;
  }
  .clauses > li > h3::before {
    content: counter(c1) ".";
    display: inline-block;
    width: 12mm;
    margin-left: -12mm;            /* hanging indent */
  }
  .clauses > li > ol > li {
    counter-increment: c2;
    break-inside: avoid;
    margin: 0 0 3pt 12mm;
  }
  .clauses > li > ol > li::before {
    content: counter(c1) "." counter(c2);
    display: inline-block;
    width: 12mm;
    margin-left: -12mm;
  }
</style>

What breaks when it is built the obvious way

Typing the numbers into the markup because the counter syntax looked fiddly. It works until the day a clause is inserted at 4.2, after which every number below it is wrong, and nothing about a wrong clause number is visible on inspection.

How to prove it survived pagination

Insert a clause in the middle of the document and render. Every number after it should have moved by one with no other edit. Then search the body text for any literal clause number and confirm each one still points where it claims.

Where it sits in a finished document

This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The non-disclosure agreement template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.

Frequently asked

Will this fragment work on its own?

Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.

Why does it look right in a browser and wrong in the PDF?

Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.

Do I need a special option on the render request for this?

No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.

Other parts of a document

The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.

Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.