User Guide & API Reference · Version 1.0.0

annotex Documentation

Every command, environment, layout mode, reproducible example, and searchable key-value option — designed to get you from raw PDF to publication-grade annotated edition in minutes.

Section 01 · Getting Started

Installation & Engine Compatibility

annotex consists of two core runtime files — annotex.sty (LaTeX3/TikZ) and annotex.lua (pure-Lua vector-PDF text parser) — and requires LaTeX2e (2021-06-01 or newer) along with standard TeX Live / MiKTeX packages (expl3, xparse, l3keys2e, iftex, graphicx, xcolor, tikz). No external binaries and no --shell-escape flag are needed.

TeX Engine Core Features (Grid, Sidebar, Book Boxes, \atxnote, \atxmemo, Auto-Fit, Lightbulb) Native Vector Text Search (\atxquote, \atxhl)
LuaLaTeX Recommended Full support Full native support (pure Lua, zero --shell-escape)
pdfLaTeX Full support Graceful fallback with informative warning
XeLaTeX Full support Graceful fallback with informative warning
Local / Manual TDS Installation
# Option A: Place annotex.sty and annotex.lua directly beside your .tex document
# Option B: Install into your personal TEXMFHOME tree:
mkdir -p "$(kpsewhich -var-value=TEXMFHOME)/tex/latex/annotex"
cp annotex.sty annotex.lua "$(kpsewhich -var-value=TEXMFHOME)/tex/latex/annotex/"
mktexlsr  # only needed if your TeX distribution caches TEXMFHOME

Section 02 · Quick Start

Recommended Three-Step Workflow

1

Inspect the Coordinate Grid

Load your PDF with default grid=true and compile once with lualatex. Read exact decimal (row, col) positions directly off the translucent blueprint grid.

2

Annotate Page by Page

Open an annotexpage environment for each page you want to annotate, mixing \atxnote, \atxquote, and \atxmemo freely. Unannotated pages pass through automatically.

3

Export the Clean Final PDF

Switch grid=false inside \annotexsetup to hide both the coordinate overlay and dashed box frames (when box-frame=auto) for a clean archival edition.

minimal-example.tex — lualatex minimal-example.tex
\documentclass{article}  % For Chinese notes, use \documentclass[UTF8]{ctexart}
\usepackage{annotex}

\annotexsetup{
  sidebar        = true,        % extended side margin (default)
  sidebar-side   = right,       % right | left | outer | inner
  sidebar-width  = 0.25,        % 1/4 of original page width (or e.g. 5cm)
  grid           = true,        % set false for final reading copy
  opacity        = 0.35,        % global positioning-layer opacity
  note-font-size = 8pt,         % global base note font size
  auto-fit       = true,        % shrink font on overflow (zero extra pages)
  numbering      = continuous,  % continuous | per-page | none
}

\begin{document}
\annotexload{examples/sample-source.pdf}

\begin{annotexpage}{1}
  \atxmemo{Page summary pinned automatically to the top of the sidebar.}
  \atxquote{introduce a hierarchical refinement workflow}{Vector sentence highlight!}
  \atxnote{45.5}{53.0}{Coordinate note at row 45.5, col 53.0.

    Supports multiple paragraphs, equations $E=mc^2$, and figures:
    \includegraphics[width=\linewidth]{examples/sample-chart.pdf}}
\end{annotexpage}
\end{document}

Section 03 · Page Layout

Extended Sidebar vs. In-Page Book-Symmetric Boxes

All global layout options are declared after \usepackage{annotex} (before \begin{document}) via \annotexsetup and \annotexarea, and can be overridden on any single page inside annotexpage. Every source PDF page keeps its exact original physical dimensions — even across mixed portrait and landscape PDFs.

\annotexsetup{key=value list} Preamble or Per-Page

Applies options globally when called in the preamble (or before \annotexload). When called inside \begin{annotexpage}...\end{annotexpage}, changes apply strictly to that page and revert automatically upon closing the environment.

\annotexarea[pages=all|odd|even, label=..., replace=false]{row1}{col1}{row2}{col2} sidebar=false

