Commits

Anonymous committed 3ef4888

use separate labels for inline and commandline macros

Comments (0)

Files changed (2)

 %    \begin{macrocode}
 \newcounter{ST@inline}
 \newcounter{ST@plot}
+\newcounter{ST@cmdline}
 \setcounter{ST@inline}{0}
 \setcounter{ST@plot}{0}
+\setcounter{ST@cmdline}{0}
 \newlength{\sagetexindent}
 \setlength{\sagetexindent}{5ex}
 \newif\ifST@paused
 % \end{macro}
 %
 % \begin{macro}{\sagestr}
-% ilike above, but doesn't run latex
+% Like above, but doesn't run |latex()| on its argument.
 %    \begin{macrocode}
 \newcommand{\sagestr}[1]{\ST@sage{#1}}
 %    \end{macrocode}
 \newenvironment{sagecommandline}{%
    \ST@wsf{%
 try:^^J
- _st_.commandline(\theST@inline, r"""}%
+ _st_.commandline(\theST@cmdline, r"""}%
    \ST@dodfsetup%
    \ST@wdf{Sage commandline, line \the\inputlineno::^^J}%
    \begingroup%
   \ifST@paused%
     \mbox{(Sage\TeX{} is paused)}%
   \else%
-    \begin{NoHyper}\ref{@sageinline\theST@inline}\end{NoHyper}%
-    \@ifundefined{r@@sageinline\theST@inline}{\gdef\ST@rerun{x}}{}%
+    \begin{NoHyper}\ref{@sagecmdline\theST@cmdline}\end{NoHyper}%
+    \@ifundefined{r@@sagecmdline\theST@cmdline}{\gdef\ST@rerun{x}}{}%
   \fi%
   \ST@wdf{}%
-  \stepcounter{ST@inline}}
+  \stepcounter{ST@cmdline}}
 %    \end{macrocode}
 % \end{environment}
 %
 % nefarious purposes. The function writes a |\newlabel| line with a
 % label made from a counter and the text from running Sage on |s|.
 %
+% The |labelname| defaults to the the name used by the usual |\sage|
+% inline macro, but this function is also used by the |sagecommandline|
+% environment. It's important to keep the corresponding labels separate,
+% because |\sage| macros often (for example) appear inside math mode,
+% and the labels from |sagecommandline| contain a |lstlistings|
+% environment---pulling such an environment into math mode produces
+% strange, unrecoverable errors, and if you can't typeset your file, you
+% can't product an updated |.sagetex.sage| file to run Sage on to
+% produce a reasonable |.sagetext.sout| file that will fix the label
+% problem. So it works much better to use distinct labels for such
+% things.
+%
 % We print out the line number so if something goes wrong, the user can
 % more easily track down the offending |\sage| command in the source
 % file.
 %
 % That's a lot of explanation for a very short function:
 %    \begin{macrocode}
-  def inline(self, counter, s):
-    self.progress('Inline formula {0}'.format(counter))
-    self.souttmp.write('\\newlabel{@sageinline' + str(counter) + '}{{%\n' +
-                 s.rstrip() + '}{}{}{}{}}\n')
+  def inline(self, counter, s, labelname=None):
+      if labelname is None:
+          labelname = 'sageinline'
+          self.progress('Inline formula {0}'.format(counter))
+      elif labelname == 'sagecmdline':
+          pass # output message already printed
+      else:
+          raise ValueError, 'inline() got a bad labelname'
+      self.souttmp.write(r'\newlabel{@' + labelname + str(counter) + 
+                         '}{{%\n' + s.rstrip() + '}{}{}{}{}}\n')
 %    \end{macrocode}
 % We are using five fields, just like |hyperref| does, because that
 % works whether or not |hyperref| is loaded. Using two fields, as in
 % plain \LTX, doesn't work if |hyperref| is loaded.
 % \end{macro}
-
+%
 % \begin{macro}{savecmd}
-%   Analogous to |inline|, this method saves the input string |s| to
-%   the temporary |.scmd| file. As an added bonus, it returns a pair
-%   of line numbers in the |.scmd| file, the first and last line of
-%   the newly-added output.
+% Analogous to |inline|, this method saves the input string |s| to
+% the temporary |.scmd| file. As an added bonus, it returns a pair
+% of line numbers in the |.scmd| file, the first and last line of
+% the newly-added output.
 %    \begin{macrocode}
   def savecmd(self, counter, s):
-    self.scmdtmp.write(s.rstrip() + "\n")
-    begin = self.scmdpos
-    end = begin + len(s.splitlines()) - 1
-    self.scmdpos = end+1
-    return begin, end
+      self.scmdtmp.write(s.rstrip() + "\n")
+      begin = self.scmdpos
+      end = begin + len(s.splitlines()) - 1
+      self.scmdpos = end + 1
+      return begin, end
 %    \end{macrocode}
 % \end{macro}
 %
           if line is None: break
           sage_block += 1
       latex_string += bottom_skip + r"\noindent" + "\n"
-      self.inline(counter, latex_string)
+      self.inline(counter, latex_string, labelname='sagecmdline')
 %    \end{macrocode}
 % \end{macro}
 %
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301, USA.
 
+The files |tkz-{arith,berge,graph}.sty| are distributed with \ST, but
+are not part of \ST. They were written by Alain Matthes and are
+available from \url{http://www.altermundus.fr}. I couldn't find a clear
+license statement for them, but other \LTX things written by Alain are
+released under the LPPL, so I'm guessing that's the license for those
+files.
+
 The \emph{documentation} of the \ST package is licensed under the
 Creative Commons Attribution-Share Alike 3.0 License. To view a copy of
 this license, visit \url{http://creativecommons.org/licenses/by-sa/3.0/}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.