diff options
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 | 170 |
1 files changed, 0 insertions, 170 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 deleted file mode 100644 index e16a5dd71..000000000 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex +++ /dev/null @@ -1,170 +0,0 @@ -\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} -% 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{../../data/pygments-default} -\ifthenelse{\isundefined{\hypersetup}}{ -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} -}{} -\title{Example for syntax highlight with Pygments} -\author{} -\date{} -\hypersetup{ -pdftitle={Example for syntax highlight with Pygments} -} -\raggedbottom -\begin{document} -\maketitle - -\setlength{\locallinewidth}{\linewidth} - -Translate this document to HTML with a pygments enhanced frontend: -\begin{quote}\begin{verbatim} -rst2html-pygments --stylesheet=pygments-default.css -\end{verbatim} -\end{quote} - -or to LaTeX with: -\begin{quote}\begin{verbatim} -rst2latex-pygments --stylesheet=pygments-default.sty -\end{verbatim} -\end{quote} - -to gain syntax highlight in the output. - -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} - - -%___________________________________________________________________________ - -\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=@\[\]] -@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=@\[\]] -@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=@\[\]] -@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=@\[\]] -@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=@\[\]] -@PYaO[>>> ]loop2(@PYaX[range](@PYaw[3])) -@PYaa[0] -@PYaa[Ende] -\end{Verbatim} - -The empty iterator runs as expected: -\begin{Verbatim}[commandchars=@\[\]] -@PYaO[>>> ]loop2(@PYaX[range](@PYaw[0])) -@PYaa[iterable empty] -@PYaa[Ende] -\end{Verbatim} - -\end{document} |