You will typically include a language package:
\input Tcode_C.tex
for example.
The command for inline code is \ncode, and the environment for displayed code is {Code}:
Some inline code: \ncode{float y=1/(1-x);}. Some
displayed code:
\begin{Code}
#include
int main(int argc, char **argv){
printf(argv[0]);
return 0;
}
\end{Code}
If you don't have the \begin \end environments you can use \Code \endCode.
- Several examples are distributed with the package. Their names being by “example”.
examplepy_plain.tex, for instance. They can be taken as templates.
One of the first things you'd likely want to do is changing the choices of syntax highlighting:
\TcodeDefineFormat{Keyword}{\color{darkgreen}}
You may need to define you own colours. You may use your usual colour package and the
\definecolor macro for that. But note that Tcode comes with a small colour package that is
less general than the well known color package and other variants, but much faster. It is totally
independent from Tcode, but comes with it. The files Tcode_C.tex, etc. that come with Tcode
include that package if no colour package has been included at that point. In that case you should use
\DefineColor{darkgreen}{0, 0.5, 0}
say. \DefineColor detects the colour package in force and adapts
its definition accordingly. Thus, you may use it even if you are using a typical colour package.
For adding more words, write
\DeclareWord[py]{invert}{Function} (say)
\DeclareWord{invert}{Function}
The first variant specifies which language the word is being added to. The second one
takes the “current language” for that.
If you want to mix several language in a document just include the corresponding language files:
\input Tcode_C.tex
\input Tcode_py.tex
Then, write {CCode}, {pyCode},
etc. instead of a plain {Code}.
There are no such shortcuts for the inline macros. You will need to change the current language:
\TcodeSelectLanguage{C}
Inline code usually belongs all to the same language. You may define macros that
select the language locally:
\def\pycode#1{\bgroup\TcodeSelectLanguage{py}\ncode{#1}\egroup}
When you want to place in the code something that the package does not foresee (or maybe you
don't know about it), the easiest way is to declare an argument-less macro to do that:
\def\mge{$\ge$}
\begin{Code}
//z must have a size \mge 2*n.
int match(const int x[], const int y[], unsigned int n, int z[]);
\end{Code}
Spaces after control sequences can be forced by writing, e.g., \dosome\ (not the final \ ),
though in many cases it is not necessary, as in the example above. In \ncode, within strings, you may
get an extra space after some control sequences. In order to remove it, add \ignorespaces to
the definition of your macro:
\def\clear{clear\ignorespaces}
\ncode{"This is a \clear\ day"}. \ncode{"The day is \clear"}.
If you want to sent every word in the code to the index, or only every recognised word, or to
perform any other action upon the words, you can do it by means of \PrePrintHook.
See examplepy_plain.tex for an examle of how to use it.
In some cases you need to prefix some command with \cprotect. For example, a
\footnote within which you insert a Code display snippet. That macro is
provided by the cprotect package. However, that package is only available for Latex and
it generates auxiliary .cpt files. You can use cprotect_other.tex that comes with
Tcode. The macro that this file provides is also called \cprotect. It is also considerably
faster, but you typically don't place many of these in one project.