# Inserting a box with shaded background text, in plain TeX.

I'm using Plain TeX and trying to create a box that has a shaded background, containing a mixture of both mathmode and textmode TeX. It would be great if I could add colour to the background (i.e. like black text over a pale yellow background) but grayscale would be fine, as well.

I've looked around and I've found some implementations of this but I have not found a flexible Plain TeX package. Is there not one? Perhaps I don't know what to search for.

Thanks for any help.

• Have a look at OPmac, petr.olsak.net/opmac-e.html – User Mar 30 '16 at 23:31
• Apologies, it appears I did not try OPmac. I've installed csplain and have tried setting text colors using both \coltext and \localcolor, and the \coloron macro. {\localcolor\Red blah} prints out black on white text. \coloron\Yellow\Blue{blah2} prints out a black box. \coltext\Yellow\Blue{blah blah blah} complains about an undefined control sequence. – Ryan Budney Mar 31 '16 at 1:06
• I notice the colors do not appear in the dvi file, and if I use either dvips or dvipdf, neither add in the colours. I suspect there's some kind of set-up problem with these macros but the documentation doesn't seem to indicate you need anything other than csplain... Aha! I seem to have figured it out. You don't run csplain, you run pdfcsplain. It appears if you output to dvi first, it strips-out the colours. – Ryan Budney Mar 31 '16 at 3:28
• You can use TikZ with Plain TeX. Try using pdfTeX to compile your doc to produce pdf output directly, I don't think there is any advantage to output DVI, except for synchronisation in some setups. – corporal Mar 31 '16 at 3:57
• I am unable to get the \setbgcolor macro in OPmac to work. Strange since all the other color macros seem to be working. – Ryan Budney Mar 31 '16 at 4:08

For example

\input opmac

\def\yellowbox#1{\setbox0=\vbox{{\medskip#1\medskip}}%
{\localcolor \Yellow \hrule height\ht0 width\wd0}\kern-\ht0
\box0
}

\yellowbox{
This is text
$$a^2+b^2=c^2 \eqno (1)$$
another text.
}
\bye


If you want to print only coloured rectangles then you need not TikZ. TeX primitives \vrule or \hrule are sufficient.

Question answered in comments. It appears the TikZ library, combined with OPmac does the job. When I switch to TikZ I have to use pdftex, which disables the epsf macros. So now I import my images via OPmac.

The only downside to this I see at present is I can't use psfrag with this set-up. But thankfully my current application does not call for psfrag.