Changes

Jump to navigation Jump to search
894 bytes added ,  10:11, 16 December 2021
Add hints on bracket usage; c&p from the list: https://www.mail-archive.com/ntg-context@ntg.nl/msg87937.html
< [[Main Page]] >= Programming Topics =
== Programming Topics ConTeXt Features ==* [[Modes]]: Conditional processing of text* [[Setups]]: An alternative to macros for storing chunks of code
==Commands and Arguments = ConTeXt Features =* [[System Macros]] (''Recommended reading''. Topics: temporary variables, expansion control, argument grabbing and handling, definitions and assignments, branches and decisions, cases, comma separated lists, assignments and parameters, user interaction.)* [[Programming in LuaTeX]] (Topic: alleviating the more cumbersome sides of TeX programming.)* [[Commands with KeyVal arguments|Commands with Key=Value arguments]]: (Topic: things like <code>\command[thiskey=thatvalue]</code>.) * [[ModesCommands with optional arguments]]: Document options that can be selected when the document is processed(Topic: one or more optional arguments within brackets.)
==Module Parameters = Commands and Arguments ===* [[Commands with KeyVal arguments|Commands with Key=Value arguments]]: For things like <code>\command[thiskey=thatvalue]</code>. * [[Commands with optional argumentsModule Parameters]]: One or more optional arguments within bracketsPassing parameters to modules.
=== Programming Techniques ===* [[Processing Lists]]: Processing lists of values* [[Counters]]: Manipulating counters in context* [[Expressions]]: Evaluating expressions of type number, dimen, glue or muglue* [[Executesystemcommand]]: process contents of an environment by another program* Loops and expansion [http://randomdeterminism.wordpress.com/2009/03/05/tex-programming-the-past-the-present-and-the-future/ (blog post)]
=== Debugging ===
* [[Console Mode]]: Using ConTeXt on keyboard input directly, rather than loading a <tt>.tex</tt> file.
=Use of brackets = One must '''not''' confuse with the LaTeX convention where "mandatory"arguments are contained in curly braces and brackets indicate"optional" arguments. Curly braces not only give grouping but generallyare used for objects to be typeset, as for \in{Figure}{a} [fig:ref]. For new users, it is worth repeating here that arguments within bracescan be either a comma-separated list of words OR a comma-separatedlist of keyword=value pairs, BUT NOT A MIXTURE OF BOTH. Generally, akeyword=value exists for all words, for example \cite[authoryear][ref]and \cite[alternative=authoryear,reference=ref] values can be grouped using curly braces, as in\cite[alternative=authoryear,lefttext={{see },}][ref1,ref2] where thelefttext is associated with the first cite reference (and none with thesecond). This can be tricky but is in fact rather straight-forward. = Using variables ==
There are several ways to handle variables in ConTeXt.
\getvariable{namespace}{key}
</texcode>
 
To avoid problems, also pay attention to the following:
On the other hand you can only process one variable at the same time, so
<tt>\getvariable</tt> uses the '''singular''' form and works with '''braces'''.
 
 
OK, here comes a simple example. Let's say, that we want to have variable
And don't forget:
'''Just ensure, Ensure that all variables are set, before you use them!'''
== Defining new commands CLD ==How to pass variable from TeX to Lua and vice versa? See [[CLD_passing_variables#Variables|CLD passing variables]].
=Defining new commands = == Special characters in command names ===
Some commands have special characters in their names, that TeX normally does not consider to be
letters: <tt>@</tt>, <tt>!</tt> and <tt>?</tt>.
Before and after the use or definition of such protected commands in your input files, the catcode of these
characters has to be changed. This is done by <{{cmd>|unprotect</cmd> }} and <{{cmd>|protect</cmd>}}:
<texcode>
</texcode>
The newly defined command <tt>\!test</tt> can of course only be called upon when we are in the <{{cmd>|unprotect</cmd>}}ed state, otherwise TeX reads the command <tt>\!</tt>, followed by the word <tt>test</tt> (and probably complains loudly about not being in math mode). These protection/unprotection commands can be nested. When the nesting becomes deeper than one level, the system reports the current protection level. It is a good habit to always start your macro files with <{{cmd>|unprotect</cmd> }} and end them with <{{cmd>|protect</cmd>}}.
= Passing verbatim text as macro parameter =
== Passing (For passing text to LuaTex verbatim text as macro parameter ==, see the [[Programming_in_LuaTeX#Manipulating_verbatim_text_for_dummies|Programming in LuaTeX]] article on this wiki.)
In case you want to write macros that should handle verbatim text,
</context>
  == Setups ==In ConTeXt it is easy to create local variables and grouping. Local variables can be simulated as in: <texcode>\startsetups whatever% some useful definitions here\stopsetups \definestartstop[whatever][commands=\setups{whatever}] \startwhateverUsing definitions here.\stopwhatever</texcode> But you can place setups almost everywhere and environment will not be affected by their execution. It is useful to wrap overlay definitions Category:Programming and such in setups as in (copied from [[Colorful_CD_Inlay]] page): <texcode>\defineoverlay [originDatabases] [\setups{origin}\startsetups origin \vbox to \overlayheight { \vfill\tfxx\setstrut \hsize\overlaywidth \hfill Fiona Apple\enspace EM\enspace2005\quad\strut\endgraf \kern1ex }\stopsetups</texcode> You can even do things like: <texcode>\starttext\startsetups settest\def\command{do something with}I want to \command{} command.\stopsetups \start\setups{settest}\stop \command aaa % will give "undefined control sequence" error \stoptext</texcode> [[Category:Inside ConTeXtTools]]
57

edits

Navigation menu