Honour \definecolor - #31
Merged
Merged
Conversation
xcolor lets a document name its own colours. Without that, a page wanting a
shade xcolor does not define had no valid way to ask for it — and the pages on
latex2js.com ask for `lightblue`, which real LaTeX rejects outright:
! Package xcolor Error: Undefined color `lightblue'.
So those pages could not compile at all, and only rendered here because this
handed unknown names to the browser, where CSS happens to know that one. That
is the gap this closes: `\definecolor{lightblue}{RGB}{173,216,230}` says
exactly which colour is meant, in a line LaTeX and this agree on.
All five xcolor models are read — rgb and cmyk as fractions, RGB as 0-255,
gray as one fraction, HTML as six hex digits — and a definition may shadow a
built-in of the same name, as it may in xcolor. A model this cannot read is
reported against the declaration rather than silently ignored.
Definitions belong to a document, not to the parser: they are cleared at the
start of each parse, next to the counters, so a reused instance does not
inherit the previous document's palette.
Intercepted where \psset is rather than in the command walk. The grammar
delivers a command inside the line that holds it, not as a node of its own, so
a walk-level handler never fires and the declaration would be rendered as text.
A blank line became a `<br>`, one per blank line, so the gap between two paragraphs was however many times the author happened to press return, and no stylesheet could reach it. That is not what a blank line means in TeX. In TeX a run of blank lines — of any length — is a single \par, and the space between paragraphs comes from \parskip: a document style, set once. Two blank lines and one are the same input. So text is grouped into real paragraphs now. A run of breaks ends one, however long the run is, and the gap is the paragraph's own margin, named in the stylesheet as --latex2js-parskip. That is the whole point of the change: the spacing became a style, which is both what TeX means and the only version a theme can restyle. A picture takes the same value, so a figure and a paragraph sit apart by the same amount. Only the plain text environment is grouped. A list keeps its \item lines for its own component to turn into <li>, verbatim is literal, a picture is commands, and a nicebox is one inline run — wrapping any of those in paragraphs breaks the element that consumes them. The text container is a div rather than a span, because a <p> inside a <span> is invalid nesting that a browser silently hoists out, taking the text with it. This supersedes the blank-line collapsing added a few commits ago. That change was written for a real problem — a break beside a heading stacks against the heading's own margin — but it also folded runs of breaks between ordinary paragraphs into one, which halved the gap on every page. The problem was adjacency, not repetition, and modelling paragraphs properly removes both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
xcolor lets a document name its own colours. Without that, a page wanting a shade xcolor does not define had no valid way to ask for it.
Why this came up
The pages on latex2js.com ask for
lightblue. Real LaTeX rejects it:So those pages could not compile at all, and rendered here only because unknown names were handed to the browser, where CSS happens to know that one.
\definecolor{lightblue}{RGB}{173,216,230}says exactly which colour is meant, in a line LaTeX and this agree on.What it does
rgbandcmykas fractions,RGBas 0-255,grayas one fraction,HTMLas six hex digits.Intercepted where
\pssetis rather than in the command walk: the grammar delivers a command inside the line that holds it, not as a node of its own, so a walk-level handler never fires and the declaration would be rendered as text.Verified against real LaTeX
The snippet the site now uses compiles with zero errors through
latex → dvips → ps2pdf → gs, and renders the intended colours.10 new tests; 568 across the repo.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HBYcp3Go9naDWgFThChaDf