Changes

Jump to navigation Jump to search
1,858 bytes added ,  19:03, 6 December 2023
more intro
< {{todo|Add more examples of usage of textbackgrounds.}} == Basics == Pages, paragraphs, words can have a background color or [[Main PageOverlays|overlay]] | . ConTeXt creates these using [[VisualsMetaPost]] >. But a usual frame is only one object, its contents can’t flow over to the next page. You can use {{cmd|definetextbackground}} to define a named text background. The environment is based on {{cmd|framed}} and understands its parameters, but can contain several paragraphs and page breaks.
After `\definetextbackground[Name]` you can use `\startName ... \stopName` (if there’s no name conflict) or `\starttextbackground[Name] ... \stoptextbackground`. Usually you won’t need {{todocmd|Add more examples of usage of textbackgrounds.setuptextbackground}}.
Pages, The `location` parameter changes the behaviour between `text` (highlighting running text) and `paragraph` (boxed paragraphs, words can have a background: color or screen).
(See, eventually, the [[manual:details.pdf| details]] manual or the {{src|anch-bck.mkvi|source}} for further explanations.)
== What if textbackground doesn't work? ==
'''Beware''': The textbackground commands require [[write18]] to examples using {{cmd|startnarrower}} may be enabledmisleading – of course you can use {{cmd|startbackground}} without the `narrower` environment; see that page for more informationit behaves differently without `\starttext ... \stoptext`.
== Example: multi-page backgrounded text ==
In the following example, we also reduce the textwidth and bodyfont size.
<context source="yes">
\setupcolors[state=start]
 
\definetextbackground[secondary][
location=paragraph, background=color, backgroundcolor=middlegraylightgray, leftoffset=.5\bodyfontsize, rightoffset=.5\bodyfontsize, topoffset=.5\bodyfontsize, bottomoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\stopnarrower}, frame=off,]
\starttext
 \input samplefile{knuth}
\startsecondary
\input samplefile{knuth}
\stopsecondary
\input samplefile{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=color, backgroundcolor=middlegraylightgray, backgroundoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\stopnarrower}, frame=off,]
\starttext
 \input samplefile{knuth}
\startsecondary
\input samplefile{knuth}
\stopsecondary
\input samplefile{knuth}\stoptext</context> == Underlining with Text Backgrounds ==
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. <context source="yes">\stoptextdefinetextbackground[underline] [location=text,alternative=1,background=,frame=off] \definestartstop[underline] [before={\starttextbackground[underline]}, after=\stoptextbackground] \startTEXpageAn example with \startunderline underlined\stopunderline\ text.\stopTEXpage</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] \startTEXpageAn example with \startunderline underlined\stopunderline\ text.\stopTEXpage
</context>
== Example: dashed underbar (by WS, 4/2011) ==
<context>=== Example: dashed underbar ===\setuppapersize[B5]\setupbodyfont[10pt](by WS, 4/2011)
<context source="yes">
\definetextbackground
[dashed]
[ location=text, framecolor=black,
alternative=1,
voffset=-\strutdp, background=, frame=off, dash=1]
\starttextstartdashed \startdashed\input samplefile{ward }\stopdashed\stoptext
</context>
 
[[Category:Basics]]

Navigation menu