From 826a444ee70419487a4dabcec775fb1a45472300 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Fri, 20 May 2022 21:38:39 +0000
Subject: hvextern (20may22)

git-svn-id: svn://tug.org/texlive/trunk@63346 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/hvextern/hvextern.sty | 138 +++++++++++++++-------
 1 file changed, 96 insertions(+), 42 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/hvextern/hvextern.sty')

diff --git a/Master/texmf-dist/tex/latex/hvextern/hvextern.sty b/Master/texmf-dist/tex/latex/hvextern/hvextern.sty
index 2f7fb9d6ff1..0b6eafa6c6d 100644
--- a/Master/texmf-dist/tex/latex/hvextern/hvextern.sty
+++ b/Master/texmf-dist/tex/latex/hvextern/hvextern.sty
@@ -11,10 +11,11 @@
 %% and version 1.3c or later is part of all distributions of LaTeX
 %% version 2005/12/01 or later.
 
-\def\hvexternFileversion{0.24}
-\ProvidesFile{hvextern}[2022/05/11 v\hvexternFileversion: package for running external documents (HV)]
+\def\hvexternFileversion{0.25}
+\ProvidesFile{hvextern}[2022/05/19 v\hvexternFileversion: package for running external documents (HV)]
 
-\RequirePackage{shellesc,xkeyval,graphicx,marginnote,fancyvrb,tikz,listings,ifplatform}
+\RequirePackage{shellesc,xkeyval,graphicx}
+\RequirePackage{fancyvrb,tikz,listings,ifplatform}
 \RequirePackage{tcolorbox,xparse}
 \tcbuselibrary{skins,breakable}
 
@@ -30,8 +31,15 @@
 \newcounter{@@@runs} 
 \newsavebox\hv@extern@box
 \newlength\hv@LineWidth
+\newlength\hv@TextWidth
 \newlength\hv@extern@pagesep
 \newlength\hv@extern@mpsep
+\newlength\hv@extern@framesep
+\newlength\hv@extern@aboveskip
+\newlength\hv@extern@belowpreambleskip
+\newlength\hv@extern@belowbodyskip
+\newlength\hv@extern@belowskip
+
 \AtBeginDocument{\setlength\hv@LineWidth{\dimexpr\linewidth-2\fboxsep-2\fboxrule}}
 \newlength\hv@extern@mpwidth \setlength\hv@extern@mpwidth{\z@}
 
