Commits

Anonymous committed 575b3b2

handle spaces in some filenames

  • Participants
  • Parent commits f54eef1

Comments (0)

Files changed (2)

File py-and-sty.dtx

 %   valid Python, though, so I haven't bothered figuring out how to get
 %   a single hash. We are assuming that the extension is |.tex|; see the
 %   |initplot| documentation on page~\pageref{initplot} for discussion
-%   of file extensions. The ``|(\jobname.sagetex.sage)|'' business is
-%   there because the comment below will get pulled into the
+%   of file extensions. (There is now the \texttt{currfile} package
+%   (\url{http://www.ctan.org/pkg/currfile/}) which can figure out file
+%   extensions, apparently.) The ``|(\jobname.sagetex.sage)|'' business
+%   is there because the comment below will get pulled into the
 %   autogenerated |.py| file (second order autogeneration!) and I'd like
 %   to reduce possible confusion if someone is looking around in those
 %   files. Finally, we check for version mismatch and bail if the .py
 % error message gets printed whether you run the script with Sage or
 % with Python. Since \ST is now distributed with Sage and |sagetex.py|
 % now lives almost exclusively deep within the Sage ecosystem, this
-% check is not so necessary and will be removed sometime soon.
+% check is not so necessary and will be removed by the end of 2011.
 %    \begin{macrocode}
 import sys
 if __name__ == "__main__":
 % functions, but this seems a bit nicer and easier.
 %    \begin{macrocode}
 class SageTeXProcessor():
+%    \end{macrocode}
+% If the original |.tex| file has spaces in its name, the |\jobname|
+% we get is surrounded by double quotes, so fix that. Technically, it
+% is possible to have double quotes in a legitimate filename, but
+% dealing with that sort of quoting is
+% \href{http://tug.org/pipermail/xetex/2006-August/004712.html}{unpleasant}.
+% And yes, we're ignoring the possibility of tabs and other whitespace
+% in the filename. Patches for handling pathological filenames welcome.
+%
+% \changes{v2.3.1}{2011/02/02}{Handle filenames with
+% spaces in SageTeXProcessor and sagecommandline env.}
+%    \begin{macrocode}
   def __init__(self, jobname):
+    if ' ' in jobname:
+      jobname = jobname.strip('"')
     self.progress('Processing Sage code for {0}.tex...'.format(jobname))
     self.didinitplot = False
     self.useimagemagick = False
 % |ltx| extension or whatever, We could find out the correct extension,
 % but it would involve a lot of irritating mucking around---on
 % |comp.text.tex|, the best solution I found for finding the file
-% extension is to look through the |.log| file.
+% extension is to look through the |.log| file. (Although see the
+% \texttt{currfile} package.)
 %    \begin{macrocode}
     if os.path.isdir(self.plotdir):
       shutil.rmtree(self.plotdir)
               escapeoption = ''
 
           begin, end = self.savecmd(counter,current_lines)
-          latex_string += r"\lstinputlisting[firstline={0},lastline={1},firstnumber={2},style=SageInput{3}]{{{4}.sagetex.scmd}}".format(begin, end, begin-2, escapeoption, self.name)+"\n"
+%    \end{macrocode}
+% If there's a space in the filename, we need to quote it for \TeX.
+%    \begin{macrocode}
+          filename = self.name + '.sagetex.scmd'
+          if ' ' in filename:
+              filename = '"' + filename + '"'
+          latex_string += r"\lstinputlisting[firstline={0},lastline={1},firstnumber={2},style=SageInput{3}]{{{4}}}".format(begin, end, begin-2, escapeoption, filename)+"\n"
 
           current_statement = preparse(current_statement)
           try:  # is it an expression?
               resultstr = "{0}".format(result)
               begin, end = self.savecmd(counter,resultstr)
               if text_output:
-                latex_string += r"\lstinputlisting[firstline={0},lastline={1},firstnumber={2},style=SageOutput]{{{3}.sagetex.scmd}}".format(begin, end, begin-2, self.name)+"\n"
+                latex_string += r"\lstinputlisting[firstline={0},lastline={1},firstnumber={2},style=SageOutput]{{{3}}}".format(begin, end, begin-2, filename)+"\n"
                 bottom_skip = r"\vspace{\sagecommandlineskip}" + "\n"
               else:
                 latex_string += (
 % \iffalse meta-comment
 %
-% Copyright (C) 2008--2010 by Dan Drake <ddrake (at) member (dot) ams (dot) org>
+% Copyright (C) 2008--2011 by Dan Drake <ddrake (at) member (dot) ams (dot) org>
 % -------------------------------------------------------
 %
 % See the "Copying and licenses" section in this file for the terms
 %<latex>\ProvidesPackage{sagetex}
 %<python>__version__ = """
 %<*latex|python>
-  [2010/10/20 v2.3 embedding Sage into LaTeX documents]
+  [2011/02/02 v2.3.1 embedding Sage into LaTeX documents]
 %</latex|python>
 %<python>""".strip()
 %<latex>\newcommand{\ST@ver}{2010/10/20 v2.3}
 %   Sage scripts in the same directory as your \ST-ified \LTX documents,
 %   use a different file name!}
 %
+%   \noindent\warningbox{\textbf{WARNING!} Speaking of filenames, \ST
+%   really works best on files whose names don't have spaces or other
+%   ``funny'' characters in them. \ST \emph{should} work on such
+%   files---and you should let us know if it doesn't---but it's safest
+%   to stick to files with alphanumeric characters and ``safe''
+%   punctuation (i.e., nothing like |<|, |"|, |!|, |\| or other
+%   characters that would confuse a shell).}
+%
 % \paragraph{The final option} On a similar note, \ST, like many \LTX
 % packages, accepts the |final| option. When passed this option, either
 % directly in the |\usepackage| line, or from the |\documentclass| line,