diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2009-02-24 11:40:50 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2009-02-24 11:40:50 +0000 |
commit | 17b8a432d43e18bec738fbec1ebd2cca1ebcf041 (patch) | |
tree | bbdad678bad69c9f957066e2a2d1c74f7b2fa4d7 /sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex | |
parent | 3eeffd4ba5169690bf321b6a96a1e814e74e259d (diff) | |
download | docutils-17b8a432d43e18bec738fbec1ebd2cca1ebcf041.tar.gz |
sandbox/code-block-directive: Add LaTeX front end, update
documentation and examples
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@5873 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex')
-rw-r--r-- | sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex | 124 |
1 files changed, 64 insertions, 60 deletions
diff --git a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex index b664d4865..e16a5dd71 100644 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex +++ b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex @@ -1,20 +1,20 @@ -\documentclass[10pt,a4paper,english]{article} +\documentclass[10pt,a4paper,english]{scrartcl} \usepackage{babel} -\usepackage{ae} -\usepackage{aeguill} +\usepackage[T1]{fontenc} \usepackage{shortvrb} -\usepackage[latin1]{inputenc} +\usepackage{ucs} +\usepackage[utf8x]{inputenc} \usepackage{tabularx} \usepackage{longtable} +\usepackage{booktabs} \setlength{\extrarowheight}{2pt} \usepackage{amsmath} \usepackage{graphicx} \usepackage{color} \usepackage{multirow} \usepackage{ifthen} -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} -\usepackage[DIV12]{typearea} -%% generator Docutils: http://docutils.sourceforge.net/ +\typearea{12} +% generated by Docutils <http://docutils.sourceforge.net/> \newlength{\admonitionwidth} \setlength{\admonitionwidth}{0.9\textwidth} \newlength{\docinfowidth} @@ -55,7 +55,11 @@ \newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}} \newcommand{\titlereference}[1]{\textsl{#1}} % end of "some commands" -\input{pygments-default.sty} +% user specified packages and stylesheets: +\usepackage{../../data/pygments-default} +\ifthenelse{\isundefined{\hypersetup}}{ +\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} +}{} \title{Example for syntax highlight with Pygments} \author{} \date{} @@ -66,22 +70,33 @@ pdftitle={Example for syntax highlight with Pygments} \begin{document} \maketitle - \setlength{\locallinewidth}{\linewidth} -% # -*- rst-mode -*- Translate this document to HTML with a pygments enhanced frontend: -\begin{quote}{\ttfamily \raggedright \noindent -rst2html-pygments~-{}-stylesheet=pygments-default.css -}\end{quote} +\begin{quote}\begin{verbatim} +rst2html-pygments --stylesheet=pygments-default.css +\end{verbatim} +\end{quote} or to LaTeX with: -\begin{quote}{\ttfamily \raggedright \noindent -rst2latex-pygments~-{}-stylesheet=pygments-default.sty -}\end{quote} +\begin{quote}\begin{verbatim} +rst2latex-pygments --stylesheet=pygments-default.sty +\end{verbatim} +\end{quote} to gain syntax highlight in the output. -% Run the doctests with ``pylit --doctest for-else-test.py``. + +Convert between text {\textless}-{\textgreater} code source formats with: +\begin{quote}\begin{verbatim} +pylit --code-block-marker='.. code-block:: python' +\end{verbatim} +\end{quote} + +Run the doctests with: +\begin{quote}\begin{verbatim} +pylit --doctest for-else-test.py +\end{verbatim} +\end{quote} %___________________________________________________________________________ @@ -89,78 +104,67 @@ to gain syntax highlight in the output. \hypertarget{for-else-test}{} \pdfbookmark[0]{for-else-test}{for-else-test} \section*{for-else-test} +\label{for-else-test} Test the flow in a \titlereference{for} loop with \titlereference{else} statement. First define a simple \titlereference{for} loop. \begin{Verbatim}[commandchars=@\[\]] -@Cax[def] @CaJ[loop1](iterable): - @Car["""simple for loop with `else` statement"""] - @Cax[for] i @Cam[in] iterable: - @Cax[print] i - @Cax[else]: - @Cax[print] @Cad["]@Cad[iterable empty]@Cad["] - @Cax[print] @Cad["]@Cad[Ende]@Cad["] - +@PYay[def] @PYaK[loop1](iterable): + @PYas["""simple for loop with `else` statement"""] + @PYay[for] i @PYan[in] iterable: + @PYay[print] i + @PYay[else]: + @PYay[print] @PYad["]@PYad[iterable empty]@PYad["] + @PYay[print] @PYad["]@PYad[Ende]@PYad["] \end{Verbatim} Now test it: The first test runs as I expect: iterator empty -{\textgreater} else clause applies: \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop1(@CaW[range](@Cag[0])) -@Caa[iterable empty] -@Caa[Ende] - +@PYaO[>>> ]@PYaX[execfile](@PYad[']@PYad[for-else-test.py]@PYad[']) +@PYaO[>>> ]loop1(@PYaX[range](@PYaw[0])) +@PYaa[iterable empty] +@PYaa[Ende] \end{Verbatim} However, the else clause even runs if the iterator is not empty in the first place but after it is ``spent'': \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop1(@CaW[range](@Cag[3])) -@Caa[0] -@Caa[1] -@Caa[2] -@Caa[iterable empty] -@Caa[Ende] - +@PYaO[>>> ]loop1(@PYaX[range](@PYaw[3])) +@PYaa[0] +@PYaa[1] +@PYaa[2] +@PYaa[iterable empty] +@PYaa[Ende] \end{Verbatim} It seems like the else clause can only be prevented, if we break out of the loop. Let's try \begin{Verbatim}[commandchars=@\[\]] -@Cax[def] @CaJ[loop2](iterable): - @Car["""for loop with `break` and `else` statement"""] - @Cax[for] i @Cam[in] iterable: - @Cax[print] i - @Cax[break] - @Cax[else]: - @Cax[print] @Cad["]@Cad[iterable empty]@Cad["] - @Cax[print] @Cad["]@Cad[Ende]@Cad["] - +@PYay[def] @PYaK[loop2](iterable): + @PYas["""for loop with `break` and `else` statement"""] + @PYay[for] i @PYan[in] iterable: + @PYay[print] i + @PYay[break] + @PYay[else]: + @PYay[print] @PYad["]@PYad[iterable empty]@PYad["] + @PYay[print] @PYad["]@PYad[Ende]@PYad["] \end{Verbatim} And indeed, the else clause is skipped after breaking out of the loop: \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop2(@CaW[range](@Cag[3])) -@Caa[0] -@Caa[Ende] - +@PYaO[>>> ]loop2(@PYaX[range](@PYaw[3])) +@PYaa[0] +@PYaa[Ende] \end{Verbatim} The empty iterator runs as expected: \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop2(@CaW[range](@Cag[0])) -@Caa[iterable empty] -@Caa[Ende] - +@PYaO[>>> ]loop2(@PYaX[range](@PYaw[0])) +@PYaa[iterable empty] +@PYaa[Ende] \end{Verbatim} -\begin{center}\small - -Generated on: 2007-04-24. - - -\end{center} - \end{document} |