Skip to content

Commit

Permalink
Attempt to improve color documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vlasakm committed Jul 11, 2021
1 parent 0890455 commit efc05d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
44 changes: 20 additions & 24 deletions optex/base/colors.opm
Original file line number Diff line number Diff line change
Expand Up @@ -320,30 +320,26 @@ PDF.

\TeX/ itself has no concept of colors. Colors have always been handled by
inserting whatsits (either using `\special` for DVI or using
`\pdfliteral`/`\pdfcolorstack` for PDF). It is very efficient way of doing
it, \TeX/ doesn't have to know anything about colors, it just inserts the
relevant literals when doing `\shipout`. However, it is also problematic in
many ways.

This is reason we decide to change colors handling from `\pdfcolorstack` to
\LuaTeX/ attributes in version 1.04 of \OpTeX. Using attributes, the color
setting looks exacly like font selection from \TeX/ point of view: it
respects \TeX/ groups, colors can span to more pages, independent colors
can be set for in all `\insert`s. Moreover, once a material is typeset
(using `\setbox` for example) then it has its fonts and its colors
definitelly set and you can rely on it when you are using `\unhbox` etc.\
operations. There are no internal whatsits for colors which can interferre
with other typesetting material.

The \LuaTeX/ attributes can be set like other register settings and after
such a setting, their values are bound to essentially everything \TeX/ creates
(characters, rules, glues, \dots).
We use one attribute \^`\_colorattr` for information of currently selected
color. Setting a color means only to set appropriate value to this attribute.
The value is propagated to each created typesetting element until the attribute
is unset or set to another value. So, setting the attribute behaves exactly
like selecting the font. You can use `{\bf text}` to have text in bold and
`{\Red text}` to have text in red.
`\pdfliteral`/`\pdfcolorstack` for PDF). It is very efficient and \TeX/ doesn't
even have to know anything about colors, but it is also problematic in many
ways.

That is the reason why we decided to change color handling from
`\pdfcolorstack` to \LuaTeX/ attributes in version 1.04 of \OpTeX. Using
attributes, the color setting behaves exactly like font selection from \TeX/
point of view: it respects \TeX/ groups, colors can span more pages,
independent colors can be set for `\insert`s, etc. Moreover, once a material is
created (using `\setbox` for example) then it has its fonts and its colors
frozen and you can rely on it when you are using e.g. `\unhbox`. There are no
internal whatsits for colors which can interfere with other typesetting
material. In the end something like setting text to red (`{\Red text}`) should
have the same nice behavior like setting text to bold (`{\bf text}`).

\LuaTeX/ attributes can be set like count register -- one attribute holds one
number at a time. But the value of attribute is propagated to each created
typesetting element until the attribute is unset or set to another value. Very
much like the font property. We use one attribute \^`\_colorattr` for storing
the currently selected color (in number form).

Macros \^`\setcmykcolor``{<C> <M> <Y> <K>}` or \^`\setrgbcolor``{<R> <G> <B>}`
or\nl \^`\setgreycolor``{<Grey>}` are used in color selectors. These
Expand Down
8 changes: 4 additions & 4 deletions optex/doc/optex-userdoc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1413,18 +1413,18 @@
\setbox0=\hbox{#2#3}\leavevmode
\rlap{#1\strut \vrule width\wd0}\box0
}
The following example defines the macro for the
\coloron\Yellow\Brown{colored text on the colored background}. Usage:
The following example defines the macro for
\coloron\Yellow\Brown{colored text on colored background}. Usage:
`\coloron<background><foreground>{<text>}`
The `\coloron` can be defined as follows:
The `\coloron` macro can be defined as follows:
\begtt
\def\coloron#1#2#3{%
\setbox0=\hbox{#2#3}%
\leavevmode \rlap{#1\strut \vrule width\wd0}\box0
}
\coloron\Yellow\Brown{The brown text on the yellow background}
\coloron\Yellow\Brown{Brown text on yellow background}
\endtt
\secc Images
Expand Down

0 comments on commit efc05d3

Please sign in to comment.