diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2010-11-30 11:59:33 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2010-11-30 11:59:33 +0000 |
commit | c5880303ec69f984827af77f08cf3d9a54f83cd2 (patch) | |
tree | 8730121b4af5e5ae5a3d01f5f8b3027b394aeef6 /sandbox/code-block-directive/docs/myfunction.py.tex | |
parent | 976cec43efc64e68a9e2a1fc27135a11b27938aa (diff) | |
download | docutils-c5880303ec69f984827af77f08cf3d9a54f83cd2.tar.gz |
Prepare CodeBlock directive for inclusion in the Docutils core.
Rename directive and class from "code-block" to "code".
Fix fallback if pygments not found.
Use class-based interface.
Add "number-lines" option.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@6488 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/code-block-directive/docs/myfunction.py.tex')
-rw-r--r-- | sandbox/code-block-directive/docs/myfunction.py.tex | 131 |
1 files changed, 52 insertions, 79 deletions
diff --git a/sandbox/code-block-directive/docs/myfunction.py.tex b/sandbox/code-block-directive/docs/myfunction.py.tex index 6d5ddd5dd..c72da4eac 100644 --- a/sandbox/code-block-directive/docs/myfunction.py.tex +++ b/sandbox/code-block-directive/docs/myfunction.py.tex @@ -1,93 +1,66 @@ -\documentclass[10pt,a4paper,english]{scrartcl} -\usepackage{babel} -\usepackage[T1]{fontenc} -\usepackage{shortvrb} -\usepackage{ucs} -\usepackage[utf8x]{inputenc} -\usepackage{tabularx} -\usepackage{longtable} -\usepackage{booktabs} -\setlength{\extrarowheight}{2pt} -\usepackage{amsmath} -\usepackage{graphicx} -\usepackage{color} -\usepackage{multirow} -\usepackage{ifthen} -\typearea{12} +\documentclass[a4paper]{article} % generated by Docutils <http://docutils.sourceforge.net/> -\newlength{\admonitionwidth} -\setlength{\admonitionwidth}{0.9\textwidth} -\newlength{\docinfowidth} -\setlength{\docinfowidth}{0.9\textwidth} -\newlength{\locallinewidth} -\newcommand{\optionlistlabel}[1]{\bf #1 \hfill} -\newenvironment{optionlist}[1] -{\begin{list}{} - {\setlength{\labelwidth}{#1} - \setlength{\rightmargin}{1cm} - \setlength{\leftmargin}{\rightmargin} - \addtolength{\leftmargin}{\labelwidth} - \addtolength{\leftmargin}{\labelsep} - \renewcommand{\makelabel}{\optionlistlabel}} -}{\end{list}} -\newlength{\lineblockindentation} -\setlength{\lineblockindentation}{2.5em} -\newenvironment{lineblock}[1] -{\begin{list}{} - {\setlength{\partopsep}{\parskip} - \addtolength{\partopsep}{\baselineskip} - \topsep0pt\itemsep0.15\baselineskip\parsep0pt - \leftmargin#1} - \raggedright} -{\end{list}} -% begin: floats for footnotes tweaking. -\setlength{\floatsep}{0.5em} -\setlength{\textfloatsep}{\fill} -\addtolength{\textfloatsep}{3em} -\renewcommand{\textfraction}{0.5} -\renewcommand{\topfraction}{0.5} -\renewcommand{\bottomfraction}{0.5} -\setcounter{totalnumber}{50} -\setcounter{topnumber}{50} -\setcounter{bottomnumber}{50} -% end floats for footnotes -% some commands, that could be overwritten in the style file. -\newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}} -\newcommand{\titlereference}[1]{\textsl{#1}} -% end of "some commands" -% user specified packages and stylesheets: +\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} -\ifthenelse{\isundefined{\hypersetup}}{ -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} -}{} -% Custom roles: -% \DUrole{NAME}{content} calls \docutilsroleNAME if it exists -\providecommand{\DUrole}[2]{% - \ifcsname docutilsrole#1\endcsname% - \csname docutilsrole#1\endcsname{#2}% - \else% - #2% + +%%% 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% } -\title{} -\author{} -\date{} -\raggedbottom + +% 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} -\setlength{\locallinewidth}{\linewidth} +This is a test of the new ``code'' directive: -This is a test of the new code-block directive: % Translate this document to HTML with a pygments enhanced frontend, e.g. % -% rst2html-highlight --stylesheet=../data/pygments-default.css --link-stylesheet +% ../rst2html-highlight --stylesheet=../data/pygments-default.css % -% rst2latex-highlight --stylesheet=../data/pygments-docutileroles.sty +% ../rst2latex-highlight --stylesheet=../data/pygments-docutilsroles.sty +% \begin{quote}{\ttfamily \raggedright \noindent -\DUrole{k}{def}~\DUrole{nf}{my{\_}function}\DUrole{p}{():}~\\ -~~~~\DUrole{s}{"just~a~test"}~\\ -~~~~\DUrole{k}{print}~\DUrole{mf}{8}\DUrole{o}{/}\DUrole{mf}{2}~\\ +\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{sd}{~~~~just~a~test"{}"{}"}~\\ +\DUrole{ln}{11~}~\\ +\DUrole{ln}{12~}~~~~\DUrole{c}{\#~and~now~for~something~completely~different}~\\ +\DUrole{ln}{13~}~~~~\DUrole{k}{print}~\DUrole{mi}{8}\DUrole{o}{/}\DUrole{mi}{2} +} +\end{quote} -}\end{quote} +The end. \end{document} |