summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/pythontex/pythontex.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/pythontex/pythontex.dtx')
-rw-r--r--Master/texmf-dist/source/latex/pythontex/pythontex.dtx183
1 files changed, 147 insertions, 36 deletions
diff --git a/Master/texmf-dist/source/latex/pythontex/pythontex.dtx b/Master/texmf-dist/source/latex/pythontex/pythontex.dtx
index d91e6e1eac0..f18d8d3fae0 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-2017 by Geoffrey M. Poore <gpoore@gmail.com>
+% Copyright (C) 2012-2019 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>
- [2017/07/20 v0.16 execute and typeset Python code and other languages]
+ [2019/09/22 v0.17 execute and typeset Python code and other languages]
%</package>
%
%<*driver>
@@ -40,6 +40,20 @@
\usepackage{environ}
\usepackage{enumitem}
\usepackage{fvextra}
+% The typesetting for macrocode doesn't use \@noligs, which upquote modifies.
+% So apply the upquote fix to \verbatim@nolig@list as well, which is in macrocode.
+\begingroup
+\catcode`'=\active
+\catcode``=\active
+\g@addto@macro\verbatim@nolig@list{%
+ \let'\textquotesingle
+ \let`\textasciigrave
+ \ifx\encodingdefault\upquote@OTone
+ \ifx\ttdefault\upquote@cmtt
+ \def'{\char13 }%
+ \def`{\char18 }%
+ \fi\fi}
+\endgroup
\usepackage{pythontex}
\usepackage{hyperref}
\hypersetup{
@@ -134,7 +148,7 @@
%</driver>
% \fi
%
-% \CheckSum{3218}
+% \CheckSum{3289}
%
% \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
@@ -153,7 +167,27 @@
% Right brace \} Tilde \~}
%
%
-
+%
+% \begin{changelog}{v0.17}{2019/09/22}
+% \begin{itemize}
+% \item Pygments syntax highlighting for the Python console (\texttt{pycon} lexer) now uses the \texttt{python3} option, and the default Python lexer is now \texttt{python3} (\#156).
+% \item Added support for JavaScript (\#147; thanks to Nathan Carter).
+% \item Updated Julia support for Julia versions 0.6 (\#107), and 0.7 and 1.0 (\#126, \#130).
+% \item There are now meaningful error messages for the Julia console when Weave.jl is not installed or raises errors (\#131).
+% \item \texttt{pythontexcustomcode} and \texttt{\string\pythontexcustomc} now set \texttt{pytex.context} (\#65).
+% \item Added support for R. The \texttt{R} family of commands and environments (\texttt{\string\R}, \texttt{\string\Rc}, \texttt{Rcode}, ...) executes code as a script. There is currently no utilities class or equivalent. The \texttt{Rcon} family (\texttt{Rconsole}) executes code to emulate an interactive R session (\#121).
+% \item \texttt{fancyvrb} settings from \texttt{\string\setpythontexfv} and console environments now work with Julia and R consoles.
+% \item \texttt{pythontexcustomcode} now works with \texttt{juliacon}. There are now proper \texttt{juliaconcode} and \texttt{Rconcode} environments that execute code but typeset nothing, to parallel \texttt{pyconcode} (\#134).
+% \item Added support for Perl with the \texttt{perl} and \texttt{pl} families of commands and environments. There is currently no utilities class or equivalent.
+% \item Added support for Perl 6 with the \texttt{perlsix} and \texttt{psix} families of commands and environments (\#104). There is currently no utilities class or equivalent.
+% \item Updated Rust support by using \texttt{dyn} with traits in utilities object.
+% \item Under Windows, capitalization of script paths in \texttt{stderr} is now preserved.
+% \item Fixed a bug that prevented the \texttt{sub} environment from working with \texttt{depythontex} (\#155).
+% \item Fixed a bug in checking mtime of dependencies to see if they have been modified while \texttt{pythontex} is running. The check failed for dependencies that do not exist or were deleted before \texttt{pythontex} can read them (\#136).
+% \end{itemize}
+% \end{changelog}
+%
+%
% \begin{changelog}{v0.16}{2017/07/20}
% \begin{itemize}
% \item Added preliminary console support for Julia (\#98).
@@ -436,8 +470,9 @@
%
% 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, Julia, and Octave.
+% 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, Octave, Bash, Rust, R, Perl, Perl 6, and JavaScript.
% \end{abstract}
+%
%
%
% \section*{\centering Warning}
@@ -660,7 +695,7 @@
%
% \DescribeMacro{usefamily=\meta{basename}/\marg{basename1,~basename2,~...}}
%
-% By default, only the |py|, |sympy|, and |pylab| families of commands and environments are defined, to prevent possible package conflicts.\footnote{For example, a \texttt{\string\ruby} command for Ruby code, and the \texttt{\string\ruby} command defined by the Ruby package in the \href{http://www.ctan.org/pkg/cjk}{CJK package}.} This option defines preconfigured families for other available languages. It takes either a single language base name, or a list of comma-separated names enclosed in curly braces. Currently, the Ruby families |rb| and |ruby|, the Julia families |jl| and |julia|, and the Octave family |octave| may be created.
+% By default, only the |py|, |sympy|, and |pylab| families of commands and environments are defined, to prevent possible package conflicts.\footnote{For example, a \texttt{\string\ruby} command for Ruby code, and the \texttt{\string\ruby} command defined by the Ruby package in the \href{http://www.ctan.org/pkg/cjk}{CJK package}.} This option defines preconfigured families for other available languages. It takes either a single language base name, or a list of comma-separated names enclosed in curly braces. For example, the Ruby families |rb| and |ruby|, the Julia families |jl| and |julia|, and the Octave family |octave| may be enabled. For a full list of supported languages, see \Cref{sec:other-languages}.
%
%
% \DescribeMacro{gobble=none/auto default:none}
@@ -1519,11 +1554,13 @@
% \section{Support for additional languages}
% \label{sec:other-languages}
%
-% Beginning with v0.12, it is much simpler to add support for languages beyond Python. Support for several additional languages will be added in coming months.
+% Details about adding support for additional languages are in \Cref{sec:other-languages:adding}. This section begins with a brief overview of supported languages and available features.
%
-% In the immediate future, support for additional languages will be part of \pytex. Later, it may make sense to provide an alternative interface for other languages. For example, a package could be created that provides access to \pytex\ internals in a language-agnostic manner, without having the word ``python'' as part of the command names.
-%
-% Languages beyond Python will typically not be enabled by default, to prevent potential macro naming conflicts with other packages. At least two possible base names for commands and environments will be provided for each language. Typically these will be the name of the language and the language's file extension. For example, Ruby has the |ruby| and |rb| base names. You can choose which base name to use for creating a family of commands and environments based on personal preference and potential naming conflicts.
+% Languages beyond Python are typically not be enabled by default to prevent potential macro naming conflicts with other packages. Languages are enabled via the |usefamily| package option (\Cref{sec:usage}). For example,
+%\begin{verbatim}
+%\usepackage[usefamily=ruby]{pythontex}
+%\end{verbatim}
+% Usually at least two possible base names for commands and environments will be provided for each language. Typically these will be the name of the language and the language's file extension. For example, Ruby has the |ruby| and |rb| base names. You can choose which base name to use for creating a family of commands and environments based on personal preference and potential naming conflicts.
%
%
% \subsection{Ruby}
@@ -1549,7 +1586,7 @@
%
% \subsubsection*{Console}
%
-% Preliminary Julia console support was added in v0.16, under the base name |juliacon|. Unlike the Python console environments that allow invalid input, currently everything entered in a |juliaconsole| environment must be valid. The Julia console uses \href{https://github.com/mpastell/Weave.jl}{\textsf{Weave.jl}} internally to evaluate code, and it currently does not support invalid input.
+% Julia console support was added in v0.16. It may be enabled by loading \pytex\ with |usefamily=juliacon|. The |juliaconsole| environment uses \href{https://github.com/mpastell/Weave.jl}{\textsf{Weave.jl}} internally to evaluate code. There is also a |juliaconcode| environment that executes code but typesets nothing.
%
%
% \subsection{Octave}
@@ -1587,7 +1624,40 @@
% Additionally, when using |\rust| and |\rs|, keep in mind that these wrap code in a block, so you \emph{cannot} use |rstex| by value in these contexts (both shared and mutable references are still fine, though).
%
%
+% \subsection{R}
+%
+% Support for R was added in v0.17.
+%
+% Loading \pytex\ with |usefamily=R| enables the |R| family of commands and environments (|\R|, |\Rc|, |Rcode|, ...). These execute code with |Rscript|. The |methods| library is loaded automatically as part of the template code. Expressions passed to the |\R| command are converted into strings via |toString()|. There is currently no utilities class or related features. A null graphics device, |pdf(file=NULL)|, is created by default to avoid the automatic, unintentional creation of plot files with default names. Plots that are to be saved require explicit graphics commands.
+%
+% \subsubsection*{Console}
+%
+% Loading \pytex\ with |usefamily=Rcon| enables the |Rconsole| environment, which executes code to emulate an interactive R session. There is also an |Rconcode| environment that executes code but typesets nothing. Code is executed with |Rscript|. The |methods| library is loaded automatically as part of the template code. The option |echo=TRUE| is used to intersperse code with output, while |error=function(){}| is used to avoid halting on errors. A null graphics device, |pdf(file=NULL)|, is created by default to avoid the automatic, unintentional creation of plot files with default names. Plots that are to be saved require explicit graphics commands.
+%
+%
+% \subsection{Perl}
+%
+% Support for Perl was added in v0.17.
+%
+% Loading \pytex\ with |usefamily=perl| enables the |perl| family of commands and environments. Alternatively, |usefamily=pl| may be used to enable the |pl| family. There is currently no utilities class or related features.
+%
+%
+% \subsection{Perl 6}
+%
+% Support for Perl 6 was added in v0.17.
+%
+% Loading \pytex\ with |usefamily=perlsix| enables the |perlsix| family of commands and environments. Alternatively, |usefamily=psix| may be used to enable the |psix| family. There is currently no utilities class or related features.
+%
+%
+% \subsection{JavaScript}
+%
+% Support for JavaScript was added in v0.17.
+%
+% Loading \pytex\ with |usefamily=javascript| enables the |javascript| family of commands and environments. Alternatively, |usefamily=js| may be used to enable the |js| family. There is a utilities object |jstex|.
+%
+%
% \subsection{Adding support for a new language}
+% \label{sec:other-languages:adding}
%
% Adding support for an additional language involves creating two templates, creating a new instance of a class, and using a \pytex\ macro. In some cases, additional changes may be necessary for full support. The information below does not deal with creating |console| families; additional support for user-defined |console| families will be added in the future.
%
@@ -1794,6 +1864,8 @@
%
% Thanks to Alexander Altman for suggesting Rust support and providing template code.
%
+% Thanks to Nathan Carter for suggesting JavaScript support and providing template code.
+%
%
% \PrintChangelog
%
@@ -1813,7 +1885,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}{0.16}
+\newcommand{\pytx@packageversion}{0.17}
% \end{macrocode}
%
% \subsection{Required packages}
@@ -3349,7 +3421,7 @@
}%
\xdef\pytx@type{CC:#2:#1}%
\edef\pytx@cmd{c}%
- \def\pytx@context{}%
+ \pytx@SetContext
\def\pytx@group{none}%
\let\pytx@InlineShow\@empty
\let\pytx@InlineSave\pytx@InlineSaveCode
@@ -3683,6 +3755,22 @@
}%
{\end{VerbatimOut}%
\xdef\pytx@stdfile{\pytx@type_\pytx@session_\pytx@group_\arabic{\pytx@counter}}%
+ \ifcsname pytx@nonpyconsole@\pytx@type\endcsname
+ \ifcsname pytx@code@as@console\endcsname
+ \setcounter{FancyVerbLine}{\value{\pytx@linecount}}%
+ \pytx@FVSet
+ \ifdefstring{\pytx@fvopttmp}{}{}{\expandafter\fvset\expandafter{\pytx@fvopttmp}}%
+ \pytx@ConfigPygments
+ \InputIfFileExists{\pytx@outputdir/\pytx@stdfile.stdout}%
+ {\DepyFile{p:\pytx@outputdir/\pytx@stdfile.stdout}}%
+ {\par\textbf{??~\pytx@packagename~??}\par
+ \PackageWarning{\pytx@packagename}{Non-existent console content}}%
+ \setcounter{\pytx@linecount}{\value{FancyVerbLine}}%
+ \else
+ \fi
+ \let\pytx@EnvAutoprint\relax
+ \else
+ \fi
\setcounter{FancyVerbLine}{\value{pytx@FancyVerbLineTemp}}%
\stepcounter{\pytx@counter}%
\pytx@EnvAutoprint
@@ -3699,6 +3787,8 @@
\ifstrempty{#1}{\edef\pytx@session{default}}{\StrSubstitute{#1}{:}{-}[\pytx@session]}%
\xdef\pytx@counter{pytx@\pytx@type @\pytx@session @\pytx@group}%
\pytx@CheckCounter{\pytx@counter}%
+ \edef\pytx@linecount{\pytx@counter @line}%
+ \pytx@CheckCounter{\pytx@linecount}%
\pytx@WriteCodefileInfo
\begingroup
\obeylines
@@ -3712,6 +3802,8 @@
% As described above, this macro captures a second optional argument, if present, and then starts the |VerbatimOut| environment. Note that |VerbatimOut| does not have a mandatory argument, because we are invoking our custom |\pytx@FVB@VerbatimOut| macro. The default |fancyvrb| macro needs an argument to tell it the name of the file to which to save the verbatim content. But in our case, we are always writing to the same file, and the custom macro accounts for this by not having a mandatory file name argument. We must perform the typical |FancyVerbLine| trickery, to prevent the |fancyvrb| line counter from being affected by \textbf{writing} content!
% \begin{macrocode}
\def\pytx@BeginCodeEnv@i[#1]{%
+ \def\pytx@fvopttmp{#1}%
+ \def\pytx@argspprint{#1}%
\setcounter{pytx@FancyVerbLineTemp}{\value{FancyVerbLine}}%
\let\FVB@VerbatimOut\pytx@FVB@VerbatimOut
\let\FVE@VerbatimOut\pytx@FVE@VerbatimOut
@@ -3742,7 +3834,7 @@
}%
\xdef\pytx@type{CC:#2:#1}%
\edef\pytx@cmd{code}%
- \def\pytx@context{}%
+ \pytx@SetContext
\def\pytx@group{none}%
\pytx@BeginCodeEnv[none]}%
{\end{VerbatimOut}%
@@ -3763,7 +3855,7 @@
\newcommand{\pytx@MakeSubFV}[1]{%
\expandafter\newenvironment{#1sub}{%
\VerbatimEnvironment
- \Depythontex{env:#1sub:om|:p}%
+ \Depythontex{env:#1sub:oo|:p}%
\xdef\pytx@type{#1}%
\edef\pytx@cmd{sub}%
\pytx@SetContext
@@ -4000,6 +4092,34 @@
% \end{macrocode}
% \end{macro}
%
+%
+% \begin{macro}{\makepythontexfamily@con}
+% This macro creates |console| and |code| environments for non-Python consoles. \pytex\ was not designed with commands and environments for non-Python consoles. Non-Python consoles are currently created via specially customized |code| environments. Note that simply creating these |console| and |code| environments is typically not enough to create non-Python consoles; |pythontex2.py| and |pythontex3.py| usually also require customization. This macro's definition should not be treated as stable; it will change in the future. The ultimate long-term goal is to eliminate it entirely, by redesigning the code execution core of \pytex\ to accomodate non-Python consoles more easily.
+% \begin{macrocode}
+\newcommand{\makepythontexfamily@con}[2][text]{%
+ \pgfkeys{/PYTX/family, name=#2con, default, pyglexer=#1, console=true}%
+ \expandafter\xdef\csname pytx@macroformatter@#2con\endcsname{\pytx@tmp@pprinter}%
+ \expandafter\gdef\csname pytx@fvsettings@#2con\endcsname{}%
+ \expandafter\xdef\csname pytx@pyglexer@#2con\endcsname{\pytx@tmp@pyglexer}%
+ \expandafter\xdef\csname pytx@pygopt@#2con\endcsname{\pytx@tmp@pygopt}%
+ \expandafter\xdef\csname pytx@console@#2con\endcsname{\pytx@tmp@console}%
+ \AtEndDocument{\immediate\write\pytx@codefile{pygfamily=#2con|%
+ \csname pytx@pyglexer@#2con\endcsname|%
+ \csname pytx@pygopt@#2con\endcsname}%
+ }%
+ \pytx@MakeCodeFV{#2con}%
+ \expandafter\global\expandafter\let\csname pytx@nonpyconsole@#2con\endcsname\relax
+ \newenvironment{#2console}%
+ {\VerbatimEnvironment
+ \def\pytx@type{#2con}%
+ \let\pytx@code@as@console\relax
+ \begin{#2concode}}%
+ {\end{#2concode}}%
+}
+% \end{macrocode}
+% \end{macro}
+
+%
% \begin{macro}{\setpythontexpyglexer}
% We need to be able to reset the lexer associated with a family after the family has already been created.
% \begin{macrocode}
@@ -4068,11 +4188,11 @@
%
% All of these command and environment families are created conditionally, depending on whether the package option |pygments| is used, via |\makepythontexfamily|. We recommend that any custom families created by the user be constructed in the same manner.
% \begin{macrocode}
-\makepythontexfamily[pyglexer=python]{py}
+\makepythontexfamily[pyglexer=python3]{py}
\makepythontexfamily[pyglexer=pycon, console=true]{pycon}
-\makepythontexfamily[pyglexer=python]{sympy}
+\makepythontexfamily[pyglexer=python3]{sympy}
\makepythontexfamily[pyglexer=pycon, console=true]{sympycon}
-\makepythontexfamily[pyglexer=python]{pylab}
+\makepythontexfamily[pyglexer=python3]{pylab}
\makepythontexfamily[pyglexer=pycon, console=true]{pylabcon}
% \end{macrocode}
% We also need to create any additional families specified via the |usefamily| package option.\footnote{The loop here is accomplished via \texttt{etoolbox}. \texttt{pgffor} might be an alternative, but making definitions global requires trickery.}
@@ -4081,24 +4201,7 @@
\ifstrequal{#1}{ruby}{\makepythontexfamily[pyglexer=ruby]{ruby}}{}%
\ifstrequal{#1}{rb}{\makepythontexfamily[pyglexer=ruby]{rb}}{}%
\ifstrequal{#1}{julia}{\makepythontexfamily[pyglexer=julia]{julia}}{}%
- \ifstrequal{#1}{juliacon}{\pgfkeys{/PYTX/family, name=juliacon, default, pyglexer=jlcon}%
- \expandafter\xdef\csname pytx@macroformatter@juliacon\endcsname{\pytx@tmp@pprinter}%
- \expandafter\gdef\csname pytx@fvsettings@juliacon\endcsname{}%
- \expandafter\xdef\csname pytx@pyglexer@juliacon\endcsname{\pytx@tmp@pyglexer}%
- \expandafter\xdef\csname pytx@pygopt@juliacon\endcsname{\pytx@tmp@pygopt}%
- \expandafter\xdef\csname pytx@console@juliacon\endcsname{\pytx@tmp@console}%
- \AtEndDocument{\immediate\write\pytx@codefile{pygfamily=juliacon|%
- \csname pytx@pyglexer@juliacon\endcsname|%
- \csname pytx@pygopt@juliacon\endcsname}%
- }%
- \pytx@MakeCodeFV{juliacon}%
- \newenvironment{juliaconsole}%
- {\VerbatimEnvironment
- \def\pytx@type{juliacon}%
- \pytx@ConfigPygments
- \begin{juliaconcode}}%
- {\end{juliaconcode}%
- \ifbool{pytx@opt@autoprint}{}{\printpythontex{}}}}{}%
+ \ifstrequal{#1}{juliacon}{\makepythontexfamily@con[jlcon]{julia}}{}%
\ifstrequal{#1}{jl}{\makepythontexfamily[pyglexer=julia]{jl}}{}%
\ifstrequal{#1}{matlab}{\makepythontexfamily[pyglexer=matlab]{matlab}}{}%
\ifstrequal{#1}{octave}{\makepythontexfamily[pyglexer=octave]{octave}}{}%
@@ -4106,6 +4209,14 @@
\ifstrequal{#1}{sage}{\makepythontexfamily[pyglexer=sage]{sage}}{}%
\ifstrequal{#1}{rust}{\makepythontexfamily[pyglexer=rust]{rust}}{}%
\ifstrequal{#1}{rs}{\makepythontexfamily[pyglexer=rust]{rs}}{}%
+ \ifstrequal{#1}{R}{\makepythontexfamily[pyglexer=r]{R}}{}%
+ \ifstrequal{#1}{Rcon}{\makepythontexfamily@con[rconsole]{R}}{}%
+ \ifstrequal{#1}{perl}{\makepythontexfamily[pyglexer=perl]{perl}}{}%
+ \ifstrequal{#1}{pl}{\makepythontexfamily[pyglexer=perl]{pl}}{}%
+ \ifstrequal{#1}{perlsix}{\makepythontexfamily[pyglexer=perl6]{perlsix}}{}%
+ \ifstrequal{#1}{psix}{\makepythontexfamily[pyglexer=perl6]{psix}}{}%
+ \ifstrequal{#1}{javascript}{\makepythontexfamily[pyglexer=js]{javascript}}{}%
+ \ifstrequal{#1}{js}{\makepythontexfamily[pyglexer=js]{js}}{}%
}
\expandafter\docsvlist\expandafter{\pytx@families}
% \end{macrocode}