summaryrefslogtreecommitdiff
path: root/sandbox/code-block-directive/docs/myfunction.py.tex
blob: 5a77212958a33d6faeb5e11bee3e2a2863b54266 (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
\documentclass[a4paper]{article}
% generated by Docutils <http://docutils.sourceforge.net/>
\usepackage{fixltx2e} % LaTeX patches, \textsubscript
\usepackage{cmap} % fix search and cut-and-paste in Acrobat
\usepackage{ifthen}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\setcounter{secnumdepth}{0}

%%% Custom LaTeX preamble
% suppress the (LaTeX-added) References section heading
\AtBeginDocument{\renewcommand{\refname}{\vspace{-1em}}}
\newlength{\DUlineblockindent}
\setlength{\DUlineblockindent}{1em}

%%% User specified packages and stylesheets
\usepackage{../data/pygments-docutilsroles}

%%% Fallback definitions for Docutils-specific commands

% inline markup (custom roles)
% \DUrole{#1}{#2} tries \DUrole#1{#2}
\providecommand*{\DUrole}[2]{%
  \ifcsname DUrole#1\endcsname%
    \csname DUrole#1\endcsname{#2}%
  \else% backwards compatibility: try \docutilsrole#1{#2}
    \ifcsname docutilsrole#1\endcsname%
      \csname docutilsrole#1\endcsname{#2}%
    \else%
      #2%
    \fi%
  \fi%
}

% hyperlinks:
\ifthenelse{\isundefined{\hypersetup}}{
  \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=black]{hyperref}
  \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
}{}


%%% Body
\begin{document}

This is a test of the new ``code'' directive:

% Translate this document with a pygments enhanced frontend, e.g.
% 
%  ../rst2html-highlight.py --stylesheet=../data/pygments-default.css
%  ../rst2latex-highlight.py --stylesheet=../data/pygments-docutilsroles.sty
% 
% or via the test case in
% 
%  ../pygments_code_block_directive.py --traceback

The example from Docutils TODO list:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{k}{print}~\DUrole{s}{'This~is~Python~code.'}~\\
\DUrole{k}{for}~\DUrole{n}{i}~\DUrole{ow}{in}~\DUrole{nb}{range}\DUrole{p}{(}\DUrole{mi}{10}\DUrole{p}{):}~\\
~~~~\DUrole{k}{print}~\DUrole{n}{i}
}
\end{quote}

Numbered lines:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{ln}{1~}\DUrole{c}{\#~This~is~Python~code,}~\\
\DUrole{ln}{2~}\DUrole{c}{\#~that~prints~the~integers~from~0~to~9}~\\
\DUrole{ln}{3~}\DUrole{k}{for}~\DUrole{n}{i}~\DUrole{ow}{in}~\DUrole{nb}{range}\DUrole{p}{(}\DUrole{mi}{10}\DUrole{p}{):}~\\
\DUrole{ln}{4~}~~~~\DUrole{k}{print}~\DUrole{n}{i}
}
\end{quote}

Another example:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{ln}{~7~}\DUrole{k}{def}~\DUrole{nf}{my\_function}\DUrole{p}{():}~\\
\DUrole{ln}{~8~}~~~~\DUrole{sd}{"{}"{}"Test~the~lexer.\\
}\DUrole{ln}{~9~}\DUrole{sd}{~~~~"{}"{}"}~\\
\DUrole{ln}{10~}~\\
\DUrole{ln}{11~}~~~~\DUrole{c}{\#~and~now~for~something~completely~different}~\\
\DUrole{ln}{12~}~~~~\DUrole{k}{print}~\DUrole{mi}{8}\DUrole{o}{/}\DUrole{mi}{2}
}
\end{quote}

The end.

\end{document}