Changes

Jump to navigation Jump to search
1,457 bytes added ,  10:38, 5 February 2019
Moved and edited contents of Underlining_With_TextBackgrounds
{{todo|Add more examples of usage of textbackgrounds.}}
Pages, paragraphs, words can have a backgroundcolor or frame. ConTeXt creates these using [[MetaPost]]. (See, eventually, the [[manual: color details.pdf| details]] manual or screenthe {{src|anch-bck.mkvi|source}} for further explanations.)
== Example: multi-page backgrounded text ==
Perhaps one might like to offset examples from the running text, or signal to the reader that the following paragraphs contain secondary, detailed information that is of interest only to the specialists. This can be achieved using textbackgroundstextbackground.
In contrast, [[Framed]] creates text blocks that do not span columns or pages.
In the following example, we also reduce the textwidth and bodyfont size.
<context source="yes">
\setupcolors[state=start]
 
\definetextbackground[secondary][
location=paragraph, % background=screencolor, %doesn't work?? background=color,backgroundscreen backgroundcolor=middlegraylightgray, leftoffset=.5\bodyfontsize, rightoffset=.5\bodyfontsize, topoffset=.5\bodyfontsize, bottomoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\switchtobodyfont[normal]\stopnarrower}, frame=off,\starttext
\input knuth
\startsecondary
\input knuth
\stopsecondary
\input knuth
 
\stoptext
</context>
{{todo|The background does not show here using the live, online conTeXt processor. Why?}} == backgroundoffset Background Offset ==
The options left, right, top, bottomoffset can be replaced by backgroundoffset yielding a different result:
<context source="yes">
\setupcolors[state=start]
 
\definetextbackground[secondary][
location=paragraph, % background=screencolor, %doesn't work?? background backgroundcolor=color,backgroundscreen=middlegraylightgray, backgroundoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\switchtobodyfont[normal]\stopnarrower}, frame=off,\starttext
\input knuth
\startsecondary
\input knuth
\stopsecondary
\input knuth
</context>
 
== Underlining with Text Backgrounds ==
 
Underlining is generally frowned upon by experienced TeXnicians. Occasionally,
however, it is necessary and <cmd>ul</cmd> or <cmd>underbar</cmd> doesn’t do what you want. In those
cases using <cmd>definetextbackground</cmd> for the underlining may also be tried.
 
<context source="yes">
\definetextbackground[underline]
[location=text,alternative=1,background=,frame=off]
\definestartstop[underline]
[before={\starttextbackground[underline]},
after=\stoptextbackground]
An example with \stoptextstartunderline underlined\stopunderline\ text.
</context>
 
If desired, the location of the line can also be adjusted.
 
<context source="yes">
\startuseMPgraphic{mpos:par:columnset} % Shift underlining down a touch
\iftracepositions show_multi_pars \else draw_multi_pars \fi ;
path p ; p := boundingbox currentpicture ;
currentpicture := currentpicture shifted (0,-StrutDepth/3) ;
setbounds currentpicture to p ;
\stopuseMPgraphic
\definetextbackground[underline]
[location=text,alternative=1,background=,frame=off]
\definestartstop[underline]
[before={\starttextbackground[underline]},
after=\stoptextbackground]
An example with \startunderline underlined\stopunderline\ text.
</context>
 
 
=== Example: dashed underbar ===
(by WS, 4/2011)
 
<context source="yes">
\definetextbackground
[dashed]
[location=text,
framecolor=black,
alternative=1,
voffset=-\strutdp,
background=,
frame=off,
dash=1]
 
\startdashed
\input ward
\stopdashed
</context>
 
== What if textbackground doesn’t work? (MkII) ==
 
The textbackground commands require [[write18]] to be enabled; see that page for more information.

Navigation menu