summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-03-18 20:05:01 +0000
committerKarl Berry <karl@freefriends.org>2024-03-18 20:05:01 +0000
commitd752714fad79e11b79a6f00fba88f7633aa83db2 (patch)
tree7ac3b3430966436524c564843ea3a521cacbc15b
parent21ccace31d42de9b654d0afad8bbb8ca81b15565 (diff)
pythonhighlight (18mar24)
git-svn-id: svn://tug.org/texlive/trunk@70698 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/pythonhighlight/README.md11
-rw-r--r--Master/texmf-dist/tex/latex/pythonhighlight/pythonhighlight.sty38
2 files changed, 36 insertions, 13 deletions
diff --git a/Master/texmf-dist/doc/latex/pythonhighlight/README.md b/Master/texmf-dist/doc/latex/pythonhighlight/README.md
index 06fc5b02af3..1ed233417c5 100644
--- a/Master/texmf-dist/doc/latex/pythonhighlight/README.md
+++ b/Master/texmf-dist/doc/latex/pythonhighlight/README.md
@@ -25,9 +25,12 @@ The special method \pyth{__init__}...
```
Last but not least, you can load an external Python file with:
-
```tex
-\inputpython{python_file.py}{23}{50}
+\inputpythonfile{python_file.py}[23][50]
```
-
-to display the contents of the file ``python_file`` from line 23 to line 50.
+to display the contents of the file ``python_file`` from line 23 to line 50,
+or with
+```tex
+\inputpythonfile{python_file.py}
+```
+to input the whole Python file.
diff --git a/Master/texmf-dist/tex/latex/pythonhighlight/pythonhighlight.sty b/Master/texmf-dist/tex/latex/pythonhighlight/pythonhighlight.sty
index 88561ed326f..0c772a1e261 100644
--- a/Master/texmf-dist/tex/latex/pythonhighlight/pythonhighlight.sty
+++ b/Master/texmf-dist/tex/latex/pythonhighlight/pythonhighlight.sty
@@ -1,11 +1,13 @@
-% Copyright 2009--2017 by Olivier Verdier
+% Copyright 2009--2024 by Olivier Verdier
% License: see the file LICENSE.rst
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pythonhighlight}[2017/02/09 python code highlighting; provided by Olivier Verdier <olivier.verdier@gmail.com>]
+\UseRawInputEncoding
+\ProvidesPackage{pythonhighlight}[2024/03/18 python code highlighting; provided by Olivier Verdier <olivier.verdier@gmail.com>]
\RequirePackage{listings}
\RequirePackage{xcolor}
+\RequirePackage{xparse}
\renewcommand*{\lstlistlistingname}{Code Listings}
\renewcommand*{\lstlistingname}{Code Listing}
@@ -27,7 +29,7 @@
\newcommand*{\pythonprompt}{\textcolor{promptcolour}{{>}{>}{>}}}
-\lstdefinestyle{mypython}{
+\lstdefinestyle{pythonhighlight-style}{
%\lstset{
%keepspaces=true,
language=python,
@@ -40,7 +42,7 @@ showstringspaces=false,
alsoletter={1234567890},
otherkeywords={\%, \}, \{, \&, \|},
keywordstyle=\color{keywordcolour}\bfseries,
-emph={and,break,class,continue,def,yield,del,elif ,else,%
+emph={and,as,async,await,break,class,continue,def,yield,del,elif ,else,%
except,exec,finally,for,from,global,if,import,in,%
lambda,not,or,pass,print,raise,return,try,while,assert,with},
emphstyle=\color{blue}\bfseries,
@@ -98,12 +100,30 @@ breakindent=.5\textwidth,frame=single,breaklines=true%
%}
}
-\newcommand*{\inputpython}[3]{\lstinputlisting[firstline=#2,lastline=#3,firstnumber=#2,frame=single,breakindent=.5\textwidth,frame=single,breaklines=true,style=mypython]{#1}}
+\newcommand*{\inputpython}[3]{\lstinputlisting[firstline=#2,lastline=#3,firstnumber=#2,frame=single,breakindent=.5\textwidth,frame=single,breaklines=true,style=pythonhighlight-style]{#1}}
+\NewDocumentCommand\inputpythonfile{moo}{\lstinputlisting[
+ firstline=\IfValueTF{#2}{#2}{0},
+ % firstnumber=\IfValueTF{#2}{#2}{0},
+ lastline=\IfValueTF{#3}{#3}{9999999},
+ frame=single,
+ breakindent=.5\textwidth,
+ frame=single,
+ breaklines=true,
+ style=pythonhighlight-style
+ ]{#1}}
-\lstnewenvironment{python}[1][]{\lstset{style=mypython}}{}
+\lstnewenvironment{python}[2][]{%
+ \lst@TestEOLChar{#2}%
+ \lstset{style=pythonhighlight-style}%
+ \lstset{#1}% % has to be in an extra \lstset{} command so that labels work correctly
+ \csname\@lst @SetFirstNumber\endcsname%
+}{%
+ \let\if@nobreak\iffalse%
+ \csname\@lst @SaveFirstNumber\endcsname%
+}
-\lstdefinestyle{mypythoninline}{
-style=mypython,%
+\lstdefinestyle{pythonhighlight-inline-style}{
+ style=pythonhighlight-style,%
basicstyle=\ttfamily,%
keywordstyle=\color{keywordcolour},%
emphstyle={[7]\color{keywordcolour}},%
@@ -135,5 +155,5 @@ literate=*%
%% emphstyle=\color{blue},%
}
-\newcommand*{\pyth}{\lstinline[style=mypythoninline]}
+\newcommand*{\pyth}{\lstinline[style=pythonhighlight-inline-style]}