Declares a rectangular annotation container directly inside the original PDF's coordinate space (top-to-bottom rows 0–100, left-to-right cols 0–100). Call multiple times to register several boxes per page (overflowing notes spill automatically into subsequent boxes). Clear active boxes with \annotexclearareas.

  • book=true (aliases twoside, mirror-even): Automatically mirrors every pages=all box horizontally across the page centerline on even (verso) pages: [col1, col2] → [cols − col2, cols − col1].
  • page-parity-offset=1: Shifts odd/even parity detection when a PDF begins with an unnumbered cover page.
  • sidebar-side=outer|inner: In sidebar mode, dynamically switches the extended margin between right/left on odd and even pages.
Odd book page right margin box Zoom
Odd (recto) page: declared once at {8}{70}{92}{96}
Even book page left margin mirrored box Zoom
Even (verso) page: mirrored automatically to cols 4–30

Section 04 · Coordinate Overlay

Semi-Transparent Coordinate Grid & Global Opacity

Enabled by default (grid=true, opacity=0.35), annotex draws a crisp non-obscuring positioning overlay over every source PDF page: dense edge tick marks & row/column numbers, major horizontal and vertical lines every N units (default 10), periodic inline R/C coordinates along the grid lines, optional dotted minor lines, and dashed frames around user-defined annotation boxes when sidebar=false.

custom-grid-example.tex
\annotexsetup{
  grid            = true,
  opacity         = 0.35,           % global transparency for grid & box frames
  rows            = 100,            % vertical coordinate scale (0 top .. 100 bottom)
  cols            = 100,            % horizontal coordinate scale (0 left .. 100 right)
  grid-step       = 10,             % major horizontal & vertical line interval
  minor-grid      = true,           % dotted sub-grid every minor-step (default 5)
  row-label-step  = 2,              % dense row labels along vertical edge
  col-label-step  = 5,              % column labels along horizontal edge
  grid-edges      = all,            % tl (default) | tr | bl | br | all
  inline-labels   = true,           % periodic R10 / C20 labels on grid lines
  grid-color      = teal!75!black,
}
Default coordinate grid Zoom
Default grid (grid-edges=tl, opacity=0.35)
Customized 4-edge minor grid Zoom
Customized 4-edge teal grid with minor dotted lines

Section 05 · Document Flow

Loading PDFs & Per-Page Scope Control

\annotexload[pages=all|annotated|1-4,7, ...]{file.pdf} After \begin{document}

Loads the target PDF after \begin{document}. Use pages=all (default) to emit every page, pages=annotated to emit only pages that have an annotexpage block, or explicit page ranges like pages=1-3,6,9-. Remaining unrendered pages are flushed automatically at \end{document} (or manually via \annotexflush). Use \annotexpagecount to read total pages and \annotexdebugtext{p} to dump Lua-extracted text of page p to your .log.

\begin{annotexpage}[inherit=true|false, local options]{page} ... \end{annotexpage} Per-Page Environment

Targets physical page <page> (1-based) of the loaded PDF. Any earlier pages skipped since the last block are emitted automatically in order. By default, every global option is inherited. Passing inherit=false (alias reset-layout) resets all visual/layout/grid/sidebar/box settings to clean package defaults so you can build that page's layout from scratch with local \annotexsetup / \annotexarea — while note numbering STILL continues seamlessly from the previous page by default!

Section 06 · Core Commands

Three Note Modes & Two Highlighting Helpers

All five commands below are used inside an annotexpage environment. All public command names use the annotex or atx prefix and are verified conflict-free against mainstream TeX Live packages (amsmath, tikz, hyperref, tcolorbox, todonotes, marginnote, pdfpages, ctex).

\atxnote[per-note options]{row}{col}{note content} Type 1 · Coordinate Note

Places a translucent numbered badge at decimal coordinates (row, col) on the PDF body (default: multiply-blended yellow circle with black non-bold digit, never obscuring text underneath) and starts typesetting <note content> aligned to <row> inside the sidebar or annotation box. Full LaTeX body support: blank-line multi-paragraph text, equations, itemized lists, tables, and \includegraphics[width=\linewidth]{...}.

\atxquote[occurrence=1|all, ignore-case, marker-pos, ...]{sentence}{note content} Type 2 · Vector Sentence Highlight

Searches the vector PDF page natively in pure Lua (LuaLaTeX, zero --shell-escape), highlights every spanned line of <sentence> in translucent multiply-blended yellow, places the badge neatly beside the match (default marker-pos=end with gentle offset so text is never covered), and aligns <note content> to the quote's vertical row (quote-align=first|center|last). Handles line wraps, two-column reading order, ligatures (fi/fl), end-of-line hyphenation, TeX escapes (\%, \&, \$, \_), and CJK UTF-8.

