summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-07-20 22:15:27 +0000
committerKarl Berry <karl@freefriends.org>2014-07-20 22:15:27 +0000
commit2ae660fc4775456c4c1344061dc0b6cd7af28276 (patch)
tree8634639183e76d8647467445e371ce4bea3835b1 /Master
parent97666739085cbc6593468e7f5a2cc04f2eaf0de2 (diff)
pythontex (20jul14)
git-svn-id: svn://tug.org/texlive/trunk@34673 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/pythontex/NEWS541
-rw-r--r--Master/texmf-dist/doc/latex/pythontex/pythontex.pdfbin915100 -> 917227 bytes
-rw-r--r--Master/texmf-dist/doc/latex/pythontex/syncpdb.py14
-rwxr-xr-xMaster/texmf-dist/scripts/pythontex/depythontex2.py8
-rwxr-xr-xMaster/texmf-dist/scripts/pythontex/depythontex3.py8
-rwxr-xr-xMaster/texmf-dist/scripts/pythontex/pythontex2.py63
-rwxr-xr-xMaster/texmf-dist/scripts/pythontex/pythontex3.py63
-rwxr-xr-xMaster/texmf-dist/source/latex/pythontex/depythontex.bat4
-rwxr-xr-xMaster/texmf-dist/source/latex/pythontex/pythontex.bat4
-rw-r--r--Master/texmf-dist/source/latex/pythontex/pythontex.dtx102
-rwxr-xr-xMaster/texmf-dist/source/latex/pythontex/pythontex_install.bat8
-rw-r--r--Master/texmf-dist/tex/latex/pythontex/pythontex.sty49
12 files changed, 761 insertions, 103 deletions
diff --git a/Master/texmf-dist/doc/latex/pythontex/NEWS b/Master/texmf-dist/doc/latex/pythontex/NEWS
new file mode 100644
index 00000000000..c83bd81a256
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/pythontex/NEWS
@@ -0,0 +1,541 @@
+==================================================
+ PythonTeX News
+==================================================
+
+
+Version History
+===============
+
+
+v0.14 (2014/07/17)
+------------------
+
+New features
+~~~~~~~~~~~~
+
+* All commands for working with code inline are now robust, via
+ ``etoolbox``'s ``\newrobustcmd``. Among other things, this allows
+ commands like ``\py`` to work in standard captions that have not been
+ redefined to avoid protection issues.
+* Upgraded ``syncpdb`` to v0.2, which provides better list formatting.
+
+Backward-incompatible changes
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* The default working directory is now the main document directory instead
+ of the output directory. Using the output directory was a common source
+ of confusion for new users and was incompatible with plans for future
+ development. Old documents in which the working directory was not
+ specified will continue to use the output directory, but PythonTeX will
+ print an upgrade message; new documents will use the new setting. The
+ output directory may be selected as the working directory manually, or
+ with the shorthand
+ "``\setpythontexworkingdir{<outputdir>}``".
+
+* Standardized version numbering by removing the "v" prefix from the stored
+ version numbers in Python variables and LaTeX macros. Standardized the
+ PythonTeX scripts by renaming ``version`` to ``__version__``.
+
+
+
+v0.13 (2014/07/14)
+------------------
+
+New features
+~~~~~~~~~~~~
+
+* Added ``--interactive`` command-line option. This runs a single
+ session in interactive mode, allowing user input. Among other things,
+ this is useful when working with debuggers.
+
+* Added ``--debug`` command-line option. This runs a single session
+ with the default debugger in interactive mode. Currently, only
+ standard (non-console) Python sessions are supported. The default
+ Python debugger is the new ``syncpdb``, which wraps ``pdb`` and
+ synchronizes code line numbers with document line numbers. All
+ ``pdb`` commands that take a line number or filename:lineno as an
+ argument will refer to document files and line numbers when the
+ argument has a percent symbol (``%``) as a prefix. For example,
+ ``list %50`` lists code that came from around line 50 in the
+ document. The ``--debug`` option will support other languages and
+ provide for customization in the future.
+
+* Added command-line option ``--jobs``, which allows the maximum number
+ of concurrent processes to be specified (#35).
+
+* Added support for GNU Octave, via the ``octave`` family of commands
+ and environments (#36). Parsing of Octave stderr is not ideal, though
+ synchronization works in most cases; this will be addressed by a
+ future rewrite of the stderr parser.
+
+* Installer now automatically works with MiKTeX, not just TeX Live.
+
+* The PythonTeX utilities class has a new ``open()`` method that opens
+ files and automatically tracks dependencies/created files.
+
+* When ``pythontex2.py`` and ``pythontex3.py`` are run directly, the
+ Python interpreter is automatically set to a reasonable default
+ (``py -2`` or ``py -3`` under Windows, using the Python 3.3+ wrapper;
+ ``python2`` or ``python3`` under other systems).
+
+* The installer now creates symlinks for the numbered scripts
+ ``pythontex*.py`` and ``depythontex*.py``.
+
+* Added Python version checking to all numbered scripts.
+
+* Under Python, the type of data passed via ``\setpythontexcontext`` may
+ now be set using YAML-style tags (``!!str``, ``!!int``, ``!!float``). For
+ example, ``{myint=!!int 123}``.
+
+* The ``fancyvrb`` options ``firstline`` and ``lastline`` now work with
+ the ``pygments`` environment and ``\inputpygments`` command. This required
+ some additional patching of ``fancyvrb``.
+
+* The ``pytx@Verbatim`` and ``pytx@SaveVerbatim`` environments are now
+ used for typesetting verbatim code. These are copies of the
+ ``fancyvrb`` environments. This prevents conflicts when literal
+ ``Verbatim`` and ``SaveVerbatim`` environments need to be typeset.
+
+* Improved ``latexmk`` compatibility (#40). Added discussion of
+ ``latexmk`` usage to documentation.
+
+* Tildes ``~`` may now be used in ``outputdir`` and ``workingdir`` to
+ refer to the user’s home directory, even under Windows.
+
+Bugfixes
+~~~~~~~~
+
+* Fixed a bug that prevented created files from being cleaned up when
+ the working directory was not the document root directory and the
+ full path to the files was not provided.
+
+* Fixed a bug that prevented the ``fvextfile`` option from working when
+ external files were highlighted.
+
+
+
+v0.13-beta (2014/02/06)
+-----------------------
+
+New features
+~~~~~~~~~~~~
+
+* Switching to GitHub's Releases for downloads.
+
+* TeX information such as page dimensions may now be easily passed to the
+ programming-language side, using the new ``\setpythontexcontext`` command.
+ Contextual information is stored in the ``context`` attribute of the
+ utilities class, which is a dictionary (and also has attributes in Python).
+
+* The utilities class now has ``pt_to_in()``, ``pt_to_cm()``, and
+ ``pt_to_mm()`` methods for converting units of TeX points into inches,
+ centimeters, and millimeters. These work with integers and floats, as
+ well as strings that consist of numbers and optionally end in "pt". There
+ is also a ``pt_to_bp()`` for converting TeX points (1/72.27 inch) into big
+ (DTP or PostScript) points (1/72 inch).
+
+* Expanded Quickstart. Quickstart is now compatible with all LaTeX engines.
+ Quickstart now avoids ``microtype`` issues on some systems (#32).
+
+* Added information on citing PythonTeX (#28).
+
+* Utilities class has a new attribute ``id``, which is a string that joins
+ the command family name, session name, and session restart parameters with
+ underscores. This may be used in creating files that need a name that
+ contains a unique, session-based identifier (for example, names for
+ figures that are saved automatically).
+
+Backward-incompatible changes
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* All utilities-class attributes with names of the form ``input_*`` have
+ been renamed with the "``input_``" removed. Among other things, this
+ makes it easier to access the ``context`` attribute (``pytex.context``
+ vs. ``pytex.input_context``).
+
+* ``depythontex`` now has ``-o`` and ``--output`` command-line options for
+ specifying the name of the output file. If an output file is not
+ specified, then output is written to ``stdout``. This allows
+ ``depythontex`` output to be piped to another program.
+
+* All scripts ``*2.py`` now have shebangs with ``env python2``, and all
+ scripts ``*3.py`` now have shebangs with ``env python3``. This allows the
+ wrapper scripts (``env python`` shebang) to be used with the default
+ Python installation, and the numbered scripts to be used with specific
+ versions. Remember that except for console content, the ``--interpreter``
+ option is what determines the Python version that actually executes code.
+ The version of Python used to launch ``pythontex.py`` merely determines
+ the version that manages code execution. (``--interpreter`` support for
+ console content is coming.)
+
+* Changed the template style used in the ``CodeEngine`` class. Replacement
+ fields are now surrounded by single curly braces (as in Python's format
+ string syntax), rather than double curly braces. Literal curly braces are
+ obtained by doubling braces. This allows the use of literal adjacent
+ double braces in templates, which was not possible previously.
+
+* The Julia template now uses the new ``in()`` function, replacing
+ ``contains()``. This requires Julia v0.2.0+.
+
+Bugfixes
+~~~~~~~~
+
+* Modified test for LuaTeX, so that ``\directlua`` is not ``\let`` to
+ ``\relax`` if it does not exist. This was causing incompatibility with
+ ``babel`` under pdfTeX and XeTeX (#33).
+
+* Added missing shebangs to ``depythontex*.py``. Handling of ``utilspath``
+ is now more forgiving, so that ``pythontex_utils.py`` can be installed in
+ alternate locations (#23).
+
+* ``depythontex`` no longer leaves a blank line where
+ ``\usepackage{pythontex}`` was removed.
+
+* Console environments typeset with ``fancyvrb`` no longer end with an
+ unnecessary empty line.
+
+* Fixed bug in installer when ``kpsewhich`` was not found (#21).
+
+
+
+v0.12 (2013/08/26)
+------------------
+
+* Added support for the Julia language, with the ``julia`` and ``jl``
+ families of commands and environments. (Note that Pygments only added
+ Julia support in version 1.6.)
+
+* Warnings and errors are now synchronized with the line numbers of files
+ brought in via ``\input``, ``\include``, etc. This is accomplished using
+ the ``currfile`` package.
+
+* Added package option ``gobble``. When ``gobble=auto``, all code is
+ dedented before being executed and/or typeset. The current
+ implementation is functional but basic; it will be improved and extended
+ in the future.
+
+* The document root directory is now always added to ``sys.path`` (or its
+ equivalent), even when it is not the working directory. (The working
+ directory has been added to ``sys.path`` since v0.12beta.) The document
+ directory is added after the working directory, so that the working
+ directory has precedence.
+
+* Fixed a bug in ``console`` commands and environments; ``sys.path`` now
+ contains the working and document directories, and the working directory
+ is now the output directory by default. This parallels the behavior of
+ non-``console`` commands and environments.
+
+* Added command-line option ``--interpreter`` that allows an interpreter to
+ be invoked via a specific command. This allows, for example, a specific
+ version of Python to be invoked.
+
+* Improved synchronization of stderr in cases when an error is triggered
+ far after its origin (for example, an error caused by a multiline string
+ that is lacking a closing quote/delimiter, and thus may span several
+ chunks of user code).
+
+* Modified usage of the ``shlex`` module to work around its lack of Unicode
+ support in Python versions prior to 2.7.3.
+
+* Fixed a bug from v0.12beta that prevented ``\inputpygments`` from working
+ when ``pygments=true``.
+
+* Fixed a bug with counters that caused errors when content spanning
+ multiple columns was created within a ``tabular`` environment.
+
+* Added checking for compatible Python versions in ``pythontex.py``.
+
+* Improved execution of ``*.bat`` and ``*.cmd`` files under Windows. The
+ solution from v0.12beta allowed ``*.bat`` and ``*.cmd`` to be found and
+ executed when the extension was not given, but did not give correct
+ return codes.
+
+
+v0.12beta (2013/06/24)
+----------------------
+
+* Merged ``pythontex_types*.py`` into a single replacement
+ ``pythontex_engines.py`` compatible with both Python 2 and 3. It is
+ now much simpler to add support for additional languages.
+
+* Added support for the Ruby language as a demonstration of new
+ capabilities. The ``ruby`` and ``rb`` families of commands and
+ environments may be enabled via the new ``usefamily`` package option.
+ Support for additional languages is coming soon. See the new section
+ in the documentation on support for other languages for more
+ information.
+
+* Reimplemented treatment of Pygments content for better efficiency.
+ Now a Pygments process only runs if there is content to highlight.
+ Eliminated redundant highlighting of unmodified code.
+
+* Improved treatment of dependencies. If a dependency is modified
+ (``os.path.getmtime()``) after the current PythonTeX run starts, then
+ code that depends on it will be re-executed the next time PythonTeX
+ runs. A message is also issued to indicate that this is the case.
+
+* The utilities class now has ``before()`` and ``after()`` methods that
+ are called immediately before and after user code. These may be
+ redefined to customize output. For example, LaTeX commands could be
+ printed before and after user code; stdout could be redirected to
+ ``StringIO`` for further processing; or matplotlib figures could be
+ automatically detected, saved, and included in the document.
+
+* Added explanation of how to track dependencies and created files
+ automatically, and how to include matplotlib figures automatically,
+ to the documentation for the PythonTeX utilities class.
+
+* Created a new system for parsing and synchronizing stderr.
+
+ - Exceptions that do not reference a line number in user code (such
+ as those from ``warnings.warn()`` in a module) are now traced back
+ to a single command or environment. Previously no synchronization
+ was attempted. This is accomplished by writing delimiters to
+ stderr before executing the code from each command/environment.
+
+ - Exceptions that do reference a line in user code are more
+ efficiently synchronized with a document line number. This is
+ accomplished by careful record keeping as each script is
+ assembled. Line number synchronization no longer involves parsing
+ the script that was executed.
+
+ - Improved and generalized parsing of stderr, in preparation for
+ supporting additional languages. Exceptions that cannot be
+ identified as errors or warnings are treated based on
+ ``Popen.returncode``.
+
+* Created a new system for ``console`` content.
+
+ - There are now separate families of ``console`` commands and
+ environments. No Pygments or ``fancyvrb`` settings are shared with
+ the non-``console`` families, as was previously the case. There
+ is a new family of commands and environments based on ``pycon``,
+ including the ``\pycon`` command (inline reference to console variable),
+ ``pyconsole`` environment (same as the old one), ``\pyconc`` and
+ ``pyconcode`` (execute only), and ``\pyconv`` and ``pyconverbatim``
+ (typeset only). There are equivalent families based on
+ ``pylabcon`` and ``sympycon``.
+
+ - Each console session now runs in its own process and is cached
+ individually. Console output is now cached so that changing
+ Pygments settings no longer requires re-execution.
+
+ - Unicode is now supported under Python 2.
+
+ - The new package option ``pyconfuture`` allows automatic imports
+ from ``__future__`` for ``console`` families under Python 2,
+ paralleling the ``pyfuture`` option.
+
+ - Any errors or warnings caused by code that is not typeset
+ (``code`` command and environment, startup code) are reported in
+ the run summary. This ensures that such code does not create
+ mischief.
+
+ - ``customcode`` is now supported for ``console`` content.
+
+* Better support for ``latexmk`` and similar build tools. PythonTeX
+ creates a file of macros (``*.pytxmcr``) that is always included in a
+ document, and thus can be automatically detected and tracked by
+ ``latexmk``. This file now contains the time at which PythonTeX last
+ created files. When new files are created, the macro file will have a
+ new hash, triggering another document compile.
+
+* Improved the way in which the PythonTeX ``outputdir`` is added to the
+ graphics path. This had been done with ``\graphicspath``, but that
+ overwrites any graphics path previously specified by the user. Now the
+ ``outputdir`` is appended to any pre-existing path.
+
+* Added the ``depythontex`` option ``--graphicspath``. This adds the
+ ``outputdir`` to the graphics path of the ``depythontex`` document.
+
+* The installer now provides more options for installation locations.
+ It will now create missing directories if desired.
+
+* The working directory (``workingdir``) is now appended to
+ ``sys.path``, so that code there may be imported.
+
+* Under Windows, ``subprocess.Popen()`` is now invoked with
+ ``shell=True`` if ``shell=False`` results in a WindowsError. This
+ allows commands involving ``*.bat`` and ``*.cmd`` files to be
+ executed when the extension is not specified; otherwise, only ``*.exe``
+ can be found and run.
+
+* The path to utils is now found in ``pythontex.py`` via
+ ``sys.path[0]`` rather than ``kpsewhich``. This allows the PythonTeX
+ scripts to be executed in an arbitrary location; they no longer must
+ be installed in a texmf tree where ``kpsewhich`` can find them.
+
+* Added ``rerun`` value ``never``.
+
+* At the end of each run, data and macros are only saved if modified,
+ improving efficiency.
+
+* The number of temporary files required by each process was reduced by
+ one. All macros for commands like ``\py`` are now returned within
+ stdout, rather than in their own file.
+
+* Fixed a bug with ``\stderrpythontex``; it was defaulting to ``verb``
+ rather than ``verbatim`` mode.
+
+
+v0.11 (2013/04/21)
+------------------
+
+* As the first non-beta release, this version adds several features and introduces several changes. You should read these release notes carefully, since some changes are not backwards-compatible. Changes are based on a thorough review of all current and planned features. PythonTeX's capabilities have already grown beyond what was originally intended, and a long list of features still remains to be implemented. As a result, some changes are needed to ensure consistent syntax and naming in the future. Insofar as possible, all command names and syntax will be frozen after this release.
+* Added the ``pythontex.py`` and ``depythontex.py`` wrapper scripts. When run, these detect the current version of Python and import the correct PythonTeX code. It is still possible to run ``pythontex*.py`` and ``depythontex*.py`` directly, but the new wrapper scripts should be used instead for simplicity. There is now only a single ``pythontex_utils.py``, which works with both Python 2 and Python 3.
+* Added the ``beta`` package option. This makes the current version behave like v0.11beta, for compatibility. This option is temporary and will probably only be retained for a few releases.
+* Backward-incompatible changes (require the ``beta`` option to restore old behavior)
+
+ - The ``pyverb`` environment has been renamed ``pyverbatim``. The old name was intended to be concise, but promoted confusion with LaTeX's ``\verb`` macro.
+ - For ``\printpythontex``, ``\stdoutpythontex``, and ``\stderrpythontex``, the modes ``inlineverb`` and ``v`` have been replaced by ``verb``, and the old mode ``verb`` has been replaced by ``verbatim``. This brings naming conventions in line with standard LaTeX ``\verb`` and ``verbatim``, avoiding a source of potential confusion.
+ - The ``\setpythontexpyglexer``, ``\setpythontexpygopt``, and ``\setpygmentspygopt`` commands now take an optional argument and a mandatory argument, rather than two mandatory arguments. This creates better uniformity among current and planned settings macros.
+ - The ``\setpythontexformatter`` and ``\setpygmentsformatter`` commands have been replaced by the ``\setpythontexprettyprinter`` and ``\setpygmentsprettyprinter`` commands. This anticipates possible upcoming features. It also avoids potential confusion with Pygments's formatters and the utilities class's ``formatter()`` method.
+
+* Deprecated (still work, but raise warnings; after a few releases, they will raise errors instead, and after that eventually be removed)
+
+ - The ``rerun`` setting ``all`` was renamed ``always``, in preparation for upcoming features.
+ - The ``stderr`` option is replaced by ``makestderr``. The ``print``/``stdout`` option is replaced by ``debug``. These are intended to prevent confusion with future features.
+ - The ``fixlr`` option is deprecated. It was originally introduced to deal with some of SymPy's LaTeX formatting, which has since changed.
+ - The utilities class method ``init_sympy_latex()`` is deprecated. The ``sympy_latex()`` and ``set_sympy_latex()`` methods now automatically initialize themselves on first use.
+
+* Added ``autostdout`` package option and ``\setpythontexautostdout``, to complement ``autoprint``. Added ``prettyprinter`` and ``prettyprintinline`` package options to complement new settings commands.
+* Added quickstart guide.
+* Installer now installs gallery and quickstart files, if present.
+
+
+v0.11beta (2013/02/17)
+----------------------
+
+* Commands like ``\py`` can now bring in any valid LaTeX code, including verbatim content, under the pdfTeX and XeTeX engines. Verbatim content was not allowed previously. LuaTeX cannot bring in verbatim, due to a known bug.
+* Added package option ``depythontex`` and scripts ``depythontex*.py``. These allow a PythonTeX document to be converted into a pure LaTeX document, with no Python dependency. The package option creates an auxiliary file with extension ``.depytx``. The ``depythontex*.py`` scripts take this auxiliary file and the original LaTeX document, and combine the two to produce a new document that does not rely on the PythonTeX package. All PythonTeX commands and environments are replaced by their output. All Python-generated content is substituted directly into the document. By default, all typeset code is wrapped in ``\verb`` and ``verbatim``, but ``depythontex*.py`` has a ``--listing`` option that allows ``fancyvrb``, ``listings``, ``minted``, or ``pythontex`` to be used instead.
+* The current PythonTeX version is now saved in the ``.pytxcode``. If this does not match the version of the PythonTeX scripts, a warning is issued. This makes it easier to determine errors due to version mismatches.
+* Fixed an incompatibility with the latest release of ``xstring`` (version 1.7, 2013/01/13).
+* Fixed a bug in the ``console`` environment that could cause problems when switching from Pygments highlighting to ``fancyvrb`` when using the ``fvextfile`` option. Fixed a bug introduced in the v0.10beta series that prevented the ``console`` environment from working with ``fancyvrb``.
+* Fixed a bug with PythonTeX verbatim commands and environments that use Pygments. The verbatim commands and environments were incorrectly treated as if they had the attributes of executed code in the v0.10beta series.
+* Fixed a bug from the v0.10beta series that sometimes prevented imports from ``__future__`` from working when there were multiple sessions.
+* Fixed a bug related to hashing dependencies' mtime under Python 3.
+
+
+v0.10beta2 (2013/01/23)
+-----------------------
+
+* Improved ``pythontex*.py``'s handling of the name of the file being processed. A warning is no longer raised if the name is given with an extension; extensions are now processed (stripped) automatically. The filename may now contain a path to the file, so you need not run ``pythontex*.py`` from within the document's directory.
+* Added command-line option ``--verbose`` for more verbose output. Currently, this prints a list of all processes that are launched.
+* Fixed a bug that could crash ``pythontex*.py`` when the package option ``pygments=false``.
+* Added documentation about ``autoprint`` behavior in the preamble. Summary: ``code`` commands and environments are allowed in the preamble as of v0.10beta. ``autoprint`` only applies to the body of the document, because nothing can be typeset in the preamble. Content printed in the preamble can be brought in by explicitly using ``\printpythontex``, but this should be used with great care.
+* Revised ``\stdoutpythontex`` and ``\printpythontex`` so that they work in the preamble. Again, this should be used with great care if at all.
+* Revised treatment of any content that custom code attempts to print. Custom code is not allowed to print to the document (see documentation). If custom code attempts to print, a warning is raised, and the printed content is included in the ``pythontex*.py`` run summary.
+* One-line entries in stderr, such as those produced by Python's ``warnings.warn()``, were not previously parsed because they are of the form ``:<linenumber>:`` rather than ``line <linenumber>``. These are now parsed and synchronized with the document. They are also correctly parsed for inclusion in the document via ``\stderrpythontex``.
+* If the package option ``stderrfilename`` is changed, all sessions that produced errors or warnings are now re-executed automatically, so that their stderr content is properly updated with the new filename.
+
+
+v0.10beta (2013/01/09)
+----------------------
+
+* Backward-incompatible: Redid treatment of command-line options for
+ ``pythontex*.py``, using Python's ``argparse`` module. Run
+ ``pythontex*.py`` with option ``-h`` to see new command line options.
+* Deprecated: ``\setpythontexcustomcode`` is deprecated in favor of the
+ ``\pythontexcustomc`` command and ``pythontexcustomcode``
+ environment. These allow entry of pure code, unlike
+ ``\setpythontexcustomcode``. These also allow custom code to be
+ added to the beginning or end of a session, via an optional argument.
+ Improved treatment of errors and warnings associated with custom
+ code.
+* The summary of errors and warnings now correctly differentiates
+ errors and warnings produced by user code, rather than treating all
+ of them as errors. By default, ``pythontex*.py`` now returns an
+ exit code of 1 if there were errors.
+* The PythonTeX utilities class now allows external file dependencies
+ to be specified via ``pytex.add_dependencies()``, so that sessions
+ are automatically re-executed when external dependencies are
+ modified (modification is determined via either hash or mtime; this
+ is governed by the new ``hashdependencies`` option).
+* The PythonTeX utilities class now allows created files to be
+ specified via ``pytex.add_created()``, so that created files may be
+ automatically cleaned up (deleted) when the code that created them
+ is modified (for example, name change for a saved plot).
+* Added the following package options.
+
+ - ``stdout`` (or ``print``): Allows input of stdout to be disabled.
+ Useful for debugging.
+ - ``runall``: Executes everything. Useful when code depends on
+ external data.
+ - ``rerun``: Determines when code is re-executed. Code may be set
+ to always run (same as ``runall`` option), or only run when it is
+ modified or when it produces errors or warnings. By default,
+ code is always re-executed if there are errors or modifications,
+ but not re-executed if there are warnings.
+ - ``hashdependencies``: Determines whether external dependencies
+ (data, external code files highlighted with Pygments, etc.) are
+ checked for modification via hashing or modification time.
+ Modification time is default for performance reasons.
+
+* Added the following new command line options. The options that are
+ equivalent to package options are overridden by the package options
+ when present.
+
+ - ``--error-exit-code``: Determines whether an exit code of 1 is
+ returned if there were errors. On by default, but can be turned
+ off since it is undesirable when working with some editors.
+ - ``--runall``: Equivalent to new package option.
+ - ``--rerun``: Equivalent to new package option.
+ - ``--hashdependencies``: Equivalent to new package option.
+
+* Modified the ``fixlr`` option, so that it only patches commands if
+ they have not already been patched (avoids package conflicts).
+* Added ``\setpythontexautoprint`` command for toggling autoprint
+ on/off within the body of the document.
+* Installer now attempts to create symlinks under OS X and Linux with
+ TeX Live, and under OS X with MacPorts Tex Live.
+* Performed compatibility testing under lualatex and xelatex
+ (previously, had only tested with pdflatex). Added documentation
+ for using these TeX engines; at most, slightly different preambles
+ are needed. Modified the PythonTeX gallery to support all three
+ engines.
+* Code commands and environments may now be used in the preamble.
+ This, combined with the new treatment of custom code, allows
+ PythonTeX to be used in creating LaTeX packages.
+* Added documentation for using PythonTeX in LaTeX programming.
+* Fixed a bug that sometimes caused incorrect line numbers with
+ ``stderr`` content. Improved processing of stderr.
+* Fixed a bug in automatic detection of pre-existing listings
+ environment.
+* Improved the detection of imports from ``__future__``. Detection
+ should now be stricter, faster, and more accurate.
+
+
+v0.9beta3 (2012/07/17)
+----------------------
+
+* Added Unicode support, which required the Python code to be split into
+ one set for Python 2 and another set for Python 3. This will require
+ any old installation to be completely removed, and a new installation
+ created from scratch.
+* Refactoring of Python code. Documents should automatically re-execute
+ all code after updating to the new version. Otherwise, you should delete
+ the PythonTeX directory and run PythonTeX.
+* Improved installation script.
+* Added package options: ``pyfuture``, ``stderr``, ``upquote``,
+ ``pyglexer``, ``pyginline``. Renamed the ``pygextfile`` option to
+ ``fvextfile``.
+* Added custom code and workingdir commands.
+* Added the ``console`` environment and associated options.
+* Rewrote ``pythontex_utils*.py``, creating a new, context-aware interface to
+ SymPy's LatexPrinter class.
+* Content brought in via macros no longer uses labels. Rather, long defs
+ are used, which allows line breaks.
+* Pygments highlighting is now default for PythonTeX commands and environments.
+
+
+v0.9beta2 (2012/05/09)
+----------------------
+
+* Changed Python output extension to ``.stdout``.
+
+
+v0.9beta (2012/04/27)
+---------------------
+
+* Initial public beta release.
+
diff --git a/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf b/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf
index 23d50da9790..bd0d1788cdc 100644
--- a/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf
+++ b/Master/texmf-dist/doc/latex/pythontex/pythontex.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/pythontex/syncpdb.py b/Master/texmf-dist/doc/latex/pythontex/syncpdb.py
index fa4ee6e8b80..7f8d9778422 100644
--- a/Master/texmf-dist/doc/latex/pythontex/syncpdb.py
+++ b/Master/texmf-dist/doc/latex/pythontex/syncpdb.py
@@ -114,7 +114,7 @@ from collections import defaultdict, namedtuple
import traceback
-__version__ = '0.1'
+__version__ = '0.2'
__all__ = ["run", "pm", "SyncPdb", "runeval", "runctx", "runcall", "set_trace",
@@ -650,9 +650,11 @@ class SyncPdb(pdb.Pdb):
if len(s) < 4: s = s + ' '
if lineno in breaklist: s = s + 'B'
else: s = s + ' '
+ # SPdb
if lineno == self.curframe.f_lineno:
s = s + '->'
- # SPdb
+ else:
+ s = s + ' '
f, l = self.code_to_doc(filename, lineno)
if f == self.main_doc_fname:
s = self._format_line_main_doc(s, l)
@@ -664,8 +666,8 @@ class SyncPdb(pdb.Pdb):
self._last_doc_fname = f
if f is not None:
print(self._doc_switch_template.format(f))
+ print >>self.stdout, s + ' ' + line,
# /SPdb
- print >>self.stdout, s + '\t' + line,
self.lineno = lineno
except KeyboardInterrupt:
pass
@@ -1099,11 +1101,13 @@ class SyncPdb(pdb.Pdb):
s += 'B'
else:
s += ' '
+ # SPdb
if lineno == current_lineno:
s += '->'
elif lineno == exc_lineno:
s += '>>'
- # SPdb
+ else:
+ s += ' '
f, l = self.code_to_doc(filename, lineno)
if f == self.main_doc_fname:
s = self._format_line_main_doc(s, l)
@@ -1115,8 +1119,8 @@ class SyncPdb(pdb.Pdb):
self._last_doc_fname = f
if f is not None:
self.message(self._doc_switch_template.format(f))
+ self.message(s + ' ' + line.rstrip())
# /SPdb
- self.message(s + '\t' + line.rstrip())
# SPdb
if len(lines) < last - first + 1:
self.message(self._eof_template)
diff --git a/Master/texmf-dist/scripts/pythontex/depythontex2.py b/Master/texmf-dist/scripts/pythontex/depythontex2.py
index cc6f30b0a68..155df48d510 100755
--- a/Master/texmf-dist/scripts/pythontex/depythontex2.py
+++ b/Master/texmf-dist/scripts/pythontex/depythontex2.py
@@ -86,7 +86,7 @@ import codecs
# Script parameters
# Version
-version = 'v0.13'
+__version__ = '0.14'
# Functions and parameters for customizing the script output
@@ -674,7 +674,7 @@ def replace_print_env(name, arglist, linenum,
# Parse argv
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version',
- version='DePythonTeX {0}'.format(version))
+ version='DePythonTeX {0}'.format(__version__))
parser.add_argument('--encoding', default='utf-8',
help='encoding for all text files (see codecs module for encodings)')
parser.add_argument('--overwrite', default=False, action='store_true',
@@ -726,7 +726,7 @@ elif args.listing == 'pythontex':
# Let the user know things have started
if args.output is not None:
- print('This is DePythonTeX {0}'.format(version))
+ print('This is DePythonTeX {0}'.format(__version__))
sys.stdout.flush()
@@ -792,7 +792,7 @@ while depytx[n].startswith('=>DEPYTHONTEX:SETTINGS#'):
depytx[n] = ''
n -= 1
# Check .depytx version to make sure it is compatible
-if settings['version'] != version:
+if settings['version'] != __version__:
print('* DePythonTeX warning:')
print(' Version mismatch with DePythonTeX auxiliary file')
print(' Do a complete compile cycle to update the auxiliary file')
diff --git a/Master/texmf-dist/scripts/pythontex/depythontex3.py b/Master/texmf-dist/scripts/pythontex/depythontex3.py
index eef2f75b8f8..7fb97cce61d 100755
--- a/Master/texmf-dist/scripts/pythontex/depythontex3.py
+++ b/Master/texmf-dist/scripts/pythontex/depythontex3.py
@@ -86,7 +86,7 @@ import codecs
# Script parameters
# Version
-version = 'v0.13'
+__version__ = '0.14'
# Functions and parameters for customizing the script output
@@ -674,7 +674,7 @@ def replace_print_env(name, arglist, linenum,
# Parse argv
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version',
- version='DePythonTeX {0}'.format(version))
+ version='DePythonTeX {0}'.format(__version__))
parser.add_argument('--encoding', default='utf-8',
help='encoding for all text files (see codecs module for encodings)')
parser.add_argument('--overwrite', default=False, action='store_true',
@@ -726,7 +726,7 @@ elif args.listing == 'pythontex':
# Let the user know things have started
if args.output is not None:
- print('This is DePythonTeX {0}'.format(version))
+ print('This is DePythonTeX {0}'.format(__version__))
sys.stdout.flush()
@@ -792,7 +792,7 @@ while depytx[n].startswith('=>DEPYTHONTEX:SETTINGS#'):
depytx[n] = ''
n -= 1
# Check .depytx version to make sure it is compatible
-if settings['version'] != version:
+if settings['version'] != __version__:
print('* DePythonTeX warning:')
print(' Version mismatch with DePythonTeX auxiliary file')
print(' Do a complete compile cycle to update the auxiliary file')
diff --git a/Master/texmf-dist/scripts/pythontex/pythontex2.py b/Master/texmf-dist/scripts/pythontex/pythontex2.py
index d266616ce90..f0d509f0d7b 100755
--- a/Master/texmf-dist/scripts/pythontex/pythontex2.py
+++ b/Master/texmf-dist/scripts/pythontex/pythontex2.py
@@ -77,7 +77,7 @@ else:
# Script parameters
# Version
-version = 'v0.13'
+__version__ = '0.14'
@@ -452,6 +452,7 @@ def load_code_get_settings(data, temp_data):
settings_func['version'] = set_kv_data
settings_func['outputdir'] = set_kv_data
settings_func['workingdir'] = set_kv_data
+ settings_func['workingdirset'] = set_kv_data
settings_func['gobble'] = set_kv_data
settings_func['rerun'] = set_kv_temp_data_if_not_default
settings_func['hashdependencies'] = set_kv_temp_data_if_not_default
@@ -481,11 +482,10 @@ def load_code_get_settings(data, temp_data):
# Check for compatility between the .pytxcode and the script
if 'version' not in settings or settings['version'] != data['version']:
- print('* PythonTeX warning')
- print(' The version of the PythonTeX scripts does not match')
- print(' the last code saved by the document--run LaTeX to create')
- print(' an updated version. Attempting to proceed.')
- sys.stdout.flush()
+ print('* PythonTeX error')
+ print(' The version of the PythonTeX scripts does not match the last code')
+ print(' saved by the document--run LaTeX to create an updated version.\n')
+ sys.exit(1)
# Store all results that haven't already been stored.
data['settings'] = settings
@@ -524,6 +524,41 @@ def load_code_get_settings(data, temp_data):
+def set_upgrade_compatibility(data, old, temp_data):
+ '''
+ When upgrading, modify settings to maintain backward compatibility when
+ possible and important
+ '''
+ if (old['version'].startswith('v') and
+ not data['settings']['workingdirset'] and
+ data['settings']['outputdir'] != '.'):
+ old['compatibility'] = '0.13'
+ do_upgrade_compatibility(data, old, temp_data)
+
+
+def do_upgrade_compatibility(data, old_data, temp_data):
+ if 'compatibility' in old_data:
+ c = old_data['compatibility']
+ if (c == '0.13' and not data['settings']['workingdirset'] and
+ data['settings']['outputdir'] != '.'):
+ data['compatibility'] = c
+ data['settings']['workingdir'] = data['settings']['outputdir']
+ msg = '''
+ **** PythonTeX upgrade message ****
+ Beginning with v0.14, the default working directory is the document
+ directory rather than the output directory. PythonTeX has detected
+ that you have been using the output directory as the working directory.
+ It will continue to use the output directory for now. To keep your
+ current settings long-term and avoid seeing this message in the future,
+ add the following command to the preamble of your document, right after
+ the "\\usepackage{pythontex}": "\setpythontexworkingdir{<outputdir>}".
+ If you wish to continue with the new settings instead, simply delete
+ the file with extension .pkl in the output directory, and run PythonTeX.
+ **** End PythonTeX upgrade message ****
+ '''
+ temp_data['upgrade_message'] = textwrap.dedent(msg)
+
+
def get_old_data(data, old_data, temp_data):
'''
Load data from the last run, if it exists, into the dict old_data.
@@ -558,7 +593,10 @@ def get_old_data(data, old_data, temp_data):
if 'vitals' in old and data['vitals'] == old['vitals']:
temp_data['loaded_old_data'] = True
old_data.update(old)
+ do_upgrade_compatibility(data, old_data, temp_data)
else:
+ if 'version' in old and old['version'] != data['version']:
+ set_upgrade_compatibility(data, old, temp_data)
temp_data['loaded_old_data'] = False
# Clean up all old files
if 'files' in old:
@@ -2544,7 +2582,7 @@ def main(python=None):
# from within functions, as long as the dicts are passed to the functions.
# For simplicity, variables will often be created within functions to
# refer to dictionary values.
- data = {'version': version, 'start_time': time.time()}
+ data = {'version': __version__, 'start_time': time.time()}
temp_data = {'errors': 0, 'warnings': 0, 'python': python}
old_data = dict()
@@ -2558,7 +2596,7 @@ def main(python=None):
# (rather than just exit due to --version or --help command-line options),
# print PythonTeX version. Flush to make the message go out immediately,
# so that the user knows PythonTeX has started.
- print('This is PythonTeX ' + version)
+ print('This is PythonTeX {0}'.format(__version__))
sys.stdout.flush()
# Once we have the encoding (from argv), we set stdout and stderr to use
# this encoding. Later, we will parse the saved stderr of scripts
@@ -2606,9 +2644,11 @@ def main(python=None):
# Execute the code and perform Pygments highlighting via multiprocessing.
do_multiprocessing(data, temp_data, old_data, engine_dict)
- # Skip exit message if in debug more
+ # Skip exit message if in debug mode
# #### May want to refactor
if temp_data['debug'] is not None or temp_data['interactive'] is not None:
+ if 'upgrade_message' in temp_data:
+ print(temp_data['upgrade_message'])
sys.exit()
# Print exit message
@@ -2632,7 +2672,10 @@ def main(python=None):
print(' - Current: {0} error(s), {1} warnings(s)'.format(temp_data['errors'], temp_data['warnings']))
else:
print('PythonTeX: {0} - {1} error(s), {2} warning(s)\n'.format(data['raw_jobname'], temp_data['errors'], temp_data['warnings']))
-
+
+ if 'upgrade_message' in temp_data:
+ print(temp_data['upgrade_message'])
+
# Exit with appropriate exit code based on user settings.
if temp_data['error_exit_code'] and temp_data['errors'] > 0:
sys.exit(1)
diff --git a/Master/texmf-dist/scripts/pythontex/pythontex3.py b/Master/texmf-dist/scripts/pythontex/pythontex3.py
index 1129b483f7b..83d744adeee 100755
--- a/Master/texmf-dist/scripts/pythontex/pythontex3.py
+++ b/Master/texmf-dist/scripts/pythontex/pythontex3.py
@@ -77,7 +77,7 @@ else:
# Script parameters
# Version
-version = 'v0.13'
+__version__ = '0.14'
@@ -452,6 +452,7 @@ def load_code_get_settings(data, temp_data):
settings_func['version'] = set_kv_data
settings_func['outputdir'] = set_kv_data
settings_func['workingdir'] = set_kv_data
+ settings_func['workingdirset'] = set_kv_data
settings_func['gobble'] = set_kv_data
settings_func['rerun'] = set_kv_temp_data_if_not_default
settings_func['hashdependencies'] = set_kv_temp_data_if_not_default
@@ -481,11 +482,10 @@ def load_code_get_settings(data, temp_data):
# Check for compatility between the .pytxcode and the script
if 'version' not in settings or settings['version'] != data['version']:
- print('* PythonTeX warning')
- print(' The version of the PythonTeX scripts does not match')
- print(' the last code saved by the document--run LaTeX to create')
- print(' an updated version. Attempting to proceed.')
- sys.stdout.flush()
+ print('* PythonTeX error')
+ print(' The version of the PythonTeX scripts does not match the last code')
+ print(' saved by the document--run LaTeX to create an updated version.\n')
+ sys.exit(1)
# Store all results that haven't already been stored.
data['settings'] = settings
@@ -524,6 +524,41 @@ def load_code_get_settings(data, temp_data):
+def set_upgrade_compatibility(data, old, temp_data):
+ '''
+ When upgrading, modify settings to maintain backward compatibility when
+ possible and important
+ '''
+ if (old['version'].startswith('v') and
+ not data['settings']['workingdirset'] and
+ data['settings']['outputdir'] != '.'):
+ old['compatibility'] = '0.13'
+ do_upgrade_compatibility(data, old, temp_data)
+
+
+def do_upgrade_compatibility(data, old_data, temp_data):
+ if 'compatibility' in old_data:
+ c = old_data['compatibility']
+ if (c == '0.13' and not data['settings']['workingdirset'] and
+ data['settings']['outputdir'] != '.'):
+ data['compatibility'] = c
+ data['settings']['workingdir'] = data['settings']['outputdir']
+ msg = '''
+ **** PythonTeX upgrade message ****
+ Beginning with v0.14, the default working directory is the document
+ directory rather than the output directory. PythonTeX has detected
+ that you have been using the output directory as the working directory.
+ It will continue to use the output directory for now. To keep your
+ current settings long-term and avoid seeing this message in the future,
+ add the following command to the preamble of your document, right after
+ the "\\usepackage{pythontex}": "\setpythontexworkingdir{<outputdir>}".
+ If you wish to continue with the new settings instead, simply delete
+ the file with extension .pkl in the output directory, and run PythonTeX.
+ **** End PythonTeX upgrade message ****
+ '''
+ temp_data['upgrade_message'] = textwrap.dedent(msg)
+
+
def get_old_data(data, old_data, temp_data):
'''
Load data from the last run, if it exists, into the dict old_data.
@@ -558,7 +593,10 @@ def get_old_data(data, old_data, temp_data):
if 'vitals' in old and data['vitals'] == old['vitals']:
temp_data['loaded_old_data'] = True
old_data.update(old)
+ do_upgrade_compatibility(data, old_data, temp_data)
else:
+ if 'version' in old and old['version'] != data['version']:
+ set_upgrade_compatibility(data, old, temp_data)
temp_data['loaded_old_data'] = False
# Clean up all old files
if 'files' in old:
@@ -2544,7 +2582,7 @@ def main(python=None):
# from within functions, as long as the dicts are passed to the functions.
# For simplicity, variables will often be created within functions to
# refer to dictionary values.
- data = {'version': version, 'start_time': time.time()}
+ data = {'version': __version__, 'start_time': time.time()}
temp_data = {'errors': 0, 'warnings': 0, 'python': python}
old_data = dict()
@@ -2558,7 +2596,7 @@ def main(python=None):
# (rather than just exit due to --version or --help command-line options),
# print PythonTeX version. Flush to make the message go out immediately,
# so that the user knows PythonTeX has started.
- print('This is PythonTeX ' + version)
+ print('This is PythonTeX {0}'.format(__version__))
sys.stdout.flush()
# Once we have the encoding (from argv), we set stdout and stderr to use
# this encoding. Later, we will parse the saved stderr of scripts
@@ -2606,9 +2644,11 @@ def main(python=None):
# Execute the code and perform Pygments highlighting via multiprocessing.
do_multiprocessing(data, temp_data, old_data, engine_dict)
- # Skip exit message if in debug more
+ # Skip exit message if in debug mode
# #### May want to refactor
if temp_data['debug'] is not None or temp_data['interactive'] is not None:
+ if 'upgrade_message' in temp_data:
+ print(temp_data['upgrade_message'])
sys.exit()
# Print exit message
@@ -2632,7 +2672,10 @@ def main(python=None):
print(' - Current: {0} error(s), {1} warnings(s)'.format(temp_data['errors'], temp_data['warnings']))
else:
print('PythonTeX: {0} - {1} error(s), {2} warning(s)\n'.format(data['raw_jobname'], temp_data['errors'], temp_data['warnings']))
-
+
+ if 'upgrade_message' in temp_data:
+ print(temp_data['upgrade_message'])
+
# Exit with appropriate exit code based on user settings.
if temp_data['error_exit_code'] and temp_data['errors'] > 0:
sys.exit(1)
diff --git a/Master/texmf-dist/source/latex/pythontex/depythontex.bat b/Master/texmf-dist/source/latex/pythontex/depythontex.bat
index 77fe1ec6366..d80ddad79fc 100755
--- a/Master/texmf-dist/source/latex/pythontex/depythontex.bat
+++ b/Master/texmf-dist/source/latex/pythontex/depythontex.bat
@@ -1,2 +1,2 @@
-@echo off
-depythontex.py %*
+@echo off
+depythontex.py %*
diff --git a/Master/texmf-dist/source/latex/pythontex/pythontex.bat b/Master/texmf-dist/source/latex/pythontex/pythontex.bat
index f200d2e9f6b..0dfa442b4f7 100755
--- a/Master/texmf-dist/source/latex/pythontex/pythontex.bat
+++ b/Master/texmf-dist/source/latex/pythontex/pythontex.bat
@@ -1,2 +1,2 @@
-@echo off
-pythontex.py %*
+@echo off
+pythontex.py %*
diff --git a/Master/texmf-dist/source/latex/pythontex/pythontex.dtx b/Master/texmf-dist/source/latex/pythontex/pythontex.dtx
index cdba66cae41..612de45fc0d 100644
--- a/Master/texmf-dist/source/latex/pythontex/pythontex.dtx
+++ b/Master/texmf-dist/source/latex/pythontex/pythontex.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 2012-2013 by Geoffrey M. Poore <gpoore@gmail.com>
+% Copyright (C) 2012-2014 by Geoffrey M. Poore <gpoore@gmail.com>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
@@ -26,7 +26,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{pythontex}
%<*package>
- [2014/07/14 Version~0.13 ]
+ [2014/07/17 Version~0.14 ]
%</package>
%
%<*driver>
@@ -67,7 +67,7 @@
%</driver>
% \fi
%
-% \CheckSum{3010}
+% \CheckSum{3018}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -86,6 +86,19 @@
% Right brace \} Tilde \~}
%
%
+% \begin{changelog}{v0.14}{2014/07/17}
+% \textbf{New features}
+% \begin{itemize}
+% \item All commands for working with code inline are now robust, via \texttt{etoolbox}'s \texttt{\string\newrobustcmd}. Among other things, this allows commands like \texttt{\string\py} to work in standard captions that have not been redefined to avoid protection issues.
+% \item Upgraded \texttt{syncpdb} to v0.2, which provides better list formatting.
+% \end{itemize}
+% \textbf{Backward-incompatible changes}
+% \begin{itemize}
+% \item The default working directory is now the main document directory instead of the output directory. Using the output directory was a common source of confusion for new users and was incompatible with plans for future development. Old documents in which the working directory was not specified will continue to use the output directory, but PythonTeX will print an upgrade message; new documents will use the new setting. The output directory may be selected as the working directory manually, or with the shorthand ``\texttt{\string\setpythontexworkingdir\{<outputdir>\}}''.
+% \item Standardized version numbering by removing the ``v'' prefix from the stored version numbers in Python variables and LaTeX macros. Standardized the PythonTeX scripts by renaming \texttt{version} to \texttt{\_\_version\_\_}.
+% \end{itemize}
+% \end{changelog}
+%
% \begin{changelog}{v0.13}{2014/07/14}
% \textbf{New features}
% \begin{itemize}
@@ -327,7 +340,7 @@
%
% Because documents that use \pytex\ mix \LaTeX\ and Python code, they are less suitable than plain \LaTeX\ documents for journal submission, sharing, and conversion to other formats. \pytex\ includes a |depythontex| utility that creates a copy of a document in which all \pytex\ content is replaced by its output.
%
-% While Python is the focus of \pytex, adding basic support for an additional language is usually as simple as creating a new class instance and a few templates, usually totaling less than 100 lines of code. The following languages already have built-in support: Ruby and Julia.
+% While Python is the focus of \pytex, adding basic support for an additional language is usually as simple as creating a new class instance and a few templates, usually totaling less than 100 lines of code. The following languages already have built-in support: Ruby, Julia, and Octave.
% \end{abstract}
%
%
@@ -347,8 +360,8 @@
%
% \LaTeX\ can do a lot,\footnote{\TeX\ is a Turing-complete language.} but the programming required can sometimes be painful.\footnote{As I learned in creating this package.} In spite of the many packages available for \LaTeX, the libraries and packages of a general-purpose programming language are lacking. Furthermore, it can be convenient to include non-\LaTeX\ code in a document to make it more reproducible. For these reasons, there have been multiple systems that allow other languages to be used within \LaTeX\ documents.\footnote{I am not including the various web and weave dialects in my discussion, since they typically involve a web or weave document from which the .tex source is generated, and thus weaker integration with \LaTeX. Two sophisticated examples of this approach are \href{http://www.stat.uni-muenchen.de/~leisch/Sweave/}{Sweave} and \href{http://yihui.name/knitr/}{knitr}, both of which combine \LaTeX\ with the R language for tasks such as dynamic report generation.}
% \begin{itemize}
-% \item \href{http://www.ctan.org/tex-archive/macros/latex/contrib/perltex/}{Perl\TeX} allows the bodies of \LaTeX\ macros to be written in Perl.
-% \item \href{http://www.ctan.org/tex-archive/macros/latex/contrib/sagetex/}{Sage\TeX} allows code for the Sage mathematics software to be executed from within a \LaTeX\ document.
+% \item \href{http://www.ctan.org/pkg/perltex}{Perl\TeX} allows the bodies of \LaTeX\ macros to be written in Perl.
+% \item \href{http://www.ctan.org/pkg/sagetex/}{Sage\TeX} allows code for the Sage mathematics software to be executed from within a \LaTeX\ document.
% \item Martin R.\ Ehmsen's \href{http://www.ctan.org/pkg/python}{|python.sty|} provides a very basic method of executing Python code from within a \LaTeX\ document.
% \item \href{http://elec.otago.ac.nz/w/index.php/SympyTeX}{Sympy\TeX} allows more sophisticated Python execution, and is largely based on a subset of Sage\TeX.
% \item \href{http://www.luatex.org/}{Lua\TeX} extends the pdf\TeX\ engine to provide Lua as an embedded scripting language, and as a result yields tight, low-level Lua integration.
@@ -720,7 +733,7 @@
%
% All commands and environments take a session name as an optional argument. The session name determines the session in which the code is executed. This allows code to be executed in multiple independent sessions, increasing speed (sessions run in parallel) and preventing naming conflicts. If a session is not specified, then the |default| session is used. Session names should use the characters a-z, A-Z, 0-9, the hyphen, and the underscore. All characters used \textbf{must} be valid in file names, since session names are used to create temporary files. The colon is also allowed, but it is replaced with a hyphen internally, so the sessions |code:1| and |code-1| are identical.
%
-% In addition, all environments take |fancyvrb| settings as a second, optional argument. See the \href{http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb}{|fancyvrb| documentation} for an explanation of accepted settings. This second optional argument \textbf{must} be preceeded by the first optional argument (session name). If a named session is not desired, the optional argument can be left empty (|default| session), but the square brackets |[]| must be present so that the second optional argument may be correctly identified:
+% In addition, all environments take |fancyvrb| settings as a second, optional argument. See the \href{http://www.ctan.org/pkg/fancyvrb}{|fancyvrb| documentation} for an explanation of accepted settings. This second optional argument \textbf{must} be preceeded by the first optional argument (session name). If a named session is not desired, the optional argument can be left empty (|default| session), but the square brackets |[]| must be present so that the second optional argument may be correctly identified:
% \begin{quote}
% |\begin{|\meta{environment}|}[]|\oarg{fancyvrb~settings}
% \end{quote}
@@ -889,7 +902,7 @@
% \begin{itemize}
% \item |pytex.add_dependencies(|\meta{dependencies}|)| This adds \meta{dependencies} to a list. If any dependencies in the list change, code is re-executed, even if the code itself has not changed (unless |rerun=never|). Modified dependencies are determined via either modification time (default) or hash; see the package option |hashdependencies| for details. This method is useful for tracking changes in external data and similar files.
%
-% \meta{dependencies} should be one or more strings, separated by commas, that are the file names of dependencies. Dependencies should be given with relative paths from the current working directory, with absolute paths, or with paths based on the user's home directory (that is, starting with a tilde |~|). Paths can use a forward slash ``|/|'' even under Windows. Remember that by default, the working directory is the |pythontex-files-|\meta{jobname} directory where all \pytex\ temporary files are stored. This can be adjusted with |\setpythontexworkingdir|.
+% \meta{dependencies} should be one or more strings, separated by commas, that are the file names of dependencies. Dependencies should be given with relative paths from the current working directory, with absolute paths, or with paths based on the user's home directory (that is, starting with a tilde |~|). Paths can use a forward slash ``|/|'' even under Windows. Remember that by default, the working directory is the main document directory. This can be adjusted with |\setpythontexworkingdir|.
%
% It is possible that a dependency of one session might be modified by another session while \pytex\ runs. The first session might not be executed during the \pytex\ run because its dependency was unmodified at the beginning. A more serious case occurs when the first session does run, but we don't know whether it accessed the dependency before or after the dependency was updated (remember, sessions run in parallel). \pytex\ keeps track of the time at which it started. Any sessions with dependencies that were modified after that time are set to re-execute on the next run. A warning is also issued to indicate that this is the case.
%
@@ -1186,13 +1199,16 @@
%
% \DescribeMacro{\setpythontexworkingdir\marg{working~directory}}
%
-% The \pytex\ working directory is the current working directory for \pytex\ scripts. This is the directory in which any open or save operations will take place, unless a path is explicitly specified. By default, the working directory is the same as the output directory. For example, if you are writing |my_file.tex| and save a matplotlib figure with |savefig('my_figure.pdf')|, then |my_figure.pdf| will be created in the output directory |pythontex-files-my_file|. But maybe you have a directory called |plots| in your document root directory. In that case, you could leave the working directory unchanged, and simply specify the relative path to |plots| when saving. Or you could set the working directory to |plots| using |\setpythontexworkingdir{plots}|, so that all content would automatically be saved there. If you want your working directory to be the document root directory, you should use a period (|.|) for \meta{working~directory}: |\setpythontexworkingdir{.}|.
+% The \pytex\ working directory is the current working directory for \pytex\ scripts. This is the directory in which any open or save operations will take place, unless a path is explicitly specified. By default, the working directory is the same as the main document directory. For example, if you are writing |my_file.tex| and save a matplotlib figure with |savefig('my_figure.pdf')|, then |my_figure.pdf| will be created in the same directory as |my_file.tex|. But maybe you have a directory called |plots| in your document root directory. In that case, you could leave the working directory unchanged, and simply specify the relative path to |plots| when saving. Or you could set the working directory to |plots| using |\setpythontexworkingdir{plots}|, so that all content would automatically be saved there.
%
% Any slashes in \meta{working~directory} should be forward slashes ``|/|'' (even under Windows). Tildes |~| may be used to refer to the user's home directory, including under Windows.
%
% The working directory is automatically added to Python's |sys.path|, so that code in the working directory there may be imported without a path being specified.
%
-% Note that in typical use scenarios, you should be able to use the output directory as the working directory. The |graphicx| package will automatically look for images and figures in the output directory, so long as you do not use the |\graphicspath| command outside the preamble.\footnote{\texttt{graphicx} looks for graphics in the document root directory and in the most recent graphics path defined by \texttt{\string\graphicspath}. \texttt{\string\graphicspath} stores the graphics path in \texttt{\string\Ginput@path}, overwriting any previous value. At the end of the preamble, \pytex\ appends the output directory to \texttt{\string\Ginput@path}. Thus, that directory will always be checked for graphics, so long as \texttt{\string\Ginput@path} is not overwritten by a subsequent use of \texttt{\string\graphicspath}. If you need to use \texttt{\string\graphicspath} within the document, you could consider creating a custom version that redefines \texttt{\string\Ginput@path} with the \pytex\ output directory automatically appended.}
+% Note that in many use cases, you may be able to use the output directory as the working directory. The |graphicx| package will automatically look for images and figures in the output directory when it is used as the working directory, so long as you do not use the |\graphicspath| command outside the preamble.\footnote{\texttt{graphicx} looks for graphics in the document root directory and in the most recent graphics path defined by \texttt{\string\graphicspath}. \texttt{\string\graphicspath} stores the graphics path in \texttt{\string\Ginput@path}, overwriting any previous value. At the end of the preamble, \pytex\ appends the output directory to \texttt{\string\Ginput@path} if the output directory is being used as the working directory. Thus, that directory will always be checked for graphics, so long as \texttt{\string\Ginput@path} is not overwritten by a subsequent use of \texttt{\string\graphicspath}. If you need to use \texttt{\string\graphicspath} within the document, you could consider creating a custom version that redefines \texttt{\string\Ginput@path} with the \pytex\ output directory automatically appended.} To use the output directory as the working directory, you may enter the full name of the output directory manually, or use the text ``|<outputdir>|'' as a shortcut:
+%\begin{verbatim}
+%\setpythontexworkingdir{<outputdir>}
+%\end{verbatim}
%
% It is also possible to change the working directory from within Python code, via |os.chdir()|.
%
@@ -1201,21 +1217,25 @@
%
% \subsubsection{\texttt{latexmk}}
%
-% \pytex\ is compatible with |latexmk|. If you are compiling in the same location as the document source (if you are \emph{not} using |-auxdir|, |-outdir|, or |$out_dir|, or alternatively |TEXINPUTS|), then adding a simple rule such as the following to your |.latexmkrc| should usually be sufficient.
+% \pytex\ is compatible with |latexmk|. How you configure |latexmk| largely depends on how you are using \pytex.
+%
+% If you are compiling in the same location as the document source (if you are \emph{not} using |-auxdir|, |-outdir|, or |$out_dir|, or alternatively |TEXINPUTS|), and are not using \pytex's dependency tracking, then adding a simple rule such as the following to your |.latexmkrc| should usually be sufficient.
%\begin{verbatim}
%add_cus_dep('pytxcode', 'tex', 0, 'pythontex');
%sub pythontex { return system("pythontex \"$_[0]\""); }
%\end{verbatim}
% This tells |latexmk| that the document (|tex|) depends on the file of code extracted from the document (|pytxcode|).\footnote{This is a slightly atypical use, if not a ``misuse,'' of \texttt{add\_cus\_dep()}. In the standard usage, the first argument is the extension of a file that is used to create another file with the extension given in the second argument, via the rule named in the fourth argument. In this case, we just want to run the rule whenever files with the first extension are modified. The extension given in the second argument is irrelevant, so long as a file with the document name and that extension exists. Since the \texttt{tex} file itself will exist, its extension is a logical choice for the second argument.} Whenever the document is compiled, the file of code is updated. If |latexmk| detects that the code changed, then it will run \pytex. When \pytex\ runs, it will modify at least one file that is brought into the document. |latexmk| will detect this modification, and automatically recompile the document.
%
-% If you are compiling to a different directory (using |-auxdir|, |-outdir|, or |$out_dir|, or alternatively |TEXINPUTS|), then this rule may fail due to the different directory configuration. In that case, you should use |\setpythontexoutputdir{.}| so that \pytex\ will store its output in the current default location, rather than in a subdirectory, to ensure that |latexmk| will locate the output files. Since the |tex| source is no longer in the location of the compiled output, you also need a different dependency specification. It is probably simplest to use the |pytxmcr| file that \pytex\ always generates.
+% If you are compiling to a different directory (using |-auxdir|, |-outdir|, or |$out_dir|, or alternatively |TEXINPUTS|), then the preceding rule may fail due to the different directory configuration. In that case, you should use |\setpythontexoutputdir{.}| so that \pytex\ will store its output in the current default location, rather than in a subdirectory, to ensure that |latexmk| will locate the output files. Since the |tex| source is no longer in the location of the compiled output, you also need a different dependency specification. It is probably simplest to use the |pytxmcr| file that \pytex\ always generates.
%\begin{verbatim}
%add_cus_dep('pytxcode','pytxmcr',0,'pythontex');
%sub pythontex { return system("pythontex.py \"$_[0]\""); }
%\end{verbatim}
% Note that this configuration should \emph{always} work, but has the disadvantage of requiring that \pytex\ not use a subdirectory to isolate the files it automatically generates.
%
-% If you are using the |rerun=always| setting, the above rules will fail to run \pytex\ on each and every compile; in that situation, you should configure your |.latexmkrc| so that \pytex\ always runs after the first \LaTeX\ run.
+% If you are using \pytex's dependency tracking, then you should run \pytex\ once during \emph{every} compile cycle (unless you simply wish to run it manually, as needed). Checking the |pytxcode| for modification is not sufficient, because it does not reflect the state of dependencies. If you are testing for dependency modification using modification time (the default) rather than hashing, this should typically add very little overhead. If \pytex\ detects modified dependencies and actually does execute code, then the |pytxmcr| file will be updated, which will trigger another compile. It is possible to have \pytex\ run after each individual \LaTeX\ run by modifying |latexmk|'s |-latex|, |-pdflatex|, or |-xelatex| options. Ideally, however, \pytex\ would only run once per compile cycle.
+%
+% The situation is similar if you are using the |rerun=always| setting. The above rules will fail to run \pytex\ on each and every compile; in that situation, you should configure your |.latexmkrc| so that \pytex\ always runs at least once during \emph{every} compile cycle.
%
%
%
@@ -1275,7 +1295,7 @@
%
% The original and |depythontex| files should be nearly identical. All Python-generated content is substituted directly, so it should be unchanged. Usually, any differences will be due to changes in the way that code is typeset. For example, by default all code in the |depythontex| file is typeset with |\verb| and |verbatim|. But |\verb| is more fragile than the inline \pytex\ commands (it isn't allowed inside other commands), and |verbatim| does not support line numbering or syntax highlighting.
%
-% Remember that the |depythontex| file will need to include any graphics created by \pytex. By default, these are saved in the \pytex\ |outputdir|, which is |pythontex-files-<jobname>| unless you have customized it. They may be in other locations if you have set a non-default |workingdir| or have specified a path when saving graphics. Depending on your needs and configuration, you may wish to copy the graphics into a new location or specify their location via |\graphicspath|. Or you can run |depythontex| with the |--graphicspath| option, which will add the |outputdir| to any existing usage of |\graphicspath|, or add a |\graphicspath| command if one does not already exist.\footnote{Keep in mind that any time \texttt{\string\graphicspath} is used, it overwrites any previously specified path. If your document is using \texttt{\string\graphicspath} at multiple points in the preamble, or using it anywhere outside the preamble, then the \texttt{-{}-graphicspath} option will fail due to the path being overwritten.}
+% Remember that the |depythontex| file will need to include any graphics created by \pytex. By default, these are saved in the document root directory. They may be in other locations if you have set a non-default |workingdir| or have specified a path when saving graphics. Depending on your needs and configuration, you may wish to copy the graphics into a new location or specify their location via |\graphicspath|. If you are using the |outputdir| as the |workingdir|, you can run |depythontex| with the |--graphicspath| option, which will add the |outputdir| to any existing usage of |\graphicspath|, or add a |\graphicspath| command if one does not already exist.\footnote{Keep in mind that any time \texttt{\string\graphicspath} is used, it overwrites any previously specified path. If your document is using \texttt{\string\graphicspath} at multiple points in the preamble, or using it anywhere outside the preamble, then the \texttt{-{}-graphicspath} option will fail due to the path being overwritten.}
%
% Depending on your needs, you may wish to customize |depythontex.py|. The actual substitutions are performed in a few functions that are defined at the beginning of the script.
% \end{enumerate}
@@ -1638,7 +1658,7 @@
% We store the name of the package in a macro for later use in warnings and error messages.
% \begin{macrocode}
\newcommand{\pytx@packagename}{PythonTeX}
-\newcommand{\pytx@packageversion}{v0.13}
+\newcommand{\pytx@packageversion}{0.14}
% \end{macrocode}
%
% \subsection{Required packages}
@@ -2202,38 +2222,41 @@
% \begin{macro}{\pytx@outputdir}\begin{macro}{\setpythontexoutputdir}
% To keep things tidy, all \pytex\ files are stored in a directory that is created in the document root directory. By default, this directory is called |pythontex-files-|\meta{sanitized~jobname}, but we want to provide the user with the option to customize this. For example, when \meta{sanitized~jobname} is very long, it might be convenient to use |pythontex-|\meta{abbreviated~name}.
%
-% The command |\setpythontexoutputdir| stores the name of \pytex's output directory in |\pytx@outputdir|. If the |graphicx| package is loaded, the output directory is also added to the graphics path at the beginning of the document, so that files in the output directory may be included within the main document without the necessity of specifying path information. The command |\setpythontexoutputdir| is only allowed in the preamble, because the location of \pytex\ content should be specified before the body of the document is typeset.
+% The command |\setpythontexoutputdir| stores the name of \pytex's output directory in |\pytx@outputdir|. The command |\setpythontexoutputdir| is only allowed in the preamble, because the location of \pytex\ content should be specified before the body of the document is typeset.
% \begin{macrocode}
+\def\pytx@outputdir{pythontex-files-\pytx@jobname}
\newcommand{\setpythontexoutputdir}[1]{%
\Depythontex{cmd:setpythontexoutputdir:m:n}%
\def\pytx@outputdir{#1}}
-\setpythontexoutputdir{pythontex-files-\pytx@jobname}
-\AtBeginDocument{%
- \@ifpackageloaded{graphicx}{%
- \ifx\Ginput@path\@undefined
- \graphicspath{{\pytx@outputdir/}}%
- \else
- \g@addto@macro\Ginput@path{{\pytx@outputdir/}}%
- \fi
- }{}%
-}
\@onlypreamble\setpythontexoutputdir
% \end{macrocode}
%
%
% \begin{macro}{pytx@workingdir}\begin{macro}{\setpythontexworkingdir}
-% We need to be able to set the current working directory for the scripts executed by \pytex. By default, the working directory should be the same as the output directory. That way, any files saved in the current working directory will be in the \pytex\ output directory, and will thus be kept separate. But in some cases the user may wish to specify a different working directory, such as the document root.
+% We need to be able to set the current working directory for the scripts executed by \pytex. By default, the working directory should be the same as the document root directory. But in some cases the user may wish to specify a different working directory. We want to be able to use ``|<outputdir>|'' as a shortcut for setting the working directory to the output directory.
%
+% If the |graphicx| package is loaded, and the output directory is being used as the working directory, then the output directory is added to the graphics path at the beginning of the document, so that files in the output directory may be included within the main document without the necessity of specifying path information.
% \begin{macrocode}
+\def\pytx@workingdir{.}
+\def\pytx@workingdirset{false}
\newcommand{\setpythontexworkingdir}[1]{%
\Depythontex{cmd:setpythontexworkingdir:m:n}%
\def\pytx@workingdir{#1}%
+ \def\pytx@workingdirset{true}%
}
\@onlypreamble\setpythontexworkingdir
\AtBeginDocument{%
- \ifcsname pytx@workingdir\endcsname\else
- %\setpythontexworkingdir{\pytx@outputdir}\fi Depythontex
- \let\pytx@workingdir\pytx@outputdir\fi
+ \ifdefstring{\pytx@workingdir}{<outputdir>}%
+ {\let\pytx@workingdir\pytx@outputdir}{}%
+ \ifdefstrequal{\pytx@workingdir}{\pytx@outputdir}{%
+ \@ifpackageloaded{graphicx}{%
+ \ifx\Ginput@path\@undefined
+ \graphicspath{{\pytx@outputdir/}}%
+ \else
+ \g@addto@macro\Ginput@path{{\pytx@outputdir/}}%
+ \fi
+ }{}%
+ }{}%
}
% \end{macrocode}
% \end{macro}\end{macro}
@@ -2310,6 +2333,7 @@
\immediate\write\pytx@codefile{version=\pytx@packageversion}%
\immediate\write\pytx@codefile{outputdir=\pytx@outputdir}%
\immediate\write\pytx@codefile{workingdir=\pytx@workingdir}%
+ \immediate\write\pytx@codefile{workingdirset=\pytx@workingdirset}%
\immediate\write\pytx@codefile{gobble=\pytx@opt@gobble}%
\immediate\write\pytx@codefile{rerun=\pytx@opt@rerun}%
\immediate\write\pytx@codefile{hashdependencies=\pytx@opt@hashdependencies}%
@@ -2967,13 +2991,13 @@
%
%
% \subsubsection{Inline command constructors}
-% With the core inline macros complete, we are ready to create constructors for different kinds of inline commands. All of these consctructors take a string and define an inline command named using that string as a base name. Two forms of each constructor are created, one that uses Pygments and one that does not. The Pygments variants have names ending in ``Pyg''.
+% With the core inline macros complete, we are ready to create constructors for different kinds of inline commands. All of these consctructors take a string and define an inline command named using that string as a base name. Two forms of each constructor are created, one that uses Pygments and one that does not. The Pygments variants have names ending in ``Pyg''. All commands are created using |etoolbox|'s |\newrobustcmd|. Among other things, this is needed so that commands will work within the default caption command.
%
% \begin{macro}{\pytx@MakeInlinebFV}\begin{macro}{\pytx@MakeInlinebPyg}
% These macros creates inline block commands, which both typeset code and save it so that it may be executed. The base name of the command is stored in |\pytx@type|. A string representing the kind of command is stored in |\pytx@cmd|. Then |\pytx@SetContext| is used to set |\pytx@context| and |\pytx@SetGroup| is used to set |\pytx@group|. Macros for showing, saving, and printing are set to appropriate values. Then the core inline macros are invoked through |\pytx@Inline|.
% \begin{macrocode}
\newcommand{\pytx@MakeInlinebFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1b\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1b\endcsname}{%
\expandafter\let\expandafter\pytx@lexer\csname pytx@pyglexer@#1\endcsname
\Depythontex{cmd:#1b:ov:c}%
\xdef\pytx@type{#1}%
@@ -2987,7 +3011,7 @@
}%
}%
\newcommand{\pytx@MakeInlinebPyg}[1]{%
- \expandafter\newcommand\expandafter{\csname #1b\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1b\endcsname}{%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{b}%
\pytx@SetContext
@@ -3006,7 +3030,7 @@
% This macro creates inline verbatim commands, which only typeset code. |\pytx@type|, |\pytx@cmd|, |\pytx@context|, and |\pytx@group| are still set, for symmetry with other commands. They are not needed for |fancyvrb| typesetting, though. We use |\pytx@SetGroupVerb| to split verbatim content (|v| and |verb|) off into its own group. That way, verbatim content doesn't affect the instance numbers of executed code, and thus executed code is not affected by the addition or removal of verbatim content.
% \begin{macrocode}
\newcommand{\pytx@MakeInlinevFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1v\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1v\endcsname}{%
\expandafter\let\expandafter\pytx@lexer\csname pytx@pyglexer@#1\endcsname
\Depythontex{cmd:#1v:ov:c}%
\xdef\pytx@type{#1}%
@@ -3020,7 +3044,7 @@
}%
}%
\newcommand{\pytx@MakeInlinevPyg}[1]{%
- \expandafter\newcommand\expandafter{\csname #1v\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1v\endcsname}{%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{v}%
\pytx@SetContext
@@ -3039,7 +3063,7 @@
% This macro creates inline code commands, which save code for execution but do not typeset it. If the code prints content, this content is inputted automatically if the package option |autoprint| is on. Since no code is typeset, there is no difference between the |fancyvrb| and Pygments forms.
% \begin{macrocode}
\newcommand{\pytx@MakeInlinecFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1c\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1c\endcsname}{%
\Depythontex{cmd:#1c:ov:p}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{c}%
@@ -3060,7 +3084,7 @@
% This macro creates plain inline commands, which save code and then bring in the output of |pytex.formatter(|\meta{code}|)| (|pytex.formatter()| is the formatter function in Python sessions that is provided by |pythontex_utils*.py|). The Python output is saved in a \TeX\ macro, and the macro is written to a file shared by all \pytex\ sessions. This greatly reduces the number of external files needed. Since no code is typeset, there is no difference between the |fancyvrb| and Pygments forms.
% \begin{macrocode}
\newcommand{\pytx@MakeInlineFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1\endcsname}{%
\Depythontex{cmd:#1:ov:p}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{i}%
@@ -3081,7 +3105,7 @@
% This is the inline form for |console| types. It brings in |SaveVerbatim|.
% \begin{macrocode}
\newcommand{\pytx@MakeInlineConsFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1\endcsname}{%
\Depythontex{cmd:#1:ov:c}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{i}%
@@ -3101,7 +3125,7 @@
%\begin{macro}{\pythontexcustomc}
% This macro takes a single line of code and adds it to all sessions within a family. It is the inline version of the |pythontexcustomcode| environment.
% \begin{macrocode}
-\newcommand{\pythontexcustomc}[2][begin]{%
+\newrobustcmd{\pythontexcustomc}[2][begin]{%
\Depythontex{cmd:pythontexcustomc:omv:p}%
\ifstrequal{#1}{begin}{}{%
\ifstrequal{#1}{end}{}{\PackageError{\pytx@packagename}%
diff --git a/Master/texmf-dist/source/latex/pythontex/pythontex_install.bat b/Master/texmf-dist/source/latex/pythontex/pythontex_install.bat
index e32fa0ba210..e3932fa0a12 100755
--- a/Master/texmf-dist/source/latex/pythontex/pythontex_install.bat
+++ b/Master/texmf-dist/source/latex/pythontex/pythontex_install.bat
@@ -1,4 +1,4 @@
-@echo off
-@setlocal enableextensions
-@cd /d "%~dp0"
-pythontex_install.py %*
+@echo off
+@setlocal enableextensions
+@cd /d "%~dp0"
+pythontex_install.py %*
diff --git a/Master/texmf-dist/tex/latex/pythontex/pythontex.sty b/Master/texmf-dist/tex/latex/pythontex/pythontex.sty
index 500c20cd289..8bd9c677422 100644
--- a/Master/texmf-dist/tex/latex/pythontex/pythontex.sty
+++ b/Master/texmf-dist/tex/latex/pythontex/pythontex.sty
@@ -20,10 +20,10 @@
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{pythontex}
- [2014/07/14 Version~0.13 ]
+ [2014/07/17 Version~0.14 ]
\newcommand{\pytx@packagename}{PythonTeX}
-\newcommand{\pytx@packageversion}{v0.13}
+\newcommand{\pytx@packageversion}{0.14}
\RequirePackage{fancyvrb}
\RequirePackage{etex}
\RequirePackage{etoolbox}
@@ -284,29 +284,31 @@
\StrSubstitute{\jobname}{ }{-}[\pytx@jobname]
\StrSubstitute{\pytx@jobname}{"}{}[\pytx@jobname]
\StrSubstitute{\pytx@jobname}{*}{-}[\pytx@jobname]
+\def\pytx@outputdir{pythontex-files-\pytx@jobname}
\newcommand{\setpythontexoutputdir}[1]{%
\Depythontex{cmd:setpythontexoutputdir:m:n}%
\def\pytx@outputdir{#1}}
-\setpythontexoutputdir{pythontex-files-\pytx@jobname}
-\AtBeginDocument{%
- \@ifpackageloaded{graphicx}{%
- \ifx\Ginput@path\@undefined
- \graphicspath{{\pytx@outputdir/}}%
- \else
- \g@addto@macro\Ginput@path{{\pytx@outputdir/}}%
- \fi
- }{}%
-}
\@onlypreamble\setpythontexoutputdir
+\def\pytx@workingdir{.}
+\def\pytx@workingdirset{false}
\newcommand{\setpythontexworkingdir}[1]{%
\Depythontex{cmd:setpythontexworkingdir:m:n}%
\def\pytx@workingdir{#1}%
+ \def\pytx@workingdirset{true}%
}
\@onlypreamble\setpythontexworkingdir
\AtBeginDocument{%
- \ifcsname pytx@workingdir\endcsname\else
- %\setpythontexworkingdir{\pytx@outputdir}\fi Depythontex
- \let\pytx@workingdir\pytx@outputdir\fi
+ \ifdefstring{\pytx@workingdir}{<outputdir>}%
+ {\let\pytx@workingdir\pytx@outputdir}{}%
+ \ifdefstrequal{\pytx@workingdir}{\pytx@outputdir}{%
+ \@ifpackageloaded{graphicx}{%
+ \ifx\Ginput@path\@undefined
+ \graphicspath{{\pytx@outputdir/}}%
+ \else
+ \g@addto@macro\Ginput@path{{\pytx@outputdir/}}%
+ \fi
+ }{}%
+ }{}%
}
\newbool{pytx@usedpygments}
\AfterEndPreamble{%
@@ -335,6 +337,7 @@
\immediate\write\pytx@codefile{version=\pytx@packageversion}%
\immediate\write\pytx@codefile{outputdir=\pytx@outputdir}%
\immediate\write\pytx@codefile{workingdir=\pytx@workingdir}%
+ \immediate\write\pytx@codefile{workingdirset=\pytx@workingdirset}%
\immediate\write\pytx@codefile{gobble=\pytx@opt@gobble}%
\immediate\write\pytx@codefile{rerun=\pytx@opt@rerun}%
\immediate\write\pytx@codefile{hashdependencies=\pytx@opt@hashdependencies}%
@@ -703,7 +706,7 @@
}
\ifbool{pytx@opt@stdout}{}{\let\pytx@InlineMacroprint\@empty}
\newcommand{\pytx@MakeInlinebFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1b\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1b\endcsname}{%
\expandafter\let\expandafter\pytx@lexer\csname pytx@pyglexer@#1\endcsname
\Depythontex{cmd:#1b:ov:c}%
\xdef\pytx@type{#1}%
@@ -717,7 +720,7 @@
}%
}%
\newcommand{\pytx@MakeInlinebPyg}[1]{%
- \expandafter\newcommand\expandafter{\csname #1b\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1b\endcsname}{%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{b}%
\pytx@SetContext
@@ -729,7 +732,7 @@
}%
}%
\newcommand{\pytx@MakeInlinevFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1v\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1v\endcsname}{%
\expandafter\let\expandafter\pytx@lexer\csname pytx@pyglexer@#1\endcsname
\Depythontex{cmd:#1v:ov:c}%
\xdef\pytx@type{#1}%
@@ -743,7 +746,7 @@
}%
}%
\newcommand{\pytx@MakeInlinevPyg}[1]{%
- \expandafter\newcommand\expandafter{\csname #1v\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1v\endcsname}{%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{v}%
\pytx@SetContext
@@ -755,7 +758,7 @@
}%
}%
\newcommand{\pytx@MakeInlinecFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1c\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1c\endcsname}{%
\Depythontex{cmd:#1c:ov:p}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{c}%
@@ -769,7 +772,7 @@
}%
\let\pytx@MakeInlinecPyg\pytx@MakeInlinecFV
\newcommand{\pytx@MakeInlineFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1\endcsname}{%
\Depythontex{cmd:#1:ov:p}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{i}%
@@ -783,7 +786,7 @@
}%
\let\pytx@MakeInlinePyg\pytx@MakeInlineFV
\newcommand{\pytx@MakeInlineConsFV}[1]{%
- \expandafter\newcommand\expandafter{\csname #1\endcsname}{%
+ \expandafter\newrobustcmd\expandafter{\csname #1\endcsname}{%
\Depythontex{cmd:#1:ov:c}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{i}%
@@ -796,7 +799,7 @@
}%
}%
\let\pytx@MakeInlineConsPyg\pytx@MakeInlineConsFV
-\newcommand{\pythontexcustomc}[2][begin]{%
+\newrobustcmd{\pythontexcustomc}[2][begin]{%
\Depythontex{cmd:pythontexcustomc:omv:p}%
\ifstrequal{#1}{begin}{}{%
\ifstrequal{#1}{end}{}{\PackageError{\pytx@packagename}%