From d7aac52ac7a9b44dca9d8082f737b139454401c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= <4056726+mwaeckerlin@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:14:55 +0100 Subject: [PATCH] 1.0.2: converter searches no subfolders, safer filters, forms, links and watermark A document at the root of a checkout of 68377 folders needed 56 minutes, because the converter named the suite, the document folder and the build folder with `//` in TEXINPUTS; it now names them without recursion and the same document converts in 11.5 seconds. A file below the document no longer replaces a package of TeX Live. The security review of the pending changes found four defects, each fixed with a test proven red against the old files and green against the new ones twice: an HTML table read in an empty sandbox, so an iframe opens no address; form labels written through the LaTeX writer, so they are set as text; the form pattern scans a line once instead of quadratically; a kept build folder no longer lays the links of an earlier drawing over a new one. The form tests remove the PDF of an earlier run before each conversion. Also carried: forms out of Markdown, link colours from the company, clickable links in prose, HTML tables and SVG drawings, the watermark, and the further changes of 1.0.1 and 1.0.2 in the CHANGELOG. npm test: 1232 of 1232 checks. Co-Authored-By: Claude Opus 5.5 --- BUGS.md | 38 + CHANGELOG.md | 41 + FEATURES.md | 44 +- README.md | 104 +- TESTS.md | 106 +- TODO.md | 13 +- bin/code.lua | 48 +- bin/figures.lua | 22 +- bin/forms.lua | 248 +++++ bin/html.lua | 26 + bin/logo.py | 97 ++ bin/md2pdf.py | 88 +- bin/svg.lua | 94 +- examples/letter.pdf | Bin 29277 -> 29270 bytes examples/logo-example.pdf | Bin 29425 -> 29413 bytes examples/presentation.pdf | Bin 35877 -> 41259 bytes examples/report.pdf | Bin 41555 -> 41607 bytes examples/sample.pdf | Bin 73270 -> 73250 bytes package.json | 5 +- tests/forms.py | 303 ++++++ tests/identity.py | 910 ++++++++++++++++++ tests/layout.py | 265 +++++ tests/md2pdf.py | 842 +++++++++++++++- tests/origin.py | 20 +- tests/support.py | 27 +- .../latex/business-suite/business-beamer.sty | 62 +- .../business-suite/business-identity.sty | 266 ++++- .../latex/business-suite/business-suite.sty | 386 +++++++- 28 files changed, 3918 insertions(+), 137 deletions(-) create mode 100644 BUGS.md create mode 100644 bin/forms.lua create mode 100644 bin/html.lua create mode 100755 bin/logo.py create mode 100644 tests/forms.py diff --git a/BUGS.md b/BUGS.md new file mode 100644 index 0000000..7dc2824 --- /dev/null +++ b/BUGS.md @@ -0,0 +1,38 @@ +# Bugs + +Defects of the suite, each with its cause, its correction and the test that measures it. + +## Search through every folder below the document + +- **Found:** 2026-11-14, converting a document at the root of a checkout of 68377 folders: the conversion took 56 minutes 24 seconds, of which the probe 12 minutes 39 seconds and the first of the two LaTeX runs of the document 21 minutes 41 seconds. +- **Cause:** the converter named the suite, the folder of the document and the build folder in `TEXINPUTS` with a trailing `//`. kpathsea expands such an entry into every folder below it and tries each file name in all of them before the TeX tree, which comes last: one lookup of `fontspec.sty` took 257 seconds instead of 0.15. A file named like a package of TeX Live anywhere below the document replaced that package, and a package in a test build of the suite could serve as the identity of a company. +- **Fix:** the converter names the package folder of the suite, the folder of the document and the build folder without `//`. The same document converts in 11.5 seconds. +- **Test:** `tests/md2pdf.py` › `subfolders` (F11.16). + +## An HTML table opens the address of an iframe + +- **Found:** 2026-11-14, in the security review of the HTML table filter: a cell with `\n" + "\n") + result = support.run(["python3", CONVERTER, "--identity", "nordwind", + os.path.join(folder, "doc.md")], cwd=folder) + finally: + server.shutdown() + server.server_close() + check.that(not asked, f"reading the HTML table asked {asked} of a server") + pdf = os.path.join(folder, "doc.pdf") + check.that(os.path.exists(pdf), + "the document with an HTML table did not build:\n" + + result.stdout[-1000:]) + if not os.path.exists(pdf): + return + text = support.text(pdf) + check.that("Kept text" in text, "the HTML table did not reach the PDF") + check.that("Zebra marker" not in text, + "the page an iframe of the HTML table names was fetched into the PDF") + + +def form_pattern(check): + """The pattern that recognises a form reads a line once. + + `^.*\\S.*:` tried every split of a line between its two `.*`: 0.29 seconds + for a line of 20000 characters and 1.01 for 40000, measured on 2026-11-14, + so a megabyte of inline data on one line held the build for minutes. The + limit lies far below the 7 seconds the old pattern needs for 100000. + """ + spec = importlib.util.spec_from_file_location("converter_under_test", CONVERTER) + converter = importlib.util.module_from_spec(spec) + spec.loader.exec_module(converter) + for line, form in (("Name: ________", True), (" Remarks: ____ ", True), + ("- [ ] An item", True), (": ________", False), + ("No label ________", False), ("Two: colons: ____", True)): + check.that(bool(converter.FORM.search(line)) == form, + f"«{line}» is {'not ' if form else ''}read as a form") + start = time.monotonic() + converter.FORM.search("a" + "b" * 100000 + "\n") + seconds = time.monotonic() - start + check.that(seconds < 1, f"a line of 100000 characters took {seconds:.2f} s") + + +UNLINKED_SVG = re.sub(r"]*>", "", LINKED_SVG) +STALE_MD = """# Drawing + +![Functions](drawing.svg) + +## Terms + +| Term | Meaning | +| --- | --- | +| Payment service | Payments | +| PAT | Pre-approval estimate | +""" + + +def stale_links(check): + """A kept build folder lays no links of an earlier drawing over a new one. + + The drawings are numbered from one in every run, and a drawing without links + wrote no link file, so with `--keep-tex` the file of the earlier drawing of + that number stayed and the template laid its links over the new picture. + """ + folder = os.path.join(support.BUILD, "stale-links") + shutil.rmtree(folder, ignore_errors=True) + os.makedirs(folder) + source = os.path.join(folder, "doc.md") + with open(source, "w", encoding="utf-8") as handle: + handle.write(STALE_MD) + pdf = os.path.join(folder, "doc.pdf") + for drawing in (LINKED_SVG, UNLINKED_SVG): + with open(os.path.join(folder, "drawing.svg"), "w", encoding="utf-8") as handle: + handle.write(drawing) + result = support.run(["python3", CONVERTER, "--identity", "nordwind", + "--keep-tex", source], cwd=folder) + check.that(os.path.exists(pdf), "the document with a drawing did not " + "build:\n" + result.stdout[-1000:]) + if not os.path.exists(pdf): + return + links = "\n".join(annotations(pdf)).count("/D (term-pat)") + if drawing is LINKED_SVG: + check.that(links == 1, f"the drawing with links carries {links} " + "links to its term, so this check proves nothing") + check.that(links == 0, f"the drawing without links carries {links} links " + "of the drawing that stood there before") + + def main(): check = Check("md2pdf") runnable(check) @@ -333,6 +1127,20 @@ def main(): pictures(check) twins(check) missing(check) + foreign_rc(check) + shell_escape(check) + linked_content(check) + html_sandbox(check) + form_pattern(check) + stale_links(check) + same_name_drawings(check) + inherited_search(check) + own_probe(check) + subfolders(check) + running_head(check) + code_line(check) + leading_hyphens(check) + short_page(check) return check.done() diff --git a/tests/origin.py b/tests/origin.py index cb5c54b..3316f7e 100644 --- a/tests/origin.py +++ b/tests/origin.py @@ -34,9 +34,11 @@ HEIGHTS = ( ("logoheight", r"\\newcommand\{\\pacta@logoheight\}\{([^}]*)\}", r"\\newcommand\{\\business@logoheight\}\{([^}]*)\}", "the logo of the page head"), - ("titlelogoheight", r"\\newcommand\{\\pacta@titlelogoheight\}\{([^}]*)\}", - r"\\newcommand\{\\business@titlelogoheight\}\{([^}]*)\}", - "the logo of the title block"), +) +FAMILY_HEIGHTS = ( + ("logoheight", "2em", + r"\\newcommand\{\\business@logoheight\}\{([^}]*)\}", + "the logo of the page head"), ) # The three proportions of the lockup, as the origin writes them: the name at # 0.8 of the height, the gap beside it at 0.1, the gap over the address at 0.1. @@ -73,11 +75,23 @@ def main(): check.that(mine is not None and abs(float(mine) - value) < 0.0001, f"{what}: this suite says {mine}, the family {value}") + # The height of the page head is a value of the family as well, and it + # stands here as one: since 2026-10-05 the origin is a configuration of + # this suite and carries no height of its own to read. + for name, value, pattern, what in FAMILY_HEIGHTS: + mine = first(pattern, ours) + check.that(mine == value, + f"{what}: this suite says {mine}, the family {value}") + origin = support.run(["kpsewhich", "pacta.sty"]).stdout.strip() if not origin or not os.path.exists(origin): print(" pacta.sty is not installed; the heights were not compared") return check.done() theirs = read(origin) + if "\\RequirePackage{business-identity}" in theirs: + print(" pacta.sty is a configuration of this suite; its heights are " + "the ones of this suite and were not compared again") + return check.done() for name, there, here, what in HEIGHTS: want = first(there, theirs) mine = first(here, ours) diff --git a/tests/support.py b/tests/support.py index b10f698..d2e2ce7 100644 --- a/tests/support.py +++ b/tests/support.py @@ -23,6 +23,18 @@ def run(command, cwd=ROOT, environment=None): encoding="utf-8", errors="replace") +def name_example_company(): + """The directory of the example company in the TEXINPUTS of every call. + + The example company lies in examples/, outside the TeX tree, and the + converter searches no subfolder of this repository: a test of the converter + names that directory the way every company outside the TeX tree names its + own. + """ + os.environ["TEXINPUTS"] = os.pathsep.join( + [os.path.join(ROOT, "examples"), os.environ.get("TEXINPUTS", "")]) + + def searchpath(*directories): return os.pathsep.join([directory + "//" for directory in (ROOT,) + directories] + [""]) @@ -79,12 +91,19 @@ class Page: """One rendered page, as pixels, with the questions a layout test asks.""" def __init__(self, pdf, page=1, dpi=150): + # One file under one name, written fresh for every page. pdftoppm names + # a page after the number of digits of the LAST page of the document, so + # page 1 of a document of ten pages is `page-01` and of one of nine + # `page-1`; the name was guessed in that order, and the guess found the + # `page-1` an earlier test had left behind. Measured on 2026-10-05, when + # three pages of a fifteen-page fixture were read as the pixels of a + # document of two pages built before it. stem = os.path.join(BUILD, "page") + name = stem + ".pgm" + if os.path.exists(name): + os.remove(name) run(["pdftoppm", "-r", str(dpi), "-f", str(page), "-l", str(page), - "-gray", pdf, stem]) - name = f"{stem}-{page}.pgm" - if not os.path.exists(name): - name = f"{stem}-{page:02d}.pgm" + "-gray", "-singlefile", pdf, stem]) with open(name, "rb") as handle: data = handle.read() fields, offset = [], 0 diff --git a/texmf/tex/latex/business-suite/business-beamer.sty b/texmf/tex/latex/business-suite/business-beamer.sty index a0c0b7d..009a1d3 100644 --- a/texmf/tex/latex/business-suite/business-beamer.sty +++ b/texmf/tex/latex/business-suite/business-beamer.sty @@ -67,6 +67,55 @@ \setbeamercolor*{titlelike}{parent=palette primary} \setbeamercolor*{frametitle}{parent=palette primary} \setbeamercolor*{sidebar}{fg=business-heading-fg,bg=business-brand} +% The sidebar runs from its top colour to its bottom colour, and both are the +% brand where the company names neither: then the shading is one colour. +% A ground that runs from one colour at the top to another at the bottom, drawn +% as a hundred bands, each in its share of the two. beamer's own shading is no +% use here: it is declared once in the preamble and drawn as one object on every +% page, and xdvipdfmx writes that object into the first page alone, so every +% later page names an object that is not there. Measured on 2026-10-05, where a +% reader of the PDF reported «XObject 'Fm2' is unknown» on three of four slides. +% Where both colours are the same, the hundred bands are one colour. +% +% The bands are drawn by a step that calls itself and not by `\loop`: mixing a +% colour runs a `\loop` of its own inside xcolor, which takes over the one +% around it, and the ground came out as its first band alone. +\newcount\business@band +\newcommand{\business@groundstep}{% + \edef\business@mix{\business@groundbottom!\the\business@band + !\business@groundtop}% + \pgfsetfillcolor{\business@mix}% + \pgfpathrectangle + {\pgfpoint{0pt}{\dimexpr\business@groundheight + -\business@groundheight*\numexpr\business@band+1\relax/100\relax}}% + {\pgfpoint{\business@groundwidth}% + {\dimexpr\business@groundheight/100+0.2pt\relax}}% + \pgfusepath{fill}% + \advance\business@band\@ne + \ifnum\business@band<100 \expandafter\business@groundstep\fi} +\newcommand{\business@ground}[4]{% + \begin{pgfpicture}{0pt}{0pt}{#1}{#2}% + \edef\business@groundwidth{\the\dimexpr#1\relax}% + \edef\business@groundheight{\the\dimexpr#2\relax}% + \edef\business@groundtop{#3}% + \edef\business@groundbottom{#4}% + \business@band=\z@ + \business@groundstep + \end{pgfpicture}} +% The template names the role it reads and copies no colour. Which role that is +% is asked where the slide is drawn and not where this file is loaded: a deck +% that names its colours in its own preamble does so after the theme, and a +% choice made at loading took the fallback for it. Measured on 2026-10-05. +\def\business@sidebartop{% + \business@ifrole{sidebar-top}{business-sidebar-top}{business-brand}} +\def\business@sidebarbottom{% + \business@ifrole{sidebar-bottom}{business-sidebar-bottom}{\business@sidebartop}} +\setbeamertemplate{sidebar canvas left}{% + \business@ground{\beamer@leftsidebar}{\paperheight}% + {\business@sidebartop}{\business@sidebarbottom}} +\setbeamertemplate{sidebar canvas right}{% + \business@ground{\beamer@rightsidebar}{\paperheight}% + {\business@sidebartop}{\business@sidebarbottom}} \setbeamercolor*{palette sidebar primary}{fg=business-heading-fg,bg=business-brand} \setbeamercolor*{palette sidebar secondary}{fg=business-heading-fg,bg=business-brand} \setbeamercolor*{palette sidebar tertiary}{fg=business-heading-fg,bg=business-brand} @@ -83,8 +132,17 @@ \setbeamercolor{normal text}{fg=business-heading-fg,bg=business-brand}% \setbeamercolor{background canvas}{bg=business-brand}% }{% - \setbeamercolor{normal text}{fg=business-text,bg=white}% - \setbeamercolor{background canvas}{bg=white}% + % The paper of the company: from the top colour of the ground to its bottom + % colour, white where the company names none, and the text on it in the text + % role unless the company names another colour for text on its ground. + \def\business@canvasbottom{% + \business@ifrole{canvas-bottom}{business-canvas-bottom}{business-canvas-top}}% + \def\business@canvastext{% + \business@ifrole{canvas-text}{business-canvas-text}{business-text}}% + \setbeamercolor{normal text}{fg=\business@canvastext,bg=business-canvas-top}% + \setbeamertemplate{background canvas}{% + \business@ground{\paperwidth}{\paperheight}% + {business-canvas-top}{\business@canvasbottom}}% } \setbeamertemplate{blocks}[rounded][shadow=true] diff --git a/texmf/tex/latex/business-suite/business-identity.sty b/texmf/tex/latex/business-suite/business-identity.sty index 4f6ea09..b5d22a5 100644 --- a/texmf/tex/latex/business-suite/business-identity.sty +++ b/texmf/tex/latex/business-suite/business-identity.sty @@ -54,10 +54,107 @@ % the key afterwards, so setting it later writes "Option `bookmarks' has % already been used" into every build log and changes nothing. Measured on % 2026-09-21 over eight logs. -\PassOptionsToPackage{bookmarks=true,bookmarksopen=true,bookmarksnumbered=false}% - {hyperref} +% +% Every destination of the document is named after the label that marks it. +% Without this, hyperref numbers them — `section.1`, `section.2` — and the +% numbers move as soon as a section is added, so a link from another document +% into a section of this one lands wherever that number now sits. The names come +% out of the document instead, and a converted Markdown file brings one per +% heading, because pandoc writes a label for each. The option stands HERE, where +% hyperref is loaded: the document template passed it after this file had loaded +% hyperref already, so it reached no company until 2026-10-05. +\PassOptionsToPackage{bookmarks=true,bookmarksopen=true,bookmarksnumbered=false, + destlabel}{hyperref} \RequirePackage{hyperref} \hypersetup{colorlinks=false, hidelinks} +% =================== +% What a link looks like +% =================== +% `\businesslinks{…}` says it, and a company sets it from the stylesheet of its +% own website, so the PDF and the page read alike: +% +% \businesslinks{colour = link, external = link-external, underline = true} +% +% `colour` is the role or the colour a link of this document stands in, +% `external` the one for an address that leaves it, and `underline` draws the +% line under the words that HTML draws by default. What a PDF cannot carry is +% the state: there is no hover and no visited link on a printed page, and a +% reader that shows one invents it. +% +% Nothing is set until a company sets it. Without it a link keeps the colour of +% the text and no frame, which is what this package has always done. +\newif\ifbusiness@linkunderline +\newcommand{\business@linkcolour}{} +\newcommand{\business@linkexternal}{} +\pgfkeys{ + /business/links/.cd, + colour/.store in=\business@linkcolour, + external/.store in=\business@linkexternal, + underline/.is if=business@linkunderline, + underline/.default=true, +} +% The line under a link is drawn by `ulem`, with `normalem`, so that `\emph` +% keeps the italic of the document: the package would otherwise underline every +% emphasis of every text. Loaded only where a company asks for the line. +\newcommand{\business@underline}[1]{#1} +\newcommand{\businesslinks}[1]{% + \pgfkeys{/business/links/.cd,#1}% + \ifx\business@linkcolour\@empty\else + \ifx\business@linkexternal\@empty + \let\business@linkexternal\business@linkcolour + \fi + \hypersetup{colorlinks=true, + linkcolor=business-\business@linkcolour, + citecolor=business-\business@linkcolour, + filecolor=business-\business@linkexternal, + urlcolor=business-\business@linkexternal}% + \fi + \ifbusiness@linkunderline + \RequirePackage[normalem]{ulem}% + \renewcommand{\business@underline}[1]{\uline{##1}}% + \business@underlinelinks + \fi} +% The two commands a link reaches the page through: `\href` for an address and +% `\hyperref` for a place in the document, which is what a converted Markdown +% file and a document written by hand both use. `\url` keeps its own shape: its +% text is set verbatim, and a line drawn through that box breaks it. They are wrapped once, at the beginning of the +% document, so that a company may set the line before or after the identity. +% Both replacements are robust, because a link also stands inside a section +% title, and a title travels: into the table of contents, into the running head +% and into the bookmark, each of them a place where the text is written out +% rather than typeset. A command defined with `\def` falls apart there — it is +% expanded while its argument is still unread, and the heading +% `\texorpdfstring{5.3 \hyperref[term-payment]{Payment} Core}{…}`, which pandoc +% writes for a Markdown title that carries a link, then ends the paragraph in +% the middle of the title (reported from PLIM on 2026-10-23: «Argument of +% \H@old@sect has an extra }»). A robust command writes itself, with its +% arguments, and draws the line when the page is set. +% The name of a bookmark is a string, and no line can be drawn into a string: +% there the three commands hand over the text of the link alone. +\def\business@pdf@href#1#2{#2} +\def\business@pdf@label[#1]#2{#2} +\def\business@pdf@hyperref{\@ifnextchar[\business@pdf@label\@firstofone} +\newcommand{\business@underlinelinks}{% + \AtBeginDocument{% + \@ifundefined{business@wrapped@href}{% + \let\business@wrapped@href\href + \DeclareRobustCommand{\business@href}[2]{% + \business@wrapped@href{##1}{\business@underline{##2}}}% + \let\href\business@href + \let\business@wrapped@hyperref\hyperref + \DeclareRobustCommand{\business@hyperref}{% + \@ifnextchar[{\business@hyperref@label}% + {\business@wrapped@hyperref}}% + \let\hyperref\business@hyperref + \def\business@hyperref@label[##1]##2{% + \business@wrapped@hyperref[##1]{\business@underline{##2}}}% + \pdfstringdefDisableCommands{% + \let\business@underline\@firstofone + \expandafter\let\csname business@href\space\endcsname + \business@pdf@href + \expandafter\let\csname business@hyperref\space\endcsname + \business@pdf@hyperref}% + }{}}} % A size the class does not know: the name beside the logo and the address line % under it are set at a size that is measured, not chosen from the ten steps a % class offers. @@ -70,10 +167,11 @@ % extension is resolved. The order puts the vector formats first: a logo that % exists as PDF and as PNG is set from the PDF, which scales to any height. % -% SVG is not in the list and cannot be: no TeX engine reads one. The build -% converts every SVG beside a template into a PDF of the same name (bin/logo.py), -% so a company names its logo `logo` and never a format — which is what makes the -% format the user's non-decision. +% SVG is not in the list and cannot be: no TeX engine reads one. `bin/logo.py` +% converts every SVG of a directory into a PDF of the same name beside it, so a +% company names its logo `logo` and never a format — which is what makes the +% format the user's non-decision. A logo that exists as an SVG alone stops the +% build with the command that converts it, below. \DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg,.jpeg} % =================== @@ -118,11 +216,21 @@ tagline color/.store in=\business@taglinecolour, url/.store in=\business@url, address/.store in=\business@address, - logo/.store in=\business@logofile, - icon/.store in=\business@iconfile, + % A file and a drawing are the two answers to one question, so each of them + % takes the other away. A company that builds on another — the second of a + % family, a daughter that keeps the type and the measures and brings its own + % mark — loads that identity and then names its own `logo` or `icon`; without + % this, the drawing of the first company stayed and `\business@setlogo` + % preferred it, so the daughter carried the mark of the mother and nothing + % said so. Measured on 2026-10-06, in the step that puts a second company of + % this house on the identity of the first. + logo/.code={\def\business@logofile{#1}\let\business@logocode\relax}, + icon/.code={\def\business@iconfile{#1}\let\business@iconcode\relax}, lockup/.store in=\business@lockup, - logo code/.code={\def\business@logocode##1{#1{##1}}}, - icon code/.code={\def\business@iconcode##1{#1{##1}}}, + logo code/.code={\def\business@logocode##1{#1{##1}}% + \let\business@logofile\@empty}, + icon code/.code={\def\business@iconcode##1{#1{##1}}% + \let\business@iconfile\@empty}, } % What a template wants to know when the identity changes. A company declares % itself in the preamble, after the template was loaded, so everything the @@ -163,6 +271,13 @@ \business@role{rowrule}{black!30} \business@role{title}{black} \business@role{titlemeta}{black!65} +% A link, and an address that leaves the document. They are roles like every +% other, so a company sets them where its website sets the colour of its links, +% and the two documents then read alike. Their default is the text colour: a +% company that says nothing keeps a link that is read and not seen, which is +% what a printed page wants. +\business@role{link}{business-text} +\business@role{link-external}{business-link} % A pass and a failure are read before a word of the line they stand in, and no % brand palette is obliged to carry a colour that says them. They are therefore % roles of their own with their own defaults, outside the palette, and a company @@ -176,6 +291,81 @@ \business@role{border}{black} \business@role{thick-border}{black} \business@role{black-border}{black} +% The ground of a slide, top and bottom, and the text on it; and the sidebar of a +% deck, top and bottom. A company that names none of them gets the deck of the +% family: white ground, the text role, the sidebar in the brand colour. Those +% defaults are other ROLES, and a role is copied when it is declared, before +% the company sets the one it follows, so the deck asks whether the company set +% each of these and falls back to the other role where it did not. +\business@role{canvas-top}{white} +\business@role{canvas-bottom}{white} +\business@role{canvas-text}{black} +\business@role{sidebar-top}{black} +\business@role{sidebar-bottom}{black} +% The word that lies across a page which is not the final one: a draft, a copy +% for an internal round, a text under embargo. It is as quiet as the paper +% allows — a reader has to read the page through it — so it is a role of its +% own and the company may make it louder or quieter. +\business@role{watermark}{black!8} +% Whether the company set a role. A template that needs a role to follow another +% one asks this. +\newcommand{\business@ifrole}[3]{% + \ifcsname business@set@#1\endcsname#2\else#3\fi} + +% =================== +% The word across the page +% =================== +% `\businesswatermark{DRAFT}` in the preamble lays one word across every page of +% the document, in the `watermark` role. It is the identity and not the page +% that carries it, so a letter, a deck and a document all take it, and a letter +% is the case it was asked for. +% +% Nothing about it is written down. The word is set once, turned by the angle of +% the diagonal of the paper in use, and then made as large as the page carries: +% a word turned by that angle takes `width * cos + height * sin` across the +% paper and `width * sin + height * cos` down it, so the larger of the two +% demands decides the size, and nine tenths of the page is what it is allowed. +% A size in centimetres fits one paper and one word; `DRAFT` and `CONFIDENTIAL` +% are of very different length, and the second one stood over the edge of the +% sheet at the size that fitted the first. +\RequirePackage{eso-pic} +\newsavebox{\business@watermarkbox} +\newcommand{\business@watermarkword}{} +\newcommand{\business@watermarkdraw}{% + \begingroup + \sbox{\business@watermarkbox}{% + \color{business-watermark}% + \normalfont\bfseries\business@watermarkword}% + \edef\business@slant{% + \fpeval{atand(\number\paperheight / \number\paperwidth)}}% + \edef\business@markwide{\number\wd\business@watermarkbox}% + \edef\business@markhigh{% + \fpeval{\number\ht\business@watermarkbox + + \number\dp\business@watermarkbox}}% + \edef\business@markscale{% + \fpeval{min(0.9 * \number\paperwidth + / (\business@markwide * cosd(\business@slant) + + \business@markhigh * sind(\business@slant)), + 0.9 * \number\paperheight + / (\business@markwide * sind(\business@slant) + + \business@markhigh * cosd(\business@slant)))}}% + \AtPageCenter{% + \makebox(0,0){% + \rotatebox{\business@slant}{% + \resizebox{\fpeval{\business@markscale * \business@markwide}sp}{!}{% + \usebox{\business@watermarkbox}}}}}% + \endgroup} +% How much room the next thing needs to stand whole. A form uses it: a box, the +% text beside it and the field under it are one thing to read and one thing to +% fill in, and a page that breaks between them lets the reader tick on one page +% and write on the next. The caller says how many lines it needs, because only +% the caller knows how long its text is; the page reserves them in front of the +% thing, so the whole of it moves when it does not fit. +\RequirePackage{needspace} +\newcommand{\businessneed}[1]{\Needspace*{#1\baselineskip}} +\newcommand{\businesswatermark}[1]{% + \renewcommand{\business@watermarkword}{#1}% + \AddToShipoutPictureBG{\business@watermarkdraw}} \newcommand{\businesscolour}[2]{\colorlet{business-#1}{#2}} \newcommand{\businesscolours}[1]{% @@ -187,7 +377,8 @@ \@ifundefined{\string\color@business-\business@thisrole}{% \PackageWarning{business-identity}{% `\business@thisrole' is no colour role of this package}% - }{\colorlet{business-\business@thisrole}{#1}}}, + }{\colorlet{business-\business@thisrole}{#1}% + \expandafter\gdef\csname business@set@\business@thisrole\endcsname{}}}, } % =================== @@ -457,6 +648,26 @@ iconwidth/.store in=\business@iconwidth, } +% A file of the company at a height. A name that exists as an SVG and in none of +% the formats above stops the build with the command that converts it: graphicx +% would say «File not found» about a file the company can see in its directory, +% and name no way out. +\newcommand{\business@includefile}[2]{% + \let\business@svgonly\relax + \IfFileExists{#2.svg}{% + \def\business@svgonly{#2}% + \@for\business@extension:={pdf,eps,png,jpg,jpeg}\do{% + \IfFileExists{#2.\business@extension}{\let\business@svgonly\relax}{}}% + }{}% + \ifx\business@svgonly\relax + \includegraphics[height=#1]{#2}% + \else + \PackageError{business-identity}{% + The logo `#2' exists as an SVG only}{% + No TeX engine reads an SVG. Convert it once into a PDF beside it with + the converter of the suite: python3 bin/logo.py }% + \fi} % What sets the logo at a given height: the company command where there is one, % the file otherwise. Both leave a box of exactly that height. \newcommand{\business@setlogo}[1]{% @@ -465,7 +676,7 @@ \PackageWarning{business-identity}{% No logo: set `logo=' or `logo code='}% \else - \includegraphics[height=#1]{\business@logofile}% + \business@includefile{#1}{\business@logofile}% \fi \else \business@logocode{#1}% @@ -478,7 +689,7 @@ % lockup then says which of the two this is. \business@setlogo{#1}% \else - \includegraphics[height=#1]{\business@iconfile}% + \business@includefile{#1}{\business@iconfile}% \fi \else \business@iconcode{#1}% @@ -512,8 +723,16 @@ % reads the number and drops the rest, so `0.8 * 2cm` would come out as 1.6 % POINTS. The height therefore goes through a length register first, and the % factor is applied to that. +% The three measured sizes are set GLOBALLY. A logo may stand inside a link, and +% a link with the line under it is set by `ulem`, which reads the text of the +% link a second time to break the line: the group of the first reading is gone by +% then, and a size defined inside it with `\edef` is undefined on the second. +% Measured on 2026-10-24 on the second page of the MRW example document, where +% the logo in the head stands in a link and the build stopped with «Undefined +% control sequence \business@namesize». Every path computes the size immediately +% before it sets the text, so a global value is never an old one. \newcommand{\business@fitname}{% - \edef\business@namesize{% + \xdef\business@namesize{% \fpeval{\business@namefactor * \number\business@heightdim / 65536}}} \newcommand{\business@nametext}{% @@ -550,11 +769,11 @@ \sbox{\business@taglinebox}{% \fontsize{10pt}{10pt}\selectfont \business@taglineface\business@tagline}% - \edef\business@taglinesize{% + \xdef\business@taglinesize{% \fpeval{10 * \number\wd\business@namebox / \number\wd\business@taglinebox}}% \else - \edef\business@taglinesize{% + \xdef\business@taglinesize{% \fpeval{\business@taglinefactor * \business@namesize}}% \fi} @@ -657,7 +876,10 @@ \newcommand{\business@lockupline}{% \business@fitblock \business@fiticon - \sbox{\business@logobox}{\business@seticon{\business@iconhigh}} + % The end of this line is no space: a space here stood in front of every icon, + % so the logo began a word space to the right of its box and the address line + % under it reached that far past the icon. Measured on 2026-10-05. + \sbox{\business@logobox}{\business@seticon{\business@iconhigh}}% % The icon is CENTRED on the text beside it: the middle of the block meets the % middle of the icon, whether the block has one line or two. A drawing may % hang below its own baseline — a TikZ picture whose bounding box is centred @@ -718,7 +940,7 @@ % A box cannot break, so the line stays one line. \sbox{\business@textbox}{% \fontsize{10pt}{10pt}\selectfont\business@address}% - \edef\business@addresssize{% + \xdef\business@addresssize{% \fpeval{10 * \number\wd\business@logobox / \number\wd\business@textbox}}% % The block hands the line it stands in the BASELINE OF THE NAME, and that is % what `[t]` gives by itself: a `[t]` box aligns on its first baseline, and @@ -817,10 +1039,16 @@ \AtBeginDocument{% \setlength{\aboverulesep}{0.4ex}% \setlength{\belowrulesep}{0.65ex}} +% The three rules that hold a table together are drawn in the ink of the text, +% and so is everything after the quiet line between two rows. colortbl draws in +% its own pure black until it is told otherwise, and that black is a colour no +% brand chose: measured on 2026-10-05, when a company whose text is a dark of its +% own carried pure black in the rules of every table. +\AtBeginDocument{\arrayrulecolor{business-text}} \newcommand{\business@rowrulewidth}{0.3pt} \newcommand{\businessrowrule}{% \arrayrulecolor{business-rowrule}\midrule[\business@rowrulewidth]% - \arrayrulecolor{black}} + \arrayrulecolor{business-text}} % The head of a table, the row that names the columns. A reader finds it by its % weight before reading a word of it, so it is set in the emphasis face of the diff --git a/texmf/tex/latex/business-suite/business-suite.sty b/texmf/tex/latex/business-suite/business-suite.sty index b00f791..3e85d46 100644 --- a/texmf/tex/latex/business-suite/business-suite.sty +++ b/texmf/tex/latex/business-suite/business-suite.sty @@ -28,20 +28,60 @@ \RequirePackage{xcolor} \RequirePackage{calc} \RequirePackage{xfp} -% Every destination of the document is named after the label that marks it. -% Without this, hyperref numbers them — `section.1`, `section.2` — and the -% numbers move as soon as a section is added, so a link from another document -% into a section of this one lands wherever that number now sits. The names -% come out of the document instead, and a converted Markdown file brings one -% per heading, because pandoc writes a label for each. -\PassOptionsToPackage{destlabel}{hyperref} +% hyperref, with the destinations named after their labels, comes from the +% identity, which loads it with its options before this file is read. \RequirePackage{hyperref} +% A drawing may carry links in a sidecar written by the Markdown converter. +% graphicx embeds the converted PDF as page content and drops its annotations, +% so the links are placed over that content at the coordinates of the SVG text. +% The rectangles contain no paint; they exist only as PDF annotations. +\newsavebox{\business@linkedimage} +\newdimen\business@linkedimageheight +\let\business@plainincludegraphics\includegraphics +\newcommand{\business@linkedincludegraphics}[2]{% + \IfFileExists{#1.links.tex}{% + \sbox{\business@linkedimage}{#2}% + \business@linkedimageheight=\ht\business@linkedimage + \advance\business@linkedimageheight by \dp\business@linkedimage + \leavevmode\hbox to \wd\business@linkedimage{% + \rlap{\usebox{\business@linkedimage}}% + \raisebox{-\dp\business@linkedimage}{\input{#1.links.tex}}% + \hfill}% + }{#2}} +\RenewDocumentCommand{\includegraphics}{s O{} m}{% + \IfBooleanTF{#1}{% + \business@linkedincludegraphics{#3}{% + \business@plainincludegraphics*[#2]{#3}}% + }{% + \business@linkedincludegraphics{#3}{% + \business@plainincludegraphics[#2]{#3}}% + }} +\newcommand{\businessimagelink}[5]{% + \raisebox{#3\business@linkedimageheight}[0pt][0pt]{% + \makebox[0pt][l]{\hspace{#2\wd\business@linkedimage}% + \@tempdima=#4\wd\business@linkedimage + \@tempdimb=#5\business@linkedimageheight + \special{pdf: ann width \the\@tempdima\space + height \the\@tempdimb\space depth 0pt + << /Type /Annot /Subtype /Link /Border [0 0 0] + /A << /S /GoTo /D (#1) >> >>}}}} % What the PDF says about itself when a program asks: the title, the author and % the language of the document, and the XMP stream that the parsers of today % read instead of the old info dictionary. A file whose properties say % "untitled" is a file nobody finds again, and the values are already in the % document — they carry the title block. -\RequirePackage{hyperxmp} +% +% Only where the kernel does not manage the PDF itself. A document that opens +% with `\DocumentMetadata` — which is what a document asking for PDF/UA does — +% gets that stream from the kernel, and the kernel turns this package away with +% a warning. A warning is an error in the projects that build such documents, +% so it is not asked for there: reported on 2026-10-14 from eight curricula +% vitae built for PDF/UA-2, where it blocked the commit. +\ifdefined\IfPDFManagementActiveTF + \IfPDFManagementActiveTF{}{\RequirePackage{hyperxmp}} +\else + \RequirePackage{hyperxmp} +\fi % The document has the last word, and the package fills in what it leaves open. % hyperref keeps what a document set in stores of its own — `\@pdftitle` and % `\@pdfauthor` are empty and `\@pdflang` is `\relax` until somebody uses the @@ -55,12 +95,27 @@ % about. A class that predefines an empty `\@title` is the other half of the % same case, and both end in a title of nothing written over the one the % document gave hyperref itself. -\newcommand{\business@carryover}[3]{% +% +% A document that gave NO title is the third case, and it is neither `\relax` +% nor empty: the kernel fills both stores with the command that complains about +% the omission. Handed to hyperref, that command becomes the title of the PDF +% and leaves "Option `pdftitle' has already been used" in the log — measured on +% 2026-10-05 in the two deck fixtures, where a deck without a title warned at +% `\begin{document}`. The two references below carry exactly what the kernel +% puts there, read off a build rather than assumed: the title raises an ERROR +% and the author only a warning, and the two therefore do not have the same +% shape. Where a future kernel words one of them differently, the comparison +% misses and that store is carried over as it was before. +\def\business@notitle{\@latex@error{No \noexpand\title given}\@ehc} +\def\business@noauthor{\@latex@warning@no@line{No \noexpand\author given}} +\newcommand{\business@carryover}[4]{% \ifx#1\@empty \ifcsname #2\endcsname \expandafter\ifx\csname #2\endcsname\relax\else \expandafter\ifx\csname #2\endcsname\@empty\else - \hypersetup{#3={\csname #2\endcsname}}% + \expandafter\ifx\csname #2\endcsname#4\else + \hypersetup{#3={\csname #2\endcsname}}% + \fi \fi \fi \fi @@ -73,8 +128,8 @@ % the eight logs of this suite, and the language stands in the XMP of both % without this block. \AtBeginDocument{% - \business@carryover\@pdftitle{@title}{pdftitle}% - \business@carryover\@pdfauthor{@author}{pdfauthor}} + \business@carryover\@pdftitle{@title}{pdftitle}\business@notitle + \business@carryover\@pdfauthor{@author}{pdfauthor}\business@noauthor} \RequirePackage{currfile} % =================== @@ -83,13 +138,13 @@ % Every measure of the page is an option, and every one of them has a default % that is derived or measured rather than written down. % -% How high the logo stands in the page head and in the title block. Both are -% the values this family of templates decided, and a measurement replaced them -% here for half a day until the page showed what that costs: a logo whose ink -% fills its whole box came out larger than in the two companies beside this one, -% and the address line under it was scaled to a width nobody can read. +% How high the logo stands in the page head. It is the value this family of +% templates decided, and a measurement replaced it here for half a day until the +% page showed what that costs: a logo whose ink fills its whole box came out +% larger than in the two companies beside this one, and the address line under +% it was scaled to a width nobody can read. The title block carries no logo, so +% it has no height of its own. \newcommand{\business@logoheight}{2em} -\newcommand{\business@titlelogoheight}{6em} % Room for what stands in the head. Empty means that the package measures it % off the head itself, which is what a document gets unless it says otherwise. \def\business@headerheight{} @@ -111,7 +166,7 @@ \newcommand{\business@measureletters}{AÄdgjpq} % How far the spaces of one paragraph may be stretched where no line of it fits % otherwise. An em, so it follows the size of the type. -\newcommand{\business@emergencystretch}{1em} +\newcommand{\business@emergencystretch}{3em} % How far the space between two paragraphs may be stretched so that a page ends % where every other page ends. Half a line, so it follows the type as well. \newcommand{\business@pagestretch}{0.5\baselineskip} @@ -153,9 +208,12 @@ % 2026-09-21 from a fourth company, where the letter and the deck stopped % building with "Too many }'s". \newif\ifbusiness@untitled +% Whether the page being filled ends early on purpose, because a picture that +% does not fit moves to the next page and leaves its room empty. Here for the +% same reason as the flags above. +\newif\ifbusiness@shortpage \DeclareOptionX{logoheight}{\renewcommand{\business@logoheight}{#1}} -\DeclareOptionX{titlelogoheight}{\renewcommand{\business@titlelogoheight}{#1}} \DeclareOptionX{headerheight}{\def\business@headerheight{#1}} \DeclareOptionX{headsep}{\renewcommand{\business@headsep}{#1}} \DeclareOptionX{bordertop}{\renewcommand{\business@bordertop}{#1}} @@ -172,6 +230,13 @@ \DeclareOptionX{landscapeheight}{\renewcommand{\business@landscapeheight}{#1}} \DeclareOptionX{pictureempty}{\renewcommand{\business@pictureempty}{#1}} \DeclareOptionX{picturezoom}{\renewcommand{\business@picturezoom}{#1}} +% The word across the page, as an option of the document: `watermark=ENTWURF` +% writes that word, and the bare `draft` writes DRAFT, which is the word this +% was asked for. A document that wants it later, or wants it in a letter class +% of its own, writes `\businesswatermark{…}` in its preamble instead; both end +% in the same command. +\DeclareOptionX{watermark}{\businesswatermark{#1}} +\DeclareOptionX{draft}{\businesswatermark{DRAFT}} \DeclareOptionX{nologo}{\business@pagelogofalse} \DeclareOptionX{plain}{\business@plaintrue\business@pagelogofalse} % The values of the company, so that a document can override one of them without @@ -190,6 +255,12 @@ \RequirePackage{geometry} \RequirePackage{etoolbox} + % The body text is set in the text role of the company. LaTeX writes in its + % own pure black until it is told otherwise, and that black is a colour no + % brand chose: measured on 2026-10-03 in a family package, whose palette + % carries a dark of its own and whose pages carried pure black beside it. + \AtBeginDocument{\color{business-text}} + % Nothing of the document may stand outside the page, and two of the defaults % of LaTeX let it. % @@ -285,6 +356,7 @@ \newdimen\business@picturew \newdimen\business@pictureh \newdimen\business@pictureroom + \newdimen\business@fitroom \newcommand{\business@picturescale}{1} % The file kinds that are a raster of pixels and cannot be enlarged freely. \newcommand{\business@rasters}{png,jpg,jpeg,bmp,gif,tif,tiff} @@ -309,14 +381,33 @@ \fi \fi \fi + % Inside a figure the caption stands under the picture and needs its line + % and the space above it as well: a picture made exactly as high as the room + % does not fit with its caption, and moves to the next page after all. + % Measured on 2026-10-05 with a picture that left a third of a page empty. + \ifx\@captype\@undefined\else + \advance\business@pictureroom by -\dimexpr\abovecaptionskip + +\baselineskip\relax + \fi \ifdim\business@pictureroom>\textheight \business@pictureroom=\textheight \fi + % The height a lying picture is made to fill. Where more than a quarter of + % the page is left, it is that rest; where less is left, the picture does not + % shrink into it, it moves and fills the next page. Taking the rest whatever + % it was set a picture of the full line width 60 points high into the last + % strip of a page: measured on 2026-10-05, where the rule that a picture + % moves when it would leave less than a quarter empty never came into play. + \ifdim\business@pictureroom>\business@pictureempty\textheight + \business@fitroom=\business@pictureroom + \else + \business@fitroom=\textheight + \fi \ifdim\business@pictureh<\business@picturew \edef\business@picturescale{\fpeval{min( \business@landscapewidth * \number\linewidth / \number\business@picturew, - \business@landscapeheight * \number\business@pictureroom + \business@landscapeheight * \number\business@fitroom / \number\business@pictureh)}}% \else \edef\business@picturescale{\fpeval{min( @@ -349,6 +440,129 @@ \scalebox{\business@picturescale}{\usebox{\business@picturebox}}\hss}% \fi \global\business@bitmapfalse} + % =================== + % A document that is filled in + % =================== + % A checklist somebody ticks and writes into, saved as the file it was sent + % as: the boxes and the lines are fields of the PDF, which every reader of the + % last ten years can fill in and save. The fields are hyperref's own, + % `\CheckBox` and `\TextField` inside its `Form`; what this package adds is + % the shape of the family — the frame in the colour of the company, the size + % of the type, the height of a field in lines of the body text — and the one + % decision a document should not have to make: every text field takes several + % lines, so an entry longer than the box scrolls instead of ending at the + % frame. + % + % `\businessform` in the PREAMBLE opens the form around the body. A document + % without it carries no form dictionary at all, which is why the command + % stands in the document and not in this package: what fills in nothing comes + % out exactly as it did before. + \newcommand{\businessform}{% + \AtBeginDocument{\begin{Form}}% + \AtEndDocument{\end{Form}}} + % The size of the type in a field and the side of a box: both follow the body + % text, measured once where the body font really stands, so a field grows with + % the type instead of beside it. A box is as high as a capital, so a list of + % boxes reads as a list and not as a stack of squares. + \newlength{\business@fieldsize} + \newlength{\business@boxside} + \newlength{\business@fieldindent} + \AtBeginDocument{% + \setlength{\business@fieldsize}{\f@size\p@}% + \setlength{\business@fieldsize}{0.9\business@fieldsize}% + \settoheight{\business@boxside}{X}} + % The three things a form is made of. Each takes the name the field carries in + % the PDF first — whoever reads the filled file sees that name, so it is the + % identifier of the document and never a running number of this package. + % + % \businesscheckbox{S1}{Write-off request. No write-off goes out …} + % \businesscheckbox[checked=true]{S2}{… a box that arrives ticked} + % \businessremark{S1-remarks}{Remarks}{3} + % \businessline{Name}{Name} + % + % The text beside a box is not part of the field: a reader that draws no label + % still shows it, and it wraps under itself instead of under the box. + \newcommand{\businesscheckbox}[3][]{% + \par\addvspace{0.3\baselineskip}% + \settowidth{\business@fieldindent}{% + \framebox[\business@boxside]{}\hspace{0.6em}}% + \noindent + \raisebox{-0.1\business@boxside}{% + \CheckBox[name={#2}, width=\business@boxside, height=\business@boxside, + bordercolor=business-rowrule, backgroundcolor={}, + borderwidth=0.5, #1]{}}% + \hspace{0.6em}% + \begin{minipage}[t]{\dimexpr\linewidth-\business@fieldindent\relax}% + #3% + \end{minipage}\par} + % A field of several lines: its label over it in the quiet colour of the + % furniture, the field under it over the whole measure. The height is given in + % lines of the body text, so a field grows with the type instead of beside it. + \newcommand{\businessremark}[3]{% + \par\addvspace{0.3\baselineskip}% + % No break between what stands above and this label: the label belongs to + % the item over it, and the room for both was reserved in front of that + % item. + \penalty\@M + \noindent{\small\textcolor{business-running-quiet}{#2}}\par + \nopagebreak + \noindent\TextField[name={#1}, multiline=true, width=\linewidth, + height=#3\baselineskip, bordercolor=business-rowrule, + backgroundcolor={}, borderwidth=0.5, + charsize=\business@fieldsize]{}% + \par\addvspace{0.3\baselineskip}} + % A field of one line, with its label beside it: the shape of a signature + % block, where the label is short and the line belongs next to it. It carries + % several lines all the same, so a long entry scrolls. + % Every label of a block stands on one edge and every frame begins on one + % edge, whatever the labels are called: the label is set in a box as wide as + % the widest of them, which the document says with `\businesslabelwidth`, and + % the frame starts where that box ends. Without it «Name», «Role» and «Date» + % each pushed their own frame to a different place. + % + % And the label sits on the middle of the frame beside it, not on its foot: + % the frame is taller than the line of the label, so a label on the baseline + % of the text reads as hanging under its field. + \newlength{\business@labelwidth} + \newlength{\business@labelone} + % The labels of one block, separated by commas: the widest of them sets the + % edge. Which one is the widest is a question of the type and not of the + % number of letters — «Name» and «Date» are four letters and not the same + % width — so it is measured here and not counted anywhere else. + \newcommand{\businesslabelwidth}[1]{% + \setlength{\business@labelwidth}{\z@}% + \@for\business@label:=#1\do{% + \settowidth{\business@labelone}{\small\business@label}% + \ifdim\business@labelone>\business@labelwidth + \setlength{\business@labelwidth}{\business@labelone}% + \fi}} + \newcommand{\businessline}[2]{% + \par\addvspace{0.3\baselineskip}% + \settowidth{\business@fieldindent}{\small#2\hspace{0.6em}}% + \ifdim\business@labelwidth>\z@ + \setlength{\business@fieldindent}{% + \dimexpr\business@labelwidth+0.6em\relax}% + \fi + \noindent\makebox[\business@fieldindent][l]{% + \raisebox{0.35\baselineskip}{% + \small\textcolor{business-running-quiet}{#2}}}% + % The field is put into a box of the width that is left, and asked for the + % frame narrower than that box: hyperref draws the frame outside the width + % it is given, so the line came out too wide and TeX reported an overfull + % box on every such line while the rectangle in the PDF sat right. The + % frame costs 1.8 points beside the width in a paragraph of the document, + % against the 1.2 the same field measures inside a box of its own — + % measured in the build log and in the rectangles of the finished PDF, and + % the 0.6 points the field then falls short of the text block are invisible + % and cost nothing. + \makebox[\dimexpr\linewidth-\business@fieldindent\relax][l]{% + \TextField[name={#1}, multiline=true, + width=\dimexpr\linewidth-\business@fieldindent-1.8\p@\relax, + height=1.4\baselineskip, bordercolor=business-rowrule, + backgroundcolor={}, borderwidth=0.5, + charsize=\business@fieldsize]{}}% + \par\addvspace{0.3\baselineskip}} + % What a document writes for a picture of its own. The options are the ones of % `\includegraphics`, and a document that gives a size there has said what it % wants: the picture is then set at that size and the rules above step back. @@ -373,8 +587,14 @@ \renewcommand*\pandocbounded[1]{% \sbox{\business@picturebox}{#1}% \business@setpicture}} + % The caption stands centred under its picture, over one line and over + % several, and a picture that stands alone is centred on the line itself. The + % caption of a drawing used to begin at the left edge of the text while the + % drawing stood in the middle of the line, so the two read as two things. + % `singlelinecheck=false` makes the short caption follow the same rule as the + % long one instead of the one the class would pick for it. \captionsetup{labelformat=empty, font={small}, textfont={color=business-caption}, - justification=raggedright, singlelinecheck=false, + justification=centering, singlelinecheck=false, skip=0.5\baselineskip} % The package measures what a table needs where it begins, and it measures it @@ -421,8 +641,14 @@ % The value is an em and therefore follows the size of the type, where the % two companies this comes from wrote 15 points and three ems. `\sloppy` is NOT % taken over with it: it lifts the limit on every line of every paragraph and - % pays for the rare overflow with loose word spacing throughout, and measured - % over the examples of this suite no line runs over the edge without it. + % pays for the rare overflow with loose word spacing throughout, while this + % acts on the paragraph that would otherwise fail and on no other. + % + % Three ems, because one was not enough for the paragraph that lists the names + % of a convention: a sentence of eleven inline code spans, each a word TeX may + % not hyphenate, left two lines 3.5 and 7.9 points past the edge of the text + % block. Measured on 2026-10-14 over that paragraph, with one em and with + % three, and three ems leaves no line over the edge. \setlength{\emergencystretch}{\business@emergencystretch} % A paragraph is set apart by space, not by an indent: its first line starts @@ -445,6 +671,29 @@ \setlength{\@tempskipa}{\business@pagestretch} \advance\parskip by \z@ \@plus\@tempskipa \flushbottom + % The play is all the page gets. A page whose spaces cannot reach the last + % line within it — a picture that did not fit moved to the next page and left + % up to a quarter of this one — keeps the rest EMPTY at its foot. Without that + % the page builder stretched every space past its play: the author stood 240 + % points under the title, and a heading over a picture ended up inside the + % picture. Measured on 2026-10-05. + % + % Whether the play reaches is measured on the page itself: it is packed once to + % the height of the column as a trial, and a badness over 100 says the spaces + % had to stretch further than they may. + \newcommand{\business@trialpage}{% + \setbox\@tempboxa\vbox to\@colht{\@texttop\unvcopy\@outputbox}% + \ifnum\badness>100 \global\business@shortpagetrue\fi} + \def\@textbottom{% + \ifbusiness@shortpage + \vskip \z@ \@plus 1fil\relax + \global\business@shortpagefalse + \fi} + \@ifundefined{@make@normalcolbox}{% + \PackageWarningNoLine{business-suite}{% + This LaTeX builds its pages without \string\@make@normalcolbox, so a page + whose spaces cannot fill it is stretched past their play}}{% + \pretocmd{\@make@normalcolbox}{\business@trialpage}{}{}} % The first line of a page takes as much room as every other line. `\topskip` % is the distance from the upper edge of the text block to the first baseline, @@ -511,11 +760,18 @@ % exists to say where the reader is. % % The question is whether anything was OPEN when the page began, and that is - % `\TopMark`: empty on the title page, and never empty again afterwards. The - % second line stays empty there, because the title has no part under it yet. + % the top mark of the first level, `\TopMark{2e-left}`: empty on the title + % page, and never empty again afterwards. The class of the head of this + % template is no answer, because it carries a heading only where the heading + % opens a page: a section that begins in the middle of a page left it empty, + % and every page of a document out of Markdown carried the title in its head, + % measured on 2026-10-05. A page that a section opens is no title page either, + % and that one is the first mark of this class. The second line stays empty + % on the title page, because the title has no part under it yet. \newcommand{\business@beforeheadings}{% \begingroup - \protected@edef\business@carried{\TopMark{businesssection}}% + \protected@edef\business@carried{% + \TopMark{2e-left}\FirstMark{businesssection}}% \ifx\business@carried\@empty \global\business@untitledtrue \else @@ -677,12 +933,57 @@ % name inside the block and travels with it. \newcommand{\business@headbox}[2]{% \parbox[t]{#1}{#2}} + % How the line of the head is divided between the running head and the logo: + % the logo takes what it needs, measured on itself, and the running head takes + % the rest. A share of the line fits one company — the lockup of the house this + % suite came from takes 0.45 of it, the three words and the long address of + % another house take more, and the head then runs over the edge of the paper: + % measured on 2026-10-06 at a logo height of four ems, 65.11 points past the + % right edge, with the annotation of the link outside the page box. A gap of a + % quarter of the line keeps the two apart, and a logo wider than three quarters + % of the line is held there, so that the running head keeps a measure to break + % in. + \newlength{\business@logoroom} + \newlength{\business@logofit} + \newsavebox{\business@logoroombox} + % The height the head really sets the logo at. It is the height the document + % asked for, as long as the block that grows out of it fits the line: a name, + % a tagline and an address of a length nobody fixes make the block as wide as + % they make it, and at three quarters of the line the running head has nothing + % left to break in. Where it does not fit, the block is set at the height at + % which it does, which keeps every proportion inside it. + \newcommand{\business@logofitheight}{\business@logoheight} + \newcommand{\business@measurelogoroom}{% + \ifbusiness@pagelogo + \begingroup + \normalfont\normalsize + \global\let\business@logofitheight\business@logoheight + \sbox{\business@logoroombox}{% + \businesslogo[tagline, address, height=\business@logoheight]}% + \setlength{\business@logofit}{0.75\textwidth}% + \ifdim\wd\business@logoroombox>\business@logofit + \edef\business@logoratio{% + \fpeval{\number\business@logofit + / \number\wd\business@logoroombox}}% + \setlength{\business@logofit}{\business@logoheight}% + \setlength{\business@logofit}{\business@logoratio\business@logofit}% + \xdef\business@logofitheight{\the\business@logofit}% + \sbox{\business@logoroombox}{% + \businesslogo[tagline, address, + height=\business@logofitheight]}% + \fi + \global\business@logoroom=\dimexpr\wd\business@logoroombox+1em\relax + \endgroup + \else + \global\business@logoroom=\z@ + \fi} \newcommand{\business@headleftbox}[1]{% - \business@headbox{0.55\textwidth}{\raggedright#1}} + \business@headbox{\dimexpr\textwidth-\business@logoroom\relax}% + {\raggedright#1}} \newcommand{\business@headleft}{% \business@headleftbox{\business@runninghead}} \newcommand{\business@headright}[1]{% - \business@headbox{0.45\textwidth}{\raggedleft#1}} + \business@headbox{\business@logoroom}{\raggedleft#1}} \renewcommand{\sectionmark}[1]{\markboth{#1}{}} \renewcommand{\subsectionmark}[1]{\markright{#1}} @@ -791,6 +1092,17 @@ % carries both. \newcommand{\business@markahead}[3]{% \ifvmode\else\par\fi + % Whether the announcement above really stands directly above is asked here + % as it is asked at a sentence and at a table: a list between two headings + % sets an `\everypar` of its own, so the forgetting of the first paragraph + % never runs, and the lower heading took over the number of the upper one + % although a list stood between them. Every further heading then carried the + % same number, and the table at the end wrote its measurement under it: + % reserved in front of the FIRST heading, the whole distance down to the + % table. Reported on 2026-10-12 from a weekly report of four headings, each + % with a list, at 624 points — a page and a half, so the body began on page + % two and the document ran to three pages instead of two. + \ifx\business@announced\@empty\else\business@stale\fi \stepcounter{business@announcements}% \ifx\business@announced\@empty \business@carriesfalse @@ -1077,12 +1389,12 @@ \renewcommand{\footrulewidth}{0pt}% \fancyhead[L]{\business@headleft}% \fancyhead[R]{\business@headright{% - \businesslogo[tagline, address, height=\business@logoheight]}}% + \businesslogo[tagline, address, height=\business@logofitheight]}}% \fancyfoot[L]{\business@foot}% \fancyfoot[R]{\business@folio}% } \fancyhead[R]{\business@headright{% - \businesslogo[tagline, height=\business@logoheight]}} + \businesslogo[tagline, height=\business@logofitheight]}} \AtBeginDocument{\thispagestyle{firstpage}} \fi @@ -1186,12 +1498,14 @@ % reported on 2026-09-21 from a fourth company, at 0.13879 points, constant % over three documents. \normalfont\normalsize + \business@measurelogoroom \f@nch@checkfalse \fancyhead[L]{\business@headleftbox{% \business@runningstack{\business@measureletters}{}}}% \ifbusiness@pagelogo \fancyhead[R]{\business@headright{% - \businesslogo[tagline, address, height=\business@logoheight]}}% + \businesslogo[tagline, address, + height=\business@logofitheight]}}% \fi \setbox\@tempboxa\hbox{\@oddhead}% \global\business@headroom=\f@nch@height @@ -1200,7 +1514,7 @@ {\business@measureletters}}}% \ifbusiness@pagelogo \fancyhead[R]{\business@headright{% - \businesslogo[tagline, height=\business@logoheight]}}% + \businesslogo[tagline, height=\business@logofitheight]}}% \fi \setbox\@tempboxa\hbox{\@oddhead}% \ifdim\f@nch@height>\business@headroom @@ -1212,6 +1526,12 @@ \renewcommand{\business@identitychanged}{% \ifx\@onlypreamble\@notprerr\else\business@headmeasure\fi} \else + % The room the head takes is given, the room the logo takes is measured all + % the same: the division of the line is a width and has nothing to do with + % the height somebody wrote down. + \renewcommand{\business@identitychanged}{% + \ifx\@onlypreamble\@notprerr\else\business@measurelogoroom\fi} + \business@measurelogoroom \geometry{headheight=\business@headerheight} \fi % And the foot is measured the same way, on every document: what it takes is