Difference between revisions of "Framed"

From Wiki
Jump to navigation Jump to search
(added subsection on gray math background)
m (Fix typesetting of \, in its explanation.)
 
(55 intermediate revisions by 13 users not shown)
Line 1: Line 1:
< [[Visuals]] |
 
 
 
{{todo|the page devoted to all kinds of framed stuff}}
 
 
 
= How to achieve specific results =
 
= How to achieve specific results =
  
 
== Preventing hyphenation ==
 
== Preventing hyphenation ==
  
One can prevent hyphenation inside a frame by passing <code>nothypenated</code> option to <code>align</code>. It is also a good idea to add <code>verytolerant</code> and <code>strectch</code> options.
+
One can prevent hyphenation inside a frame by passing {{code|1=nothypenated}} option to {{code|1=align}}. It is also a good idea to add {{code|1=verytolerant}} and {{code|1=stretch}} options.
  
 
<context source="yes">
 
<context source="yes">
\startcombination[2*1]
+
\setuppapersize[A5]
 +
\startcombination[2*2]
 
{\framed
 
{\framed
 
   [width=5cm,
 
   [width=5cm,
Line 21: Line 17:
 
     align={flushleft,nothyphenated,verytolerant}] % maybe also stretch
 
     align={flushleft,nothyphenated,verytolerant}] % maybe also stretch
 
   {\input ward \endgraf}}
 
   {\input ward \endgraf}}
{flushleft,\crlf nothypenated, \crlf verytolerant}
+
{flushleft,\crlf nothyphenated, \crlf verytolerant}
 +
{\framed
 +
  [width=5cm,
 +
    align={flushright,nothyphenated,verytolerant}] % maybe also stretch
 +
  {\input ward \endgraf}}
 +
{flushright,\crlf nothyphenated, \crlf verytolerant}
 +
{\framed
 +
  [width=5cm,
 +
    align={width,nothyphenated,verytolerant}] % maybe also stretch
 +
  {\input ward \endgraf}}
 +
{width,\crlf nothyphenated, \crlf verytolerant}
 
\stopcombination
 
\stopcombination
 
</context>
 
</context>
Line 27: Line 33:
 
== Specify the width no longer than needed ==
 
== Specify the width no longer than needed ==
  
I want to specify the maximum width of a frame. If the size of the box is smaller than the maximum width, I want a tight box. This can be done using the <code>autowidth=force</code> option to framed.
+
I want to specify the maximum width of a frame. If the size of the box is smaller than the maximum width, I want a tight box. This can be done using the {{code|1=autowidth=force}} option to framed.
  
 
<context source="yes">
 
<context source="yes">
 +
\setuppapersize[A5]
 
\defineframed
 
\defineframed
 
   [tightframed][width=5cm,autowidth=force,align=middle]
 
   [tightframed][width=5cm,autowidth=force,align=middle]
Line 37: Line 44:
 
\tightframed{A really really long line that is split at 5cm}
 
\tightframed{A really really long line that is split at 5cm}
  
 +
</context>
 +
 +
== Ruled Frames ==
 +
 +
{{cmd|framed}} allows you to specify specific edges to be ruled.
 +
As an alternative to {{code|1=frame=on}} (the default), one can specify
 +
{{code|1=topframe=on}}, etc.
 +
Note that, as the default is to draw a complete frame,
 +
it is necessary to either specify the state (on/off) for all four edges
 +
or include the keyword {{code|1=frame=off}}.
 +
 +
<context source="yes">
 +
\setuppapersize[A5]
 +
\framed[frame=off,topframe=on,leftframe=on]{A fancy title}
 +
</context>
 +
 +
The thickness of the frame rule can be specified using {{code|1=rulethickness=}}
 +
 +
<context source="yes">
 +
\setuppapersize[A5]
 +
\framed[frame=off,leftframe=on,rulethickness=2pt]{\tfa\bf A fancy title}
 
</context>
 
</context>
  
 
== Rounded Corners ==
 
== Rounded Corners ==
  
