blob: 548ef8ee21b7a0f773cef44dadddfb6b9656ad1e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
\input cap
\let\IdentifierColor=\Black
\let\KeywordColor=\MidnightBlue
\let\SpecialColor=\Black
\let\SymbolColor=\Black
\let\CommentColor=\Gray
\let\TextColor=\ForestGreen
\let\DirectiveColor=\Tan
\SpaceSkip=1.3ex
% Just for fun, you can use a cyrillic font for identifiers
% Of course, any font can be changed just like in the non-color
% version of cap.
%\font\cirm=wncyi10\let\IdentifierFont=\cirm
A short program in C. It was inserted directly into the \TeX\ source file.
\medskip
\BeginC
#include <stdio.h>
void main()
{
a=~a;
printf("Hello, world!\n");
// printf("Hello, world!\n");
}
\EndC
\hrule
\bigskip
And now a program inserted from a separate file.
\medskip
\InputC{prog/sun.c}
\vfill\eject
And now programs written in Pascal. This one was typed directly into this
file.
\medskip
\BeginPascal
program Hello_world;
begin
writeln('Hello, world!');
{ writeln('Hello, world!'); }
end.
\EndPascal
\hrule
\bigskip
This one was imported from another file.
\medskip
\InputPascal{prog/guess.pas}
\vfill\eject
And now, my latest addition: programs written in Python. The first one
is typed directly into the file.
\medskip
\BeginPython
def fib(n):
"""Calculates Fibonacci series.
It returns the first member of Fibonacci series larger than n"""
a,b=1,1
while b <= n:
a,b = b,a+b # see how we use multiple assignment?
return b
fib(10)
\EndPython
\hrule
\bigskip
This one was imported from another file.
\medskip
\InputPython{prog/fib.py}
\bye
|