[luatex] Change background color for Plain TeX using LuaTeX?

Henri Menke henrimenke at gmail.com
Sun Nov 25 03:39:01 CET 2018


On 11/25/18 3:30 PM, Henri Menke wrote:
> On 11/25/18 2:56 PM, Steve Litt wrote:
>> This regards Plain TeX. I know there are ways to easily do it in
>> LaTeX.
>> 
>> Is there something I can put within \directlua{} or anywhere else
>> to change the background color of a series of letters or a series of
>> lines?
> 
> You can change the backgroundcolor of the page like shown below.  You
> can easily adapt the code for only a single box.
> 
> {\catcode`\.=12
>  \catcode`\p=12
>  \catcode`\t=12
>  \gdef\WITHOUTPT#1pt{#1}}
> 
> \def\withoutpt#1%
>   {\expandafter\WITHOUTPT#1}
> 
> \pdfextension literal page {
>   q % push current graphics state onto the stack
>   0 0 1 rg % RGB color for non-stroking operation
>   0 0 1 RG % RGB color for stroking operation
>   n % end the current path object without filling or stroking
>   0 0 \withoutpt{\the\pagewidth} \withoutpt{\the\pageheight} re %
> construct rectangle
>   f % fill the path
>   Q % pop previous graphics state off the stack
> }
> 
> Hello World!
> 
> \bye

To set the background color of a single box, I'd just put a colored rule
behind it.

\protected\def\colorbox[#1]#2{%
  \setbox0=\hbox{#2}
  \leavevmode\rlap{%
    \pdfextension literal direct {
      q
      #1 rg
    }%
    \vrule width \wd0 height \ht0 depth \dp0\relax
    \pdfextension literal direct {
      Q
    }%
  }\box0
}

\colorbox[0 0 1]{Hello World!}

\colorbox[1 0 0]{\it different}

\colorbox[.3 .7 .1]{\TeX}

\bye

> 
>> 
>> Thanks,
>> 
>> SteveT
>> 
>> Steve Litt
>> November 2018 featured book: Manager's Guide to Technical
>> Troubleshooting Brand new, second edition
>> http://www.troubleshooters.com/mgr
>> 
> 



More information about the luatex mailing list