Changes

Jump to navigation Jump to search
1,721 bytes added ,  10:27, 3 September 2017
scite pretty printing
=Displayed text=
<{{cmd>|starttyping</cmd>}},<{{cmd>|typebuffer</cmd>}}
Unlike LaTeX's <code>verbatim</code> environment, ConTeXt's <code>typing</code> environments have quite a range of built-in options for formatting the verbatim text, see below.
=In-line Inline text=
To typeset code inside the paragraph, you have the command <code>\startTEX ... \stopTEXtype</code> only works when typesetting the whole paragraph. If you need to type only a command or two as in-line text, you It can use the following be configured with <code>\setuptype[type][User:Taco|Taco's...]] macro (hopefully this will land in the core once in the future):</code>.
To have colored code, you need to use <texcodecode>\def\typeTEX {\bgroup \def\processinlineverbatim##1% {\processingverbatimtrue \localcatcodestrue \def\endofverbatimcommand{\TEXendofcommand##1}% \bgroup \aftergroup\endofverbatimcommand \futurelet\next\doprocessinlineverbatim}% \initializetyping{definetype[NAME][option=TEX}% \startverbatimcolor \processinlineverbatim\egroup }]</code> and use it with the name you chose. Other values are: <code>mp lua xml parsed-xml nested tex context</texcodecode>. An example that shows both features:
Now you can say:<context source="yes">\definetype[inlineTEX][option=TEX]
<texcode>\typeTEX+\typeTEX{\typeTEX This is a wonderful macro}+, isn't it?</texcode><context>\setupcolors[state=start]\defthe way to type code: \typeTEX type{the \bgroup \def\processinlineverbatim##1% {\processingverbatimtrue \localcatcodestrue \def\endofverbatimcommand{\TEXendofcommand##1}% \bgroup \aftergroup\endofverbatimcommand \futurelet\next\doprocessinlineverbatim}% \initializetyping{TEX}% \startverbatimcolor \processinlineverbatimConTeXt\egroup command}.
And this is the way to have colored code: \typeTEX+inlineTEX{the \typeTEX{ConTeXt\typeTEX is a wonderful macrocommand}+, isn't it?
</context>
 
Source: [http://archive.contextgarden.net/thread/20050907.093522.baf795f5.en.html]
= Making a tight vertical fit =
</context>
Note that this does not currently In mkiv option-commands is gone and escape no longer is an escape character but a condition (2009.06.30range or start) seem to work , as in MkIVthis example: <texcode>\setuptyping[TEX][escape=yes] \startTEX/BTEX\em sometex/ETEX/BTEX\em sometex/ETEX \after\before /BTEX\em sometex/ETEX\before /BTEX\em sometex/ETEX \after\before /BTEX\em sometex/ETEX \inbetween /BTEX\em sometex/ETEX \after\before \after\stopTEX \setuptyping[TEX][escape={[[,]]}] \startTEX[[\em sometex]][[\em sometex]] \after\before [[\em sometex]]\before [[\em sometex]] \after\before [[\em sometex]] \inbetween [[\em sometex]] \after\before \after\stopTEX \setuptyping[TEX][escape=//] \startTEX//\em sometex\before //\em sometex\stopTEX</texcode> [[Image:Verbatim-mkiv.png‎]] 
= Pretty printing =
The context distribution includes a number of formatters (or pretty
== Included Formatters ==
 
There are already some formatters for several programming languages in
the ConTeXt distributionr. The following list is for MkII, and MkIV definesa subset of these (look for files called <tt>pret-*.lua</tt> in<tt>texmf/tex/context/base</tt> in the ConTeXt distribution).
{|
! Language !! Code for MkII !! LanguageCode for MkIV
|-
| C || [[source:verb-c.texmkii|C]] || [[modules:pret-c| C]]
|-
| Eiffel || [[source:verb-eif.texmkii|EIF]] || Eiffel
|-
| JavaScript || [[source:verb-js.texmkii|JS]] || JavaScript
|-
| Java || [[source:verb-jv.texmkii|JV]] || Java
|-
| Lua || || [[source:verbpret-mplua.texlua|MPLUA]] || MetaPost & MetaFont
|-
| MetaPost & MetaFont || [[source:verb-pasmp.texmkii|PASMP]] || Pascal & Modula[[source:pret-mp.lua|MP]]
|-
| Pascal & Modula || [[source:verb-plpas.texmkii|PLPAS]] || Perl 5
|-
| Perl 5 || [[source:verb-sqlpl.texmkii|SQLPL]] || SQL
|-
| SQL || [[source:verb-texsql.texmkii|TEXSQL]] || TeX
|-
| TeX || [[source:verb-tex.mkii|TEX]] || [[source:pret-tex.lua|TEX]] |- | XML || [[source:verb-xml.texmkii|XML]] || [[source:pret-xml.lua| XML]]
|-
|}
of input and produces tex output. The details about this are discussed
at [[Custom_pretty_printer]].
 
== Improved pretty printing ==
 
Default ConTeXt comment handling can be shown in the following sample:
 
<context source="yes">
\starttext
\startbuffer[texcode]
This is text. % and this is a comment
\stopbuffer
 
\startbuffer[xmlcode]
<p>This is text.<!--and this is a comment--></p>
\stopbuffer
 
\startbuffer[luacode]
if code=="code" then --this is a comment
 
--[[
this is a
 
multiline comment
--]]
 
---[[
but this isn’t a
 
multiline comment
--]]
\stopbuffer
 
\typebuffer[texcode][option=TEX]
\typebuffer[xmlcode][option=XML]
\typebuffer[luacode][option=LUA]
\stoptext
</context>
 
If you want to improve Lua multiline comments and to color the whole comments (not only the comment marker), write <code>\usemodule[scite]</code> before <code>\starttext</code>. (I cannot show it here, since ConTeXt at the wiki seems to have a problem with that.)
= Tabbing =
= Line numbering =
In technical documents it can be required to display some code listings with the line numbers. You can do this with ConTeXt, and even more. All the features shown here are also available when displaying external files with <{{cmd>|typefile</cmd>}}.
== Preliminary setting ==
== Line numbers in the text ==
To have the line numbers in the text, change the linenumbering setup like this(<tt>location=text</tt> for mkiv resp.):
<texcode>
\stopcode
</context>
 
== Referencing line numbers ==
The following example from the mailing list [http://archive.contextgarden.net/thread/20101026.191201.55344b94.en.html#20101026.191201.55344b94] shows how to reference line numbers from a typing in the surrounding text (MkIV).
 
<texcode>
\setuptyping[numbering=line,escape=yes]
 
\starttext
 
See \inline[line:single] and also \inline[line:range].
 
See \inline{typeline}[line:single] and also \inline{typelines}[line:range].
 
See line~\inlinerange[line:single] and also lines~\inlinerange[line:range].
 
\starttyping
line 1
line 2/BTEX\startline[line:range]/ETEX
line 3/BTEX\someline[line:single]/ETEX
line 4
line 5/BTEX\stopline[line:range]/ETEX
line 6
\stoptyping
 
\stoptext
</texcode>
<texcode>
\startSC
/BTEX{\color[SCred] {//// an example starting with a comment}/ETEX/BTEX{\color[SCgrey] {"this is a string"}/ETEX .postln ;
/BTEX{\color[SCgreen] {\letterbackslash aSymbol}/ETEX ;
/BTEX{\color[SCblue] {ThisClassDoesNotExists}/ETEX ;
\stopSC
</texcode>
The example.tex file uses some definitions (explained in the previous sections) which have to be put in the ConTeXt file(use <tt>escape=yes</tt> instead of <tt>option=commands</tt> for mkiv).
<texcode>
139

edits

Navigation menu