@latex-kit/template 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/document.d.ts +6 -0
- package/document.js +5 -1
- package/esm/document.d.ts +6 -0
- package/esm/document.js +4 -1
- package/esm/evaluate.d.ts +6 -0
- package/esm/evaluate.js +6 -1
- package/esm/signature.d.ts +2 -1
- package/esm/signature.js +4 -3
- package/esm/sty.d.ts +1 -1
- package/esm/sty.js +98 -7
- package/evaluate.d.ts +6 -0
- package/evaluate.js +6 -1
- package/package.json +2 -2
- package/signature.d.ts +2 -1
- package/signature.js +4 -3
- package/sty.d.ts +1 -1
- package/sty.js +98 -7
package/document.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { Variant } from './evaluate';
|
|
2
|
+
export type BlankStyle = 'labelled' | 'lines' | 'names';
|
|
3
|
+
export declare const BLANK_STYLES: BlankStyle[];
|
|
2
4
|
export interface WrapOptions {
|
|
3
5
|
variant: Variant;
|
|
4
6
|
/** Short text printed on draft pages, e.g. date and git commit. */
|
|
5
7
|
stamp?: string;
|
|
8
|
+
/** How blanks print: a small labelled line (default), an empty line, or the field's name in brackets. */
|
|
9
|
+
blanks?: BlankStyle;
|
|
10
|
+
/** Draft builds: print a missing value as a red marker (default) or as a blank. */
|
|
11
|
+
missing?: 'marker' | 'blank';
|
|
6
12
|
}
|
|
7
13
|
/**
|
|
8
14
|
* Make a filled template ready for TeX: tell `latex-kit.sty` it is rendering
|
package/document.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BLANK_STYLES = void 0;
|
|
3
4
|
exports.wrapDocument = wrapDocument;
|
|
4
5
|
const escape_1 = require("@latex-kit/escape");
|
|
6
|
+
exports.BLANK_STYLES = ['labelled', 'lines', 'names'];
|
|
5
7
|
const USES_PACKAGE = /\\(?:usepackage|RequirePackage)\s*(?:\[[^\]]*\])?\s*\{[^}]*\blatex-kit\b[^}]*\}/;
|
|
6
8
|
/**
|
|
7
9
|
* Make a filled template ready for TeX: tell `latex-kit.sty` it is rendering
|
|
@@ -13,7 +15,9 @@ const USES_PACKAGE = /\\(?:usepackage|RequirePackage)\s*(?:\[[^\]]*\])?\s*\{[^}]
|
|
|
13
15
|
*/
|
|
14
16
|
function wrapDocument(tex, options) {
|
|
15
17
|
const stamp = options.stamp ? (0, escape_1.escapeLatex)(options.stamp) : '';
|
|
16
|
-
const
|
|
18
|
+
const blanks = options.blanks === 'lines' ? ',blanklines' : options.blanks === 'names' ? ',blanknames' : '';
|
|
19
|
+
const missing = options.missing === 'blank' ? ',missingblank' : '';
|
|
20
|
+
const prefix = `\\PassOptionsToPackage{rendered,${options.variant}${blanks}${missing}}{latex-kit}\\def\\lkstamp{${stamp}}`;
|
|
17
21
|
let body = tex;
|
|
18
22
|
if (!USES_PACKAGE.test(body)) {
|
|
19
23
|
const at = body.indexOf('\\begin{document}');
|
package/esm/document.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { Variant } from './evaluate';
|
|
2
|
+
export type BlankStyle = 'labelled' | 'lines' | 'names';
|
|
3
|
+
export declare const BLANK_STYLES: BlankStyle[];
|
|
2
4
|
export interface WrapOptions {
|
|
3
5
|
variant: Variant;
|
|
4
6
|
/** Short text printed on draft pages, e.g. date and git commit. */
|
|
5
7
|
stamp?: string;
|
|
8
|
+
/** How blanks print: a small labelled line (default), an empty line, or the field's name in brackets. */
|
|
9
|
+
blanks?: BlankStyle;
|
|
10
|
+
/** Draft builds: print a missing value as a red marker (default) or as a blank. */
|
|
11
|
+
missing?: 'marker' | 'blank';
|
|
6
12
|
}
|
|
7
13
|
/**
|
|
8
14
|
* Make a filled template ready for TeX: tell `latex-kit.sty` it is rendering
|
package/esm/document.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { escapeLatex } from '@latex-kit/escape';
|
|
2
|
+
export const BLANK_STYLES = ['labelled', 'lines', 'names'];
|
|
2
3
|
const USES_PACKAGE = /\\(?:usepackage|RequirePackage)\s*(?:\[[^\]]*\])?\s*\{[^}]*\blatex-kit\b[^}]*\}/;
|
|
3
4
|
/**
|
|
4
5
|
* Make a filled template ready for TeX: tell `latex-kit.sty` it is rendering
|
|
@@ -10,7 +11,9 @@ const USES_PACKAGE = /\\(?:usepackage|RequirePackage)\s*(?:\[[^\]]*\])?\s*\{[^}]
|
|
|
10
11
|
*/
|
|
11
12
|
export function wrapDocument(tex, options) {
|
|
12
13
|
const stamp = options.stamp ? escapeLatex(options.stamp) : '';
|
|
13
|
-
const
|
|
14
|
+
const blanks = options.blanks === 'lines' ? ',blanklines' : options.blanks === 'names' ? ',blanknames' : '';
|
|
15
|
+
const missing = options.missing === 'blank' ? ',missingblank' : '';
|
|
16
|
+
const prefix = `\\PassOptionsToPackage{rendered,${options.variant}${blanks}${missing}}{latex-kit}\\def\\lkstamp{${stamp}}`;
|
|
14
17
|
let body = tex;
|
|
15
18
|
if (!USES_PACKAGE.test(body)) {
|
|
16
19
|
const at = body.indexOf('\\begin{document}');
|
package/esm/evaluate.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface EvaluateOptions {
|
|
|
18
18
|
* for `draft`; `final` and `signed` always fail on a missing value.
|
|
19
19
|
*/
|
|
20
20
|
allowMissing?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap every value a `\field` fills in with `\lkvalue{…}`, which prints it
|
|
23
|
+
* in red: a review copy that shows what came from the record. Not for
|
|
24
|
+
* `\raw` fields, whose LaTeX may not survive being an argument.
|
|
25
|
+
*/
|
|
26
|
+
markValues?: boolean;
|
|
21
27
|
/** Resolve \snippet{name} from the file that uses it. */
|
|
22
28
|
loadSnippet?: (name: string, from: string) => CompiledTemplate | null;
|
|
23
29
|
/** Resolve \clause{id} from the clause library. */
|
package/esm/evaluate.js
CHANGED
|
@@ -175,7 +175,12 @@ export function evaluateTemplate(template, options) {
|
|
|
175
175
|
}
|
|
176
176
|
const isGone = !result.defaulted && isMissing(result.value);
|
|
177
177
|
fields.push({ path, ...node.loc, missing: isGone });
|
|
178
|
-
|
|
178
|
+
if (isGone)
|
|
179
|
+
out += missing(path, node.loc);
|
|
180
|
+
else {
|
|
181
|
+
const tex = toTex(result.value, node.raw, result.newlines, path, node.loc);
|
|
182
|
+
out += options.markValues && tex && !node.raw ? `\\lkvalue{${tex}}` : tex;
|
|
183
|
+
}
|
|
179
184
|
break;
|
|
180
185
|
}
|
|
181
186
|
case 'docid':
|
package/esm/signature.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export declare class SignatureError extends Error {
|
|
|
26
26
|
name: string;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}
|
|
29
|
+
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}`,
|
|
30
|
+
* after `\lksignaturefor{party}` so the block can mark where that party signs.
|
|
30
31
|
*
|
|
31
32
|
* A party with a `signer` (or `kind: organization`) is an organization: its
|
|
32
33
|
* name in bold, then the signer's name and title. Anything else signs for
|
package/esm/signature.js
CHANGED
|
@@ -8,7 +8,8 @@ const text = (v) => (typeof v === 'string' && v.trim() !== '' ? v : undefined);
|
|
|
8
8
|
/** Image paths must be plain relative names, so they can never inject LaTeX. */
|
|
9
9
|
const SAFE_IMAGE_PATH = /^[A-Za-z0-9_./-]+$/;
|
|
10
10
|
/**
|
|
11
|
-
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}
|
|
11
|
+
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}`,
|
|
12
|
+
* after `\lksignaturefor{party}` so the block can mark where that party signs.
|
|
12
13
|
*
|
|
13
14
|
* A party with a `signer` (or `kind: organization`) is an organization: its
|
|
14
15
|
* name in bold, then the signer's name and title. Anything else signs for
|
|
@@ -18,7 +19,7 @@ const SAFE_IMAGE_PATH = /^[A-Za-z0-9_./-]+$/;
|
|
|
18
19
|
export function signatureBlock(value, o) {
|
|
19
20
|
const p = o.path;
|
|
20
21
|
if (o.variant === 'blank') {
|
|
21
|
-
return `\\lksignature{\\lkblank{${p}.name}}{\\lkblank{${p}.signer.name}}{\\lkblank{${p}.signer.title}}{}{}`;
|
|
22
|
+
return `\\lksignaturefor{${p}}\\lksignature{\\lkblank{${p}.name}}{\\lkblank{${p}.signer.name}}{\\lkblank{${p}.signer.title}}{}{}`;
|
|
22
23
|
}
|
|
23
24
|
if (value === undefined || value === null)
|
|
24
25
|
return o.missing(p);
|
|
@@ -50,5 +51,5 @@ export function signatureBlock(value, o) {
|
|
|
50
51
|
if (signed)
|
|
51
52
|
date = escapeLatex(String(FILTERS.date.apply(signed, 'long', { locale: o.locale }, {})));
|
|
52
53
|
}
|
|
53
|
-
return `\\lksignature{${org}}{${nameTex}}{${titleTex}}{${sign}}{${date}}`;
|
|
54
|
+
return `\\lksignaturefor{${p}}\\lksignature{${org}}{${nameTex}}{${titleTex}}{${sign}}{${date}}`;
|
|
54
55
|
}
|
package/esm/sty.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* every generated document; `latex-kit sty <dir>` writes it for previewing
|
|
4
4
|
* templates in an editor.
|
|
5
5
|
*/
|
|
6
|
-
export declare const LATEX_KIT_STY = "% latex-kit.sty: support for latex-kit templates.\n%\n% Load it in a template with \\usepackage{latex-kit}. Compiled directly, a\n% template previews as a blank form: every \\field becomes a labelled line.\n% When latex-kit renders a document it passes the `rendered` option and the\n% variant (draft, blank, final, signed); the template macros are gone by then.\n%\n% https://github.com/constructive-io/latex-kit (MIT)\n\\NeedsTeXFormat{LaTeX2e}\n\\ProvidesPackage{latex-kit}[2026/11/
|
|
6
|
+
export declare const LATEX_KIT_STY = "% latex-kit.sty: support for latex-kit templates.\n%\n% Load it in a template with \\usepackage{latex-kit}. Compiled directly, a\n% template previews as a blank form: every \\field becomes a labelled line.\n% When latex-kit renders a document it passes the `rendered` option and the\n% variant (draft, blank, final, signed); the template macros are gone by then.\n%\n% https://github.com/constructive-io/latex-kit (MIT)\n\\NeedsTeXFormat{LaTeX2e}\n\\ProvidesPackage{latex-kit}[2026/11/26 v0.6 latex-kit template support]\n\n\\newif\\iflk@rendered\n\\newif\\iflk@draft\n\\DeclareOption{rendered}{\\lk@renderedtrue}\n\\DeclareOption{draft}{\\lk@drafttrue}\n\\DeclareOption{blank}{}\n\\DeclareOption{final}{}\n\\DeclareOption{signed}{}\n% how a blank prints (blank builds and template previews)\n\\newif\\iflk@blanklines\n\\newif\\iflk@blanknames\n\\DeclareOption{blanklines}{\\lk@blanklinestrue}\n\\DeclareOption{blanknames}{\\lk@blanknamestrue}\n% draft builds: print a missing value as a blank instead of a red marker\n\\newif\\iflk@missingblank\n\\DeclareOption{missingblank}{\\lk@missingblanktrue}\n\\ProcessOptions\\relax\n\n\\RequirePackage{xcolor}\n\\RequirePackage{graphicx}\n% tables from latex-kit components (table(), line items)\n\\RequirePackage{array,tabularx,booktabs}\n\\definecolor{lkmeta}{gray}{0.55}\n\\providecommand\\lkstamp{}\n\n% A labelled blank line: \\lkblank{party.name}\n\\newlength\\lkblankwidth\n\\setlength\\lkblankwidth{3.5cm}\n% Four ways to print it. Redefine any of them to change the look.\n% labelled (default) the field's name, small, on a line\n% line an empty line to write on (option blanklines)\n% names the field's name in brackets, no line (option blanknames)\n% and per field, through \\formfield[blank=\u2026]: wide, none, label.\n\\newcommand\\lkblanklabelled[1]{\\leavevmode\\underline{\\makebox[\\lkblankwidth][l]{\\color{lkmeta}\\tiny\\ttfamily\\detokenize{#1}}}}\n\\newcommand\\lkblankline[1]{\\leavevmode\\underline{\\hspace{\\lkblankwidth}}}\n\\newcommand\\lkblankwide[1]{\\leavevmode\\underline{\\hspace{2\\lkblankwidth}}}\n\\newcommand\\lkblanknone[1]{}\n\\newcommand\\lkblanklabel[1]{\\mbox{[\\ifx\\lkf@label\\@empty\\detokenize{#1}\\else\\lkf@label\\fi]}}\n\\newcommand\\lkblanknames[1]{\\mbox{\\color{lkmeta}\\small\\ttfamily[\\detokenize{#1}]}}\n\\newcommand\\lkblank[1]{%\n \\iflk@blanknames\\lkblanknames{#1}%\n \\else\\ifx\\lkf@blank\\@empty\n \\iflk@blanklines\\lkblankline{#1}\\else\\lkblanklabelled{#1}\\fi\n \\else\n \\@ifundefined{lkblank\\lkf@blank}{\\lkblanklabelled{#1}}{\\csname lkblank\\lkf@blank\\endcsname{#1}}%\n \\fi\\fi}\n\n% Form hints: \\formfield[hints]{content} prints its content unchanged in a\n% finished document. The hints tell blank forms how to print the spot, and\n% tell form and signing software where it is.\n% blank=line|wide|none|label how a blank prints here; label={Company Name}\n% sets the bracketed text for blank=label\n% type=signature|date|initials|text, who=<party>\n% a spot for someone to fill in. Its page and\n% position are written to <document>.form, which\n% latex-kit turns into <document>.form.json\n% label={Printed name} also says what to type\n% in a type=text spot\n% width=, height=, raise= the box for that spot: its bottom-left corner\n% is where the content starts, moved up by raise\n% (defaults 7cm, 24pt, 0pt)\n\\def\\lkf@blank{}\\def\\lkf@label{}\\def\\lkf@type{}\\def\\lkf@who{}\n\\newlength\\lkf@width\n\\newlength\\lkf@height\n\\newlength\\lkf@raise\n\\define@key{lkf}{blank}{\\def\\lkf@blank{#1}}\n\\define@key{lkf}{label}{\\def\\lkf@label{#1}}\n\\define@key{lkf}{type}{\\def\\lkf@type{#1}}\n\\define@key{lkf}{who}{\\def\\lkf@who{#1}}\n\\define@key{lkf}{width}{\\setlength\\lkf@width{#1}}\n\\define@key{lkf}{height}{\\setlength\\lkf@height{#1}}\n\\define@key{lkf}{raise}{\\setlength\\lkf@raise{#1}}\n\\newcommand\\formfield[2][]{{%\n \\setlength\\lkf@width{7cm}\\setlength\\lkf@height{24pt}\\setlength\\lkf@raise{0pt}%\n \\setkeys{lkf}{#1}\\lkf@mark #2}}\n\n% Where a marked spot landed. One line per spot in <document>.form:\n% type who page x y width height raise [label]\n% lengths in scaled points; x and y from the bottom-left corner of the page.\n% Needs an engine that can report positions (LuaTeX, pdfTeX, XeTeX).\n\\newwrite\\lkf@out\n\\newif\\iflkf@open\n\\newif\\iflkf@can\n\\@ifundefined{ReadonlyShipoutCounter}{}{%\n \\ifdefined\\savepos\n \\lkf@cantrue\\let\\lkf@savepos\\savepos\n \\def\\lkf@x{\\the\\lastxpos}\\def\\lkf@y{\\the\\lastypos}%\n \\else\\ifdefined\\pdfsavepos\n \\lkf@cantrue\\let\\lkf@savepos\\pdfsavepos\n \\def\\lkf@x{\\the\\pdflastxpos}\\def\\lkf@y{\\the\\pdflastypos}%\n \\fi\\fi}\n\\newcommand\\lkf@mark{%\n \\ifx\\lkf@type\\@empty\\else\\iflkf@can\n \\iflkf@open\\else\\immediate\\openout\\lkf@out=\\jobname.form\\relax\\global\\lkf@opentrue\\fi\n \\leavevmode\\lkf@savepos\n \\edef\\lkf@next{\\write\\lkf@out{\\lkf@type\\space\\ifx\\lkf@who\\@empty -\\else\\lkf@who\\fi\\space\n \\noexpand\\the\\noexpand\\ReadonlyShipoutCounter\\space\\noexpand\\lkf@x\\space\\noexpand\\lkf@y\\space\n \\number\\lkf@width\\space\\number\\lkf@height\\space\\number\\lkf@raise\n \\ifx\\lkf@label\\@empty\\else\\space\\expandafter\\detokenize\\expandafter{\\lkf@label}\\fi}}%\n \\lkf@next\n \\fi\\fi}\n% \\signature blocks mark their own signature and date lines for the party\n% named by \\lksignaturefor{party}, which latex-kit writes before each block.\n\\def\\lk@sigwho{}\n\\newcommand\\lksignaturefor[1]{\\gdef\\lk@sigwho{#1}}\n\\newcommand\\lk@sigmark[3]{\\ifx\\lk@sigwho\\@empty\\else{%\n \\def\\lkf@type{#1}\\let\\lkf@who\\lk@sigwho\n \\setlength\\lkf@width{#2}\\setlength\\lkf@height{#3}\\setlength\\lkf@raise{0pt}\\lkf@mark}\\fi}\n\n% A clause from the library: \\lkclause{title}{label}. Numbered like a\n% section; with no title, a bold number. Redefine it to change the style.\n\\providecommand\\lkclause[2]{\\ifx\\relax#1\\relax\\par\\refstepcounter{section}\\label{#2}\\noindent\\textbf{\\thesection.}~\\else\\section{#1}\\label{#2}\\fi}\n\n% A signature block: \\lksignature{organization}{name}{title}{signature}{date}.\n% The organization line is left out when empty (a person signing for\n% themselves). The signature sits on the line: an image or /s/ text in signed\n% builds, nothing otherwise. Two blocks fit side by side with \\hfill.\n\\newlength\\lksignaturewidth\n\\setlength\\lksignaturewidth{0.45\\linewidth}\n\\newlength\\lksignatureheight\n\\setlength\\lksignatureheight{2.2em}\n\\providecommand\\lksignatureimage[1]{\\includegraphics[height=\\lksignatureheight,keepaspectratio]{#1}}\n\\providecommand\\lksignature[5]{%\n \\begin{minipage}[t]{\\lksignaturewidth}\\raggedright\\setlength\\parindent{0pt}%\n \\ifx\\relax#1\\relax\\else\\textbf{#1}\\par\\fi\n \\vspace{\\dimexpr\\lksignatureheight+0.4em\\relax}%\n \\lk@sigmark{signature}{\\linewidth}{\\lksignatureheight}\\rlap{\\smash{\\raisebox{1pt}{#4}}}\\rule{\\linewidth}{0.4pt}\\par\n #2\\par\n \\ifx\\relax#3\\relax\\else#3\\par\\fi\n \\vspace{0.5em}%\n Date:~\\ifx\\relax#5\\relax\\lk@sigmark{date}{0.55\\linewidth}{1.2em}\\rule{0.55\\linewidth}{0.4pt}\\else#5\\fi\n \\end{minipage}\\gdef\\lk@sigwho{}}\n\n% An exhibit: a new page headed \"Exhibit A\", then its title.\n\\newcounter{lkexhibit}\n\\renewcommand\\thelkexhibit{\\Alph{lkexhibit}}\n\\providecommand\\lkexhibit[2]{%\n \\clearpage\\refstepcounter{lkexhibit}\\label{#2}%\n \\begin{center}{\\large\\bfseries Exhibit \\thelkexhibit}\\ifx\\relax#1\\relax\\else\\\\[0.3em]{\\bfseries #1}\\fi\\end{center}\\par}\n\n% A value the data does not have yet (draft builds only).\n\\newcommand\\lkmissing[1]{\\iflk@missingblank\\lkblank{#1}\\else\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}\\fi}\n\n% A filled-in value, in builds that highlight them (build --highlight), so a\n% reviewer can see what came from the record. Redefine it to change the look.\n\\providecommand\\lkvalue[1]{{\\color{red}#1}}\n\n\\iflk@draft\n \\RequirePackage{draftwatermark}\n \\SetWatermarkText{DRAFT}\n \\SetWatermarkScale{1}\n \\SetWatermarkColor[gray]{0.9}\n \\RequirePackage{eso-pic}\n \\AddToShipoutPictureFG{%\n \\AtPageLowerLeft{\\raisebox{6mm}{\\hspace{10mm}\\color{lkmeta}\\scriptsize\\ttfamily DRAFT \\lkstamp}}}\n\\fi\n\n\\iflk@rendered\\else\n % Previewing the template itself: show its structure.\n \\newcommand\\field[1]{\\lkblank{#1}}\n \\newcommand\\raw[1]{\\lkblank{#1}}\n \\newcommand\\docid{\\lkblank{docid}}\n \\newcommand\\when[2]{{\\color{lkmeta}\\tiny[if \\detokenize{#1}]}#2}\n \\newcommand\\otherwise[1]{{\\color{lkmeta}\\tiny[otherwise]}#1}\n \\newcommand\\each[3]{{\\color{lkmeta}\\tiny[each \\detokenize{#2} in \\detokenize{#1}]}#3}\n \\newcommand\\sep[1]{#1}\n \\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}\n \\newcommand\\clause[1]{\\par\\lkblank{clause #1}\\par}\n \\newcommand\\clauseref[1]{\\lkblank{ref #1}}\n \\newcommand\\signature[1]{\\lksignaturefor{#1}\\lksignature{\\lkblank{#1.name}}{\\lkblank{#1.signer.name}}{\\lkblank{#1.signer.title}}{}{}}\n \\newcommand\\component[2]{\\par\\lkblank{component #1}\\par}\n\\fi\n\n\\endinput\n";
|
package/esm/sty.js
CHANGED
|
@@ -12,7 +12,7 @@ export const LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
12
12
|
%
|
|
13
13
|
% https://github.com/constructive-io/latex-kit (MIT)
|
|
14
14
|
\\NeedsTeXFormat{LaTeX2e}
|
|
15
|
-
\\ProvidesPackage{latex-kit}[2026/11/
|
|
15
|
+
\\ProvidesPackage{latex-kit}[2026/11/26 v0.6 latex-kit template support]
|
|
16
16
|
|
|
17
17
|
\\newif\\iflk@rendered
|
|
18
18
|
\\newif\\iflk@draft
|
|
@@ -21,6 +21,14 @@ export const LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
21
21
|
\\DeclareOption{blank}{}
|
|
22
22
|
\\DeclareOption{final}{}
|
|
23
23
|
\\DeclareOption{signed}{}
|
|
24
|
+
% how a blank prints (blank builds and template previews)
|
|
25
|
+
\\newif\\iflk@blanklines
|
|
26
|
+
\\newif\\iflk@blanknames
|
|
27
|
+
\\DeclareOption{blanklines}{\\lk@blanklinestrue}
|
|
28
|
+
\\DeclareOption{blanknames}{\\lk@blanknamestrue}
|
|
29
|
+
% draft builds: print a missing value as a blank instead of a red marker
|
|
30
|
+
\\newif\\iflk@missingblank
|
|
31
|
+
\\DeclareOption{missingblank}{\\lk@missingblanktrue}
|
|
24
32
|
\\ProcessOptions\\relax
|
|
25
33
|
|
|
26
34
|
\\RequirePackage{xcolor}
|
|
@@ -33,7 +41,86 @@ export const LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
33
41
|
% A labelled blank line: \\lkblank{party.name}
|
|
34
42
|
\\newlength\\lkblankwidth
|
|
35
43
|
\\setlength\\lkblankwidth{3.5cm}
|
|
36
|
-
|
|
44
|
+
% Four ways to print it. Redefine any of them to change the look.
|
|
45
|
+
% labelled (default) the field's name, small, on a line
|
|
46
|
+
% line an empty line to write on (option blanklines)
|
|
47
|
+
% names the field's name in brackets, no line (option blanknames)
|
|
48
|
+
% and per field, through \\formfield[blank=…]: wide, none, label.
|
|
49
|
+
\\newcommand\\lkblanklabelled[1]{\\leavevmode\\underline{\\makebox[\\lkblankwidth][l]{\\color{lkmeta}\\tiny\\ttfamily\\detokenize{#1}}}}
|
|
50
|
+
\\newcommand\\lkblankline[1]{\\leavevmode\\underline{\\hspace{\\lkblankwidth}}}
|
|
51
|
+
\\newcommand\\lkblankwide[1]{\\leavevmode\\underline{\\hspace{2\\lkblankwidth}}}
|
|
52
|
+
\\newcommand\\lkblanknone[1]{}
|
|
53
|
+
\\newcommand\\lkblanklabel[1]{\\mbox{[\\ifx\\lkf@label\\@empty\\detokenize{#1}\\else\\lkf@label\\fi]}}
|
|
54
|
+
\\newcommand\\lkblanknames[1]{\\mbox{\\color{lkmeta}\\small\\ttfamily[\\detokenize{#1}]}}
|
|
55
|
+
\\newcommand\\lkblank[1]{%
|
|
56
|
+
\\iflk@blanknames\\lkblanknames{#1}%
|
|
57
|
+
\\else\\ifx\\lkf@blank\\@empty
|
|
58
|
+
\\iflk@blanklines\\lkblankline{#1}\\else\\lkblanklabelled{#1}\\fi
|
|
59
|
+
\\else
|
|
60
|
+
\\@ifundefined{lkblank\\lkf@blank}{\\lkblanklabelled{#1}}{\\csname lkblank\\lkf@blank\\endcsname{#1}}%
|
|
61
|
+
\\fi\\fi}
|
|
62
|
+
|
|
63
|
+
% Form hints: \\formfield[hints]{content} prints its content unchanged in a
|
|
64
|
+
% finished document. The hints tell blank forms how to print the spot, and
|
|
65
|
+
% tell form and signing software where it is.
|
|
66
|
+
% blank=line|wide|none|label how a blank prints here; label={Company Name}
|
|
67
|
+
% sets the bracketed text for blank=label
|
|
68
|
+
% type=signature|date|initials|text, who=<party>
|
|
69
|
+
% a spot for someone to fill in. Its page and
|
|
70
|
+
% position are written to <document>.form, which
|
|
71
|
+
% latex-kit turns into <document>.form.json
|
|
72
|
+
% label={Printed name} also says what to type
|
|
73
|
+
% in a type=text spot
|
|
74
|
+
% width=, height=, raise= the box for that spot: its bottom-left corner
|
|
75
|
+
% is where the content starts, moved up by raise
|
|
76
|
+
% (defaults 7cm, 24pt, 0pt)
|
|
77
|
+
\\def\\lkf@blank{}\\def\\lkf@label{}\\def\\lkf@type{}\\def\\lkf@who{}
|
|
78
|
+
\\newlength\\lkf@width
|
|
79
|
+
\\newlength\\lkf@height
|
|
80
|
+
\\newlength\\lkf@raise
|
|
81
|
+
\\define@key{lkf}{blank}{\\def\\lkf@blank{#1}}
|
|
82
|
+
\\define@key{lkf}{label}{\\def\\lkf@label{#1}}
|
|
83
|
+
\\define@key{lkf}{type}{\\def\\lkf@type{#1}}
|
|
84
|
+
\\define@key{lkf}{who}{\\def\\lkf@who{#1}}
|
|
85
|
+
\\define@key{lkf}{width}{\\setlength\\lkf@width{#1}}
|
|
86
|
+
\\define@key{lkf}{height}{\\setlength\\lkf@height{#1}}
|
|
87
|
+
\\define@key{lkf}{raise}{\\setlength\\lkf@raise{#1}}
|
|
88
|
+
\\newcommand\\formfield[2][]{{%
|
|
89
|
+
\\setlength\\lkf@width{7cm}\\setlength\\lkf@height{24pt}\\setlength\\lkf@raise{0pt}%
|
|
90
|
+
\\setkeys{lkf}{#1}\\lkf@mark #2}}
|
|
91
|
+
|
|
92
|
+
% Where a marked spot landed. One line per spot in <document>.form:
|
|
93
|
+
% type who page x y width height raise [label]
|
|
94
|
+
% lengths in scaled points; x and y from the bottom-left corner of the page.
|
|
95
|
+
% Needs an engine that can report positions (LuaTeX, pdfTeX, XeTeX).
|
|
96
|
+
\\newwrite\\lkf@out
|
|
97
|
+
\\newif\\iflkf@open
|
|
98
|
+
\\newif\\iflkf@can
|
|
99
|
+
\\@ifundefined{ReadonlyShipoutCounter}{}{%
|
|
100
|
+
\\ifdefined\\savepos
|
|
101
|
+
\\lkf@cantrue\\let\\lkf@savepos\\savepos
|
|
102
|
+
\\def\\lkf@x{\\the\\lastxpos}\\def\\lkf@y{\\the\\lastypos}%
|
|
103
|
+
\\else\\ifdefined\\pdfsavepos
|
|
104
|
+
\\lkf@cantrue\\let\\lkf@savepos\\pdfsavepos
|
|
105
|
+
\\def\\lkf@x{\\the\\pdflastxpos}\\def\\lkf@y{\\the\\pdflastypos}%
|
|
106
|
+
\\fi\\fi}
|
|
107
|
+
\\newcommand\\lkf@mark{%
|
|
108
|
+
\\ifx\\lkf@type\\@empty\\else\\iflkf@can
|
|
109
|
+
\\iflkf@open\\else\\immediate\\openout\\lkf@out=\\jobname.form\\relax\\global\\lkf@opentrue\\fi
|
|
110
|
+
\\leavevmode\\lkf@savepos
|
|
111
|
+
\\edef\\lkf@next{\\write\\lkf@out{\\lkf@type\\space\\ifx\\lkf@who\\@empty -\\else\\lkf@who\\fi\\space
|
|
112
|
+
\\noexpand\\the\\noexpand\\ReadonlyShipoutCounter\\space\\noexpand\\lkf@x\\space\\noexpand\\lkf@y\\space
|
|
113
|
+
\\number\\lkf@width\\space\\number\\lkf@height\\space\\number\\lkf@raise
|
|
114
|
+
\\ifx\\lkf@label\\@empty\\else\\space\\expandafter\\detokenize\\expandafter{\\lkf@label}\\fi}}%
|
|
115
|
+
\\lkf@next
|
|
116
|
+
\\fi\\fi}
|
|
117
|
+
% \\signature blocks mark their own signature and date lines for the party
|
|
118
|
+
% named by \\lksignaturefor{party}, which latex-kit writes before each block.
|
|
119
|
+
\\def\\lk@sigwho{}
|
|
120
|
+
\\newcommand\\lksignaturefor[1]{\\gdef\\lk@sigwho{#1}}
|
|
121
|
+
\\newcommand\\lk@sigmark[3]{\\ifx\\lk@sigwho\\@empty\\else{%
|
|
122
|
+
\\def\\lkf@type{#1}\\let\\lkf@who\\lk@sigwho
|
|
123
|
+
\\setlength\\lkf@width{#2}\\setlength\\lkf@height{#3}\\setlength\\lkf@raise{0pt}\\lkf@mark}\\fi}
|
|
37
124
|
|
|
38
125
|
% A clause from the library: \\lkclause{title}{label}. Numbered like a
|
|
39
126
|
% section; with no title, a bold number. Redefine it to change the style.
|
|
@@ -52,12 +139,12 @@ export const LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
52
139
|
\\begin{minipage}[t]{\\lksignaturewidth}\\raggedright\\setlength\\parindent{0pt}%
|
|
53
140
|
\\ifx\\relax#1\\relax\\else\\textbf{#1}\\par\\fi
|
|
54
141
|
\\vspace{\\dimexpr\\lksignatureheight+0.4em\\relax}%
|
|
55
|
-
\\rlap{\\smash{\\raisebox{1pt}{#4}}}\\rule{\\linewidth}{0.4pt}\\par
|
|
142
|
+
\\lk@sigmark{signature}{\\linewidth}{\\lksignatureheight}\\rlap{\\smash{\\raisebox{1pt}{#4}}}\\rule{\\linewidth}{0.4pt}\\par
|
|
56
143
|
#2\\par
|
|
57
144
|
\\ifx\\relax#3\\relax\\else#3\\par\\fi
|
|
58
145
|
\\vspace{0.5em}%
|
|
59
|
-
Date:~\\ifx\\relax#5\\relax\\rule{0.55\\linewidth}{0.4pt}\\else#5\\fi
|
|
60
|
-
\\end{minipage}}
|
|
146
|
+
Date:~\\ifx\\relax#5\\relax\\lk@sigmark{date}{0.55\\linewidth}{1.2em}\\rule{0.55\\linewidth}{0.4pt}\\else#5\\fi
|
|
147
|
+
\\end{minipage}\\gdef\\lk@sigwho{}}
|
|
61
148
|
|
|
62
149
|
% An exhibit: a new page headed "Exhibit A", then its title.
|
|
63
150
|
\\newcounter{lkexhibit}
|
|
@@ -67,7 +154,11 @@ export const LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
67
154
|
\\begin{center}{\\large\\bfseries Exhibit \\thelkexhibit}\\ifx\\relax#1\\relax\\else\\\\[0.3em]{\\bfseries #1}\\fi\\end{center}\\par}
|
|
68
155
|
|
|
69
156
|
% A value the data does not have yet (draft builds only).
|
|
70
|
-
\\newcommand\\lkmissing[1]{\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}}
|
|
157
|
+
\\newcommand\\lkmissing[1]{\\iflk@missingblank\\lkblank{#1}\\else\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}\\fi}
|
|
158
|
+
|
|
159
|
+
% A filled-in value, in builds that highlight them (build --highlight), so a
|
|
160
|
+
% reviewer can see what came from the record. Redefine it to change the look.
|
|
161
|
+
\\providecommand\\lkvalue[1]{{\\color{red}#1}}
|
|
71
162
|
|
|
72
163
|
\\iflk@draft
|
|
73
164
|
\\RequirePackage{draftwatermark}
|
|
@@ -91,7 +182,7 @@ export const LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
91
182
|
\\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}
|
|
92
183
|
\\newcommand\\clause[1]{\\par\\lkblank{clause #1}\\par}
|
|
93
184
|
\\newcommand\\clauseref[1]{\\lkblank{ref #1}}
|
|
94
|
-
\\newcommand\\signature[1]{\\lksignature{\\lkblank{#1.name}}{\\lkblank{#1.signer.name}}{\\lkblank{#1.signer.title}}{}{}}
|
|
185
|
+
\\newcommand\\signature[1]{\\lksignaturefor{#1}\\lksignature{\\lkblank{#1.name}}{\\lkblank{#1.signer.name}}{\\lkblank{#1.signer.title}}{}{}}
|
|
95
186
|
\\newcommand\\component[2]{\\par\\lkblank{component #1}\\par}
|
|
96
187
|
\\fi
|
|
97
188
|
|
package/evaluate.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface EvaluateOptions {
|
|
|
18
18
|
* for `draft`; `final` and `signed` always fail on a missing value.
|
|
19
19
|
*/
|
|
20
20
|
allowMissing?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap every value a `\field` fills in with `\lkvalue{…}`, which prints it
|
|
23
|
+
* in red: a review copy that shows what came from the record. Not for
|
|
24
|
+
* `\raw` fields, whose LaTeX may not survive being an argument.
|
|
25
|
+
*/
|
|
26
|
+
markValues?: boolean;
|
|
21
27
|
/** Resolve \snippet{name} from the file that uses it. */
|
|
22
28
|
loadSnippet?: (name: string, from: string) => CompiledTemplate | null;
|
|
23
29
|
/** Resolve \clause{id} from the clause library. */
|
package/evaluate.js
CHANGED
|
@@ -180,7 +180,12 @@ function evaluateTemplate(template, options) {
|
|
|
180
180
|
}
|
|
181
181
|
const isGone = !result.defaulted && (0, filters_1.isMissing)(result.value);
|
|
182
182
|
fields.push({ path, ...node.loc, missing: isGone });
|
|
183
|
-
|
|
183
|
+
if (isGone)
|
|
184
|
+
out += missing(path, node.loc);
|
|
185
|
+
else {
|
|
186
|
+
const tex = toTex(result.value, node.raw, result.newlines, path, node.loc);
|
|
187
|
+
out += options.markValues && tex && !node.raw ? `\\lkvalue{${tex}}` : tex;
|
|
188
|
+
}
|
|
184
189
|
break;
|
|
185
190
|
}
|
|
186
191
|
case 'docid':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latex-kit/template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "The latex-kit template language: fill-in macros inside real .tex files, checked and escaped",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@unified-latex/unified-latex-util-parse": "^1.8.4",
|
|
33
|
-
"@latex-kit/escape": "0.3.
|
|
33
|
+
"@latex-kit/escape": "0.3.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"copy": "makage assets",
|
package/signature.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export declare class SignatureError extends Error {
|
|
|
26
26
|
name: string;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}
|
|
29
|
+
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}`,
|
|
30
|
+
* after `\lksignaturefor{party}` so the block can mark where that party signs.
|
|
30
31
|
*
|
|
31
32
|
* A party with a `signer` (or `kind: organization`) is an organization: its
|
|
32
33
|
* name in bold, then the signer's name and title. Anything else signs for
|
package/signature.js
CHANGED
|
@@ -13,7 +13,8 @@ const text = (v) => (typeof v === 'string' && v.trim() !== '' ? v : undefined);
|
|
|
13
13
|
/** Image paths must be plain relative names, so they can never inject LaTeX. */
|
|
14
14
|
const SAFE_IMAGE_PATH = /^[A-Za-z0-9_./-]+$/;
|
|
15
15
|
/**
|
|
16
|
-
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}
|
|
16
|
+
* A signature block for a party: `\lksignature{org}{name}{title}{signature}{date}`,
|
|
17
|
+
* after `\lksignaturefor{party}` so the block can mark where that party signs.
|
|
17
18
|
*
|
|
18
19
|
* A party with a `signer` (or `kind: organization`) is an organization: its
|
|
19
20
|
* name in bold, then the signer's name and title. Anything else signs for
|
|
@@ -23,7 +24,7 @@ const SAFE_IMAGE_PATH = /^[A-Za-z0-9_./-]+$/;
|
|
|
23
24
|
function signatureBlock(value, o) {
|
|
24
25
|
const p = o.path;
|
|
25
26
|
if (o.variant === 'blank') {
|
|
26
|
-
return `\\lksignature{\\lkblank{${p}.name}}{\\lkblank{${p}.signer.name}}{\\lkblank{${p}.signer.title}}{}{}`;
|
|
27
|
+
return `\\lksignaturefor{${p}}\\lksignature{\\lkblank{${p}.name}}{\\lkblank{${p}.signer.name}}{\\lkblank{${p}.signer.title}}{}{}`;
|
|
27
28
|
}
|
|
28
29
|
if (value === undefined || value === null)
|
|
29
30
|
return o.missing(p);
|
|
@@ -55,5 +56,5 @@ function signatureBlock(value, o) {
|
|
|
55
56
|
if (signed)
|
|
56
57
|
date = (0, escape_1.escapeLatex)(String(filters_1.FILTERS.date.apply(signed, 'long', { locale: o.locale }, {})));
|
|
57
58
|
}
|
|
58
|
-
return `\\lksignature{${org}}{${nameTex}}{${titleTex}}{${sign}}{${date}}`;
|
|
59
|
+
return `\\lksignaturefor{${p}}\\lksignature{${org}}{${nameTex}}{${titleTex}}{${sign}}{${date}}`;
|
|
59
60
|
}
|
package/sty.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* every generated document; `latex-kit sty <dir>` writes it for previewing
|
|
4
4
|
* templates in an editor.
|
|
5
5
|
*/
|
|
6
|
-
export declare const LATEX_KIT_STY = "% latex-kit.sty: support for latex-kit templates.\n%\n% Load it in a template with \\usepackage{latex-kit}. Compiled directly, a\n% template previews as a blank form: every \\field becomes a labelled line.\n% When latex-kit renders a document it passes the `rendered` option and the\n% variant (draft, blank, final, signed); the template macros are gone by then.\n%\n% https://github.com/constructive-io/latex-kit (MIT)\n\\NeedsTeXFormat{LaTeX2e}\n\\ProvidesPackage{latex-kit}[2026/11/
|
|
6
|
+
export declare const LATEX_KIT_STY = "% latex-kit.sty: support for latex-kit templates.\n%\n% Load it in a template with \\usepackage{latex-kit}. Compiled directly, a\n% template previews as a blank form: every \\field becomes a labelled line.\n% When latex-kit renders a document it passes the `rendered` option and the\n% variant (draft, blank, final, signed); the template macros are gone by then.\n%\n% https://github.com/constructive-io/latex-kit (MIT)\n\\NeedsTeXFormat{LaTeX2e}\n\\ProvidesPackage{latex-kit}[2026/11/26 v0.6 latex-kit template support]\n\n\\newif\\iflk@rendered\n\\newif\\iflk@draft\n\\DeclareOption{rendered}{\\lk@renderedtrue}\n\\DeclareOption{draft}{\\lk@drafttrue}\n\\DeclareOption{blank}{}\n\\DeclareOption{final}{}\n\\DeclareOption{signed}{}\n% how a blank prints (blank builds and template previews)\n\\newif\\iflk@blanklines\n\\newif\\iflk@blanknames\n\\DeclareOption{blanklines}{\\lk@blanklinestrue}\n\\DeclareOption{blanknames}{\\lk@blanknamestrue}\n% draft builds: print a missing value as a blank instead of a red marker\n\\newif\\iflk@missingblank\n\\DeclareOption{missingblank}{\\lk@missingblanktrue}\n\\ProcessOptions\\relax\n\n\\RequirePackage{xcolor}\n\\RequirePackage{graphicx}\n% tables from latex-kit components (table(), line items)\n\\RequirePackage{array,tabularx,booktabs}\n\\definecolor{lkmeta}{gray}{0.55}\n\\providecommand\\lkstamp{}\n\n% A labelled blank line: \\lkblank{party.name}\n\\newlength\\lkblankwidth\n\\setlength\\lkblankwidth{3.5cm}\n% Four ways to print it. Redefine any of them to change the look.\n% labelled (default) the field's name, small, on a line\n% line an empty line to write on (option blanklines)\n% names the field's name in brackets, no line (option blanknames)\n% and per field, through \\formfield[blank=\u2026]: wide, none, label.\n\\newcommand\\lkblanklabelled[1]{\\leavevmode\\underline{\\makebox[\\lkblankwidth][l]{\\color{lkmeta}\\tiny\\ttfamily\\detokenize{#1}}}}\n\\newcommand\\lkblankline[1]{\\leavevmode\\underline{\\hspace{\\lkblankwidth}}}\n\\newcommand\\lkblankwide[1]{\\leavevmode\\underline{\\hspace{2\\lkblankwidth}}}\n\\newcommand\\lkblanknone[1]{}\n\\newcommand\\lkblanklabel[1]{\\mbox{[\\ifx\\lkf@label\\@empty\\detokenize{#1}\\else\\lkf@label\\fi]}}\n\\newcommand\\lkblanknames[1]{\\mbox{\\color{lkmeta}\\small\\ttfamily[\\detokenize{#1}]}}\n\\newcommand\\lkblank[1]{%\n \\iflk@blanknames\\lkblanknames{#1}%\n \\else\\ifx\\lkf@blank\\@empty\n \\iflk@blanklines\\lkblankline{#1}\\else\\lkblanklabelled{#1}\\fi\n \\else\n \\@ifundefined{lkblank\\lkf@blank}{\\lkblanklabelled{#1}}{\\csname lkblank\\lkf@blank\\endcsname{#1}}%\n \\fi\\fi}\n\n% Form hints: \\formfield[hints]{content} prints its content unchanged in a\n% finished document. The hints tell blank forms how to print the spot, and\n% tell form and signing software where it is.\n% blank=line|wide|none|label how a blank prints here; label={Company Name}\n% sets the bracketed text for blank=label\n% type=signature|date|initials|text, who=<party>\n% a spot for someone to fill in. Its page and\n% position are written to <document>.form, which\n% latex-kit turns into <document>.form.json\n% label={Printed name} also says what to type\n% in a type=text spot\n% width=, height=, raise= the box for that spot: its bottom-left corner\n% is where the content starts, moved up by raise\n% (defaults 7cm, 24pt, 0pt)\n\\def\\lkf@blank{}\\def\\lkf@label{}\\def\\lkf@type{}\\def\\lkf@who{}\n\\newlength\\lkf@width\n\\newlength\\lkf@height\n\\newlength\\lkf@raise\n\\define@key{lkf}{blank}{\\def\\lkf@blank{#1}}\n\\define@key{lkf}{label}{\\def\\lkf@label{#1}}\n\\define@key{lkf}{type}{\\def\\lkf@type{#1}}\n\\define@key{lkf}{who}{\\def\\lkf@who{#1}}\n\\define@key{lkf}{width}{\\setlength\\lkf@width{#1}}\n\\define@key{lkf}{height}{\\setlength\\lkf@height{#1}}\n\\define@key{lkf}{raise}{\\setlength\\lkf@raise{#1}}\n\\newcommand\\formfield[2][]{{%\n \\setlength\\lkf@width{7cm}\\setlength\\lkf@height{24pt}\\setlength\\lkf@raise{0pt}%\n \\setkeys{lkf}{#1}\\lkf@mark #2}}\n\n% Where a marked spot landed. One line per spot in <document>.form:\n% type who page x y width height raise [label]\n% lengths in scaled points; x and y from the bottom-left corner of the page.\n% Needs an engine that can report positions (LuaTeX, pdfTeX, XeTeX).\n\\newwrite\\lkf@out\n\\newif\\iflkf@open\n\\newif\\iflkf@can\n\\@ifundefined{ReadonlyShipoutCounter}{}{%\n \\ifdefined\\savepos\n \\lkf@cantrue\\let\\lkf@savepos\\savepos\n \\def\\lkf@x{\\the\\lastxpos}\\def\\lkf@y{\\the\\lastypos}%\n \\else\\ifdefined\\pdfsavepos\n \\lkf@cantrue\\let\\lkf@savepos\\pdfsavepos\n \\def\\lkf@x{\\the\\pdflastxpos}\\def\\lkf@y{\\the\\pdflastypos}%\n \\fi\\fi}\n\\newcommand\\lkf@mark{%\n \\ifx\\lkf@type\\@empty\\else\\iflkf@can\n \\iflkf@open\\else\\immediate\\openout\\lkf@out=\\jobname.form\\relax\\global\\lkf@opentrue\\fi\n \\leavevmode\\lkf@savepos\n \\edef\\lkf@next{\\write\\lkf@out{\\lkf@type\\space\\ifx\\lkf@who\\@empty -\\else\\lkf@who\\fi\\space\n \\noexpand\\the\\noexpand\\ReadonlyShipoutCounter\\space\\noexpand\\lkf@x\\space\\noexpand\\lkf@y\\space\n \\number\\lkf@width\\space\\number\\lkf@height\\space\\number\\lkf@raise\n \\ifx\\lkf@label\\@empty\\else\\space\\expandafter\\detokenize\\expandafter{\\lkf@label}\\fi}}%\n \\lkf@next\n \\fi\\fi}\n% \\signature blocks mark their own signature and date lines for the party\n% named by \\lksignaturefor{party}, which latex-kit writes before each block.\n\\def\\lk@sigwho{}\n\\newcommand\\lksignaturefor[1]{\\gdef\\lk@sigwho{#1}}\n\\newcommand\\lk@sigmark[3]{\\ifx\\lk@sigwho\\@empty\\else{%\n \\def\\lkf@type{#1}\\let\\lkf@who\\lk@sigwho\n \\setlength\\lkf@width{#2}\\setlength\\lkf@height{#3}\\setlength\\lkf@raise{0pt}\\lkf@mark}\\fi}\n\n% A clause from the library: \\lkclause{title}{label}. Numbered like a\n% section; with no title, a bold number. Redefine it to change the style.\n\\providecommand\\lkclause[2]{\\ifx\\relax#1\\relax\\par\\refstepcounter{section}\\label{#2}\\noindent\\textbf{\\thesection.}~\\else\\section{#1}\\label{#2}\\fi}\n\n% A signature block: \\lksignature{organization}{name}{title}{signature}{date}.\n% The organization line is left out when empty (a person signing for\n% themselves). The signature sits on the line: an image or /s/ text in signed\n% builds, nothing otherwise. Two blocks fit side by side with \\hfill.\n\\newlength\\lksignaturewidth\n\\setlength\\lksignaturewidth{0.45\\linewidth}\n\\newlength\\lksignatureheight\n\\setlength\\lksignatureheight{2.2em}\n\\providecommand\\lksignatureimage[1]{\\includegraphics[height=\\lksignatureheight,keepaspectratio]{#1}}\n\\providecommand\\lksignature[5]{%\n \\begin{minipage}[t]{\\lksignaturewidth}\\raggedright\\setlength\\parindent{0pt}%\n \\ifx\\relax#1\\relax\\else\\textbf{#1}\\par\\fi\n \\vspace{\\dimexpr\\lksignatureheight+0.4em\\relax}%\n \\lk@sigmark{signature}{\\linewidth}{\\lksignatureheight}\\rlap{\\smash{\\raisebox{1pt}{#4}}}\\rule{\\linewidth}{0.4pt}\\par\n #2\\par\n \\ifx\\relax#3\\relax\\else#3\\par\\fi\n \\vspace{0.5em}%\n Date:~\\ifx\\relax#5\\relax\\lk@sigmark{date}{0.55\\linewidth}{1.2em}\\rule{0.55\\linewidth}{0.4pt}\\else#5\\fi\n \\end{minipage}\\gdef\\lk@sigwho{}}\n\n% An exhibit: a new page headed \"Exhibit A\", then its title.\n\\newcounter{lkexhibit}\n\\renewcommand\\thelkexhibit{\\Alph{lkexhibit}}\n\\providecommand\\lkexhibit[2]{%\n \\clearpage\\refstepcounter{lkexhibit}\\label{#2}%\n \\begin{center}{\\large\\bfseries Exhibit \\thelkexhibit}\\ifx\\relax#1\\relax\\else\\\\[0.3em]{\\bfseries #1}\\fi\\end{center}\\par}\n\n% A value the data does not have yet (draft builds only).\n\\newcommand\\lkmissing[1]{\\iflk@missingblank\\lkblank{#1}\\else\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}\\fi}\n\n% A filled-in value, in builds that highlight them (build --highlight), so a\n% reviewer can see what came from the record. Redefine it to change the look.\n\\providecommand\\lkvalue[1]{{\\color{red}#1}}\n\n\\iflk@draft\n \\RequirePackage{draftwatermark}\n \\SetWatermarkText{DRAFT}\n \\SetWatermarkScale{1}\n \\SetWatermarkColor[gray]{0.9}\n \\RequirePackage{eso-pic}\n \\AddToShipoutPictureFG{%\n \\AtPageLowerLeft{\\raisebox{6mm}{\\hspace{10mm}\\color{lkmeta}\\scriptsize\\ttfamily DRAFT \\lkstamp}}}\n\\fi\n\n\\iflk@rendered\\else\n % Previewing the template itself: show its structure.\n \\newcommand\\field[1]{\\lkblank{#1}}\n \\newcommand\\raw[1]{\\lkblank{#1}}\n \\newcommand\\docid{\\lkblank{docid}}\n \\newcommand\\when[2]{{\\color{lkmeta}\\tiny[if \\detokenize{#1}]}#2}\n \\newcommand\\otherwise[1]{{\\color{lkmeta}\\tiny[otherwise]}#1}\n \\newcommand\\each[3]{{\\color{lkmeta}\\tiny[each \\detokenize{#2} in \\detokenize{#1}]}#3}\n \\newcommand\\sep[1]{#1}\n \\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}\n \\newcommand\\clause[1]{\\par\\lkblank{clause #1}\\par}\n \\newcommand\\clauseref[1]{\\lkblank{ref #1}}\n \\newcommand\\signature[1]{\\lksignaturefor{#1}\\lksignature{\\lkblank{#1.name}}{\\lkblank{#1.signer.name}}{\\lkblank{#1.signer.title}}{}{}}\n \\newcommand\\component[2]{\\par\\lkblank{component #1}\\par}\n\\fi\n\n\\endinput\n";
|
package/sty.js
CHANGED
|
@@ -15,7 +15,7 @@ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
15
15
|
%
|
|
16
16
|
% https://github.com/constructive-io/latex-kit (MIT)
|
|
17
17
|
\\NeedsTeXFormat{LaTeX2e}
|
|
18
|
-
\\ProvidesPackage{latex-kit}[2026/11/
|
|
18
|
+
\\ProvidesPackage{latex-kit}[2026/11/26 v0.6 latex-kit template support]
|
|
19
19
|
|
|
20
20
|
\\newif\\iflk@rendered
|
|
21
21
|
\\newif\\iflk@draft
|
|
@@ -24,6 +24,14 @@ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
24
24
|
\\DeclareOption{blank}{}
|
|
25
25
|
\\DeclareOption{final}{}
|
|
26
26
|
\\DeclareOption{signed}{}
|
|
27
|
+
% how a blank prints (blank builds and template previews)
|
|
28
|
+
\\newif\\iflk@blanklines
|
|
29
|
+
\\newif\\iflk@blanknames
|
|
30
|
+
\\DeclareOption{blanklines}{\\lk@blanklinestrue}
|
|
31
|
+
\\DeclareOption{blanknames}{\\lk@blanknamestrue}
|
|
32
|
+
% draft builds: print a missing value as a blank instead of a red marker
|
|
33
|
+
\\newif\\iflk@missingblank
|
|
34
|
+
\\DeclareOption{missingblank}{\\lk@missingblanktrue}
|
|
27
35
|
\\ProcessOptions\\relax
|
|
28
36
|
|
|
29
37
|
\\RequirePackage{xcolor}
|
|
@@ -36,7 +44,86 @@ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
36
44
|
% A labelled blank line: \\lkblank{party.name}
|
|
37
45
|
\\newlength\\lkblankwidth
|
|
38
46
|
\\setlength\\lkblankwidth{3.5cm}
|
|
39
|
-
|
|
47
|
+
% Four ways to print it. Redefine any of them to change the look.
|
|
48
|
+
% labelled (default) the field's name, small, on a line
|
|
49
|
+
% line an empty line to write on (option blanklines)
|
|
50
|
+
% names the field's name in brackets, no line (option blanknames)
|
|
51
|
+
% and per field, through \\formfield[blank=…]: wide, none, label.
|
|
52
|
+
\\newcommand\\lkblanklabelled[1]{\\leavevmode\\underline{\\makebox[\\lkblankwidth][l]{\\color{lkmeta}\\tiny\\ttfamily\\detokenize{#1}}}}
|
|
53
|
+
\\newcommand\\lkblankline[1]{\\leavevmode\\underline{\\hspace{\\lkblankwidth}}}
|
|
54
|
+
\\newcommand\\lkblankwide[1]{\\leavevmode\\underline{\\hspace{2\\lkblankwidth}}}
|
|
55
|
+
\\newcommand\\lkblanknone[1]{}
|
|
56
|
+
\\newcommand\\lkblanklabel[1]{\\mbox{[\\ifx\\lkf@label\\@empty\\detokenize{#1}\\else\\lkf@label\\fi]}}
|
|
57
|
+
\\newcommand\\lkblanknames[1]{\\mbox{\\color{lkmeta}\\small\\ttfamily[\\detokenize{#1}]}}
|
|
58
|
+
\\newcommand\\lkblank[1]{%
|
|
59
|
+
\\iflk@blanknames\\lkblanknames{#1}%
|
|
60
|
+
\\else\\ifx\\lkf@blank\\@empty
|
|
61
|
+
\\iflk@blanklines\\lkblankline{#1}\\else\\lkblanklabelled{#1}\\fi
|
|
62
|
+
\\else
|
|
63
|
+
\\@ifundefined{lkblank\\lkf@blank}{\\lkblanklabelled{#1}}{\\csname lkblank\\lkf@blank\\endcsname{#1}}%
|
|
64
|
+
\\fi\\fi}
|
|
65
|
+
|
|
66
|
+
% Form hints: \\formfield[hints]{content} prints its content unchanged in a
|
|
67
|
+
% finished document. The hints tell blank forms how to print the spot, and
|
|
68
|
+
% tell form and signing software where it is.
|
|
69
|
+
% blank=line|wide|none|label how a blank prints here; label={Company Name}
|
|
70
|
+
% sets the bracketed text for blank=label
|
|
71
|
+
% type=signature|date|initials|text, who=<party>
|
|
72
|
+
% a spot for someone to fill in. Its page and
|
|
73
|
+
% position are written to <document>.form, which
|
|
74
|
+
% latex-kit turns into <document>.form.json
|
|
75
|
+
% label={Printed name} also says what to type
|
|
76
|
+
% in a type=text spot
|
|
77
|
+
% width=, height=, raise= the box for that spot: its bottom-left corner
|
|
78
|
+
% is where the content starts, moved up by raise
|
|
79
|
+
% (defaults 7cm, 24pt, 0pt)
|
|
80
|
+
\\def\\lkf@blank{}\\def\\lkf@label{}\\def\\lkf@type{}\\def\\lkf@who{}
|
|
81
|
+
\\newlength\\lkf@width
|
|
82
|
+
\\newlength\\lkf@height
|
|
83
|
+
\\newlength\\lkf@raise
|
|
84
|
+
\\define@key{lkf}{blank}{\\def\\lkf@blank{#1}}
|
|
85
|
+
\\define@key{lkf}{label}{\\def\\lkf@label{#1}}
|
|
86
|
+
\\define@key{lkf}{type}{\\def\\lkf@type{#1}}
|
|
87
|
+
\\define@key{lkf}{who}{\\def\\lkf@who{#1}}
|
|
88
|
+
\\define@key{lkf}{width}{\\setlength\\lkf@width{#1}}
|
|
89
|
+
\\define@key{lkf}{height}{\\setlength\\lkf@height{#1}}
|
|
90
|
+
\\define@key{lkf}{raise}{\\setlength\\lkf@raise{#1}}
|
|
91
|
+
\\newcommand\\formfield[2][]{{%
|
|
92
|
+
\\setlength\\lkf@width{7cm}\\setlength\\lkf@height{24pt}\\setlength\\lkf@raise{0pt}%
|
|
93
|
+
\\setkeys{lkf}{#1}\\lkf@mark #2}}
|
|
94
|
+
|
|
95
|
+
% Where a marked spot landed. One line per spot in <document>.form:
|
|
96
|
+
% type who page x y width height raise [label]
|
|
97
|
+
% lengths in scaled points; x and y from the bottom-left corner of the page.
|
|
98
|
+
% Needs an engine that can report positions (LuaTeX, pdfTeX, XeTeX).
|
|
99
|
+
\\newwrite\\lkf@out
|
|
100
|
+
\\newif\\iflkf@open
|
|
101
|
+
\\newif\\iflkf@can
|
|
102
|
+
\\@ifundefined{ReadonlyShipoutCounter}{}{%
|
|
103
|
+
\\ifdefined\\savepos
|
|
104
|
+
\\lkf@cantrue\\let\\lkf@savepos\\savepos
|
|
105
|
+
\\def\\lkf@x{\\the\\lastxpos}\\def\\lkf@y{\\the\\lastypos}%
|
|
106
|
+
\\else\\ifdefined\\pdfsavepos
|
|
107
|
+
\\lkf@cantrue\\let\\lkf@savepos\\pdfsavepos
|
|
108
|
+
\\def\\lkf@x{\\the\\pdflastxpos}\\def\\lkf@y{\\the\\pdflastypos}%
|
|
109
|
+
\\fi\\fi}
|
|
110
|
+
\\newcommand\\lkf@mark{%
|
|
111
|
+
\\ifx\\lkf@type\\@empty\\else\\iflkf@can
|
|
112
|
+
\\iflkf@open\\else\\immediate\\openout\\lkf@out=\\jobname.form\\relax\\global\\lkf@opentrue\\fi
|
|
113
|
+
\\leavevmode\\lkf@savepos
|
|
114
|
+
\\edef\\lkf@next{\\write\\lkf@out{\\lkf@type\\space\\ifx\\lkf@who\\@empty -\\else\\lkf@who\\fi\\space
|
|
115
|
+
\\noexpand\\the\\noexpand\\ReadonlyShipoutCounter\\space\\noexpand\\lkf@x\\space\\noexpand\\lkf@y\\space
|
|
116
|
+
\\number\\lkf@width\\space\\number\\lkf@height\\space\\number\\lkf@raise
|
|
117
|
+
\\ifx\\lkf@label\\@empty\\else\\space\\expandafter\\detokenize\\expandafter{\\lkf@label}\\fi}}%
|
|
118
|
+
\\lkf@next
|
|
119
|
+
\\fi\\fi}
|
|
120
|
+
% \\signature blocks mark their own signature and date lines for the party
|
|
121
|
+
% named by \\lksignaturefor{party}, which latex-kit writes before each block.
|
|
122
|
+
\\def\\lk@sigwho{}
|
|
123
|
+
\\newcommand\\lksignaturefor[1]{\\gdef\\lk@sigwho{#1}}
|
|
124
|
+
\\newcommand\\lk@sigmark[3]{\\ifx\\lk@sigwho\\@empty\\else{%
|
|
125
|
+
\\def\\lkf@type{#1}\\let\\lkf@who\\lk@sigwho
|
|
126
|
+
\\setlength\\lkf@width{#2}\\setlength\\lkf@height{#3}\\setlength\\lkf@raise{0pt}\\lkf@mark}\\fi}
|
|
40
127
|
|
|
41
128
|
% A clause from the library: \\lkclause{title}{label}. Numbered like a
|
|
42
129
|
% section; with no title, a bold number. Redefine it to change the style.
|
|
@@ -55,12 +142,12 @@ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
55
142
|
\\begin{minipage}[t]{\\lksignaturewidth}\\raggedright\\setlength\\parindent{0pt}%
|
|
56
143
|
\\ifx\\relax#1\\relax\\else\\textbf{#1}\\par\\fi
|
|
57
144
|
\\vspace{\\dimexpr\\lksignatureheight+0.4em\\relax}%
|
|
58
|
-
\\rlap{\\smash{\\raisebox{1pt}{#4}}}\\rule{\\linewidth}{0.4pt}\\par
|
|
145
|
+
\\lk@sigmark{signature}{\\linewidth}{\\lksignatureheight}\\rlap{\\smash{\\raisebox{1pt}{#4}}}\\rule{\\linewidth}{0.4pt}\\par
|
|
59
146
|
#2\\par
|
|
60
147
|
\\ifx\\relax#3\\relax\\else#3\\par\\fi
|
|
61
148
|
\\vspace{0.5em}%
|
|
62
|
-
Date:~\\ifx\\relax#5\\relax\\rule{0.55\\linewidth}{0.4pt}\\else#5\\fi
|
|
63
|
-
\\end{minipage}}
|
|
149
|
+
Date:~\\ifx\\relax#5\\relax\\lk@sigmark{date}{0.55\\linewidth}{1.2em}\\rule{0.55\\linewidth}{0.4pt}\\else#5\\fi
|
|
150
|
+
\\end{minipage}\\gdef\\lk@sigwho{}}
|
|
64
151
|
|
|
65
152
|
% An exhibit: a new page headed "Exhibit A", then its title.
|
|
66
153
|
\\newcounter{lkexhibit}
|
|
@@ -70,7 +157,11 @@ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
70
157
|
\\begin{center}{\\large\\bfseries Exhibit \\thelkexhibit}\\ifx\\relax#1\\relax\\else\\\\[0.3em]{\\bfseries #1}\\fi\\end{center}\\par}
|
|
71
158
|
|
|
72
159
|
% A value the data does not have yet (draft builds only).
|
|
73
|
-
\\newcommand\\lkmissing[1]{\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}}
|
|
160
|
+
\\newcommand\\lkmissing[1]{\\iflk@missingblank\\lkblank{#1}\\else\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}\\fi}
|
|
161
|
+
|
|
162
|
+
% A filled-in value, in builds that highlight them (build --highlight), so a
|
|
163
|
+
% reviewer can see what came from the record. Redefine it to change the look.
|
|
164
|
+
\\providecommand\\lkvalue[1]{{\\color{red}#1}}
|
|
74
165
|
|
|
75
166
|
\\iflk@draft
|
|
76
167
|
\\RequirePackage{draftwatermark}
|
|
@@ -94,7 +185,7 @@ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
|
|
|
94
185
|
\\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}
|
|
95
186
|
\\newcommand\\clause[1]{\\par\\lkblank{clause #1}\\par}
|
|
96
187
|
\\newcommand\\clauseref[1]{\\lkblank{ref #1}}
|
|
97
|
-
\\newcommand\\signature[1]{\\lksignature{\\lkblank{#1.name}}{\\lkblank{#1.signer.name}}{\\lkblank{#1.signer.title}}{}{}}
|
|
188
|
+
\\newcommand\\signature[1]{\\lksignaturefor{#1}\\lksignature{\\lkblank{#1.name}}{\\lkblank{#1.signer.name}}{\\lkblank{#1.signer.title}}{}{}}
|
|
98
189
|
\\newcommand\\component[2]{\\par\\lkblank{component #1}\\par}
|
|
99
190
|
\\fi
|
|
100
191
|
|