Skip to content

Commit

Permalink
Bugfix for error parsing in pythontex.py (fixes #1). Changed Python o…
Browse files Browse the repository at this point in the history
…utput file extension to .stdout. Changed README extension to .rst. Updated, more generic installer.
  • Loading branch information
gpoore committed May 9, 2012
1 parent eff410b commit 8a05f5d
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 81 deletions.
File renamed without changes.
29 changes: 19 additions & 10 deletions pythontex/pythontex.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{pythontex}
%<*package>
[2012/4/27 Version~0.9beta PythonTeX]
[2012/05/09 Version~0.9beta2 PythonTeX]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[svgnames]{xcolor}
\usepackage{pythontex}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks=true,urlcolor=Green,linkcolor=blue}
\newcommand{\pytxtodo}[1]{}
Expand Down Expand Up @@ -67,7 +68,8 @@
% Right brace \} Tilde \~}
%
%
% \changes{Version 0.9beta}{2012/4/27}{Initial public beta release}
% \changes{Version 0.9beta}{2012/04/27}{Initial public beta release.}
% \changes{Version 0.9beta2}{2012/05/09}{Changed Python output extension to .stdout.}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
Expand Down Expand Up @@ -472,6 +474,13 @@
% By default, \pytex\ saves all created content in a directory called |pythontex-files-|\meta{sanitized jobname}, where \meta{sanitized jobname} is just |\jobname| with any space characters or asterisks replaced with hyphens. This directory will be created by |pythontex.py|. If we wish to specify another directory (for example, if |\jobname| is long and complex, and there is no danger of two files trying to use the same directory), then we can use the |\setpythontexoutputdir| macro to redefine the output directory.
%
%
% \section{Questions and answers}
%
% \begin{description}[style=unboxed]
% \item[Will you add a plot command that automates the saving and inclusion of plots or other graphics?] There are no plans to add a plot command like |\pyplot|. A plot command would add a little convenience, but at the expense of power.
% \end{description}
%
%
%
% \section{Troubleshooting}
% \label{sec:troubleshooting}
Expand Down Expand Up @@ -563,7 +572,7 @@
% We begin according to custom by specifying the version of \LaTeX\ that we require and stating the package that we are providing. We also store the name of the package in a macro for later use in warnings and error messages.
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{pythontex}[2012/1/13 v0.8]
\ProvidesPackage{pythontex}[2012/05/09 v0.9beta2]
\newcommand{\pytx@packagename}{PythonTeX}
% \end{macrocode}
%
Expand Down Expand Up @@ -1113,7 +1122,7 @@
\ifbool{pytx@inline@save}{%
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{#1}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -1171,7 +1180,7 @@
\ifbool{pytx@inline@save}{%
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{\pytx@arg}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -1313,7 +1322,7 @@
\@ifnextchar[{\endgroup\pytx@BeginBlockEnv}{\endgroup\pytx@BeginBlockEnv[default]}%
}%
{\end{Verbatim}\endgroup%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\setcounter{\pytx@linecount}{\value{FancyVerbLine}}%
\setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
\stepcounter{\pytx@counter}%
Expand Down Expand Up @@ -1437,7 +1446,7 @@
\@ifnextchar[{\endgroup\pytx@BeginCodeEnv}{\endgroup\pytx@BeginCodeEnv[default]}%
}%
{\end{VerbatimOut}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\ifbool{pytx@opt@autoprint}{\InputIfFileExists{\pytx@outputdir/\pytx@outfile}{}{}}{}%
\setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
\stepcounter{\pytx@counter}%
Expand Down Expand Up @@ -1548,7 +1557,7 @@
\endgroup
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{#1}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -1604,7 +1613,7 @@
\def\pytx@InlineMargOtherGetPyg@i{%
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{\pytx@arg}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -1717,7 +1726,7 @@
\@ifnextchar[{\endgroup\pytx@BeginEnvPyg}{\endgroup\pytx@BeginEnvPyg[default]}%
}%
{\end{VerbatimOut}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\setcounter{FancyVerbLine}{\value{\pytx@linecount}}%
\begingroup
\pytx@FVSet
Expand Down
Binary file modified pythontex/pythontex.pdf
Binary file not shown.
14 changes: 5 additions & 9 deletions pythontex/pythontex.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''

'''
FEATURES TO CONSIDER ADDING
*Location of external files, other than document directory or directory specified with file name
'''


#Imports
import sys
Expand Down Expand Up @@ -98,7 +93,7 @@ def run_code(inputtype,inputsession,inputgroup,outputdir):
#If the line contains the text '=>PYTHONTEX#PRINT#', we are switching between instances; if so, we need to save any printed content from the last session and get the inputinstance for the current session
if line.startswith('=>PYTHONTEX#PRINT#'):
if len(printfile)>0:
f=open(path.join(outputdir,basename+'_'+inputinstance+'.tex'),'w')
f=open(path.join(outputdir,basename+'_'+inputinstance+'.stdout'),'w')
f.write(''.join(printfile))
f.close()
printfile=[]
Expand All @@ -107,7 +102,7 @@ def run_code(inputtype,inputsession,inputgroup,outputdir):
printfile.append(line)
#After the last line of output is processed, there may be content in the printfile list that has not yet been saved, so we take care of that
if len(printfile)>0:
f=open(path.join(outputdir,basename+'_'+inputinstance+'.tex'),'w')
f=open(path.join(outputdir,basename+'_'+inputinstance+'.stdout'),'w')
f.write(''.join(printfile))
f.close()

Expand Down Expand Up @@ -682,6 +677,7 @@ def do_pygments(outputdir, jobname, saveverbatim_threshold, oldsaveverbatim_thre
#Reset the hash value, so that the code will be run next time
hashdict[key]=''
#Open error and code files
# #### Is there any reason not to just use the code that is still in memory?
f=open(errfilename)
errfile=f.readlines()
f.close()
Expand All @@ -696,10 +692,10 @@ def do_pygments(outputdir, jobname, saveverbatim_threshold, oldsaveverbatim_thre
#Offset by one for zero indexing, one for previous line
errlinenumber=int(search('line (\d+)',errline).groups()[0])-2
offset=0
while not codefile[errlinenumber].startswith('pytex.inputline=') and errlinenumber>-1:
while errlinenumber>=0 and not codefile[errlinenumber].startswith('pytex.inputline='):
errlinenumber-=1
offset+=1
if errlinenumber>-1:
if errlinenumber>=0:
codelinenumber=int(match('pytex.inputline=\'(\d+)\'',codefile[errlinenumber]).groups()[0])
codelinenumber+=offset
print('* PythonTeX code error on line '+str(codelinenumber)+':')
Expand Down
18 changes: 9 additions & 9 deletions pythontex/pythontex.sty
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{pythontex}
[2012/4/27 Version~0.9beta PythonTeX]
[2012/05/09 Version~0.9beta2 PythonTeX]
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{pythontex}[2012/1/13 v0.8]
\ProvidesPackage{pythontex}[2012/05/09 v0.9beta2]
\newcommand{\pytx@packagename}{PythonTeX}
\RequirePackage{fancyvrb}
\RequirePackage{etex}
Expand Down Expand Up @@ -265,7 +265,7 @@
\ifbool{pytx@inline@save}{%
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{#1}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -305,7 +305,7 @@
\ifbool{pytx@inline@save}{%
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{\pytx@arg}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -387,7 +387,7 @@
\@ifnextchar[{\endgroup\pytx@BeginBlockEnv}{\endgroup\pytx@BeginBlockEnv[default]}%
}%
{\end{Verbatim}\endgroup%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\setcounter{\pytx@linecount}{\value{FancyVerbLine}}%
\setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
\stepcounter{\pytx@counter}%
Expand Down Expand Up @@ -450,7 +450,7 @@
\@ifnextchar[{\endgroup\pytx@BeginCodeEnv}{\endgroup\pytx@BeginCodeEnv[default]}%
}%
{\end{VerbatimOut}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\ifbool{pytx@opt@autoprint}{\InputIfFileExists{\pytx@outputdir/\pytx@outfile}{}{}}{}%
\setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
\stepcounter{\pytx@counter}%
Expand Down Expand Up @@ -509,7 +509,7 @@
\endgroup
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{#1}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -551,7 +551,7 @@
\def\pytx@InlineMargOtherGetPyg@i{%
\edef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\pytx@WriteCodefileInfo
\immediate\write\pytx@codefile{\pytx@arg}%
\ifdefstring{\pytx@cmd}{inlinec}%
Expand Down Expand Up @@ -622,7 +622,7 @@
\@ifnextchar[{\endgroup\pytx@BeginEnvPyg}{\endgroup\pytx@BeginEnvPyg[default]}%
}%
{\end{VerbatimOut}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
\xdef\pytx@outfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}.stdout}%
\setcounter{FancyVerbLine}{\value{\pytx@linecount}}%
\begingroup
\pytx@FVSet
Expand Down
2 changes: 1 addition & 1 deletion pythontex/pythontex_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Copyright (c) 2012, Geoffrey M. Poore
# All rights reserved.
# Licensed under the Modified BSD Licence.
# Licensed under the Modified BSD License.
#

from collections import defaultdict
Expand Down
2 changes: 1 addition & 1 deletion pythontex/pythontex_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Copyright (c) 2012, Geoffrey M. Poore
# All rights reserved.
# Licensed under the Modified BSD Licence.
# Licensed under the Modified BSD License.
#

from collections import defaultdict
Expand Down
Loading

0 comments on commit 8a05f5d

Please sign in to comment.