From b14d6227d79a3ba7ba5297db42ae5c14c02075bd Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 8 May 2022 20:23:52 +0000 Subject: hvextern (8may22) git-svn-id: svn://tug.org/texlive/trunk@63260 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/hvextern/hvextern.sty | 133 +++++++++++++++++++--- 1 file changed, 116 insertions(+), 17 deletions(-) (limited to 'Master/texmf-dist/tex/latex/hvextern') diff --git a/Master/texmf-dist/tex/latex/hvextern/hvextern.sty b/Master/texmf-dist/tex/latex/hvextern/hvextern.sty index 54a921e0a16..5179123aa2e 100644 --- a/Master/texmf-dist/tex/latex/hvextern/hvextern.sty +++ b/Master/texmf-dist/tex/latex/hvextern/hvextern.sty @@ -11,8 +11,8 @@ %% and version 1.3c or later is part of all distributions of LaTeX %% version 2005/12/01 or later. -\def\hvexternFileversion{0.21} -\ProvidesFile{hvextern}[2022/04/30 v\hvexternFileversion: package for running external documents (HV)] +\def\hvexternFileversion{0.23} +\ProvidesFile{hvextern}[2022/05/08 v\hvexternFileversion: package for running external documents (HV)] \RequirePackage{shellesc,xkeyval,graphicx,marginnote,fancyvrb,tikz,listings,ifplatform} \RequirePackage{tcolorbox,xparse} @@ -48,6 +48,7 @@ \define@key{hv}{pages}[1]{\def\hv@extern@pages{#1}} \define@key{hv}{cropmargin}[2]{\def\hv@extern@cropmargin{#1 }} \define@key{hv}{mpwidth}[0pt]{\setlength\hv@extern@mpwidth{#1}} +\define@key{hv}{mpvalign}[t]{\def\hv@extern@mpvalign{#1}} \define@key{hv}{ext}[tex]{\def\hv@extern@ext{.#1}} \define@boolkey{hv}[hv@extern@]{redirect}[true]{} \define@boolkey{hv}[hv@extern@]{usefancyvrb}[true]{} @@ -55,6 +56,7 @@ \define@boolkey{hv}[hv@extern@]{code}[true]{} \define@boolkey{hv}[hv@extern@]{force}[true]{} \define@boolkey{hv}[hv@extern@]{crop}[true]{} +\define@boolkey{hv}[hv@extern@]{tcbox}[true]{} \define@boolkey{hv}[hv@extern@]{biber}[true]{} \define@boolkey{hv}[hv@extern@]{xindex}[true]{} \define@key{hv}{xindexOptions}[]{\def\hv@extern@xindexOptions{#1}} @@ -79,7 +81,7 @@ %\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}[pdflatex]{% + xetex,pdflatex,lualatex,xelatex,context,sh,texlua}[pdflatex]{% \hv@typeout{>>>> Compiler type \nr}% \def\hv@extern@compiler{\val}% \edef\hv@extern@compilerNo{\nr}% @@ -96,6 +98,7 @@ crop=false,% erzeugte PDF "croppen" compiler=pdflatex,% zu verwendener Compiler redirect=false,% write output into a file *.txt + tcbox=true,% use tcolorbox grfOptions={},% Optionen der einzubindenden Grafik lstOptions={},% Optionen für das Listing BGpreamble=black!12,% Backgroundcolor for preamble @@ -121,12 +124,14 @@ ExampleDir=Examples,% Unterverzeichnis für Beispiele align=\centering,% Ausgabe zentrieren mpwidth=0pt,% no minipage + 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? - } + }% } + \ResetKeys {\catcode`\%=12 @@ -157,13 +162,33 @@ \lstset{belowskip=0pt,aboveskip=0pt}% global \tcbset{breakable,left=2pt,right=2pt,top=2pt,bottom=2pt,boxsep=0pt} -\newcommand\PreambleVerbatim[2][]{\begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}} +\newcommand\PreambleVerbatim[2][]{% + \ifhv@extern@tcbox + \begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}% + \else + \VerbatimInput[#1]{#2} + \fi} -\newcommand\BodyVerbatim[2][]{\begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}} +\newcommand\BodyVerbatim[2][]{% + \ifhv@extern@tcbox + \begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}% + \else + \VerbatimInput[#1]{#2} + \fi} -\newcommand\PreambleListing[2][]{\begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}} +\newcommand\PreambleListing[2][]{% + \ifhv@extern@tcbox + \begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}% + \else + \expandafter\lstinputlisting\expandafter[#1]{#2}% + \fi} -\newcommand\BodyListing[2][]{\begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}} +\newcommand\BodyListing[2][]{% + \ifhv@extern@tcbox + \begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}% + \else + \expandafter\lstinputlisting\expandafter[#1]{#2}% + \fi} \newcounter{hv@example@counter} @@ -272,6 +297,15 @@ {//StopVisiblePreamble} +%---- Shell +%\input{hvextern-sh.cfg} +\hv@extern@ExampleType{sh} + {\NumChar StartVisibleMain} + {\NumChar StopVisibleMain} + {\NumChar StartVisiblePreamble} + {\NumChar StopVisiblePreamble} + + %%%--------------------------------- end config part ------------------ %% @@ -280,6 +314,7 @@ \newenvironment{externalDocument}[2][]{% \xdef\hvExternDateiname{#2-\arabic{hv@example@counter}}% \setkeys{hv}{#1}% \begin + \hv@typeout{External filename: \hvExternDateiname}% \expandafter\IfFileExists\expandafter{\hv@extern@ExamplesDir\hvExternDateiname.pdf}{}{% \expandafter\IfFileExists\expandafter{\hv@extern@ExamplesDir\hvExternDateiname.png}{}{% \expandafter\IfFileExists\expandafter{\hv@extern@ExamplesDir\hvExternDateiname.txt}{}{% @@ -307,10 +342,11 @@ \hv@typeout{>>>> running \hv@extern@compiler~ \hvExternDateiname\hv@extern@ext}% \hv@extern@runLATEX{\hv@extern@progpath}{\hv@extern@compiler}{\hvExternDateiname}{\hv@extern@ext}% \else - \hv@typeout{>>>> running \hv@extern@compiler~ \hvExternDateiname\hv@extern@ext}% \ifhv@extern@redirect + \hv@typeout{>>>> running \hv@extern@compiler~ \hvExternDateiname\hv@extern@ext > \hvExternDateiname.txt}% \ShellEscape{\hv@extern@progpath\hv@extern@compiler\space\hvExternDateiname\hv@extern@ext\space > \hvExternDateiname.txt}% \else + \hv@typeout{>>>> running \hv@extern@compiler~ \hvExternDateiname\hv@extern@ext}% \ShellEscape{\hv@extern@progpath\hv@extern@compiler\space\hvExternDateiname\hv@extern@ext}% \fi \fi @@ -325,7 +361,7 @@ \ShellEscape{xindex \hv@extern@xindexOptions\space \hvExternDateiname.idx}% NAch xindex nochmal latex \ShellEscape{\hv@extern@progpath\hv@extern@compiler\space\hvExternDateiname}% \fi - \else + \else % runsequence \expandafter\run@hv@extern@sequenceList\expandafter{\hv@extern@runsequence}% \fi \ifhv@extern@crop @@ -335,11 +371,12 @@ \ifhv@extern@eps \ShellEscape{pdftops -eps -f 1 -l 1 \hvExternDateiname.pdf}% \fi - \fi + \fi% end force \ifhv@extern@code%-------------- Code Part + \hv@typeout{>>>>Starting Code part ...}% \par\noindent \begingroup - \ifdim\hv@extern@mpwidth>\z@ \minipage[t]{\hv@extern@mpwidth}\vspace{0pt}\fi + \ifdim\hv@extern@mpwidth>\z@ \minipage[\hv@extern@mpvalign]{\hv@extern@mpwidth}\vspace{0pt}\fi \ifhv@extern@usefancyvrb \@nameuse{\hv@extern@docType @initPreambleFancy}% \edef\@@@temp{\@nameuse{\hv@extern@docType @initPreamble}}% @@ -377,8 +414,8 @@ \fi \ifdim\hv@extern@mpwidth > \z@\relax \endminipage\fi \endgroup - \fi - \ifhv@extern@code\else + \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}}% @@ -387,6 +424,7 @@ \ifhv@extern@moveToExampleDir % \ShellEscape{mkdir\space\hv@extern@ExamplesDir/}% \hv@typeout{>>>> Move file into example dir}% + \hv@typeout{>>>>>>\hvExternDateiname ---- \hv@extern@ExamplesDir}% \ShellEscape{\hv@move \hvExternDateiname.*\space \hv@extern@ExamplesDir}% \fi \ifhv@extern@includegraphic @@ -399,7 +437,7 @@ \else \hv@typeout{>>>> No floating environment}% \ifdim\hv@extern@mpwidth>\z@ - \hfill\minipage[t]{\dimexpr\linewidth-\hv@extern@mpwidth-1em\relax}\vspace{0pt}% + \hfill\minipage[\hv@extern@mpvalign]{\dimexpr\linewidth-\hv@extern@mpwidth-1em\relax}\vspace{0pt}% \else \par\noindent\begingroup \fi @@ -427,15 +465,76 @@ \else% no graphic, only text \ifdim\hv@extern@mpwidth>\z@ \hfill\minipage[t]{\dimexpr\linewidth-\hv@extern@mpwidth-1em\relax}\vspace{0pt} - \noindent\VerbatimInput{\hv@extern@ExamplesDir\hvExternDateiname.txt} + \noindent\BodyListing{\hv@extern@ExamplesDir\hvExternDateiname.txt} \endminipage \else - \noindent\VerbatimInput{\hv@extern@ExamplesDir\hvExternDateiname.txt} + \noindent\BodyListing{\hv@extern@ExamplesDir\hvExternDateiname.txt} \fi \fi \ifhv@extern@force\expandafter\run@hv@extern@cleanup\expandafter{\hv@extern@cleanup}\fi% cleanup } + \stepcounter{hv@example@counter}% + + +\newcommand\runExtCmd[3][]{% + \begingroup + \setkeys{hv}{code=false,includegraphic=false,#1}% + \xdef\hvExternDateiname{#3-\arabic{hv@example@counter}}% + \hv@typeout{>>>> running #2}% + \ifhv@extern@redirect + \ShellEscape{\hv@extern@progpath#2 > \hv@extern@ExamplesDir\hvExternDateiname.txt}% + \else + \ShellEscape{\hv@extern@progpath#2}% + \fi + \global\stepcounter{hv@example@counter}% + %------------------------------------- output ----------------------------------- + \ifhv@extern@includegraphic + \ifhv@extern@inline + \expandafter\includegraphics\expandafter[\hv@extern@grfOptions]{\hv@extern@ExamplesDir\hvExternDateiname}% + \else + \ifhv@extern@float + \hv@typeout{>>>> Floating environment}% + \begin{figure}[!htb] + \else + \hv@typeout{>>>> No floating environment}% + \par\noindent\begingroup + \fi + \hv@extern@align + \hv@typeout{>>>> Input image \hv@extern@ExamplesDir\hvExternDateiname}% + \ifhv@extern@frame + \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}% + \else + \expandafter\@for\expandafter\next\expandafter:\expandafter=\hv@extern@pages\do{% + \expandafter\includegraphics\expandafter[\hv@extern@grfOptions,page=\next]% + {\hv@extern@ExamplesDir\hvExternDateiname}% + \hspace{5pt}}\hspace*{-5pt}% + \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}% + \else + \ifdim\hv@extern@mpwidth>\z@ \endminipage\else\par\endgroup\fi + \fi + \fi + \else% no graphic, only text + \ifhv@extern@float + \hv@typeout{>>>> Floating environment}% + \begin{figure}[!htb] + \noindent\BodyListing{\hv@extern@ExamplesDir\hvExternDateiname.txt} + \ifx\hv@extern@caption\@empty\else\caption{\hv@extern@caption}\fi + \ifx\hv@extern@label\@empty\else\label{\hv@extern@label}\fi + \end{figure} + \else + \noindent\BodyListing{\hv@extern@ExamplesDir\hvExternDateiname.txt} + \fi + \fi + \ifhv@extern@force\expandafter\run@hv@extern@cleanup\expandafter{\hv@extern@cleanup}\fi% cleanup + \endgroup +} % %% \endinput -- cgit v1.2.3