Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index error when code error #1

Closed
obtitus opened this issue May 9, 2012 · 7 comments
Closed

index error when code error #1

obtitus opened this issue May 9, 2012 · 7 comments
Labels

Comments

@obtitus
Copy link

obtitus commented May 9, 2012

I get the following error when I type something wrong in the pylabcode environment:
while not codefile[errlinenumber].startswith('pytex.inputline=') and errlinenumber>-1:
IndexError: list index out of range

@ghost ghost assigned gpoore May 9, 2012
@gpoore gpoore closed this as completed in 8a05f5d May 9, 2012
@gpoore
Copy link
Owner

gpoore commented May 9, 2012

I just pushed an updated version that will fix the IndexError. This was caused by the error message parser trying to read beyond the beginning of the error file. Since pythontex.py was trying to parse an error message (unsuccessfully), your code is apparently producing some type of error that it cannot connect with a specific line number. I would be very interested in an example, if you can post one, so I can refine error handling.

@obtitus
Copy link
Author

obtitus commented May 10, 2012

Good, the error is caused by calling an external function (so no latex line number) with the wrong argument. I can post a minimal example if you wish.

@gpoore
Copy link
Owner

gpoore commented May 10, 2012

I would be interested in a minimal example.

@obtitus
Copy link
Author

obtitus commented May 10, 2012

On May 10, 2012, at 2:52 , gpoore wrote:

I would be interested in a minimal example.


Reply to this email directly or view it on GitHub:
#1 (comment)

\documentclass{article}
\usepackage{pythontex}
\begin{document}
Hello world
\begin{pylabcode}
x = linspace(0, 2*pi)
plot(x, sin(x))
savefig('pic/sin.pdf') # fails since pythontex-files-myTest/pic/ does not exist
\end{pylabcode}
\end{document}

produces:
This is PythonTeX v0.9beta
Hashing...
Parsing...
Executing...
Cleaning up and reporting errors...

Errors for pylab_default_default
Traceback (most recent call last):

  • PythonTeX code error on line 13:
    File "pythontex-files-myTest/pylab_default_default.py", line 26, in
    savefig('pic/sin.pdf')
    Traceback (most recent call last):
    File "/Users/ob/bin/pythontex.py", line 699, in
    while not codefile[errlinenumber].startswith('pytex.inputline=') and errlinenumber>-1:
    IndexError: list index out of range

The above code is fixed by using
savefig('../pic/sin.pdf')

Another issue: it would be prefferable if user code is run in the root directory so that the original example would work. Regards,

Øystein Bjørndal

@gpoore gpoore reopened this May 10, 2012
@gpoore
Copy link
Owner

gpoore commented May 10, 2012

Thanks for the example. It turns out that the previous fix didn't actually resolve the issue. I fixed the actual cause: e064b10

@gpoore gpoore closed this as completed May 10, 2012
@gpoore
Copy link
Owner

gpoore commented May 10, 2012

Code currently runs in the pythontex-files-{jobname} directory so as to isolate all PythonTeX-generated content. But I can see why it might be useful to be able to run in a user-specified directory. I will look into adding that as a feature in the next commit.

By the way, any graphics created in pythontex-files-{jobname} are available without specifying the directory if you are using the package graphicx. For example, if you create sin.pdf in pythontex-files-myTest, you can access it via \includegraphics{sin.pdf}, without specifying the directory. This behavior is set automatically via \graphicspath. But it hasn't yet made it into the non-technical part of the documentation.

@gpoore
Copy link
Owner

gpoore commented Jul 18, 2012

Regarding the directory in which code runs: Beta 3 addresses this, with the \setpythontexworkingdir macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants