From 91e62921c8f6d17fb3a1b701c0b5f99cfeadd408 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 14 Jul 2014 22:39:29 +0000
Subject: pythontex (14jul14)

git-svn-id: svn://tug.org/texlive/trunk@34605 c570f23f-e606-0410-a88d-b1316a301751
---
 .../texmf-dist/tex/latex/pythontex/pythontex.sty   | 63 +++++++++++++++++-----
 1 file changed, 50 insertions(+), 13 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/pythontex/pythontex.sty')

diff --git a/Master/texmf-dist/tex/latex/pythontex/pythontex.sty b/Master/texmf-dist/tex/latex/pythontex/pythontex.sty
index a71b4f48d2d..500c20cd289 100644
--- a/Master/texmf-dist/tex/latex/pythontex/pythontex.sty
+++ b/Master/texmf-dist/tex/latex/pythontex/pythontex.sty
@@ -20,10 +20,10 @@
 %% 
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{pythontex}
-    [2013/08/26 Version~0.12]
+    [2014/07/14 Version~0.13 ]
 
 \newcommand{\pytx@packagename}{PythonTeX}
-\newcommand{\pytx@packageversion}{v0.12}
+\newcommand{\pytx@packageversion}{v0.13}
 \RequirePackage{fancyvrb}
 \RequirePackage{etex}
 \RequirePackage{etoolbox}
@@ -230,7 +230,7 @@
         !expandafter!scantokens!expandafter{#1!empty}}%
 }%
 !endgroup
-\expandafter\ifx\csname directlua\endcsname\relax\else
+\ifx\directlua\pytx@undefined\else
 \def\pytx@SVMCR#1 {%
     \edef\pytx@tmp{\csname #1\endcsname}%
     \pytx@SVMCR@i}
@@ -238,13 +238,24 @@
     \expandafter\gdef\pytx@tmp{#1}%
 }
 \fi
-\newcommand{\definepythontexcontext}[1]{%
+\ifx\directlua\relax\else
+\def\pytx@SVMCR#1 {%
+    \edef\pytx@tmp{\csname #1\endcsname}%
+    \pytx@SVMCR@i}
+\long\def\pytx@SVMCR@i#1\endpytx@SVMCR{%
+    \expandafter\gdef\pytx@tmp{#1}%
+}
+\fi
+\DefineVerbatimEnvironment{pytx@Verbatim}{Verbatim}{}
+\DefineVerbatimEnvironment{pytx@SaveVerbatim}{SaveVerbatim}{}
+\newcommand{\setpythontexcontext}[1]{%
+    \Depythontex{cmd:setpythontexcontext:m:n}%
     \def\pytx@SetContext{%
         \edef\pytx@context{#1}%
     }%
 }
-\definepythontexcontext{}
-\@onlypreamble\definepythontexcontext
+\setpythontexcontext{}
+\@onlypreamble\setpythontexcontext
 \newcommand{\restartpythontexsession}[1]{%
     \Depythontex{cmd:restartpythontexsession:m:n}%
     \def\pytx@SetGroup{%
@@ -304,7 +315,14 @@
 }
 \AtBeginDocument{%
     \makeatletter
-    \InputIfFileExists{\pytx@outputdir/\pytx@jobname.pytxmcr}{}{}%
+    \InputIfFileExists{\pytx@outputdir/\pytx@jobname.pytxmcr}{}%
+        {\ifstrempty{\pytx@outputdir}%
+            {\typeout{No file \pytx@jobname.pytxmcr.}}%
+            {}%
+         \IfStrEq{\pytx@outputdir}{.}%
+            {\typeout{No file \pytx@jobname.pytxmcr.}}%
+            {\typeout{No file \pytx@outputdir/\pytx@jobname.pytxmcr.}}%
+         \typeout{Run \pytx@packagename\space to create it.}}%
     \makeatother
 }
 \newwrite\pytx@codefile
@@ -350,7 +368,7 @@
             {\let\pytx@currfile\@empty}{\let\pytx@currfile\currfilename}%
     \immediate\write\pytx@codefile{\pytx@delim\pytx@type\pytx@delimchar%
         \pytx@session\pytx@delimchar\pytx@group\pytx@delimchar%
-        0\pytx@delimchar\pytx@cmd\pytx@delimchar%
+        \arabic{\pytx@counter}\pytx@delimchar\pytx@cmd\pytx@delimchar%
         \pytx@context\pytx@delimchar\pytx@argsrun\pytx@delimchar%
         \pytx@argspprint\pytx@delimchar%
         \pytx@currfile\pytx@delimchar%
@@ -377,6 +395,7 @@
 \newcounter{pytx@FancyVerbLineTemp}
 \def\pytx@FVB@SaveVerbatim#1{%
     \setcounter{pytx@FancyVerbLineTemp}{\value{FancyVerbLine}}%
+    \global\FV@CodeLineNo\z@
     \@bsphack
     \begingroup
     \FV@UseKeyValues
@@ -935,6 +954,7 @@
 }%
 \def\pytx@BeginEnvPyg@i[#1]{%
     \def\pytx@fvopttmp{#1}%
+    \def\pytx@argspprint{#1}%
     \setcounter{pytx@FancyVerbLineTemp}{\value{FancyVerbLine}}%
     \let\FVB@VerbatimOut\pytx@FVB@VerbatimOut
     \let\FVE@VerbatimOut\pytx@FVE@VerbatimOut
@@ -1059,6 +1079,7 @@
 }%
 \def\pytx@BeginConsEnvFV@i[#1]{%
     \def\pytx@fvopttmp{#1}%
+    \def\pytx@argspprint{#1}%
     \setcounter{pytx@FancyVerbLineTemp}{\value{FancyVerbLine}}%
     \let\FVB@VerbatimOut\pytx@FVB@VerbatimOut
     \let\FVE@VerbatimOut\pytx@FVE@VerbatimOut
@@ -1226,6 +1247,8 @@
     \ifstrequal{#1}{rb}{\makepythontexfamily[pyglexer=ruby]{rb}}{}%
     \ifstrequal{#1}{julia}{\makepythontexfamily[pyglexer=julia]{julia}}{}%
     \ifstrequal{#1}{jl}{\makepythontexfamily[pyglexer=julia]{jl}}{}%
+    \ifstrequal{#1}{matlab}{\makepythontexfamily[pyglexer=matlab]{matlab}}{}%
+    \ifstrequal{#1}{octave}{\makepythontexfamily[pyglexer=octave]{octave}}{}%
 }
 \expandafter\docsvlist\expandafter{\pytx@families}
 \newbool{pytx@listingenv}
@@ -1241,7 +1264,7 @@
             {\PackageWarning{\pytx@packagename}%
                 {A "listing" environment already exists \MessageBreak
                  \pytx@packagename\space will not create one \MessageBreak
-                 Use \string\setpythontexlistingenv to create a custom listing environment}}%
+                 Use \string\setpythontexlistingenv\space to create a custom listing environment}}%
     \else
         \ifbool{pytx@listingenv}{}{\DeclareFloatingEnvironment[fileext=lopytx]{listing}}
     \fi
@@ -1298,6 +1321,7 @@
 }
 \def\pytx@BEPygmentsFV[#1]{%
     \def\pytx@fvopttmp{#1}%
+    \def\pytx@argspprint{#1}%
     \begingroup
     \obeylines
     \pytx@BEPygmentsFV@i
@@ -1347,6 +1371,7 @@
 }
 \def\pytx@BEPygmentsPyg[#1]{%
     \def\pytx@fvopttmp{#1}%
+    \def\pytx@argspprint{#1}%
     \begingroup
     \obeylines
     \pytx@BEPygmentsPyg@i
@@ -1377,6 +1402,8 @@
         \pytx@SetGroupVerb
         \edef\pytx@session{EXT:##3}%
         \pytx@CheckPygmentsInit{##2}%
+        \xdef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
+        \pytx@CheckCounter{\pytx@counter}%
         \setcounter{pytx@FancyVerbLineTemp}{\value{FancyVerbLine}}%
         \begingroup
         \DepyListing %Always must be in a group
@@ -1387,32 +1414,42 @@
             {\PackageWarning{\pytx@packagename}{Input file <##3> doesn't exist}}%
         \endgroup
         \setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
+        \stepcounter{\pytx@counter}%
     }%
 }
 \def\pytx@MakePygmentsInputPyg{
     \newcommand{\inputpygments}[3][]{%
+        \begingroup
         \edef\pytx@type{PYG##2}%
         \edef\pytx@cmd{verbatim}%
         \pytx@SetContext
         \pytx@SetGroupVerb
+        \def\pytx@argspprint{##1}%
         \edef\pytx@session{EXT:##3}%
         \pytx@CheckPygmentsInit{##2}%
+        \xdef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
+        \pytx@CheckCounter{\pytx@counter}%
         \pytx@WriteCodefileInfoExt
         \IfFileExists{##3}{}{\PackageWarning{\pytx@packagename}%
-            {Input file <##3> does not exist}}
+            {Input file <##3> does not exist}}%
         \setcounter{pytx@FancyVerbLineTemp}{\value{FancyVerbLine}}%
         \begingroup
         \pytx@FVSet
         \fvset{firstnumber=auto}%
-        \ifcsname FV@SV@pytx@\pytx@type @\pytx@session @\pytx@group @0\endcsname
-            \UseVerbatim[##1]{pytx@\pytx@type @\pytx@session @\pytx@group @0}%
+        \ifcsname FV@SV@pytx@\pytx@type @\pytx@session @\pytx@group
+                    @\arabic{\pytx@counter}\endcsname
+            \UseVerbatim[##1]{pytx@\pytx@type @\pytx@session @\pytx@group
+                    @\arabic{\pytx@counter}}%
         \else
-            \InputIfFileExists{\pytx@outputdir/##3_##2.pygtex}{}%
+            \InputIfFileExists{\pytx@outputdir/\pytx@type_##3_\pytx@group
+                    _\arabic{\pytx@counter}.pygtex}{}%
                 {\textbf{??~\pytx@packagename~??}%
                     \PackageWarning{\pytx@packagename}{Non-existent Pygments content}}%
         \fi
         \endgroup
         \setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
+        \stepcounter{\pytx@counter}%
+        \endgroup
     }%
 }
 \newcommand{\setpygmentsfv}[2][]{%
-- 
cgit v1.2.3

