ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 30 Sep 2013 11:46:50 +0200Difficulty with sagetexhttps://ask.sagemath.org/question/10404/difficulty-with-sagetex/Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl!
I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.
\begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
produces the error
> **** Error in Sage code on line 36 of sequences01.tex! Traceback follows.
> Traceback (most recent call last):
> File "sequences01.sagetex.py", line
> 43, in <module>
> _st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not
> defined
When I try to access 'S' with `$\sage{S}$`, am beginning to feel at a loss as to where to look now.Wed, 25 Sep 2013 16:23:39 +0200https://ask.sagemath.org/question/10404/difficulty-with-sagetex/Comment by td01 for <p>Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl! </p>
<p>I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.</p>
<pre><code> \begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
</code></pre>
<p>produces the error</p>
<blockquote>
<p><em>*</em>* Error in Sage code on line 36 of sequences01.tex! Traceback follows.
Traceback (most recent call last): <br/>
File "sequences01.sagetex.py", line
43, in <module>
_st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not
defined</p>
</blockquote>
<p>When I try to access 'S' with <code>$\sage{S}$</code>, am beginning to feel at a loss as to where to look now.</p>
https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16985#post-id-16985Many thanks kcrisman, works for me too now! Am going to have to study the indentation a bit more when typing into sagetex. Thanks a lot for your speedy response.Wed, 25 Sep 2013 18:55:50 +0200https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16985#post-id-16985Comment by kcrisman for <p>Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl! </p>
<p>I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.</p>
<pre><code> \begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
</code></pre>
<p>produces the error</p>
<blockquote>
<p><em>*</em>* Error in Sage code on line 36 of sequences01.tex! Traceback follows.
Traceback (most recent call last): <br/>
File "sequences01.sagetex.py", line
43, in <module>
_st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not
defined</p>
</blockquote>
<p>When I try to access 'S' with <code>$\sage{S}$</code>, am beginning to feel at a loss as to where to look now.</p>
https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16970#post-id-16970By the way, I think Python actually accepts any consistent indentation, not just four spaces - but that is certainly the most common practice and easiest to read. You may be able to set up your editor to do this automatically after colons.Mon, 30 Sep 2013 11:46:50 +0200https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16970#post-id-16970Comment by td01 for <p>Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl! </p>
<p>I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.</p>
<pre><code> \begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
</code></pre>
<p>produces the error</p>
<blockquote>
<p><em>*</em>* Error in Sage code on line 36 of sequences01.tex! Traceback follows.
Traceback (most recent call last): <br/>
File "sequences01.sagetex.py", line
43, in <module>
_st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not
defined</p>
</blockquote>
<p>When I try to access 'S' with <code>$\sage{S}$</code>, am beginning to feel at a loss as to where to look now.</p>
https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16974#post-id-16974Thanks again, went over a Python tutorial again and got to grips with indentation and a after a little experimentation found the 4 spaces for myself and all going well now! Thanks.Sun, 29 Sep 2013 11:43:04 +0200https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16974#post-id-16974Comment by kcrisman for <p>Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl! </p>
<p>I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.</p>
<pre><code> \begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
</code></pre>
<p>produces the error</p>
<blockquote>
<p><em>*</em>* Error in Sage code on line 36 of sequences01.tex! Traceback follows.
Traceback (most recent call last): <br/>
File "sequences01.sagetex.py", line
43, in <module>
_st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not
defined</p>
</blockquote>
<p>When I try to access 'S' with <code>$\sage{S}$</code>, am beginning to feel at a loss as to where to look now.</p>
https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16983#post-id-16983No problem! Basically, just use four spaces after a colon. Going through one of the (many) Python tutorials out there wouldn't be a bad place to start.Wed, 25 Sep 2013 23:45:45 +0200https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?comment=16983#post-id-16983Answer by kcrisman for <p>Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl! </p>
<p>I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.</p>
<pre><code> \begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
</code></pre>
<p>produces the error</p>
<blockquote>
<p><em>*</em>* Error in Sage code on line 36 of sequences01.tex! Traceback follows.
Traceback (most recent call last): <br/>
File "sequences01.sagetex.py", line
43, in <module>
_st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not
defined</p>
</blockquote>
<p>When I try to access 'S' with <code>$\sage{S}$</code>, am beginning to feel at a loss as to where to look now.</p>
https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?answer=15491#post-id-15491I think your problem is indentation. This document works for me. Remember that indentation is syntax for Python.
%!TEX TS-program = sage
\documentclass[12pt]{article}
%In case I ever wanted to do horizontally
%\usepackage[landscape]{geometry}
\usepackage{amsmath,amssymb}
\usepackage[pdftex]{graphicx}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
def nmax(max=100):
n = 1
an = 20
while n <= max:
yield an
n += 1
an = 0.9*an-5
a = nmax(30)
S=[]
for i in a:
S.append(i.n())
\end{sagesilent}
$\sage{S}$
\end{document}Wed, 25 Sep 2013 17:47:17 +0200https://ask.sagemath.org/question/10404/difficulty-with-sagetex/?answer=15491#post-id-15491