Difference between revisions of "TextBackground"
m |
m (Remove MkII hint, enhance markup) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
{{todo|Add more examples of usage of textbackgrounds.}} | {{todo|Add more examples of usage of textbackgrounds.}} | ||
Line 27: | Line 25: | ||
frame=off,] | frame=off,] | ||
− | \ | + | \samplefile{knuth} |
\startsecondary | \startsecondary | ||
− | \ | + | \samplefile{knuth} |
\stopsecondary | \stopsecondary | ||
− | \ | + | \samplefile{knuth} |
</context> | </context> | ||
Line 50: | Line 48: | ||
frame=off,] | frame=off,] | ||
− | \ | + | \samplefile{knuth} |
\startsecondary | \startsecondary | ||
− | \ | + | \samplefile{knuth} |
\stopsecondary | \stopsecondary | ||
− | \ | + | \samplefile{knuth} |
</context> | </context> | ||
Line 62: | Line 60: | ||
Underlining is generally frowned upon by experienced TeXnicians. Occasionally, | Underlining is generally frowned upon by experienced TeXnicians. Occasionally, | ||
− | however, it is necessary and | + | however, it is necessary and {{cmd|ul}} or {{cmd|underbar}} doesn’t do what you want. In those |
− | cases using | + | cases using {{cmd|definetextbackground}} for the underlining may also be tried. |
<context source="yes"> | <context source="yes"> | ||
\definetextbackground[underline] | \definetextbackground[underline] | ||
[location=text,alternative=1,background=,frame=off] | [location=text,alternative=1,background=,frame=off] | ||
+ | |||
\definestartstop[underline] | \definestartstop[underline] | ||
[before={\starttextbackground[underline]}, | [before={\starttextbackground[underline]}, | ||
after=\stoptextbackground] | after=\stoptextbackground] | ||
+ | \startTEXpage | ||
An example with \startunderline underlined\stopunderline\ text. | An example with \startunderline underlined\stopunderline\ text. | ||
+ | \stopTEXpage | ||
</context> | </context> | ||
Line 84: | Line 85: | ||
setbounds currentpicture to p ; | setbounds currentpicture to p ; | ||
\stopuseMPgraphic | \stopuseMPgraphic | ||
+ | |||
\definetextbackground[underline] | \definetextbackground[underline] | ||
[location=text,alternative=1,background=,frame=off] | [location=text,alternative=1,background=,frame=off] | ||
+ | |||
\definestartstop[underline] | \definestartstop[underline] | ||
[before={\starttextbackground[underline]}, | [before={\starttextbackground[underline]}, | ||
after=\stoptextbackground] | after=\stoptextbackground] | ||
+ | |||
+ | \startTEXpage | ||
An example with \startunderline underlined\stopunderline\ text. | An example with \startunderline underlined\stopunderline\ text. | ||
+ | \stopTEXpage | ||
</context> | </context> | ||
Line 108: | Line 114: | ||
\startdashed | \startdashed | ||
− | \ | + | \samplefile{ward} |
\stopdashed | \stopdashed | ||
</context> | </context> | ||
− | + | [[Category:Basics]] | |
− | |||
− |
Revision as of 15:06, 31 August 2021
TODO: Add more examples of usage of textbackgrounds. (See: To-Do List) |
Pages, paragraphs, words can have a background color or frame. ConTeXt creates these using MetaPost.
(See, eventually, the details manual or the source for further explanations.)
Contents
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 textbackground.
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.
\definetextbackground[secondary][ location=paragraph, 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}
Background Offset
The options left, right, top, bottomoffset can be replaced by backgroundoffset yielding a different result:
\definetextbackground[secondary][ location=paragraph, background=color, backgroundcolor=lightgray, backgroundoffset=.5\bodyfontsize, before={\startnarrower\switchtobodyfont[small]}, after={\stopnarrower}, frame=off,] \samplefile{knuth} \startsecondary \samplefile{knuth} \stopsecondary \samplefile{knuth}
Underlining with Text Backgrounds
Underlining is generally frowned upon by experienced TeXnicians. Occasionally, however, it is necessary and \ul or \underbar doesn’t do what you want. In those cases using \definetextbackground for the underlining may also be tried.
\definetextbackground[underline] [location=text,alternative=1,background=,frame=off] \definestartstop[underline] [before={\starttextbackground[underline]}, after=\stoptextbackground] \startTEXpage An example with \startunderline underlined\stopunderline\ text. \stopTEXpage
If desired, the location of the line can also be adjusted.
\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] \startTEXpage An example with \startunderline underlined\stopunderline\ text. \stopTEXpage
Example: dashed underbar
(by WS, 4/2011)
\definetextbackground [dashed] [location=text, framecolor=black, alternative=1, voffset=-\strutdp, background=, frame=off, dash=1] \startdashed \samplefile{ward} \stopdashed