\atxmemo[placement=follow|top|bottom, row=..., ...]{note content} Type 3 · Pure Margin Memo

Typesets a pure margin/box note with NO marker drawn on the PDF body, while still participating in numbering (or showing the unnumbered icon). Default placement=follow pins the memo to the top of the container if it is the first note on the page, or attaches it directly beneath the preceding note. Also accepts placement=top, placement=bottom, or an explicit vertical row={...}.

\atxhl[highlight-style=box|underline|strike]{sentence}   |   \atxrect[opts]{r1}{c1}{r2}{c2} Bonus Helpers

\atxhl highlights, underlines, or strikes through a vector-PDF sentence without creating a margin note. \atxrect draws a translucent rounded rectangular callout frame over coordinates (r1, c1)–(r2, c2) — ideal for highlighting equations, charts, or regions of scanned raster PDFs.

All three note types on page 1 Zoom
Mixing \atxmemo, \atxquote, and figure-bearing \atxnote
Dense floating card notes on page 2 Zoom
Dense notes auto-floating cleanly with connectors

Section 07 · Visual Identity

Numbering Modes, Translucent Markers & Lightbulb Icon

Configure numbering globally or per page: continuous (default), per-page (restarts at page-start-number on every page), or none (unnumbered). Whenever numbering=none (or numbered=false on an individual note), Type 1 and Type 2 in-page markers automatically render as a pure glowing vector yellow lightbulb icon — with NO yellow enclosing circle — keeping the page visually light and expressive.

Non-Obscuring Translucent Markers by Default

Numbered markers on the PDF body default to marker-opacity=0.48, marker-text-opacity=0.68, and marker-blend=true (PDF multiply blend mode), so even if a marker overlaps text or equations, every glyph beneath stays completely readable.