@@ -40,11 +48,18 @@
 \define@key{hv}{runs}[1]{\setcounter{hv@extern@runs}{#1}}
 \define@key{hv}{grfOptions}[]{\def\hv@extern@grfOptions{#1}}
 \define@key{hv}{lstOptions}[]{\def\hv@extern@lstOptions{#1}}
+\define@key{hv}{textOptions}[]{\def\hv@extern@textOptions{#1}}
 \define@key{hv}{BGpreamble}[black!12]{\def\hv@extern@BGpreamble{#1}}
 \define@key{hv}{BGbody}[black!8]{\def\hv@extern@BGbody{#1}}
 \define@key{hv}{BOpreamble}[black!12]{\def\hv@extern@BOpreamble{#1}}
 \define@key{hv}{BObody}[black!8]{\def\hv@extern@BObody{#1}}
 \define@key{hv}{docType}[latex]{\def\hv@extern@docType{#1}}
+%\define@choicekey*+{hv}{docType}[\val\nr]{latex,mp,tex,py,pl,lua,java,context,sh}[latex]{% 
+%  \hv@typeout{>>>> ´doc type \nr}%
+%  \def\hv@extern@docType{\val}%
+%}{\PackageWarning{hvextern}{erroneous input (#1) for docType ignored. Using latex.}%
+%  \def\hv@extern@docType{latex}%
+% }
 \define@key{hv}{caption}[]{\def\hv@extern@caption{#1}}
 \define@key{hv}{label}[]{\def\hv@extern@label{#1}}
 \define@key{hv}{pages}[1]{\def\hv@extern@pages{#1}}
@@ -65,10 +80,11 @@
 \define@boolkey{hv}[hv@extern@]{xindex}[true]{}
 \define@key{hv}{xindexOptions}[]{\def\hv@extern@xindexOptions{#1}}
 \define@boolkey{hv}[hv@extern@]{includegraphic}[true]{}
-\define@boolkey{hv}[hv@extern@]{inline}[true]{\hv@extern@codefalse}
+\define@boolkey{hv}[hv@extern@]{inline}[true]{\hv@extern@codefalse\hv@extern@showFilenamefalse}
 \define@boolkey{hv}[hv@extern@]{frame}[true]{}
+\define@key{hv}{framesep}[\the\fboxsep]{\setlength\hv@extern@framesep{#1}}
 \define@boolkey{hv}[hv@extern@]{float}[true]{}
-%\define@boolkey{hv}[hv@extern@]{cleanup}[true]{}
+\define@key{hv}{floatsetting}[]{\def\hv@extern@floatsetting{#1}}
 \define@key{hv}{cleanup}[{aux,log}]{\def\hv@extern@cleanup{#1}}% 
 \define@boolkey{hv}[hv@extern@]{moveToExampleDir}[true]{}
 \define@key{hv}{align}[\centering]{\def\hv@extern@align{#1}}
@@ -82,7 +98,6 @@
 \define@boolkey{hv}[hv@extern@]{eps}[true]{}
 \define@boolkey{hv}[hv@extern@]{verbose}[true]{}
 \def\hv@typeout#1{\ifhv@extern@verbose\typeout{#1}\fi}
-
 %\define@key{hv}{compiler}[pdflatex]{\def\hv@extern@compiler{#1}}
 \define@choicekey*+{hv}{compiler}[\val\nr]{mpost,tex,latex,luatex,python3,perl,lua,java,%
      xetex,pdflatex,lualatex,xelatex,context,sh,texlua}[pdflatex]{% 
@@ -93,6 +108,10 @@
   \def\hv@extern@compiler{pdflatex}%
   \def\hv@extern@compilerNo{9}%
  }
+\define@key{hv}{aboveskip}[\medskipamount]{\setlength\hv@extern@aboveskip{#1}}
+\define@key{hv}{belowpreambleskip}[\smallskipamount]{\setlength\hv@extern@belowpreambleskip{#1}}
+\define@key{hv}{belowbodyskip}[\smallskipamount]{\setlength\hv@extern@belowbodyskip{#1}}
+\define@key{hv}{belowskip}[\medskipamount]{\setlength\hv@extern@belowskip{#1}}
 
 \def\ResetKeys{%
  \setkeys{hv}{%
@@ -105,6 +124,7 @@
   tcbox=true,%          use tcolorbox
   grfOptions={},%	Optionen der einzubindenden Grafik
   lstOptions={},%	Optionen für das Listing
+  textOptions={},%	Options for text output
   BGpreamble=black!12,% Backgroundcolor for preamble
   BGbody=black!8,%      Backgroundcolor for body
   BOpreamble=black!12,% Bodercolor for preamble
@@ -118,7 +138,9 @@
   xindexOptions={},%     options for xindex
   force=false,%		Compiler, auch wenn PDF existiert?
   frame=false,%		keinen Rahmen um Abbildung
+  framesep=\the\fboxsep,% 
   float=false,%		nicht als Gleitumgebung
+  floatsetting=!htb,%   placement
   caption=,%	        keine Caption
   label=,%		kein Label
   pages=1,%		welche Seiten auszugeben sind
@@ -129,11 +151,16 @@
   ExampleDir=Examples,% Unterverzeichnis für Beispiele
   align=\centering,%    Ausgabe zentrieren
   mpwidth=0pt,%         no minipage
+  mpsep=1em,%           sep  between two minipages
   mpvalign=t,%          if side by side output the vertical alignment          
   usefancyvrb=false,%   use VerbatimInput instead of listings
   progpath={},
   cropmargin=2,%        2pb margin
   eps=false,%           create an eps output?          
+  aboveskip=\medskipamount,% space above everything
+  belowpreambleskip=\smallskipamount,% space below preamble
+  belowbodyskip=\smallskipamount,% space below body
+  belowskip=\medskipamount,% space below everything
   }%
 }
 
@@ -167,10 +194,14 @@
 \lstset{belowskip=0pt,aboveskip=0pt}% global
 \tcbset{breakable,left=2pt,right=2pt,top=2pt,bottom=2pt,boxsep=0pt}
 
+\def\hv@marginpar#1{%
+  \makebox[\dimexpr\hv@TextWidth+\marginparsep-1ex][r]{\makebox(0,0){\rotatebox[origin=lb]{90}{#1}}}%
+}
+
 \newcommand\PreambleVerbatim[2][]{%
   \hv@typeout{Running PreambleVerbatim with #1, #2}%
   \ifhv@extern@tcbox
-    \begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}%
+    \begin{tcolorbox}[before skip=0pt,after skip=0pt]\VerbatimInput[#1]{#2}\end{tcolorbox}%
   \else
     \VerbatimInput[#1]{#2}
   \fi}
@@ -178,7 +209,7 @@
 \newcommand\BodyVerbatim[2][]{%
   \hv@typeout{Running BodyVerbatim with #1, #2}%
   \ifhv@extern@tcbox
-    \begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}%
+    \begin{tcolorbox}[before skip=0pt,after skip=0pt]\VerbatimInput[#1]{#2}\end{tcolorbox}%
   \else
     \VerbatimInput[#1]{#2}
   \fi}
@@ -186,17 +217,19 @@
 \newcommand\PreambleListing[2][]{%
   \hv@typeout{Running PreambleListing with #1, #2}%
   \ifhv@extern@tcbox 
-    \begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}%
+    \begin{tcolorbox}[before skip=0pt,after skip=0pt%,top=-2pt
+    ]\expandafter\lstinputlisting\expandafter[#1,aboveskip=0pt,belowskip=0pt]{#2}\end{tcolorbox}%
   \else    
-    \expandafter\lstinputlisting\expandafter[#1]{#2}%
+    \expandafter\lstinputlisting\expandafter[#1,aboveskip=0pt,belowskip=0pt]{#2}%
   \fi}
 
 \newcommand\BodyListing[2][]{%
   \hv@typeout{Running BodyListing with #1, #2}%
   \ifhv@extern@tcbox 
-    \begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}%
+    \begin{tcolorbox}[before skip=0pt,after skip=0pt,%top=-2pt
+    ]\expandafter\lstinputlisting\expandafter[#1,aboveskip=0pt,belowskip=0pt]{#2}\end{tcolorbox}%
   \else
-    \expandafter\lstinputlisting\expandafter[#1]{#2}%
+    \expandafter\lstinputlisting\expandafter[#1,aboveskip=0pt,belowskip=0pt]{#2}%
   \fi}
 
 \newcounter{hv@example@counter}
@@ -382,20 +415,26 @@
      \fi
    \fi%    end force
    \ifhv@extern@code%--------------        Code Part
-     \hv@typeout{>>>>Starting Code part ...}%
-     \par\noindent
+     \hv@typeout{>>>>Starting Code part with preamble ...}%
      \begingroup
-      \ifdim\hv@extern@mpwidth>\z@ \minipage[\hv@extern@mpvalign]{\hv@extern@mpwidth}\vspace{0pt}\fi
-      \ifhv@extern@usefancyvrb
+       \hv@TextWidth=\textwidth
+       \ifdim\hv@extern@mpwidth>\z@ 
+         \noindent
+         \minipage[\hv@extern@mpvalign]{\hv@extern@mpwidth}
+         \vspace{0pt}%
+       \else
+         \vspace{\hv@extern@aboveskip}\noindent
+       \fi
+       \ifhv@extern@usefancyvrb
          \@nameuse{\hv@extern@docType @initPreambleFancy}%
          \edef\@@@temp{\@nameuse{\hv@extern@docType @initPreamble}}%
          % we need lstinputlisting, because \VerbatimInput doesn't work in a box
          \savebox\hv@extern@box{\expandafter\lstinputlisting\expandafter[\@@@temp]{\hvExternDateiname\hv@extern@ext}}%
-%         \savebox\hv@extern@box{\VerbatimInput{\hvExternDateiname\hv@extern@ext}}%
          \ifdim\wd\hv@extern@box > \z@\relax
            \expandafter\fvset\expandafter{\hv@extern@lstOptions}%
            \tcbset{colback=\hv@extern@BGpreamble,colframe=\hv@extern@BOpreamble}%
            \PreambleVerbatim{\hvExternDateiname\hv@extern@ext}%
+           \vspace{\hv@extern@belowpreambleskip}%
          \fi
       \else
         \edef\@@@temp{\@nameuse{\hv@extern@docType @initPreamble}}%
@@ -404,30 +443,35 @@
           \expandafter\lstset\expandafter{\hv@extern@lstOptions}%
           \tcbset{colback=\hv@extern@BGpreamble,colframe=\hv@extern@BOpreamble}%
           \PreambleListing[\@@@temp]{\hvExternDateiname\hv@extern@ext}%
+          \vspace{\hv@extern@belowpreambleskip}%
         \fi
       \fi
       \ifhv@extern@showFilename
-         \marginnote{\rotatebox{90}{\hvExternDateiname\hv@extern@ext}}%[-15mm]%
+         \hv@typeout{>>>> Set filename in the margin!}%
+         \noindent
+         \hv@marginpar{\hvExternDateiname\hv@extern@ext}%
       \fi
 %     
+      \hv@typeout{>>>>Starting Code body ...}%}
        \ifhv@extern@usefancyvrb
          \@nameuse{\hv@extern@docType @initTextFancy}%
          \expandafter\fvset\expandafter{\hv@extern@lstOptions}%
          \tcbset{colback=\hv@extern@BGbody,colframe=\hv@extern@BObody}%
          \expandafter\BodyVerbatim\expandafter[\hv@extern@lstOptions]{\hvExternDateiname\hv@extern@ext}%
-       \else
+      \else
          \expandafter\lstset\expandafter{\hv@extern@lstOptions}%
          \edef\@@@temp{\@nameuse{\hv@extern@docType @initText}}%
          \tcbset{colback=\hv@extern@BGbody,colframe=\hv@extern@BObody}%
          \BodyListing[\@@@temp]{\hvExternDateiname\hv@extern@ext}%
-       \fi
-     \ifdim\hv@extern@mpwidth > \z@\relax \endminipage\fi
-     \endgroup
+      \fi
+    \ifdim\hv@extern@mpwidth > \z@\relax \endminipage\fi
+    \endgroup
    \fi % end code part
    \ifhv@extern@code\else  % only if no code
       \ifhv@extern@showFilename
         \hv@typeout{>>>> Set filename in the margin!}%
-        \marginnote{\rotatebox{90}{\hvExternDateiname}}%
+        \noindent
+        \hv@marginpar{\hvExternDateiname\hv@extern@ext}%
       \fi
    \fi
    \ifhv@extern@moveToExampleDir
@@ -442,31 +486,37 @@
      \else
        \ifhv@extern@float
          \hv@typeout{>>>> Floating environment}% 
-         \begin{figure}[!htb]
+         \expandafter\figure\expandafter[\hv@extern@floatsetting]
        \else
          \hv@typeout{>>>> No floating environment}% 
+         \vspace{\hv@extern@belowbodyskip}
          \ifdim\hv@extern@mpwidth>\z@ 
            \hfill\minipage[\hv@extern@mpvalign]{\dimexpr\linewidth-\hv@extern@mpwidth-1em\relax}\vspace{0pt}%
          \else
-           \par\noindent\begingroup
+           \vspace{\hv@extern@belowbodyskip}\noindent
+           \begingroup
          \fi
        \fi
        \hv@extern@align
        \hv@typeout{>>>> Input image \hv@extern@ExamplesDir\hvExternDateiname}% 
        \ifhv@extern@frame
+         \begingroup
+         \fboxsep=\hv@extern@framesep
          \expandafter\@for\expandafter\next\expandafter:\expandafter=\hv@extern@pages\do{%
-           \fbox{\expandafter\includegraphics\expandafter[\hv@extern@grfOptions,page=\next]{\hv@extern@ExamplesDir\hvExternDateiname}}%
-              \hspace{\hv@extern@pagesep}}\hspace*{-\hv@extern@pagesep}%
+           \fbox{\expandafter\includegraphics\expandafter[\hv@extern@grfOptions,page=\next]%
+             {\hv@extern@ExamplesDir\hvExternDateiname}}\hspace{\hv@extern@pagesep}}%
+         \hspace*{-\hv@extern@pagesep}%
+         \endgroup
        \else
          \expandafter\@for\expandafter\next\expandafter:\expandafter=\hv@extern@pages\do{%
            \expandafter\includegraphics\expandafter[\hv@extern@grfOptions,page=\next]%
-             {\hv@extern@ExamplesDir\hvExternDateiname}%
-              \hspace{\hv@extern@pagesep}}\hspace*{-\hv@extern@pagesep}%
+             {\hv@extern@ExamplesDir\hvExternDateiname}\hspace{\hv@extern@pagesep}}%
+         \hspace*{-\hv@extern@pagesep}%
        \fi
        \ifx\hv@extern@caption\@empty\else\caption{\hv@extern@caption}\fi
        \ifx\hv@extern@label\@empty\else\label{\hv@extern@label}\fi
        \ifhv@extern@float
-         \end{figure}%
+         \endfigure
        \else
          \ifdim\hv@extern@mpwidth>\z@  \endminipage\else\par\endgroup\fi
        \fi
@@ -474,28 +524,26 @@
    \else% no graphic, only text
      \ifdim\hv@extern@mpwidth>\z@ 
        \hfill\minipage[t]{\dimexpr\linewidth-\hv@extern@mpwidth-\hv@extern@mpsep\relax}\vspace{0pt}
-       \noindent
        \ifhv@extern@usefancyvrb
-         \expandafter\BodyVerbatim\expandafter[\hv@extern@lstOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
+         \expandafter\VerbatimInput\expandafter[\hv@extern@textOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
        \else
-         \expandafter\BodyListing\expandafter[\hv@extern@lstOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
+         \expandafter\lstinputlisting\expandafter[\hv@extern@textOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
        \fi
        \endminipage
      \else
+       \vspace{\hv@extern@belowbodyskip}
        \noindent
        \ifhv@extern@usefancyvrb
-         \expandafter\BodyVerbatim\expandafter[\hv@extern@lstOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
+         \expandafter\VerbatimInput\expandafter[\hv@extern@textOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
        \else
-         \expandafter\BodyListing\expandafter[\hv@extern@lstOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
+         \expandafter\lstinputlisting\expandafter[\hv@extern@textOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}%
        \fi
      \fi
    \fi
    \ifhv@extern@force\expandafter\run@hv@extern@cleanup\expandafter{\hv@extern@cleanup}\fi%   cleanup
+  \vspace{\hv@extern@belowskip}%
 }
 
-\stepcounter{hv@example@counter}%
-
-
 \newcommand\runExtCmd[3][]{%
   \begingroup
   \setkeys{hv}{code=false,includegraphic=false,#1}%
@@ -514,7 +562,7 @@
      \else
        \ifhv@extern@float
          \hv@typeout{>>>> Floating environment}% 
-         \begin{figure}[!htb]
+         \expandafter\figure\expandafter[\hv@extern@floatsetting]
        \else
          \hv@typeout{>>>> No floating environment}% 
          \par\noindent\begingroup
@@ -522,9 +570,12 @@
        \hv@extern@align
        \hv@typeout{>>>> Input image \hv@extern@ExamplesDir\hvExternDateiname}% 
        \ifhv@extern@frame
+         \begingroup
+         \fboxsep=\hv@extern@framesep
          \expandafter\@for\expandafter\next\expandafter:\expandafter=\hv@extern@pages\do{%
            \fbox{\expandafter\includegraphics\expandafter[\hv@extern@grfOptions,page=\next]{\hv@extern@ExamplesDir\hvExternDateiname}}%
               \hspace{5pt}}\hspace*{-5pt}%
+         \endgroup
        \else
          \expandafter\@for\expandafter\next\expandafter:\expandafter=\hv@extern@pages\do{%
            \expandafter\includegraphics\expandafter[\hv@extern@grfOptions,page=\next]%
@@ -534,7 +585,7 @@
        \ifx\hv@extern@caption\@empty\else\caption{\hv@extern@caption}\fi
        \ifx\hv@extern@label\@empty\else\label{\hv@extern@label}\fi
        \ifhv@extern@float
-         \end{figure}%
+         \endfigure
        \else
          \ifdim\hv@extern@mpwidth>\z@  \endminipage\else\par\endgroup\fi
        \fi
@@ -542,7 +593,7 @@
    \else% no graphic, only text
      \ifhv@extern@float
        \hv@typeout{>>>> Floating environment}% 
-       \begin{figure}[!htb]
+       \expandafter\figure\expandafter[!htb]
        \ifhv@extern@usefancyvrb
          \expandafter\BodyVerbatim\expandafter[\hv@extern@lstOptions]{\hv@extern@ExamplesDir\hvExternDateiname.txt}
        \else     
@@ -550,7 +601,7 @@
        \fi
        \ifx\hv@extern@caption\@empty\else\caption{\hv@extern@caption}\fi
        \ifx\hv@extern@label\@empty\else\label{\hv@extern@label}\fi
-       \end{figure}
+       \endfigure
      \else
        \noindent
        \ifhv@extern@usefancyvrb
@@ -563,6 +614,9 @@
    \ifhv@extern@force\expandafter\run@hv@extern@cleanup\expandafter{\hv@extern@cleanup}\fi%   cleanup
   \endgroup
 }
+
+\stepcounter{hv@example@counter}%
+
 %
 %%
 \endinput
-- 
cgit v1.2.3

