Difference between revisions of "TextBackground"

From Wiki
Jump to navigation Jump to search
(Removed outdated comments and unnecessary commands)
Line 3: Line 3:
 
{{todo|Add more examples of usage of textbackgrounds.}}
 
{{todo|Add more examples of usage of textbackgrounds.}}
  
Pages, paragraphs, words can have a background: color or screen. Note that screen is depricated in MKIV.
+
Pages, paragraphs, words can have a background: color or screen. Note that "screen" is deprecated in MkIV.
  
 
(See, eventually, the [[manual:details.pdf| details]] manual for further explanations.)
 
(See, eventually, the [[manual:details.pdf| details]] manual for further explanations.)
  
== What if textbackground doesn't work? ==
+
== What if textbackground doesn’t work? ==
  
 
The textbackground commands require [[write18]] to be enabled; see that page for more information.
 
The textbackground commands require [[write18]] to be enabled; see that page for more information.
Line 19: Line 19:
 
In the following example, we also reduce the textwidth and bodyfont size.
 
In the following example, we also reduce the textwidth and bodyfont size.
 
<context source="yes">
 
<context source="yes">
\setupcolors[state=start]
 
 
 
\definetextbackground[secondary][
 
\definetextbackground[secondary][
        location=paragraph,
+
  location=paragraph,
        background=color,backgroundcolor=middlegray,
+
  background=color,
        leftoffset=.5\bodyfontsize,rightoffset=.5\bodyfontsize,
+
  backgroundcolor=lightgray,
        topoffset=.5\bodyfontsize,bottomoffset=.5\bodyfontsize,
+
  leftoffset=.5\bodyfontsize,
        before={\startnarrower\switchtobodyfont[small]},
+
  rightoffset=.5\bodyfontsize,
        after={\stopnarrower},
+
  topoffset=.5\bodyfontsize,
        frame=off]
+
  bottomoffset=.5\bodyfontsize,
 
+
  before={\startnarrower\switchtobodyfont[small]},
\starttext
+
  after={\stopnarrower},
 +
  frame=off,]
  
 
\input knuth
 
\input knuth
  
 
\startsecondary
 
\startsecondary
\input knuth
+
\input knuth
 
\stopsecondary
 
\stopsecondary
  
 
\input knuth
 
\input knuth
 
\stoptext
 
 
</context>
 
</context>
 
{{todo|The background does not show here using the live, online conTeXt processor. Why?}}
 
  
 
== backgroundoffset ==
 
== backgroundoffset ==
Line 50: Line 45:
  
 
<context source="yes">
 
<context source="yes">
\runMPgraphicsfalse %Needed because the wiki runs MkII and write18 is not enabled
 
 
\setupcolors[state=start]
 
 
 
\definetextbackground[secondary][
 
\definetextbackground[secondary][
        location=paragraph,
+
  location=paragraph,
        background=color,backgroundcolor=middlegray,
+
  background=color,
        backgroundoffset=.5\bodyfontsize,
+
  backgroundcolor=lightgray,
        before={\startnarrower\switchtobodyfont[small]},
+
  backgroundoffset=.5\bodyfontsize,
        after={\stopnarrower},
+
  before={\startnarrower\switchtobodyfont[small]},
        frame=off]
+
  after={\stopnarrower},
 
+
  frame=off,]
\starttext
 
  
 
\input knuth
 
\input knuth
  
 
\startsecondary
 
\startsecondary
\input knuth
+
\input knuth
 
\stopsecondary
 
\stopsecondary
  
 
\input knuth
 
\input knuth
 
\stoptext
 
 
</context>
 
</context>
  
Line 78: Line 66:
  
 
<context source="yes">
 
<context source="yes">
\runMPgraphicsfalse % This is needed because the wiki runs MkII and write18 is not enabled.
 
\setuppapersize[B5]
 
\setupbodyfont[10pt]
 
 
 
\definetextbackground
 
\definetextbackground
 
   [dashed]
 
   [dashed]
   [   location=text,
+
   [location=text,
    framecolor=black,
+
  framecolor=black,
 
   alternative=1,
 
   alternative=1,
      voffset=-\strutdp,
+
  voffset=-\strutdp,
    background=,
+
  background=,
        frame=off,
+
  frame=off,
          dash=1]
+
  dash=1]
  
\starttext
+
\startdashed
  \startdashed\input ward \stopdashed
+
\input ward
\stoptext
+
\stopdashed
 
</context>
 
</context>

Revision as of 10:23, 5 February 2019

< Main Page | Visuals >


TODO: Add more examples of usage of textbackgrounds. (See: To-Do List)


Pages, paragraphs, words can have a background: color or screen. Note that "screen" is deprecated in MkIV.

(See, eventually, the details manual for further explanations.)

What if textbackground doesn’t work?

The textbackground commands require write18 to be enabled; see that page for more information.

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,]

\input knuth

\startsecondary
\input knuth
\stopsecondary

\input knuth

backgroundoffset

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,]

\input knuth

\startsecondary
\input knuth
\stopsecondary

\input knuth

Example: dashed underbar (by WS, 4/2011)

\definetextbackground
  [dashed]
  [location=text,
   framecolor=black,
   alternative=1,
   voffset=-\strutdp,
   background=,
   frame=off,
   dash=1]

\startdashed
\input ward
\stopdashed