custom-markers-and-bulb.tex
% Custom pure-LaTeX marker command (avoid nested \tikz inside marker-cmd)
\newcommand{\mybadge}[1]{\colorbox{blue!15}{\color{blue!75!black}\sffamily\scriptsize\bfseries #1}}

\begin{annotexpage}[sidebar-side=left, sidebar-width=4.6cm]{1}
  \atxnote{22}{45}{Default translucent yellow circle (Note 1).}
  \atxnote[marker-shape=rounded, marker-bold=true, marker-underline=true,
           marker-color=red!80!black, marker-highlight=orange!25]{45}{38}{Custom crimson badge (Note 2).}
  \atxnote[marker-cmd=\mybadge]{63}{52}{Custom macro badge (Note 3).}
\end{annotexpage}

% Unnumbered page: pure glowing yellow vector lightbulb (no enclosing circle)
\begin{annotexpage}[numbering=none]{2}
  \atxquote{three benchmark problems}{Pure yellow lightbulb beside quote!}
\end{annotexpage}

% Local visual reset via inherit=false — numbering still continues at 4!
\begin{annotexpage}[inherit=false]{3}
  \annotexsetup{note-style=leftbar}
  \atxnote{30}{42}{Continues seamlessly from Note 3 as Note 4!}
\end{annotexpage}
Left sidebar and custom marker styles Zoom
Left sidebar & custom badges
Unnumbered pure lightbulb icons Zoom
Unnumbered pure yellow lightbulb
inherit=false continuous numbering Zoom
inherit=false with continuous 4, 5

Section 08 · Overflow & Containment

Auto-Floating, Box Containment, Auto-Fit Font & Forced Clipping

Every sidebar and in-page annotation box enforces exact column width (\hsize) with zero paragraph indentation and a hard geometric TikZ \clip boundary — notes can never bleed outside their designated box. When multiple notes compete for vertical space, two anti-collision float solvers keep them neatly separated: cascade (default row-aligned downward float with bottom rebound) or balanced (least-squares Pool Adjacent Violators Algorithm).

Zero Extra Continuation Pages — Always 1-to-1 with Source PDF

Default (auto-fit=true): If total notes exceed container height at your base note-font-size (default 8pt), annotex iteratively scales the font size down (until min-note-font-size=4.2pt) and re-typesets at full column width so everything fits on the same page.
Forced Fixed Font (auto-fit=false or overflow=clip): Keeps your exact global or per-page note-font-size untouched; any excess beyond the bottom box edge is cleanly clipped (with a log warning).

Auto-fit 12 cards onto single page Zoom
auto-fit=true: 12 dense cards fit cleanly on 1 page
Forced 12pt font cleanly clipped at bottom edge Zoom
auto-fit=false, note-font-size=12pt: clean bottom clip

Section 09 · Complete API Reference

Complete Key-Value Option Reference

Every key below can be passed as a package option, in \annotexsetup, in \annotexload, or in \begin{annotexpage}[...]{p}. Visual marker, highlight, and note keys may also be overridden on individual \atxnote, \atxquote, and \atxmemo calls.

Showing all options
Key (Aliases) Default Description
1. Sidebar & Page Layout
sidebartrueGenerate an extended margin panel beside the PDF (true/false).
sidebar-side (side)rightSide placement: right, left, outer (book outside), or inner.
sidebar-width0.25Fraction of original PDF width (e.g. 0.25, 1/3) or explicit TeX length (e.g. 5cm).
sidebar-bgnoneSidebar background tint (e.g. gray!5, yellow!6, or none).
sidebar-rule / -color / -widthtrue / black!25 / 0.5ptVertical divider rule between original PDF and sidebar, with color & thickness.
sidebar-pad-x / -top / -bottom8pt / 12ptInner horizontal and top/bottom padding inside the sidebar.
2. In-Page Annotation Boxes & Book Symmetry (sidebar=false)
book (twoside, mirror-even)falseMirror all-page annotation boxes horizontally across the center on even pages.
page-parity-offset0Integer offset added to page number before evaluating odd/even parity.
note-area / add-note-area—Replace or append an annotation box {r1,c1,r2,c2} inline inside \annotexsetup.
odd-note-area / even-note-area—Append an odd-page-only or even-page-only annotation box {r1,c1,r2,c2}.
box-frameautoShow dashed annotation box border: auto (follows grid), true, or false.
box-color / box-opacity / box-fillorange!75!black / opacity / orange!15Border stroke color, opacity (defaults to global opacity), and subtle interior tint (or none).
box-line-width / box-style / box-pad / box-label0.8pt / dashed / 4pt / trueBorder line width, TikZ stroke style, inner note padding, and corner label tag toggle.
3. Global Opacity & Coordinate Positioning Grid
opacity0.35Global default transparency for the positioning grid overlay and box frames.
gridtrueToggle the semi-transparent coordinate positioning grid (default on).
rows / cols100 / 100Coordinate resolution (top-to-bottom rows and left-to-right columns).
row-line-step / col-line-step (grid-step)10 / 10Spacing of major horizontal and vertical positioning lines.
minor-grid / minor-stepfalse / 5Enable dotted minor sub-grid lines and interval (also minor-row-step / minor-col-step).
row-tick-step / col-tick-step (tick-step)1 / 1Edge tick mark density along the borders.
row-label-step / col-label-step (label-step)2 / 5Edge numeric row/column label spacing.
grid-edgestlWhich page borders display ticks & labels: tl, all, tr, bl, br.
inline-labels / inline-steptrue / 20Periodic coordinate labels stamped along major grid lines (also inline-row-step / inline-col-step).
inline-row-prefix / inline-col-prefixR / CPrefix before inline grid labels (set empty for bare numbers).
grid-color / grid-opacity / grid-line-width / grid-fontblue!55!cyan!80!black / 0.35ptGrid color, optional dedicated opacity override, line thickness, and label font.
4. Numbering System & Unnumbered Lightbulb Icon
numberingcontinuouscontinuous (global across pages), per-page (page), or none (off — switches in-page markers to yellow lightbulb).
start-number / page-start-number1 / 1Initial global counter (or starting number for current annotexpage) and per-page reset value.
number-formatarabicCounter display format: arabic, alph, Alph, roman, or Roman.
number-prefix / number-suffixemptyOptional strings prepended/appended to numbers (e.g. prefix S gives S1, S2).
local-numberingfalseWhen true inside annotexpage, restores global counter on exit so next page continues uninterrupted.
bulb-color / bulb-highlightyellow / orangeGlass fill and radiating light-ray accent of the pure vector lightbulb icon.
bulb-border / bulb-opacityblack!75 / 0.72Outline color and translucent body opacity of the lightbulb over PDF content.
bulb-scale / bulb-rays / bulb-cmd1.0 / true / emptySize multiplier, glowing ray toggle, or custom zero-argument replacement macro.
5. Body Marker Styling
marker-shapecircleBadge shape: circle (default), square, rounded, plain, or diamond.
marker-color / marker-highlight (marker-fill)black / yellow!90!orange!80Digit text color and highlight fill color (use none for no fill).
marker-opacity / marker-text-opacity0.48 / 0.68Translucent fill opacity and digit/border opacity on the PDF body so text stays legible.
marker-blendtrueApply PDF multiply blend mode to body marker fill for razor-sharp underlying ink.
marker-border / marker-border-widthblack!70 / 0.45ptBadge outline color (none disables outline) and line thickness.
marker-bold / marker-underlinefalse / falseToggle boldface (default non-bold) and underline on the marker digit.
marker-font / marker-size / marker-scale\sffamily\scriptsize / 9.5pt / 1.0Marker typography, minimum diameter, and overall scaling factor.
marker-style / marker-cmdemptyAppend raw TikZ node styles, or supply a custom 1-arg LaTeX macro \cmd{#1}.
6. Vector-PDF Text Highlighting (\atxquote & \atxhl)
highlight-color / highlight-opacityyellow / 0.45Sentence highlight color and transparency.
highlight-blend / highlight-styletrue / boxMultiply blend toggle and highlight rendering mode: box, underline, or strike.
highlight-radius / -pad-x / -pad-y1.2pt / 0.8pt / 0.8ptCorner rounding radius and horizontal/vertical padding around matched glyphs.
marker-pos / marker-offset-x / -offset-yend / 3.5pt / 3.5ptMarker anchor beside highlight (end, start, top-end, top-start, right, left) and fine offsets.
quote-alignfirstMargin note vertical anchor for multi-line quotes: first, center, or last line.
ignore-case / occurrencefalse / 1Case-insensitive matching and occurrence selector (1, 2, ..., or all).
7. Note Typography, Auto-Fit, Floating & Connectors
note-font-size (note-size)8ptGlobal or per-page base font size for margin/box notes.
min-note-font-size / note-line-spread4.2pt / 1.22Lower font-size floor when auto-fit=true and leading multiplier.
auto-fit / overflowtrue / autofitauto-fit=true (overflow=autofit) shrinks font on overflow; auto-fit=false (overflow=clip) keeps forced size and clips at box edge.
note-font / note-color / note-sep\normalfont / black / 6ptNote font family/shape, text color, and minimum vertical spacing between notes.
note-style / note-accent-color / note-bgplain / orange!75!black / yellow!10Note presentation (plain, leftbar, card), accent stripe/border color, and card tint.
note-align / note-badgeragged / autoParagraph alignment (ragged/justify) and margin badge style (auto/same/bulb/bullet/none).
float-mode / note-ordercascade / positionCollision solver: cascade (row-aligned downward float + rebound) or balanced (PAVA); order by anchor position or source.
connector / -color / -opacity / -width / -stylefalse / black!45 / 0.55 / 0.45pt / densely dottedDraw leader line connecting each body marker to its margin/box note.
8. Loading & Per-Note Control
pages / auto-flushall / truePages to output (all, annotated, or range like 1-3,5,8-) and automatic flush at \end{document}.
inherit (reset-layout)trueInside annotexpage, false resets visual/layout settings to defaults while keeping numbering continuous.
label / numbered—Per-note custom label string override or single-note numbering toggle (true/false).
placement (position) / row / areafollow / — / 0 (auto)Per-note \atxmemo placement (follow/top/bottom), explicit vertical row, or explicit in-page box index 1, 2, …

Section 10 · Best Practices

Troubleshooting, Tips & License

Practical Tips

1. Diagnosing tricky fonts in \atxquote: Run \annotexdebugtext{p} to print the exact searchable text Lua extracted from page p into your .log file.
2. Scanned (image-only) PDFs: Raster scans have no vector text stream — pair the coordinate grid with \atxnote and \atxrect.
3. Custom marker-cmd macros: Use pure LaTeX/xcolor commands (like \colorbox) rather than nesting a second \tikz inside a TikZ node; for raw TikZ styling, pass options directly to marker-style={...}.
4. Chinese notes & Chinese PDFs: Use \documentclass[UTF8]{ctexart} and compile with lualatex for seamless CJK typography and UTF-8 vector sentence highlighting.

Author & Maintainer: Xufeng Zhang (张旭峰) · [email protected]
License: Distributed under the LaTeX Project Public License (LPPL) version 1.3c or later. See the accompanying LICENSE file.