Prepare code directive for inclusion in the core.
[docutils/kirr.git] / sandbox / code-block-directive / docs / myfunction.py.tex
blob5a77212958a33d6faeb5e11bee3e2a2863b54266
1 \documentclass[a4paper]{article}
2 % generated by Docutils <http://docutils.sourceforge.net/>
3 \usepackage{fixltx2e} % LaTeX patches, \textsubscript
4 \usepackage{cmap} % fix search and cut-and-paste in Acrobat
5 \usepackage{ifthen}
6 \usepackage[T1]{fontenc}
7 \usepackage[utf8]{inputenc}
8 \setcounter{secnumdepth}{0}
10 %%% Custom LaTeX preamble
11 % suppress the (LaTeX-added) References section heading
12 \AtBeginDocument{\renewcommand{\refname}{\vspace{-1em}}}
13 \newlength{\DUlineblockindent}
14 \setlength{\DUlineblockindent}{1em}
16 %%% User specified packages and stylesheets
17 \usepackage{../data/pygments-docutilsroles}
19 %%% Fallback definitions for Docutils-specific commands
21 % inline markup (custom roles)
22 % \DUrole{#1}{#2} tries \DUrole#1{#2}
23 \providecommand*{\DUrole}[2]{%
24 \ifcsname DUrole#1\endcsname%
25 \csname DUrole#1\endcsname{#2}%
26 \else% backwards compatibility: try \docutilsrole#1{#2}
27 \ifcsname docutilsrole#1\endcsname%
28 \csname docutilsrole#1\endcsname{#2}%
29 \else%
30 #2%
31 \fi%
32 \fi%
35 % hyperlinks:
36 \ifthenelse{\isundefined{\hypersetup}}{
37 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=black]{hyperref}
38 \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
39 }{}
42 %%% Body
43 \begin{document}
45 This is a test of the new ``code'' directive:
47 % Translate this document with a pygments enhanced frontend, e.g.
49 % ../rst2html-highlight.py --stylesheet=../data/pygments-default.css
50 % ../rst2latex-highlight.py --stylesheet=../data/pygments-docutilsroles.sty
52 % or via the test case in
54 % ../pygments_code_block_directive.py --traceback
56 The example from Docutils TODO list:
58 \begin{quote}{\ttfamily \raggedright \noindent
59 \DUrole{k}{print}~\DUrole{s}{'This~is~Python~code.'}~\\
60 \DUrole{k}{for}~\DUrole{n}{i}~\DUrole{ow}{in}~\DUrole{nb}{range}\DUrole{p}{(}\DUrole{mi}{10}\DUrole{p}{):}~\\
61 ~~~~\DUrole{k}{print}~\DUrole{n}{i}
63 \end{quote}
65 Numbered lines:
67 \begin{quote}{\ttfamily \raggedright \noindent
68 \DUrole{ln}{1~}\DUrole{c}{\#~This~is~Python~code,}~\\
69 \DUrole{ln}{2~}\DUrole{c}{\#~that~prints~the~integers~from~0~to~9}~\\
70 \DUrole{ln}{3~}\DUrole{k}{for}~\DUrole{n}{i}~\DUrole{ow}{in}~\DUrole{nb}{range}\DUrole{p}{(}\DUrole{mi}{10}\DUrole{p}{):}~\\
71 \DUrole{ln}{4~}~~~~\DUrole{k}{print}~\DUrole{n}{i}
73 \end{quote}
75 Another example:
77 \begin{quote}{\ttfamily \raggedright \noindent
78 \DUrole{ln}{~7~}\DUrole{k}{def}~\DUrole{nf}{my\_function}\DUrole{p}{():}~\\
79 \DUrole{ln}{~8~}~~~~\DUrole{sd}{"{}"{}"Test~the~lexer.\\
80 }\DUrole{ln}{~9~}\DUrole{sd}{~~~~"{}"{}"}~\\
81 \DUrole{ln}{10~}~\\
82 \DUrole{ln}{11~}~~~~\DUrole{c}{\#~and~now~for~something~completely~different}~\\
83 \DUrole{ln}{12~}~~~~\DUrole{k}{print}~\DUrole{mi}{8}\DUrole{o}{/}\DUrole{mi}{2}
85 \end{quote}
87 The end.
89 \end{document}