Changes

Jump to navigation Jump to search
2,098 bytes added ,  22:40, 27 December 2021
m
→‎Defining your own set of colors: comment on mkii only setting
< [[Visuals]] | [[Verbatim with line breaks]] >
 
=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>
SourceYou can also refer to a TeX command with: [http://archive.contextgarden.net{{cmd|tex}}<tt>{a tex command}</threadtt><context source="yes">\tex{a tex command}</20050907.093522.baf795f5.en.html]context>
= 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‎]] = Verbatim with line breaks= [[Verbatim with line breaks|Dedicated page]] [[Line breaks marker]] 
= 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.mkii|C]] || [[modules:pret-c|C]]
|-
| Eiffel || [[source:verb-ceif.texmkii|CEIF]] || C
|-
| JavaScript || [[source:verb-eifjs.texmkii|EIFJS]] || Eiffel
|-
| Java || [[source:verb-jsjv.texmkii|JSJV]] || JavaScript
|-
| Lua || || [[source:verbpret-jvlua.texlua|JVLUA]] || Java
|-
| MetaPost & MetaFont || [[source:verb-mp.texmkii|MP]] || MetaPost & MetaFont[[source:pret-mp.lua|MP]]
|-
| Pascal & Modula || [[source:verb-pas.texmkii|PAS]] || Pascal & Modula
|-
| Perl 5 || [[source:verb-pl.texmkii|PL]] || Perl 5
|-
| SQL || [[source:verb-sql.texmkii|SQL]] || SQL
|-
| TeX || [[source:verb-tex.texmkii|TEX]] || 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 =
% XML code will be typeset with the palette you just defined
\definepalet[XMLcolorpretty] [MYcolors] % the name is magic !- mkii only
\starttext
This results in:
:<context>
\setupbodyfont[8pt]
\definecolor[MYcolorone] [r=.8,g=.5,b=.5]
prettyfour=MYcolorfour]
% \definepalet[XMLcolorpretty] [MYcolors] % the name is magic !
\setupcolors[state=start]
\stoptext
</context>
 
== Syntax highlighting source code or configuration files ==
 
see [[Verbatim_with_LuaTeX]] with Python, Apache httpd.conf and zc.buildout config files examples.
= Colored background =
= 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>
\setuplinenumbering[location=intexttext]
\startcode
This is the first line
after={\stopframedcode}]
\setuplinenumbering[location=intexttext]
\startcode
This is the first line
\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>
(-a- --> [[User:Andrea]])
 
 
[[Category:Basics]]
174

edits

Navigation menu