Difference between revisions of "Help:Context"

From Wiki
Jump to navigation Jump to search
m (Remove mode=mkiv from source code as it is in the settings)
m (→‎mode="mkiv" and mode="lmtx": missed a few quotes)
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The <code><nowiki><context> ... </context></nowiki></code> tags process their ConTeXt contents on the fly and include the result on the page as an image. Whitespace is cropped out. The following options are available:
+
The <code><nowiki><context> ... </context></nowiki></code> 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:
  
* <code>source=yes</code> displays the source before the output.
+
* <code>source="yes"</code> displays the source before the output.
 
* <code>text="some text"</code> places 'some text' between the source and the output.
 
* <code>text="some text"</code> places 'some text' between the source and the output.
* <code>mode=mkiv</code> ensures [[Mark IV]] is used instead of the default Mark II.
+
* <code>mode="mkiv"</code> forces [[Mark IV]] instead of the default [[LMTX]] (should not be needed except to demonstrate a documented difference)
 +
* <code>force="yes"</code> 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 {{cmd|contextbanner}}.  
  
For some reason, examples using the default A4 paper size usually end up blown up twice as large.
+
Quotation marks around attribute strings are only required if the attribute contains non-alphabetic characters.
If this happens, include {{cmd|setuppapersize|[A5]}} in your example, and everything will display at its proper size again. This has the added advantage that the resulting image will never be too large for this wiki's main column.
 
  
 +
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 {{cmd|starttext}} ...  {{cmd|stoptext}} or not.
 +
 +
With a starttext/stoptext block, the wrapping uses:
 +
 +
<texcode>
 +
\setuppapersize[A5][A5]
 +
\setupexternalfigures[location={local,default}]
 +
\setupbodyfont[8pt]
 +
\setupcolors[state=start]
 +
.. your input here ..
 +
</texcode>
 +
 +
and without starttext/stoptext, the extension uses:
 +
 +
<texcode>
 +
\setuppapersize[A5][A5]
 +
\setupexternalfigures[location={local,default}]
 +
\setupbodyfont[8pt]
 +
\setupcolors[state=start]
 +
\starttext
 +
\startTEXpage
 +
.. your input here ..
 +
\stopTEXpage
 +
\stoptext
 +
</texcode>
 +
 
== Examples ==
 
== Examples ==
  
Line 20: Line 47:
 
\setupcolors [state=start]
 
\setupcolors [state=start]
 
\framed [background=color,
 
\framed [background=color,
         backgroundcolor=green,
+
         backgroundcolor=gray,
 
         offset=0.5cm ]{hello world!}
 
         offset=0.5cm ]{hello world!}
 
</context>
 
</context>
Line 27: Line 54:
 
\setupcolors [state=start]
 
\setupcolors [state=start]
 
\framed [background=color,
 
\framed [background=color,
         backgroundcolor=green,
+
         backgroundcolor=gray,
 
         offset=0.5cm ]{hello world!}
 
         offset=0.5cm ]{hello world!}
 
</context>
 
</context>
 
|}
 
|}
  
=== source=yes ===
+
=== source="yes" ===
  
 
{| class=wikitable
 
{| class=wikitable
Line 42: Line 69:
 
\setupcolors [state=start]
 
\setupcolors [state=start]
 
\framed [background=color,
 
\framed [background=color,
         backgroundcolor=green,
+
         backgroundcolor=gray,
 
         offset=0,5cm ]{hello world!}
 
         offset=0,5cm ]{hello world!}
 
</context>
 
</context>
Line 49: Line 76:
 
\setupcolors [state=start]
 
\setupcolors [state=start]
 
\framed [background=color,
 
\framed [background=color,
         backgroundcolor=green,
+
         backgroundcolor=gray,
 
         offset=0.5cm ]{hello world!}
 
         offset=0.5cm ]{hello world!}
 
</context>
 
</context>
 
|}
 
|}
  
=== mode=mkii and mode=mkiv ===
+
=== 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 <tt>mode="mkiv"</tt> to the tag. Because MkIV examples are visually indistinguishable from LMTX examples, it is good practice to start MkIV examples with a comment <code>% mode=mkiv</code>.
  
 
{| class=wikitable
 
{| class=wikitable
Line 61: Line 89:
 
|- style="vertical-align: top"
 
|- style="vertical-align: top"
 
| <xmlcode>
 
| <xmlcode>
<context source="yes">
+
<context source="yes" force="yes">
Version: \contextversionnumber
+
\contextbanner
 
</context>
 
</context>
 
</xmlcode>
 
</xmlcode>
| <context source="yes">
+
| <context source="yes" force="yes">
Version: \contextversionnumber
+
\contextbanner
 
</context>
 
</context>
 
|- style="vertical-align: top"
 
|- style="vertical-align: top"
 
| <xmlcode>
 
| <xmlcode>
<context mode=mkiv source="yes">
+
<context mode="mkiv" source="yes" force="yes">
Version: \contextversionnumber
+
% mode=mkiv
 +
\contextbanner
 
</context>
 
</context>
 
</xmlcode>
 
</xmlcode>
|<context mode=mkiv source="yes">
+
|<context mode="mkiv" source="yes" force="yes">
Version:
+
% mode=mkiv
\contextversionnumber
+
\contextbanner
 
</context>
 
</context>
 
|}
 
|}
Line 87: Line 116:
 
\setuppaper[nx=2, ny=2]    % arrange pages 2 by 2 (must come before \setuparranging[XY])
 
\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)
 
\setuparranging[XY]        % arrange pages n by n (across, then down)
\setuppagenumbering[footer] % page numbers are always useful
+
\setuppagenumbering[location=footer] % page numbers are always useful
 
\showframe[edge]            % Draw line around each page. Prevents overzealous cropping
 
\showframe[edge]            % Draw line around each page. Prevents overzealous cropping
  
Line 95: Line 124:
 
four
 
four
 
</context>
 
</context>
 +
 +
{{About this wiki navbox}}
 +
 +
[[Category:Help|Context]]
 +
[[Category:Wiki-Maintenance]]

Revision as of 15:22, 30 August 2020

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 
.. your input here ..
\stopTEXpage
\stoptext

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

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
internal error: copy error /var/www/contextgarden.net/wiki/htdocs/wikiteximage/f87ce326d369597c7fe5b68d7c794fba.png
<context mode="mkiv" source="yes" force="yes">
% mode=mkiv
\contextbanner
</context>
% mode=mkiv
\contextbanner
internal error: copy error /var/www/contextgarden.net/wiki/htdocs/wikiteximage/4dfeaa19842c586fbc1dd650bd442fd9.png

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

one \page[yes]
two \page[yes]
three \page[yes]
four