Changes

Jump to navigation Jump to search
1,293 bytes added ,  15:06, 31 August 2021
m
Remove MkII hint, enhance markup
< [[Main Page]] | [[Visuals]] >
 
{{todo|Add more examples of usage of textbackgrounds.}}
Pages, paragraphs, words can have a background: color or screenframe. ConTeXt creates these using [[MetaPost]].
(See, eventually, the [[manual:details.pdf| details]] manual or the {{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">
\setupcolorsdefinetextbackground[statesecondary][ location=startparagraph, background=color, backgroundcolor=lightgray, leftoffset=.5\bodyfontsize, rightoffset=.5\bodyfontsize, topoffset=.5\bodyfontsize, bottomoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\stopnarrower}, frame=off,\samplefile{knuth} \startsecondary\samplefile{knuth}\stopsecondary \samplefile{knuth}</context> == Background Offset == The options left, right, top, bottomoffset can be replaced by backgroundoffset yielding a different result:
<context source="yes">
\definetextbackground[secondary][
location=paragraph, %background=screen, %doesn't work?? background=color,backgroundscreen=middlegray, leftoffset backgroundcolor=.5\bodyfontsize,rightoffset=.5\bodyfontsizelightgray, topoffset=.5\bodyfontsize,bottomoffset backgroundoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\switchtobodyfont[normal]\stopnarrower}, frame=off,]
\starttext \input samplefile{knuth}
\startsecondary
\input samplefile{knuth}
\stopsecondary
\input samplefile{knuth}</context>
\stoptext== Underlining with Text Backgrounds ==</context>Underlining is generally frowned upon by experienced TeXnicians. Occasionally,however, it is necessary and {{cmd|ul}} or {{cmd|underbar}} doesn’t do what you want. In thosecases using {{cmd|definetextbackground}} for the underlining may also be tried.
{{todo|The <context source="yes">\definetextbackground[underline] [location=text,alternative=1,background does not show here using the live=, online conTeXt processor. Why?}}frame=off]
\definestartstop[underline] [before={\starttextbackground[underline]}, after= backgroundoffset ==\stoptextbackground]
The options left\startTEXpageAn example with \startunderline underlined\stopunderline\ text.\stopTEXpage</context> If desired, right, top, bottomoffset the location of the line can also be replaced by backgroundoffset yielding a different result:adjusted.
<context source="yes">
\setupcolors[statestartuseMPgraphic{mpos:par:columnset} % Shift underlining down a touch \iftracepositions show_multi_pars \else draw_multi_pars \fi ; path p ; p :=start]boundingbox currentpicture ; currentpicture := currentpicture shifted (0,-StrutDepth/3) ; setbounds currentpicture to p ;\stopuseMPgraphic
\definetextbackground[secondaryunderline] [ location=paragraphtext, %backgroundalternative=screen1, %doesn't work?? background=color,backgroundscreenframe=middlegray,off]  backgroundoffset=.5\bodyfontsize,definestartstop[underline] [before={\startnarrower\switchtobodyfontstarttextbackground[smallunderline]}, after={\switchtobodyfont[normal]\stopnarrower}, frame=offstoptextbackground]
\starttextstartTEXpageAn example with \startunderline underlined\stopunderline\ text.\stopTEXpage</context>
\input knuth
\startsecondary=== Example: dashed underbar === \input knuth\stopsecondary(by WS, 4/2011)
<context source="yes">\input knuthdefinetextbackground [dashed] [location=text, framecolor=black, alternative=1, voffset=-\strutdp, background=, frame=off, dash=1]
\stoptextstartdashed\samplefile{ward}\stopdashed
</context>
 
[[Category:Basics]]

Navigation menu