From 7505f2bd2ca7c1f11f2250e934216b4b752434ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Wed, 13 Aug 2003 12:02:35 +0000 Subject: [PATCH] text module: autoreset, texdebug, pyxgraphics, documentation git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@1029 069f4177-920e-0410-937b-c2a4a81bcd90 --- CHANGES | 9 ++- manual/palettename.py | 10 ++-- manual/text.tex | 49 +++++++++------ pyx/text.py | 161 ++++++++++++++++++++++++++++---------------------- 4 files changed, 128 insertions(+), 101 deletions(-) diff --git a/CHANGES b/CHANGES index 37fd96a8..5b5fe7ec 100644 --- a/CHANGES +++ b/CHANGES @@ -41,16 +41,15 @@ PyX - shouldn't strokepath/fillpath be validated by "strokepath is not None" instead of just "strokepath" - text module: - reset() method for the texrunner (done except for the documentation) - - texmessage.loadfd for accepting font description loading -> used as texmessagedefaultrun (done except for the documentation) + - automatic restart of a TeX instance with the same preamble (preamble changes are not possible) + - texmessage.loadfd for accepting font description loading - don't bail out on width_index == 0, but mark character invalid instead - - dvicopy flag - - preliminary version of pyxgraphics flag (handling of file names, no documentation) + - dvicopy flag (TODO: stdout handling) + - support for specials; pyxgraphics flag - support psfonts.map: font names, font encodings TODO: - the prolog method of the dvifile class recieves the page now -> return the prolog needed by this page only - - further improve lfs handling; pyxgraphics handling of file names - SlantFont & Co support - - document dvicopy - mention psfonts.map in docu - tex module: - bugfix \def\ProcessPyXBox -> \long\def\ProcessPyXBox diff --git a/manual/palettename.py b/manual/palettename.py index 091d3ee4..bb5d5c69 100755 --- a/manual/palettename.py +++ b/manual/palettename.py @@ -24,15 +24,13 @@ skiplevel = None for line in lines: # we yet don't use a file iterator m = p.match(line) if m: - xaxis = graph.linaxis(datavmin=0, datavmax=1, part=graph.linpart(ticks=("0.5","0.1"), labels="1"), + xaxis = graph.linaxis(datavmin=0, datavmax=1, part=graph.linpart(tickdist=("0.5","0.1"), labeldist="1"), painter=graph.axispainter(innerticklengths=None, labelattrs=None)) g = c.insert(graph.graphxy(ypos=y, width=10, height=0.5, x=xaxis, x2=graph.linkaxis(xaxis, - skipticklevel=skiplevel, - skiplabellevel=skiplevel, - painter=graph.axispainter(innerticklengths=None, - outerticklengths=graph.axispainter.defaultticklengths)), - y=graph.linaxis(datavmin=0, datavmax=1, part=graph.manualpart(ticks=None)))) + painter=graph.linkaxispainter(innerticklengths=None, + outerticklengths=graph.axispainter.defaultticklengths)), + y=graph.linaxis(datavmin=0, datavmax=1, part=None))) g.plot(pf, graph.rect(pyx.color.palette.__dict__[m.group("name")])) g.dodata() g.finish() diff --git a/manual/text.tex b/manual/text.tex index f21d6bec..debd68fd 100644 --- a/manual/text.tex +++ b/manual/text.tex @@ -27,19 +27,22 @@ following table: keyword&description\\ \hline \texttt{mode}&\texttt{"tex"} (default) or \texttt{"latex"}\\ -\texttt{lfs}&Specifies a latex font size file to be used with \TeX. Those files (with the suffix \texttt{.lfs}) can be created by \texttt{createlfs.tex}. Possible values are listed when a requested name could not be found.\\ +\texttt{lfs}&Specifies a latex font size file to be used with \TeX{} (not in \LaTeX). Those files (with the suffix \texttt{.lfs}) can be created by \texttt{createlfs.tex}. Possible values are listed when a requested name could not be found.\\ \texttt{docclass}&\LaTeX{} document class; default is \texttt{"article"}\\ \texttt{docopt}&specifies options for the document class; default is \texttt{None}\\ -\texttt{usefiles}$^1$&filenames to be as jobname files for \TeX/\LaTeX{}; default: \texttt{None}; example: \texttt{("spam.aux", "eggs.log")}\\ +\texttt{usefiles}$^1$&access to \TeX/\LaTeX{} jobname files; default: \texttt{None}; example: \texttt{("spam.aux", "eggs.log")}\\ \texttt{waitfortex}&wait this number of seconds for a \TeX/\LaTeX{} response; default \texttt{5}\\ -\texttt{texdebug}&\TeX/\LaTeX{} debug messages (boolean); default \texttt{0}\\ +\texttt{texdebug}&filename to store \TeX/\LaTeX{} commands; default \texttt{None}\\ \texttt{dvidebug}&dvi debug messages like \texttt{dvitype} (boolean); default \texttt{0}\\ +\texttt{errordebug}&verbose level of \TeX/\LaTeX{} error messages; valid values are \texttt{0}, \texttt{1} (default), \texttt{2}\\ +\texttt{dvicopy}&get rid of virtual fonts which \PyX{} cannot handle (boolean); default \texttt{0}\\ +\texttt{pyxgraphics}&enables the usage of the graphics package without further configuration (boolean); default 1\\ \texttt{texmessagestart}$^{1,2}$&parsers for the \TeX/\LaTeX{} start message; default: \texttt{texmessage.start}\\ \texttt{texmessagedocclass}$^{1,2}$&parsers for \LaTeX{}s \texttt{\textbackslash{}documentclass} statement; default: \texttt{texmessage.load}\\ \texttt{texmessagebegindoc}$^{1,2}$&parsers for \LaTeX{}s \texttt{\textbackslash{}begin\{document\}} statement; default: \texttt{(texmessage.load, texmessage.noaux)}\\ \texttt{texmessageend}$^{1,2}$&parsers for \TeX{}s \texttt{\textbackslash{}end}/ \LaTeX{}s \texttt{\textbackslash{}end\{document\}} statement; default: \texttt{texmessage.texend}\\ \texttt{texmessagedefaultpreamble}$^{1,2}$&default parsers for preamble statements; default: \texttt{texmessage.load}\\ -\texttt{texmessagedefaultrun}$^{1,2}$&default parsers for text statements; default: \texttt{None}\\ +\texttt{texmessagedefaultrun}$^{1,2}$&default parsers for text statements; default: \texttt{(texmessage.loadfd, texmessage.graphicsload)}\\ \end{tabularx} \medskip @@ -50,24 +53,25 @@ $^2$ \TeX/\LaTeX{} message parsers are described in more detail below. \medskip -The \verb|texrunner| instance provides three methods to be called by -the user. The first method is called \verb|set|. It takes the same +The \verb|texrunner| instance provides several methods to be called by +the user. First there is a method called \verb|set|. It takes the same kewword arguments as the constructor and its purpose is to provide an -access to the \verb|texrunner|s settings for a given instance. This is +access to the \verb|texrunner| settings for a given instance. This is important for the \verb|defaulttextunner|. The \verb|set| method fails, when a modification can't be applied anymore (e.g. \TeX/\LaTeX{} was already started). -Secondly there is a \verb|preamble| method, which can be called before -the \verb|text| method only (see below). It takes a \TeX/\LaTeX{} -expression and optionally one or several \TeX/\LaTeX{} message -parsers. The preamble expressions should be used to perform global -settings, but should not create any \TeX/\LaTeX{} dvi output. In -\LaTeX, the preamble expressions are inserted before the -\verb|\begin{document}| statement. - -Last, but first, there is a \verb|text| method. The first two -parameters are the x, y position of the output to be generated. The +The \verb|preamble| method can be called before the \verb|text| method +only (see below). It takes a \TeX/\LaTeX{} expression and optionally +one or several \TeX/\LaTeX{} message parsers. The preamble expressions +should be used to perform global settings, but should not create any +\TeX/\LaTeX{} dvi output. In \LaTeX, the preamble expressions are +inserted before the \verb|\begin{document}| statement. Note, that you +can use \verb|\AtBeginDocument{...}| to postpone the direct +evaluation. + +Finally there is a \verb|text| method. The first two parameters are +the \verb|x| and \verb|y| position of the output to be generated. The third parameter is a \TeX/\LaTeX{} expression and further parameters are attributes for this command. Those attributes might be \TeX/\LaTeX{} settings as described below, \TeX/\LaTeX{} message @@ -76,6 +80,14 @@ fill styles (like colors). The \verb|text| method returns a box (see chapter~\ref{module:box}), which can be inserted into a canvas instance by its \verb|insert| method to get the text. +Note that for the generation of the PostScript code the \TeX/\LaTeX{} +instance must be terminated. However, a \TeX/\LaTeX{} instance is +started again when the \verb|text| method is called again. A call of +the \verb|preamble| method will still fail, but you can explicitly +call the \verb|reset| method to allow for new \verb|preamble| settings +as well. The \verb|reset| method takes a boolean parameter +\verb|reinit| which can be set to run the old preamble settings. + \section{\TeX/\LaTeX{} settings} \begin{description} @@ -186,7 +198,8 @@ otherwise an exception is raised reporting the problem. parser name&purpose\\ \hline \texttt{texmessage.load}&loading of files (accept \texttt{(file ...)})\\ -\texttt{texmessage.graphicsload}&loading of graphic files (accept \texttt{})\\ +\texttt{texmessage.loadfd}&loading of files (accept \texttt{(file.fd)})\\ +\texttt{texmessage.graphicsload}&loading of graphic files (accept \texttt{})\\ \texttt{texmessage.ignore}&accept everything as a valid output\\ \end{tabular} \medskip diff --git a/pyx/text.py b/pyx/text.py index 98a353d4..282e6030 100644 --- a/pyx/text.py +++ b/pyx/text.py @@ -22,8 +22,8 @@ # along with PyX; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import exceptions, glob, os, threading, Queue, traceback, re, struct, tempfile, sys, atexit -import helper, unit, bbox, box, base, canvas, color, trafo, path, prolog, pykpathsea +import exceptions, glob, os, threading, Queue, traceback, re, struct, tempfile, sys, atexit, time +import helper, unit, bbox, box, base, canvas, color, trafo, path, prolog, pykpathsea, version class fix_word: def __init__(self, word): @@ -1845,7 +1845,7 @@ class texrunner: docopt=None, usefiles=None, waitfortex=5, - texdebug=0, + texdebug=None, dvidebug=0, errordebug=1, dvicopy=0, @@ -1865,7 +1865,13 @@ class texrunner: self.docopt = docopt self.usefiles = helper.ensurelist(usefiles) self.waitfortex = waitfortex - self.texdebug = texdebug + if texdebug is not None: + if texdebug[-4:] == ".tex": + self.texdebug = open(texdebug, "w") + else: + self.texdebug = open("%s.tex" % texdebug, "w") + else: + self.texdebug = None self.dvidebug = dvidebug self.errordebug = errordebug self.dvicopy = dvicopy @@ -1896,6 +1902,7 @@ class texrunner: self.page = 0 self.dvinumber = 0 self.dvifiles = [] + self.preambles = [] savetempdir = tempfile.tempdir tempfile.tempdir = os.curdir self.texfilename = os.path.basename(tempfile.mktemp()) @@ -1913,6 +1920,10 @@ class texrunner: - when self.preamblemode is unset, the expr is passed to \ProcessPyXBox """ if not self.texruns: + if self.texdebug is not None: + self.texdebug.write("%% PyX %s texdebug file\n" % version.version) + self.texdebug.write("%% mode: %s\n" % self.mode) + self.texdebug.write("%% date: %s\n" % time.asctime(time.localtime(time.time()))) for usefile in self.usefiles: extpos = usefile.rfind(".") try: @@ -1962,43 +1973,43 @@ class texrunner: *self.texmessagestart) os.remove("%s.tex" % self.texfilename) if self.mode == "tex": - try: - LocalLfsName = str(self.lfs) + ".lfs" - lfsdef = open(LocalLfsName, "r").read() - except IOError: + if len(self.lfs) > 4 and self.lfs[-4:] == ".lfs": + lfsname = self.lfs + else: + lfsname = "%s.lfs" % self.lfs + for fulllfsname in [lfsname, + os.path.join(sys.prefix, "share", "pyx", lfsname), + os.path.join(os.path.dirname(__file__), "lfs", lfsname)]: try: - try: - SysLfsName = os.path.join(sys.prefix, "share", "pyx", str(self.lfs) + ".lfs") - lfsdef = open(SysLfsName, "r").read() - except IOError: - SysLfsName = os.path.join(os.path.dirname(__file__), "lfs", str(self.lfs) + ".lfs") - lfsdef = open(SysLfsName, "r").read() + lfsdef = open(fulllfsname, "r").read() + break except IOError: - allfiles = [] - try: - allfiles += os.listdir(".") - except OSError: - pass - try: - allfiles += os.listdir(os.path.join(sys.prefix, "share", "pyx")) - except OSError: - pass - try: - allfiles += os.listdir(os.path.join(os.path.dirname(__file__), "lfs")) - except OSError: - pass - files = map(lambda x: x[:-4], filter(lambda x: x[-4:] == ".lfs", allfiles)) - raise IOError("file '%s.lfs' not found. Available latex font sizes:\n%s" % (self.lfs, files)) + pass + else: + allfiles = (glob.glob("*.lfs") + + glob.glob(os.path.join(sys.prefix, "share", "pyx", "*.lfs")) + + glob.glob(os.path.join(os.path.dirname(__file__), "lfs", "*.lfs"))) + lfsnames = [os.path.basename(x)[:-4] for x in allfiles] + lfsnames.sort() + raise IOError("file '%s' not found. Available latex font sizes: %s" % (lfsname, lfsnames)) self.execute(lfsdef) self.execute("\\normalsize%\n") self.execute("\\newdimen\\linewidth%\n") elif self.mode == "latex": if self.pyxgraphics: + for pyxdef in ["pyx.def", + os.path.join(sys.prefix, "share", "pyx", "pyx.def"), + os.path.join(os.path.dirname(__file__), "..", "contrib", "pyx.def")]: + if os.path.isfile(pyxdef): + break + else: + IOError("could not find 'pyx.def'") + pyxdef = os.path.abspath(pyxdef).replace(os.sep, "/") self.execute("\\makeatletter%\n" "\\let\\saveProcessOptions=\\ProcessOptions%\n" "\\def\\ProcessOptions{%\n" "\\saveProcessOptions%\n" - "\\def\\Gin@driver{../../contrib/pyx.def}%\n" + "\\def\\Gin@driver{" + pyxdef + "}%\n" "\\def\\c@lor@namefile{dvipsnam.def}}%\n" "\\makeatother") if self.docopt is not None: @@ -2022,8 +2033,8 @@ class texrunner: self.expr = "\\end{document}\n" else: self.expr = "\\end\n" - if self.texdebug: - print "pass the following expression to TeX/LaTeX:\n %s" % self.expr.replace("\n", "\n ").rstrip() + if self.texdebug is not None: + self.texdebug.write(self.expr) self.texinput.write(self.expr) self.gotevent.wait(self.waitfortex) # wait for the expected output gotevent = self.gotevent.isSet() @@ -2081,7 +2092,7 @@ class texrunner: self.getdvi() return self.dvifiles[dvinumber].write(file, page) - def reset(self): + def reset(self, reinit=0): "resets the tex runner to its initial state (upto its record to old dvi file(s))" if self.texruns: if not self.texdone: @@ -2090,26 +2101,33 @@ class texrunner: self.executeid = 0 self.page = 0 self.texdone = 0 - - def settex(self, mode=None, - lfs=None, - docclass=None, - docopt=None, - usefiles=None, - waitfortex=None, - dvicopy=None, - pyxgraphics=None, - texmessagestart=None, - texmessagedocclass=None, - texmessagebegindoc=None, - texmessageend=None, - texmessagedefaultpreamble=None, - texmessagedefaultrun=None): + if self.reinit: + for expr, args in self.preambles: + self.execute(expr, *args) + else: + self.preambles = [] + + def set(self, mode=None, + lfs=None, + docclass=None, + docopt=None, + usefiles=None, + waitfortex=None, + texdebug=None, + dvidebug=0, + errordebug=None, + dvicopy=None, + pyxgraphics=None, + texmessagestart=None, + texmessagedocclass=None, + texmessagebegindoc=None, + texmessageend=None, + texmessagedefaultpreamble=None, + texmessagedefaultrun=None): """provide a set command for TeX/LaTeX settings - TeX/LaTeX must not yet been started - especially needed for the defaultrunner, where no access to - the constructor is available - - do not call this method directly; better use the set method below""" + the constructor is available""" if self.texruns: raise TexRunsError if mode is not None: @@ -2127,10 +2145,21 @@ class texrunner: self.usefiles = helper.ensurelist(usefiles) if waitfortex is not None: self.waitfortex = waitfortex + if texdebug is not None: + if texdebug[-4:] == ".tex": + self.texdebug = open(texdebug, "w") + else: + self.texdebug = open("%s.tex" % texdebug, "w") + if dvidebug is not None: + self.dvidebug = dvidebug + if errordebug is not None: + self.errordebug = errordebug if dvicopy is not None: self.dvicopy = dvicopy - if dvicopy is not None: + if pyxgraphics is not None: self.pyxgraphics = pyxgraphics + if errordebug is not None: + self.errordebug = errordebug if texmessagestart is not None: texmessagestart = helper.ensuresequence(texmessagestart) helper.checkattr(texmessagestart, allowmulti=(texmessage,)) @@ -2156,23 +2185,8 @@ class texrunner: helper.checkattr(texmessagedefaultrun, allowmulti=(texmessage,)) self.texmessagedefaultrun = texmessagedefaultrun - def set(self, texdebug=None, dvidebug=None, errordebug=None, **args): - """as above, but contains all settings - - the debug level might be changed during TeX/LaTeX execution - - dvidebug gets used only once, namely when TeX/LaTeX is being finished""" - if self.texdone: - raise TexDoneError - if texdebug is not None: - self.texdebug = texdebug - if dvidebug is not None: - self.dvidebug = dvidebug - if errordebug is not None: - self.errordebug = errordebug - if len(args.keys()): - self.settex(**args) - def bracketcheck(self, expr): - """a helper method for consistant usage of "{" and "}" + """a helper method to check the usage of "{" and "}" - Michael Schindler claims that this is not necessary""" pass @@ -2208,13 +2222,13 @@ class texrunner: - preamble expressions must not create any dvi output - args might contain texmessage instances - a bracketcheck is performed on the expression""" - if self.texdone: - raise TexDoneError - if not self.preamblemode: + if self.texdone or not self.preamblemode: raise TexNotInPreambleModeError self.bracketcheck(expr) helper.checkattr(args, allowmulti=(texmessage,)) - self.execute(expr, *helper.getattrs(args, texmessage, default=self.texmessagedefaultpreamble)) + args = helper.getattrs(args, texmessage, default=self.texmessagedefaultpreamble) + self.execute(expr, *args) + self.preambles.append((expr, args)) PyXBoxPattern = re.compile(r"PyXBox:page=(?P\d+),lt=(?P-?\d*((\d\.?)|(\.?\d))\d*)pt,rt=(?P-?\d*((\d\.?)|(\.?\d))\d*)pt,ht=(?P-?\d*((\d\.?)|(\.?\d))\d*)pt,dp=(?P-?\d*((\d\.?)|(\.?\d))\d*)pt:") @@ -2232,7 +2246,10 @@ class texrunner: if expr is None: raise ValueError("None expression is invalid") if self.texdone: - raise TexDoneError + if self.texdebug is not None: + self.texdebug.write("%s\n" % reduce(lambda x, y: "%" + x, range(80), "")) + self.texdebug.write("%% a new instance of %s is started\n" % self.mode) + self.reset(reinit=1) if self.preamblemode: if self.mode == "latex": self.execute("\\begin{document}", *self.texmessagebegindoc) -- 2.11.4.GIT