Changes

Jump to navigation Jump to search
524 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}},
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 =
[[Image:Verbatim-mkiv.png‎]]
 
= Verbatim with line breaks=
 
[[Verbatim with line breaks|Dedicated page]]
 
[[Line breaks marker]]
= Pretty printing =
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 =
<texcode>
\setuplinenumbering[location=intexttext]
\startcode
This is the first line
after={\stopframedcode}]
\setuplinenumbering[location=intexttext]
\startcode
This is the first line
(-a- --> [[User:Andrea]])
 
 
[[Category:Basics]]
174

edits

Navigation menu