<cmd>framed</cmd> allows you to have round corners with <code>corner=round</code>. There are also other possibilities if you want round corners but not at all places by giving an appropriate number to <code>corner=...</code>. This example is taken from [[source:core-rul.tex | core-rul.tex]] and each frame is typeset using
+
{{cmd|framed}} allows you to have round corners with {{code|1=corner=round}}. There are also other possibilities if you want round corners but not at all places by giving an appropriate number to {{code|1=corner=...}}. This example is taken from [[source:core-rul.tex | core-rul.tex]] and each frame is typeset using
  
 
<texcode>
 
<texcode>
Line 48: Line 76:
  
 
<context>
 
<context>
 +
    \setuppapersize[A5]
 
     \dontleavehmode\framed
 
     \dontleavehmode\framed
 
         [corner=0,frame=on,
 
         [corner=0,frame=on,
Line 86: Line 115:
 
         {\tttf corner=\twodigits\recurselevel}%
 
         {\tttf corner=\twodigits\recurselevel}%
 
         \quad}
 
         \quad}
 
 
</context>
 
</context>
  
Line 94: Line 122:
 
== Coloring frame background and framed text ==
 
== Coloring frame background and framed text ==
  
First you have to turn on colors with <cmd>setupcolors</cmd><tt>[state=start]</tt>. Then you can define the background and foreground (=text) colors:
+
First you have to turn on colors with {{cmd|setupcolors|2=[state=start]}}. Then you can define the background and foreground (=text) colors:
  
 
<texcode>\framed[background=color,backgroundcolor=....,foreground=color,foregroundcolor=...]{...}</texcode>
 
<texcode>\framed[background=color,backgroundcolor=....,foreground=color,foregroundcolor=...]{...}</texcode>
  
If you want to make the frame itself disappear, add a <tt>frame=off</tt> to the setups.
+
If you want to make the frame itself disappear, add a {{code|1=frame=off}} to the setups.
  
 
+
{|
<context>
+
|<context>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 
\framed
 
\framed
Line 108: Line 136:
 
   {\ssx \bf Bold white on dark blue}
 
   {\ssx \bf Bold white on dark blue}
 
</context>
 
</context>
 
+
|<texcode>
<context>
+
\setupcolors[state=start]
 +
\framed
 +
  [background=color,backgroundcolor=darkblue,
 +
  foreground=color,foregroundcolor=white]
 +
  {\ssx \bf Bold white on dark blue}
 +
</texcode>
 +
|-
 +
|<context>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 
\framed
 
\framed
Line 116: Line 151:
 
   {\tfx Who needs highlighter pens, anyway?}
 
   {\tfx Who needs highlighter pens, anyway?}
 
</context>
 
</context>
 
+
|<texcode>
For filling frames with offset you have to add options <code>frameoffset=..., backgroundoffset=...</code>
+
\framed
 
+
  [background=color,backgroundcolor=yellow,
<context>
+
  frame=off]
 +
  {\tfx Who needs highlighter pens, anyway?}
 +
</texcode>
 +
|-
 +
|<context>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 
\framed
 
\framed
   [frame=on, corner=0, frameoffset=10pt,framecolor=black,background=color,backgroundcolor=darkgreen, backgroundoffset=10pt, foreground=color,foregroundcolor=white]
+
   [frame=on, corner=0, frameoffset=10pt,
 +
  framecolor=black,background=color,
 +
  backgroundcolor=darkgreen, backgroundoffset=10pt,
 +
  foreground=color,foregroundcolor=white]
 
   {\tfxx \bf Rounded corners with offset}
 
   {\tfxx \bf Rounded corners with offset}
 
</context>
 
</context>
 +
|For filling frames with offset you have to add options {{code|1=frameoffset=..., backgroundoffset=...}}
 +
<texcode>
 +
\framed
 +
  [frame=on, corner=0, frameoffset=10pt,
 +
  framecolor=black,background=color,
 +
  backgroundcolor=darkgreen, backgroundoffset=10pt,
 +
  foreground=color,foregroundcolor=white]
 +
  {\tfxx \bf Rounded corners with offset}
 +
</texcode>
 +
|}
  
