Help:Context

From Wiki
Jump to navigation Jump to search

The <context> ... </context> tags process their ConTeXt contents on the fly and include the result on the page as an image. Whitespace is cropped out. The following attributes may be set:

  • source="yes" displays the source before the output.
  • text="some text" places 'some text' between the source and the output.
  • mode="mkiv" forces Mark IV instead of the default LMTX (should not be needed except to demonstrate a documented difference)
  • force="yes" forces regeneration of the PNG image each time the page is loaded. This is expensive, so please only use it on special occasions (like in the example below where we are showing the \contextbanner.

Quotation marks around attribute strings are only required if the attribute contains non-alphabetic characters.

The extension wraps your code with a bit of extra ConTeXt code to get a compilable file. There are two different cases, depending on whether your code contains \starttext ... \stoptext or not.

With a starttext/stoptext block, the wrapping uses:

\setuppapersize[A5][A5]
\setupexternalfigures[location={local,default}]
\setupbodyfont[8pt]
\setupcolors[state=start]
.. your input here ..

and without starttext/stoptext, the extension uses:

\setuppapersize[A5][A5]
\setupexternalfigures[location={local,default}]
\setupbodyfont[8pt]
\setupcolors[state=start]
\starttext
\startTEXpage[offset=0.25pt]
.. your input here ..
\stopTEXpage
\stoptext

After processing, the first page of the PDF is converted to PNG using mutool:

mutool convert -o context.png -O resolution=150 context.pdf 1

Examples

Plain example

Wiki markup Wiki display
<context>
\setupcolors [state=start]
\framed [background=color,
         backgroundcolor=gray,
         offset=0.5cm ]{hello world!}
</context>

source="yes"

Wiki markup Wiki display
<context source="yes" text="produces">
\setupcolors [state=start]
\framed [background=color,
         backgroundcolor=gray,
         offset=0,5cm ]{hello world!}
</context>
  • \setupcolors [state=start]
    \framed [background=color,
             backgroundcolor=gray,
             offset=0.5cm ]{hello world!}
    

    produces

source="sidebyside"

Wiki markup Wiki display
<context source="sidebyside">
\setupcolors [state=start]
\framed [background=color,
         backgroundcolor=gray,
         offset=0,5cm ]{hello world!}
</context>
(output below, sidebyside does not work in tables)
  • \setupcolors [state=start]
    \framed [background=color,
             backgroundcolor=gray,
             offset=0.5cm ]{hello world!}
    

mode="mkiv" and mode="lmtx"

By default, the wiki compiles examples using LMTX. You can specify that you want to use MkIV by adding the option mode="mkiv" to the tag. Because MkIV examples are visually indistinguishable from LMTX examples, it is good practice to start MkIV examples with a comment % mode=mkiv.

Wiki markup Wiki display
<context source="yes" force="yes">
\contextbanner
</context>
  •  \contextbanner
    
<context mode="mkiv" source="yes" force="yes">
% mode=mkiv
\contextbanner
</context>
  • % mode=mkiv
     \contextbanner
    

Displaying multiple pages

  • \setuppapersize[A10,landscape][A8,landscape]
    
    \setuppaper[nx=2, ny=2]     % arrange pages 2 by 2 (must come before \setuparranging[XY])
    \setuparranging[XY]         % arrange pages n by n (across, then down)
    \setuppagenumbering[location=footer] % page numbers are always useful
    \showframe[edge]            % Draw line around each page. Prevents overzealous cropping
    
    \starttext
    one \page
    two \page
    three \page
    four
    \stoptext