From 3906c3b7c7f447cc710bbb7ec7ff2b50c1ef1b75 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 4 Mar 2022 21:50:31 +0000 Subject: hvpygmentex (4mar22) (branch) git-svn-id: svn://tug.org/texlive/branches/branch2021.final@62406 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/hvpygmentex/Changes | 1 + Master/texmf-dist/doc/latex/hvpygmentex/README.md | 18 + .../doc/latex/hvpygmentex/hvpygmentex.pdf | Bin 0 -> 21465 bytes .../doc/latex/hvpygmentex/hvpygmentex.tex | 67 ++++ .../tex/latex/hvpygmentex/hvpygmentex.sty | 412 +++++++++++++++++++++ Master/tlpkg/libexec/ctan2tds | 9 +- Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc | 1 + Master/tlpkg/tlpsrc/hvpygmentex.tlpsrc | 0 8 files changed, 505 insertions(+), 3 deletions(-) create mode 100644 Master/texmf-dist/doc/latex/hvpygmentex/Changes create mode 100644 Master/texmf-dist/doc/latex/hvpygmentex/README.md create mode 100644 Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.pdf create mode 100644 Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.tex create mode 100644 Master/texmf-dist/tex/latex/hvpygmentex/hvpygmentex.sty create mode 100644 Master/tlpkg/tlpsrc/hvpygmentex.tlpsrc diff --git a/Master/texmf-dist/doc/latex/hvpygmentex/Changes b/Master/texmf-dist/doc/latex/hvpygmentex/Changes new file mode 100644 index 00000000000..63758cdc8d0 --- /dev/null +++ b/Master/texmf-dist/doc/latex/hvpygmentex/Changes @@ -0,0 +1 @@ +0.01 2022-03-03 - first CTAN version diff --git a/Master/texmf-dist/doc/latex/hvpygmentex/README.md b/Master/texmf-dist/doc/latex/hvpygmentex/README.md new file mode 100644 index 00000000000..3755469e294 --- /dev/null +++ b/Master/texmf-dist/doc/latex/hvpygmentex/README.md @@ -0,0 +1,18 @@ +# hvpygmentex.sty + +Formatting source code of programming languages. + +The package is based on pygmentex but provides an automatic +run from within the document itself, with the option "--shell-escape". +It do not needs the additional action by the user to run the external +program pygmentize to create the code snippets. + +%% It may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3c or later is part of all distributions of LaTeX +%% version 2005/12/01 or later. + +hvoss@tug.org \ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.pdf b/Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.pdf new file mode 100644 index 00000000000..b28a7c357db Binary files /dev/null and b/Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.pdf differ diff --git a/Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.tex b/Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.tex new file mode 100644 index 00000000000..6850c477a74 --- /dev/null +++ b/Master/texmf-dist/doc/latex/hvpygmentex/hvpygmentex.tex @@ -0,0 +1,67 @@ +\errorcontextlines=100 +\documentclass[DIV=12]{scrartcl} + +\usepackage{libertinus-otf} +\usepackage[force]{hvpygmentex} +\usepackage{url} +\title{Typeset highlited sourcecode} +\author{Herbert Voß} +\begin{document} +\maketitle + +\section{Introduction} +This package is fully compatible to package \texttt{pygmentex}. Read +the package documentation (\url{http://ctan.org/pkg/pygmentex}) for the +supported languages a.s.o. + +\begin{verbatim} +usepackage[options]{hvpygmentex} +\end{verbatim} + + + +With \texttt{hvpygmentex} one do not needs the external Python run to +create the formatted tex snippets which are inserted into the document. +With the optional argument \texttt{--shell-escape} for the \LaTeX\ run +\TeX\ is allowed to run the external program \texttt{pygmentize} from within the document and +no additional action by the user is required. + +This package itself has an additional option \texttt{force} which is +preset to \texttt{true}. Without using it the external +formatted \TeX\ snippets for the listings will not be recreated by following \LaTeX\ runs. This +may speed up the \LaTeX\ runs and, of course, makes only sense, if you are sure that there +are no changes in the source code listings. + + +\section{Example} + +\begin{pygmented}[lang=tex,font=\ttfamily\small] +\bgroup +\initcatcodetable1 +\aftergroup{\global\catcode`¡=12}% +\catcode`\_=12 \catcode`\^=12 \catcode`\$=12 \catcode`\%=12 \catcode`\#=12 +\catcode`\&=12 \catcode`\{=12 \catcode`\}=12 \catcode`\~=12 \catcode`¡=0 +\catcode`\\=12 +¡savecatcodetable1 +¡egroup +\end{pygmented} + + +This document was run with + +\begin{verbatim} +lualatex --shell-escape hvpygmentex.tex +\end{verbatim} + +In the terminal output you'll find something like + +\begin{verbatim} +[...] +>>>> running pygmentex (option force=true) ... +>>>> ... done. +[...] +\end{verbatim} + + + +\end{document} diff --git a/Master/texmf-dist/tex/latex/hvpygmentex/hvpygmentex.sty b/Master/texmf-dist/tex/latex/hvpygmentex/hvpygmentex.sty new file mode 100644 index 00000000000..b9e7df6f225 --- /dev/null +++ b/Master/texmf-dist/tex/latex/hvpygmentex/hvpygmentex.sty @@ -0,0 +1,412 @@ +%% $Id: hvpygmentex.sty 465 2022-03-03 20:26:42Z herbert $ +%% +%% This file is distributed under the terms of the LaTeX Project Public +%% License from CTAN archives in directory macros/latex/base/lppl.txt. +%% Either version 1.3 or, at your option, any later version. +%% +% Copyright 2022 Herbert Voss hvoss@tug.org +%% +\ProvidesPackage{hvpygmentex}[% + 2022/03/03 v.0.01 (Herbert Voss) format source code with Pygments (hv)] +%% +%% Based on the package pygmentex, all of my own enhancements are marked with hv +%% +\NeedsTeXFormat{LaTeX2e} +\newif\ifpygmented@opt@force \pygmented@opt@forcefalse %% hv +\DeclareOption{force}{\pygmented@opt@forcetrue} %% hv +\ProcessOptions %% hv + +\RequirePackage{fancyvrb} +\RequirePackage{color} +\RequirePackage{ifthen} +%\RequirePackage[font=small,format=plain,labelfont=bf,up,textfont=it,up]{caption} +\RequirePackage{caption} +\RequirePackage{shellesc} %% hv +\RequirePackage{pgfkeys} +\RequirePackage{efbox} +\RequirePackage[framemethod=tikz]{mdframed} + +%\DeclareCaptionType[within=chapter]{pygcode}[Listagem][Lista de listagens] +\DeclareCaptionType{pygcode}[Listings][List of Listings] +\captionsetup[pygcode]{position=top} + +% ========================================================= +% Auxiliary: +% finding the widest string in a comma +% separated list of strings delimited by parenthesis +% ========================================================= + +% arguments: +% #1) text: a comma separeted list of strings +% #2) formatter: a macro to format each string +% #3) dimension: will hold the result + +\def\widest(#1)#2#3{% + \begingroup + \def\widest@end{\widest@end}% + \def\widest@helper##1,{% + \ifx\widest@end##1\relax + \else + \settowidth\dimen@{#2{##1}}% + \ifdim#3<\dimen@ + \global#3=\dimen@ + \else + \fi + \expandafter\widest@helper + \fi + }% + \widest@helper#1,\widest@end,% + \endgroup +} + +% ========================================================= +% fancyvrb new commands to append to a file +% ========================================================= + +% See http://tex.stackexchange.com/questions/47462/inputenc-error-with-unicode-chars-and-verbatim +\long\def\unexpanded@write#1#2{\write#1{\unexpanded{#2}}} + +\def\VerbatimOutAppend{\FV@Environment{}{VerbatimOutAppend}} + +\def\FVB@VerbatimOutAppend#1{% + \@bsphack + \begingroup + \FV@UseKeyValues + \FV@DefineWhiteSpace + \def\FV@Space{\space}% + \FV@DefineTabOut + \def\FV@ProcessLine{\immediate\unexpanded@write#1}% + \let\FV@FontScanPrep\relax + \let\@noligs\relax + \FV@Scan +} + +\def\FVE@VerbatimOutAppend{% + \endgroup + \@esphack +} + +\DefineVerbatimEnvironment{VerbatimOutAppend}{VerbatimOutAppend}{} + +% ========================================================= +% Main options +% ========================================================= + +\newif\ifpygmented@opt@texcomments +\newif\ifpygmented@opt@mathescape +\newif\ifpygmented@opt@linenos +\newif\ifpygmented@left +\newif\ifpygmented@right + +% some settings used by fancyvrb: +% * for line numbering: +% numbers, numbersep, firstnumber, stepnumber, numberblanklines +% * for selection of lines to print: +% firstline, lastline, + +\pgfkeys{% + /pygmented/.cd, + % + boxing method/.store in = \pygmented@opt@boxing@method, + inline method/.store in = \pygmented@opt@inline@method, + % + lang/.store in = \pygmented@opt@lang, + sty/.store in = \pygmented@opt@style, + escapeinside/.store in = \pygmented@opt@escapeinside, + texcomments/.is if = pygmented@opt@texcomments, + mathescape/.is if = pygmented@opt@mathescape, + % + label/.store in = \pygmented@opt@label, + caption/.store in = \pygmented@opt@caption, + % + gobble/.store in = \pygmented@opt@gobble, + tabsize/.store in = \pygmented@opt@tabsize, + % + linenos/.is if = pygmented@opt@linenos, + linenostart/.store in = \pygmented@opt@linenostart, + linenostep/.store in = \pygmented@opt@linenostep, + linenosep/.store in = \pygmented@opt@linenosep, + % + colback/.store in = \pygmented@opt@colback, + font/.store in = \pygmented@opt@font, + % + force/.default = false, + texcomments/.default = true, + mathescape/.default = true, + linenos/.default = true, +} + +\pgfqkeys{/pygmented}{ + boxing method = mdframed, + inline method = efbox, + sty = default, + linenos = false, + linenosep = 2pt, + font = \ttfamily, + tabsize = 0, +} + +% ========================================================= +% pygmented commands and environments +% ========================================================= + +\newwrite\pygmented@outfile + +\newcount\pygmented@counter + +\newcommand\pygmented@process@options[1]{% + \pgfkeys{% + /pgf/key filters/defined/.install key filter,% + /pgf/key filter handlers/append filtered to/.install key filter handler=\remainingglobaloptions + }% + \def\remainingglobaloptions{}% + \pgfkeysalsofilteredfrom{\pygmented@global@options}% + \pgfkeysalso{% + /pgf/key filter handlers/append filtered to/.install key filter handler=\remaininguseroptions + }% + \def\remaininguseroptions{}% + \pgfqkeysfiltered{/pygmented}{#1}% + % %%%%%%% DEBUGING + % \typeout{}% + % \typeout{\string\pygmented@global@options:}\typeout{\meaning\pygmented@global@options}% + % \typeout{\string\remainingglobaloptions:}\typeout{\meaning\remainingglobaloptions}% + % \typeout{\string\remaininguseroptions:}\typeout{\meaning\remaininguseroptions}% + % + \fvset{gobble=0,tabsize=0}% +} + +\newcommand\pygmented@process@adicional@options[1]{% + \pgfkeysalso{% + /pgf/key filters/false/.install key filter,% + /pgf/key filter handlers/append filtered to/.install key filter handler=\remainingoptions + }% + \def\remainingoptions{}% + \pgfkeysalsofilteredfrom{\remainingglobaloptions}% + \edef\pygmented@saved@{% + \ifcsname pygmented@#1@additional@options\endcsname + \csname pygmented@#1@additional@options\endcsname,% + \fi + }% + \pgfkeysalsofilteredfrom{\pygmented@saved@}% + \pgfkeysalsofilteredfrom{\remaininguseroptions}% + % %%%%%%% DEBUGING + % \typeout{}% + % \typeout{\string\remainingoptions:}% + % \typeout{\meaning\remainingoptions}% +} + +\newcommand\inputpygmented[2][]{% + \begingroup + \pygmented@process@options{#1}% + \immediate\write\pygmented@outfile{<@@pygmented@input@\the\pygmented@counter}% + \immediate\write\pygmented@outfile{\detokenize\expandafter{\pygmented@global@options},\detokenize{#1}}% + \immediate\write\pygmented@outfile{#2}% + \immediate\write\pygmented@outfile{>@@pygmented@input@\the\pygmented@counter}% + % + \csname pygmented@snippet@\the\pygmented@counter\endcsname + \global\advance\pygmented@counter by 1\relax + \endgroup +} + +\newenvironment{pygmented}[1][]{% + \pygmented@process@options{#1}% + \immediate\write\pygmented@outfile{<@@pygmented@display@\the\pygmented@counter}% + \immediate\write\pygmented@outfile{\detokenize\expandafter{\pygmented@global@options},\detokenize{#1}}% + \VerbatimEnvironment + \begin{VerbatimOutAppend}{\pygmented@outfile}% +}{% + \end{VerbatimOutAppend}% + \immediate\write\pygmented@outfile{>@@pygmented@display@\the\pygmented@counter}% + \csname pygmented@snippet@\the\pygmented@counter\endcsname + \global\advance\pygmented@counter by 1\relax +} + +\newcommand\pyginline[2][]{% + \begingroup + \pygmented@process@options{#1}% + \immediate\write\pygmented@outfile{<@@pygmented@inline@\the\pygmented@counter}% + \immediate\write\pygmented@outfile{\detokenize\expandafter{\pygmented@global@options},\detokenize{#1}}% + \DefineShortVerb{#2}% + \SaveVerb + [aftersave={% + \UndefineShortVerb{#2}% + \immediate\write\pygmented@outfile{\FV@SV@pygmented@verb}% + \immediate\write\pygmented@outfile{>@@pygmented@inline@\the\pygmented@counter}% + % + \csname pygmented@snippet@\the\pygmented@counter\endcsname + \global\advance\pygmented@counter by 1\relax + \endgroup + }]% + {pygmented@verb}#2% +} + + +\newcommand\pygmented@snippet@inlined[1]{% + \begingroup + \csname PYstyle\pygmented@opt@style\endcsname + \pygmented@opt@font + \pygmented@process@adicional@options{\pygmented@opt@inline@method}% + \expandafter\expandafter\csname \pygmented@opt@inline@method \endcsname\expandafter[\remainingoptions]{#1}% + \endgroup +} + +\newenvironment{pygmented@snippet@framed}{% + \begingroup + \pygmented@leftmargin\z@ + \ifpygmented@opt@linenos + \expandafter\widest\pygmented@alllinenos{\FormatLineNumber}{\pygmented@leftmargin}% + \advance\pygmented@leftmargin\pygmented@opt@linenosep + \fi + % + \ifdefined\pygmented@opt@label + \def\pygmented@title{% + \captionof{pygcode}{\label{\pygmented@opt@label}\pygmented@opt@caption}% + % \nopagebreak + \vskip -0.7\baselineskip + }% + \else + \ifdefined\pygmented@opt@caption + \def\pygmented@title{% + \captionof{pygcode}{\pygmented@opt@caption}% + % \nopagebreak + \vskip -0.7\baselineskip + }% + \fi + \fi + \ifdefined\pygmented@title + % \nopagebreak[0]% + \pygmented@title + % \nopagebreak + \fi + % + \pygmented@process@adicional@options{\pygmented@opt@boxing@method}% + \expandafter\begin\expandafter{\expandafter\pygmented@opt@boxing@method\expandafter}\expandafter[% + \remainingoptions + ]% + \csname PYstyle\pygmented@opt@style\endcsname + \pygmented@opt@font + % + \noindent + }{% + \end{\pygmented@opt@boxing@method}% + \endgroup +} + +\newcommand\pygmented@inlined[1]{% + \expandafter\efbox\expandafter[\remainingoptions]{#1}% +} + +\def\FormatLineNumber#1{{\rmfamily\tiny#1}} + +\newdimen\pygmented@leftmargin +\newdimen\pygmented@linenosep + +\def\pygmented@lineno@do#1{% + \pygmented@linenosep 0pt% + \csname pygmented@\pygmented@opt@boxing@method @margin\endcsname + \advance \pygmented@linenosep \pygmented@opt@linenosep + \makebox[0pt][r]{% + \FormatLineNumber{#1}% + \hspace*{\pygmented@linenosep}}% +} + +\newcommand\pygmented@tcbox@additional@options{% + nobeforeafter,% + tcbox raise base,% + left=0mm,% + right=0mm,% + top=0mm,% + bottom=0mm,% + boxsep=2pt,% + arc=1pt,% + boxrule=0pt,% + \ifcsname pygmented@opt@colback\endcsname + colback=\pygmented@opt@colback,% + \fi +} + +\newcommand\pygmented@efbox@additional@options{% + \ifcsname pygmented@opt@colback\endcsname + backgroundcolor=\pygmented@opt@colback,% + \fi +} + +\newcommand\pygmented@mdframed@additional@options{% + leftmargin=\pygmented@leftmargin,% + frametitlerule=true,% + \ifcsname pygmented@opt@colback\endcsname + backgroundcolor=\pygmented@opt@colback,% + \fi +} + +\newcommand\pygmented@tcolorbox@additional@options{% + grow to left by=-\pygmented@leftmargin,% + \ifcsname pygmented@opt@colback\endcsname + colback=\pygmented@opt@colback,% + \fi +} + +\newcommand\pygmented@boite@additional@options{% + leftmargin=\pygmented@leftmargin,% + \ifcsname pygmented@opt@colback\endcsname + colback=\pygmented@opt@colback,% + \fi +} + + +\newcommand\pygmented@mdframed@margin{% + \advance \pygmented@linenosep \mdflength{outerlinewidth}% + \advance \pygmented@linenosep \mdflength{middlelinewidth}% + \advance \pygmented@linenosep \mdflength{innerlinewidth}% + \advance \pygmented@linenosep \mdflength{innerleftmargin}% +} + +\newcommand\pygmented@tcolorbox@margin{% + \advance \pygmented@linenosep \kvtcb@left@rule + \advance \pygmented@linenosep \kvtcb@leftupper + \advance \pygmented@linenosep \kvtcb@boxsep +} + +\newcommand\pygmented@boite@margin{% + \advance \pygmented@linenosep \boite@leftrule + \advance \pygmented@linenosep \boite@boxsep +} + +\def\pygmented@global@options{} + +\newcommand\setpygmented[1]{% + \def\pygmented@global@options{/pygmented/.cd,#1}% +} + + +% ========================================================= +% final actions +% ========================================================= + +\AtEndOfPackage{% + \IfFileExists{\jobname.pygmented}{% + \input{\jobname.pygmented}% + }{% + \PackageWarning{pygmentex}{File `\jobname.pygmented' not found.}% + }% + \immediate\openout\pygmented@outfile\jobname.snippets% +} + +%% ------------------------------ hv begin --------------------------- +\AtEndDocument{% + \immediate\closeout\pygmented@outfile% + \ifpygmented@opt@force + \typeout{>>>> running pygmentex (option force=true) ...}% + \ShellEscape{pygmentex \jobname.snippets}% + \typeout{>>>> ... done.}% + \else + \IfFileExists{\jobname.pygmented}% + {\typeout{>>>> file \jobname.pygmented exists, not running pygmentex}}% + {\typeout{>>>> no file \jobname.pygmented, running pygmentex ...}% + \ShellEscape{pygmentex \jobname.snippets}% + \typeout{>>>> ... done.}}% + \fi +} +%% ------------------------------ hv end --------------------------- + +\endinput diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds index 13a2e2210a3..ae7019784b8 100755 --- a/Master/tlpkg/libexec/ctan2tds +++ b/Master/tlpkg/libexec/ctan2tds @@ -33,6 +33,7 @@ $CP = "cp -pv"; $RM = "rm -vf"; # -v to get feedback via GNU rm on removals $MAKEINFO = "makeinfo"; $INSTALL = "install -D -m 664"; +$RMDIR_EMPTY = "find -type d -empty -delete -print"; # GNU find for simplicity $| = 1; select ((select (STDERR), $| = 1)[0]); @@ -640,6 +641,7 @@ chomp (my $ctan_root = `tlpkginfo --ctan-root`); 'hvfloat', "&MAKEflatten", 'hvindex', "&MAKEflatten", 'hvlogos', "&MAKEflatten", + 'hvpygmentex', "&MAKEflatten", 'hvqrurl', "&MAKEflatten", 'hybrid-latex', "die 'skipping, no self-locating of Python modules'", 'hyph-utf8', "&MAKEcopy", @@ -4807,7 +4809,7 @@ sub flatten_dirtree { &SYSTEM ("yes n | find . -mindepth 2 -not -type d -exec mv -i '\{\}' . \\;"); # remove newly empty directories. - &SYSTEM ("find -depth -type d -print | xargs rmdir 2>/dev/null"); + &SYSTEM ($RMDIR_EMPTY); } sub MAKEunzipandflatten { @@ -5240,7 +5242,7 @@ sub MAKEmv_doctex { &SYSTEM ("$MV doc/* ."); # # remove newly empty directories. - &SYSTEM ("find -depth -type d -print | xargs rmdir 2>/dev/null"); + &SYSTEM ($RMDIR_EMPTY); } sub MAKEtamethebeast { @@ -5529,7 +5531,7 @@ sub MAKEtkz { &SYSTEM ("$MV doc/latex/* doc/* latex/* ."); # # remove newly empty directories. - &SYSTEM ("find -depth -type d -print | xargs rmdir 2>/dev/null"); + &SYSTEM ($RMDIR_EMPTY); } # wadalab provides nearly TDS-ready .tar.gz with additional stuff @@ -7187,6 +7189,7 @@ sub POSTstex { print "POST$package - doc files up a level\n"; &xsystem ("$MV Makefile Makefile.top"); &xsystem ("$MV */* ."); + &SYSTEM ($RMDIR_EMPTY); } sub POSTtex_ps { diff --git a/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc b/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc index 7b20f7603a1..cc2ef83b419 100644 --- a/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc @@ -636,6 +636,7 @@ depend hrefhide depend huawei depend hvindex depend hvlogos +depend hvpygmentex depend hvqrurl depend hypdestopt depend hypdoc diff --git a/Master/tlpkg/tlpsrc/hvpygmentex.tlpsrc b/Master/tlpkg/tlpsrc/hvpygmentex.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d -- cgit v1.2.3