See the [[Colors]] section for more information on available colors and color usage.
+
See the [[Color]] article for more information on available colors and color usage.
  
 
== Shaded background for part of a displayed equation ==
 
== Shaded background for part of a displayed equation ==
  
To highlight part of a formula, you can give it a gray background using <cmd>framed</cmd>:
+
To highlight part of a formula, you can give it a gray background using {{cmd|mframed}}:
  
<texcode>
+
<context source="yes">
 +
\setuppapersize[A5]
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 
\def\graymath{\mframed[frame=off,
 
\def\graymath{\mframed[frame=off,
Line 142: Line 195:
 
   \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
 
   \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
 
\stopformula
 
\stopformula
 +
</context>
 +
 +
The {{code|\,}} adds a tiny bit of space to prevent the gray background from crowding the equals and plus sign.
 +
 +
== Inline Frames ==
 +
 +
The command {{cmd|inframed}}, similar to {{cmd|framed}},
 +
differs in the definition of the baseline:
 +
 +
<context source="yes">
 +
\setuppapersize[A5]
 +
\framed[frame=off,width=10em,align=flushleft]{%
 +
Notice the difference between
 +
\framed{framed} and \inframed{inframed},
 +
especially considering its effect on linespacing...
 +
}
 +
</context>
 +
 +
== Dotted Frames ==
 +
 +
Using MetaPost:
 +
 +
<texcode>
 +
\startuniqueMPgraphic{Label}
 +
path p; p := (0,0) -- (OverlayWidth,0) -- (OverlayWidth, OverlayHeight) -- (0, OverlayHeight) -- (0,0);
 +
draw p withpen pencircle scaled 1pt dashed withdots;
 +
setbounds currentpicture to boundingbox OverlayBox;
 +
\stopuniqueMPgraphic
 +
\defineoverlay[Label][\useMPgraphic{Label}]
 +
\def\DotPicture#1#2#3%
 +
{%
 +
  \placefigure[][#3]{#2}%
 +
  {%
 +
    \framed[align={flushleft, low},%
 +
            frame=off,%
 +
            height=3in,%
 +
            width=broad]%
 +
    {%
 +
      \externalfigure[#1]%
 +
                    [width=3in,%
 +
                      background=Label,%
 +
                      backgroundoffset=1ex]%
 +
    }%
 +
  }%
 +
}%
 +
\def\DotText#1%
 +
{%
 +
  \framed[frame=off,%
 +
          background=Label,%
 +
          location=low]%
 +
  {%
 +
    #1
 +
  }%
 +
}%
 +
\starttext
 +
 +
\DotPicture{sample/cow.pdf}{All your base are belong to us}{SampleRef}%
 +
 +
AAA \DotText{BBB} CCC \DotText{DDD}
 +
\stoptext
 
</texcode>
 
</texcode>
 +
[[File:dotted_frame_mpost.png|650px]]
 +
 +
Using TikZ:
 +
 +
<context source="yes">
 +
\setuppapersize[A5]
 +
\usemodule[tikz]%
 +
\tikzstyle{block}=[rectangle,draw=black,text centered,style=dotted,inner sep=0pt]
 +
\def\Picture#1#2#3%
 +
{
 +
  \placefigure[left][#3]{#2}%
 +
  {%
 +
    \tikzpicture%
 +
      \node[block](init){\externalfigure[#1][width=3in]};%
 +
    \endtikzpicture%
 +
  }%
 +
}%
 +
\starttext
 +
\Picture{sample/cow.pdf}{All your base are belong to us}{SampleRef}
 +
\stoptext
 +
</context>
 +
 +
 +
== Colorored horizontal stripe of full paper width ==
 +
 +
<context mode="mkiv" source="yes">
 +
\definepapersize[sheet][width=120mm,height=60mm]
 +
\setuppapersize[sheet]
 +
\setuppagenumbering[location=]
 +
\setuplayout
 +
  [width=110mm,
 +
  backspace=5mm,
 +
  topspace=5mm,
 +
  header=5mm,
 +
  headerdistance=5mm,
 +
  footer=5mm,
 +
  footerdistance=5mm]
 +
 +
\showframe
 +
 +
\setupbackgrounds[page]  [background=color, backgroundcolor=lightgray]
 +
 +
\startuniqueMPgraphic{whatever}
 +
fill OverlayBox
 +
    leftenlarged BackSpace rightenlarged CutSpace
 +
    withcolor OverlayColor;
 +
setbounds currentpicture to OverlayBox enlarged max(BackSpace,CutSpace);
 +
\stopuniqueMPgraphic
 +
 +
\defineoverlay[whatever][\uniqueMPgraphic{whatever}]
 +
\starttext
 +
 +
Here some text first.
 +
 +
\framed[background=whatever,backgroundcolor=green,frame=off,width=\textwidth]{test}
 +
 +
After, again some text.
 +
 +
\stoptext
 +
 +
</context>
 +
 +
= Width broad and local =
 +
Sometimes {{code|1=width}} must be adapted to a "local" {{code|1=\hsize }}
 +
(the actual text area used by TeX to determine line breaks).
 +
For example:
 +
<context source='yes'>
 +
\setuppapersize[A5]
 +
\setuppapersize[A7,landscape][A7,landscape]
 +
\setupbodyfont[8pt,ss]
 +
\starttext
 +
\framed[width=broad]{}
 +
\startnarrower[left]
 +
\framed[width=broad]{}
 +
\dontleavehmode\framed[width=broad]{}
 +
\dontleavehmode\framed[width=local]{}
 +
\stopnarrower
 +
\blank
 +
\hsize.5\hsize
 +
\framed[width=broad]{}
 +
\startnarrower[left]
 +
\framed[width=broad]{}
 +
\dontleavehmode\framed[width=broad]{}
 +
\dontleavehmode\framed[width=local]{}
 +
\stopnarrower
 +
\stoptext
 +
</context>
  
<context>
+
Here we use {{code|1=\setlocalhsize}} after {{code|1=\startitemize}} to setup the localhsize:
 +
<context source="yes">
 +
\setuppapersize[A5]
 +
\setuppapersize[A7,landscape][A7,landscape]
 +
\setupbodyfont[8pt,ss]
 
\setupcolors[state=start]
 
\setupcolors[state=start]
\def\graymath{\mframed[frame=off,
+
\setupframed[framecolor=blue]
     background=color,
+
\showframe
     backgroundcolor=gray,
+
\starttext
     backgroundoffset=3pt]}
+
\framed[width=\hsize,align=middle]{width=hsize}
 +
\startitemize
 +
\setlocalhsize
 +
\item \framed[width=\hsize,align=middle]    {width=hsize}
 +
\item \framed[width=broad,align=middle]    {width=broad}
 +
\item \framed[width=local,align=middle]     {width=local}
 +
\stopitemize
 +
\stoptext
 +
</context>
 +
 
 +
=Spacing between frame and text=
 +
 
 +
{{cmd|framed}} comes with two different types of offsets:
 +
one for the frame itself and  another for the its content.
 +
The parameters {{code|1=frameoffset}} and {{code|1=backgroundoffset}}
 +
were already explained above in the section [[#Coloring frame background and framed text]].
 +
 
 +
In addition, the parameter [strut=no] allows removal of the initial strut when framing text that is [[Verbatim with line breaks]].
 +
 
 +
==Content offsets==
 +
Beyond those there is another four dimensions that enable you to control
 +
the safety distance of a {{cmd|framed}}’s content by orientation.
 +
Horizontally, {{code|1=loffset}} governs the left, {{code|1=roffset}} the right
 +
offset;
 +
the same goes for {{code|1=boffset}} for the bottom and {{code|1=toffset}} for
 +
the top distance.
 +
Their effects are explored in the following example (MkIV only).
 +
 
 +
==Example==
 +
<texcode>
 +
\def\offsetframe[#1]{%
 +
{\framed[
 +
      #1=1em,
 +
  align=normal,
 +
  width=5.3cm,
 +
  height=5.3cm,
 +
  ]{\tfx\input ward }
 +
}{\it#1}
 +
}
 +
 
 +
\starttext
 +
\startcombination[2*2]
 +
\offsetframe[loffset]
 +
\offsetframe[roffset]
 +
\offsetframe[toffset]
 +
\offsetframe[boffset]
 +
\stopcombination
 +
\stoptext
 +
</texcode>
 +
 
 +
==More offset parameters==
 +
Also, you can set up <nowiki>offset</nowiki>, which sets up all the <nowiki>[lrtb]offset</nowiki> parameters.
 +
 
 +
Here's a method to define a new parameter, call it <nowiki>hoffset</nowiki>, which sets up <nowiki>[lr]offset</nowiki> at the same time:
 +
<texcode>
 +
\setupframed
 +
  [loffset=\framedparameter{hoffset},
 +
     roffset=\framedparameter{hoffset},
 +
     hoffset=\zeropoint]
 +
</texcode>
 +
 
 +
= Location parameter =
  
\startformula
+
<context source="yes">
   \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
+
\ruledhbox
\stopformula
+
   {A
 +
  \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
 +
  \framed[width=2cm,align=middle,location=depth]  {location\\equals\\depth}
 +
  \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
 +
  B}
 +
\vskip2cm
 +
\ruledhbox
 +
  {A
 +
  \framed[width=2cm,align=middle,location=low]    {location\\equals\\low}
 +
  \framed[width=2cm,align=middle,location=line]  {location\\equals\\line}
 +
  \framed[width=2cm,align=middle,location=high]  {location\\equals\\high}
 +
  B}
 +
\vskip2cm
 +
\ruledhbox
 +
{A
 +
  \framed[width=2cm,align=middle,location=top]    {location\\equals\\top}
 +
  \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
 +
  \framed[width=2cm,align=middle,location=lohi]  {location\\equals\\lohi}
 +
  \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
 +
  B}
 
</context>
 
</context>
  
The <cmd>,</cmd> add a tiny bit of space to prevent the gray background from crowding the equals and plus sign.
+
and to compare with basic height and depth of the line, and looking at the end on the effect of the struct parameter:
 +
 
 +
<context source="yes">
 +
\defineframed[MonCadre][width=1.75cm,align=middle]
 +
\define[1]\DemoLoc{\ruledhbox{%
 +
    {\getbuffer \MonCadre[location=#1]
 +
    {location\\ \color[darkmagenta]{\bf #1}\\location}}}}
 +
\setupbodyfont[10pt]
 +
%\showboxes
 +
\startbuffer
 +
\blackrule[height=max,depth=0pt,width=3mm]%
 +
\blackrule[height=0pt,depth=max,width=3mm]
 +
\stopbuffer
 +
 
 +
\strut
 +
\DemoLoc{empty}  \dontleavehmode
 +
\DemoLoc{keep}  \dontleavehmode
 +
\DemoLoc{depth}  \dontleavehmode
 +
\DemoLoc{bottom} \dontleavehmode
 +
\DemoLoc{low}
 +
\blank[big]
 +
\strut
 +
\DemoLoc{middle}  \dontleavehmode
 +
\DemoLoc{lohi}    \dontleavehmode
 +
\DemoLoc{line}
 +
\blank[big]
 +
\strut
 +
\DemoLoc{top}  \dontleavehmode
 +
\DemoLoc{height}    \dontleavehmode
 +
\DemoLoc{high}  \dontleavehmode
 +
\DemoLoc{formula}    \dontleavehmode
 +
\DemoLoc{hanging}
 +
 
 +
\setupframed[MonCadre][strut=yes]
 +
\strut
 +
{\tt strut=yes}
 +
\DemoLoc{bottom}    \dontleavehmode \DemoLoc{top}
 +
 
 +
{\tt strut=no}
 +
\setupframed[MonCadre][strut=no]
 +
\DemoLoc{bottom}    \dontleavehmode \DemoLoc{top}
 +
</context>
  
 
= Similar topics =
 
= Similar topics =
Line 162: Line 487:
 
* [[Overlays]]
 
* [[Overlays]]
 
* [[Tables Overview]]
 
* [[Tables Overview]]
 +
 +
= See also =
 +
* [[:Category:Command/Frames]]
 +
 +
[[Category:Basics]]

Latest revision as of 22:14, 24 January 2024

How to achieve specific results

Preventing hyphenation

One can prevent hyphenation inside a frame by passing nothypenated option to align. It is also a good idea to add verytolerant and stretch options.

\setuppapersize[A5]
\startcombination[2*2]
{\framed
   [width=5cm,
    align={flushleft}]
   {\input ward \endgraf}}
{flushleft}
{\framed
   [width=5cm,
    align={flushleft,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{flushleft,\crlf nothyphenated, \crlf verytolerant}
{\framed
   [width=5cm,
    align={flushright,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{flushright,\crlf nothyphenated, \crlf verytolerant}
{\framed
   [width=5cm,
    align={width,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{width,\crlf nothyphenated, \crlf verytolerant}
\stopcombination

Specify the width no longer than needed

I want to specify the maximum width of a frame. If the size of the box is smaller than the maximum width, I want a tight box. This can be done using the autowidth=force option to framed.

\setuppapersize[A5]
\defineframed
   [tightframed][width=5cm,autowidth=force,align=middle]

\tightframed{Small}

\tightframed{A really really long line that is split at 5cm}

Ruled Frames

\framed allows you to specify specific edges to be ruled. As an alternative to frame=on (the default), one can specify topframe=on, etc. Note that, as the default is to draw a complete frame, it is necessary to either specify the state (on/off) for all four edges or include the keyword frame=off.

\setuppapersize[A5]
\framed[frame=off,topframe=on,leftframe=on]{A fancy title}

The thickness of the frame rule can be specified using rulethickness=

\setuppapersize[A5]
\framed[frame=off,leftframe=on,rulethickness=2pt]{\tfa\bf A fancy title}

Rounded Corners

\framed allows you to have round corners with corner=round. There are also other possibilities if you want round corners but not at all places by giving an appropriate number to corner=.... This example is taken from core-rul.tex and each frame is typeset using

 \framed[corner=....,frame=on]{...}

  • You can only fill the frame with a background color if the corner shape is closed. Otherwise, the backgroundcolor option will be silently ignored.


Coloring frame background and framed text

First you have to turn on colors with \setupcolors[state=start]. Then you can define the background and foreground (=text) colors:

\framed[background=color,backgroundcolor=....,foreground=color,foregroundcolor=...]{...}

If you want to make the frame itself disappear, add a frame=off to the setups.

\setupcolors[state=start]
\framed
  [background=color,backgroundcolor=darkblue,
   foreground=color,foregroundcolor=white]
  {\ssx \bf Bold white on dark blue}
\framed
  [background=color,backgroundcolor=yellow,
  frame=off]
  {\tfx Who needs highlighter pens, anyway?}
For filling frames with offset you have to add options frameoffset=..., backgroundoffset=...
\framed
  [frame=on, corner=0, frameoffset=10pt,
   framecolor=black,background=color,
   backgroundcolor=darkgreen, backgroundoffset=10pt, 
   foreground=color,foregroundcolor=white]
  {\tfxx \bf Rounded corners with offset}

See the Color article for more information on available colors and color usage.

Shaded background for part of a displayed equation

To highlight part of a formula, you can give it a gray background using \mframed:

\setuppapersize[A5]
\setupcolors[state=start]
\def\graymath{\mframed[frame=off,
    background=color,
    backgroundcolor=gray,
    backgroundoffset=3pt]}

\startformula
  \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
\stopformula

The \, adds a tiny bit of space to prevent the gray background from crowding the equals and plus sign.

Inline Frames

The command \inframed, similar to \framed, differs in the definition of the baseline:

\setuppapersize[A5]
\framed[frame=off,width=10em,align=flushleft]{%
Notice the difference between
\framed{framed} and \inframed{inframed},
especially considering its effect on linespacing...
}

Dotted Frames

Using MetaPost:

\startuniqueMPgraphic{Label}
path p; p := (0,0) -- (OverlayWidth,0) -- (OverlayWidth, OverlayHeight) -- (0, OverlayHeight) -- (0,0);
draw p withpen pencircle scaled 1pt dashed withdots;
setbounds currentpicture to boundingbox OverlayBox;
\stopuniqueMPgraphic
\defineoverlay[Label][\useMPgraphic{Label}]
\def\DotPicture#1#2#3%
{%
  \placefigure[][#3]{#2}%
  {%
    \framed[align={flushleft, low},%
            frame=off,%
            height=3in,%
            width=broad]%
    {%
      \externalfigure[#1]%
                     [width=3in,%
                      background=Label,%
                      backgroundoffset=1ex]%
    }%
  }%
}%
\def\DotText#1%
{%
  \framed[frame=off,%
          background=Label,%
          location=low]%
  {%
    #1
  }%
}%
\starttext

\DotPicture{sample/cow.pdf}{All your base are belong to us}{SampleRef}%

AAA \DotText{BBB} CCC \DotText{DDD}
\stoptext

Dotted frame mpost.png

Using TikZ:

\setuppapersize[A5]
\usemodule[tikz]%
\tikzstyle{block}=[rectangle,draw=black,text centered,style=dotted,inner sep=0pt]
\def\Picture#1#2#3%
{
  \placefigure[left][#3]{#2}%
  {%
    \tikzpicture%
      \node[block](init){\externalfigure[#1][width=3in]};%
    \endtikzpicture%
  }%
}%
\starttext
\Picture{sample/cow.pdf}{All your base are belong to us}{SampleRef}
\stoptext

internal error: convert failed


Colorored horizontal stripe of full paper width

\definepapersize[sheet][width=120mm,height=60mm]
\setuppapersize[sheet]
\setuppagenumbering[location=]
\setuplayout
  [width=110mm,
   backspace=5mm,
   topspace=5mm,
   header=5mm,
   headerdistance=5mm,
   footer=5mm,
   footerdistance=5mm]

\showframe

\setupbackgrounds[page]  [background=color, backgroundcolor=lightgray]

\startuniqueMPgraphic{whatever}
fill OverlayBox 
     leftenlarged BackSpace rightenlarged CutSpace
     withcolor OverlayColor;
setbounds currentpicture to OverlayBox enlarged max(BackSpace,CutSpace);
\stopuniqueMPgraphic

\defineoverlay[whatever][\uniqueMPgraphic{whatever}]
\starttext

Here some text first.

\framed[background=whatever,backgroundcolor=green,frame=off,width=\textwidth]{test}

After, again some text.

\stoptext

Width broad and local

Sometimes width must be adapted to a "local" \hsize (the actual text area used by TeX to determine line breaks). For example:

\setuppapersize[A5]
\setuppapersize[A7,landscape][A7,landscape]
\setupbodyfont[8pt,ss]
\starttext
\framed[width=broad]{}
\startnarrower[left]
\framed[width=broad]{}
\dontleavehmode\framed[width=broad]{}
\dontleavehmode\framed[width=local]{}
\stopnarrower
\blank
\hsize.5\hsize
\framed[width=broad]{}
\startnarrower[left]
\framed[width=broad]{}
\dontleavehmode\framed[width=broad]{}
\dontleavehmode\framed[width=local]{}
\stopnarrower
\stoptext

Here we use \setlocalhsize after \startitemize to setup the localhsize:

\setuppapersize[A5]
\setuppapersize[A7,landscape][A7,landscape]
\setupbodyfont[8pt,ss]
\setupcolors[state=start]
\setupframed[framecolor=blue]
\showframe
\starttext
\framed[width=\hsize,align=middle]{width=hsize}
\startitemize
\setlocalhsize
\item \framed[width=\hsize,align=middle]     {width=hsize}
\item \framed[width=broad,align=middle]     {width=broad}
\item \framed[width=local,align=middle]     {width=local}
\stopitemize
\stoptext

Spacing between frame and text

\framed comes with two different types of offsets: one for the frame itself and another for the its content. The parameters frameoffset and backgroundoffset were already explained above in the section #Coloring frame background and framed text.

In addition, the parameter [strut=no] allows removal of the initial strut when framing text that is Verbatim with line breaks.

Content offsets

Beyond those there is another four dimensions that enable you to control the safety distance of a \framed’s content by orientation. Horizontally, loffset governs the left, roffset the right offset; the same goes for boffset for the bottom and toffset for the top distance. Their effects are explored in the following example (MkIV only).

Example

\def\offsetframe[#1]{%
{\framed[
      #1=1em,
   align=normal,
   width=5.3cm,
  height=5.3cm,
  ]{\tfx\input ward }
}{\it#1}
}

\starttext
\startcombination[2*2]
\offsetframe[loffset]
\offsetframe[roffset]
\offsetframe[toffset]
\offsetframe[boffset]
\stopcombination
\stoptext

More offset parameters

Also, you can set up offset, which sets up all the [lrtb]offset parameters.

Here's a method to define a new parameter, call it hoffset, which sets up [lr]offset at the same time:

\setupframed
   [loffset=\framedparameter{hoffset},
    roffset=\framedparameter{hoffset},
    hoffset=\zeropoint]

Location parameter

\ruledhbox
  {A
   \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
   \framed[width=2cm,align=middle,location=depth]  {location\\equals\\depth}
   \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
   B}
\vskip2cm
\ruledhbox
  {A
   \framed[width=2cm,align=middle,location=low]    {location\\equals\\low}
   \framed[width=2cm,align=middle,location=line]   {location\\equals\\line}
   \framed[width=2cm,align=middle,location=high]   {location\\equals\\high}
   B}
\vskip2cm
\ruledhbox
 {A
  \framed[width=2cm,align=middle,location=top]    {location\\equals\\top}
  \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
  \framed[width=2cm,align=middle,location=lohi]   {location\\equals\\lohi}
  \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
  B}

and to compare with basic height and depth of the line, and looking at the end on the effect of the struct parameter:

\defineframed[MonCadre][width=1.75cm,align=middle]
\define[1]\DemoLoc{\ruledhbox{%
    {\getbuffer \MonCadre[location=#1]
     {location\\ \color[darkmagenta]{\bf #1}\\location}}}}
\setupbodyfont[10pt]
%\showboxes
\startbuffer
\blackrule[height=max,depth=0pt,width=3mm]%
\blackrule[height=0pt,depth=max,width=3mm]
\stopbuffer

\strut
\DemoLoc{empty}  \dontleavehmode
\DemoLoc{keep}   \dontleavehmode 
\DemoLoc{depth}  \dontleavehmode
\DemoLoc{bottom} \dontleavehmode
\DemoLoc{low} 
\blank[big]
\strut
\DemoLoc{middle}  \dontleavehmode
\DemoLoc{lohi}    \dontleavehmode 
\DemoLoc{line}
\blank[big]
\strut
\DemoLoc{top}  \dontleavehmode
\DemoLoc{height}    \dontleavehmode 
\DemoLoc{high}  \dontleavehmode
\DemoLoc{formula}    \dontleavehmode 
\DemoLoc{hanging}

\setupframed[MonCadre][strut=yes]
\strut
{\tt strut=yes}
\DemoLoc{bottom}    \dontleavehmode \DemoLoc{top}

{\tt strut=no}
\setupframed[MonCadre][strut=no]
\DemoLoc{bottom}    \dontleavehmode \DemoLoc{top}

Similar topics

See also