From e1738ea0853a78ce457cffe0611bcee5e2062154 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 30 Apr 2022 20:02:01 +0000 Subject: hvextern (30apr22) git-svn-id: svn://tug.org/texlive/trunk@63187 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/hvextern/Changes | 1 + Master/texmf-dist/doc/latex/hvextern/hvextern.pdf | Bin 1148759 -> 1185723 bytes Master/texmf-dist/doc/latex/hvextern/hvextern.tex | 91 +++++++++++++++++++--- Master/texmf-dist/tex/latex/hvextern/hvextern.sty | 33 ++++++-- 4 files changed, 108 insertions(+), 17 deletions(-) diff --git a/Master/texmf-dist/doc/latex/hvextern/Changes b/Master/texmf-dist/doc/latex/hvextern/Changes index 5543cdd49fa..9c754a92770 100644 --- a/Master/texmf-dist/doc/latex/hvextern/Changes +++ b/Master/texmf-dist/doc/latex/hvextern/Changes @@ -1,5 +1,6 @@ hvextern.sty ---------------- +v 0.21 2022-04-30 - added java support v 0.20 2022-04-27 - use L3 for the comma separated lists cleanup and runsequence - move the config files into the main file diff --git a/Master/texmf-dist/doc/latex/hvextern/hvextern.pdf b/Master/texmf-dist/doc/latex/hvextern/hvextern.pdf index bdefe9bd891..963cef8772d 100644 Binary files a/Master/texmf-dist/doc/latex/hvextern/hvextern.pdf and b/Master/texmf-dist/doc/latex/hvextern/hvextern.pdf differ diff --git a/Master/texmf-dist/doc/latex/hvextern/hvextern.tex b/Master/texmf-dist/doc/latex/hvextern/hvextern.tex index 50d93cef06f..0ad44196277 100644 --- a/Master/texmf-dist/doc/latex/hvextern/hvextern.tex +++ b/Master/texmf-dist/doc/latex/hvextern/hvextern.tex @@ -30,7 +30,7 @@ from within a main \LaTeX\ document~--v. \hvexternFileversion} \end{verbatim} \begin{sloppypar} -This package allows to write external \MP, \TeX, \ConTeXt, \LaTeX, \LuaTeX, \LuaLaTeX, \XeTeX, \XeLaTeX, Lua, Perl and/or Python +This package allows to write external \MP, \TeX, \ConTeXt, \LaTeX, \LuaTeX, \LuaLaTeX, \XeTeX, \XeLaTeX, Lua, Perl, Java and/or Python source code, which will then be run via \texttt{shell escape} to create a PDF oder text output to include it into the main \LaTeX\ document. \end{sloppypar} @@ -82,7 +82,7 @@ shown by the environment \texttt{externalDocument}. \begin{minipage}{.59\linewidth} \begin{lstlisting} \begin{externalDocument}[ - compiler=pdflatex,force,cleanup]{Roemer1} + compiler=pdflatex,force,cleanup]{voss} \documentclass{standalone} %StartVisiblePreamble \usepackage{fontenc} @@ -106,7 +106,7 @@ shown by the environment \texttt{externalDocument}. \end{minipage} \begin{minipage}{.39\linewidth} \begin{externalDocument}[ - compiler=pdflatex,force,cleanup={log,aux},verbose]{Roemer1} + compiler=pdflatex,force,cleanup={log,aux},verbose]{voss} \documentclass{standalone} %StartVisiblePreamble \usepackage{fontenc} @@ -261,11 +261,9 @@ image.save(imageName+".png", "PNG") - - \begin{externalDocument}[grfOptions={width=0.95\linewidth}, compiler=xelatex,code,mpwidth=0.6\linewidth, - crop,cleanup,force,usefancyvrb=false,ext=tex]{Senger3} + crop,cleanup,force,usefancyvrb=false,ext=tex]{voss} \documentclass{article} %StartVisiblePreamble \usepackage{tikz} @@ -400,6 +398,80 @@ Sort with xindex \verb|-l DE --config AU| \end{externalDocument} +The following Java-program creates the Mandelbrot set as png image. The valid setting for +the environment \texttt{externalDocument} is: + +\begin{verbatim} + compiler=java,ext=java,docType=java, +\end{verbatim} + +\begin{externalDocument}[ + verbose, + compiler=java,ext=java,code, + force,docType=java,includegraphic, + usefancyvrb,grfOptions={width=0.9\linewidth}]{java} +import java.awt.Color; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.image.RenderedImage; +import java.io.File; +import javax.imageio.ImageIO; + +public class Main { + +//StartVisiblePreamble + public static int iterZahl(final double cx, final double cy, int maxIt, + final double radius) { + // bestimmt Anzahl der Iterationen + int zaehler = 0; + double zx = 0.0, zy = 0.0, tmp; + do { + tmp = zx*zx - zy*zy + cx; + zy = 2*zx*zy + cy; zx = tmp; + zaehler++; + } while (zx*zx + zy*zy <= radius && zaehler < maxIt); + return zaehler; + } +//StopVisiblePreamble + public static void main(String[] argv) throws Exception { + String f_name = new File ((Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath()).getName(); + String basename = f_name.replaceAll("\\.[^.]*$", ""); + int imageBreite = 540, imageHoehe = 405; + BufferedImage bufferedImage = new BufferedImage(imageBreite, imageHoehe, BufferedImage.TYPE_INT_RGB); + Graphics g = bufferedImage.createGraphics(); +//StartVisibleMain + double xa = -2.5, xe = 0.7, ya = -1.2, ye = 1.2; // Ratio 20:15 + double dx = (xe-xa)/(imageBreite-1), dy = (ye-ya)/(imageHoehe-1); + double cx, cy; int R, G, B; + double radius = 10.0; int maxIt = 1024; + cx = xa; + for (int sp = 0; sp < imageBreite; sp++) { + cy = ye; // von oben nach unten + for (int ze = 0; ze < imageHoehe; ze++) { + int zIter = iterZahl(cx, cy, maxIt, radius); + if (zIter == maxIt) { + g.setColor(Color.WHITE); + g.drawLine(sp, ze, sp, ze); + } else { + R = zIter % 4 * 6 ; G = zIter % 8 * 32; B = zIter % 16 * 16; + g.setColor(new Color(R,G,B)); + g.drawLine(sp, ze, sp, ze); + } + cy = cy - dy; + } // for ze + cx = cx + dx; + } // for sp +//StopVisibleMain + g.dispose(); + RenderedImage rendImage = bufferedImage; + + File file = new File(basename+".png"); + ImageIO.write(rendImage, "png", file); + } +} +\end{externalDocument} + + @@ -413,7 +485,7 @@ the follwing example. \begin{externalDocument}[grfOptions={angle=90,width=\linewidth}, compiler=xelatex,code,mpwidth=0.6\linewidth, - crop,cleanup,force]{Senger3} + crop,cleanup,force]{voss} \documentclass{article} %StartVisiblePreamble \usepackage{tikz} @@ -1305,6 +1377,7 @@ it makes no difference using the optional argument \texttt{usefancyvrb} or not. showFilename, % crop, force, + cleanup, code, docType=mp, ext=mp,]{voss} @@ -1394,7 +1467,7 @@ This is the start of the introduction. \begin{externalDocument}[ grfOptions={width=0.5\linewidth}, % pages={1,3}, - frame, +% frame, verbose=false, compiler=lualatex, showFilename, @@ -1414,7 +1487,7 @@ This is the start of the introduction. \begin{pspicture}(-9,-15)(9,2) \psaxes(0,0)(-9,-15)(9,2) \psplot[algebraic,plotstyle=curve,curvature=1 1 0, - linewidth=1pt,linecolor=red]{-8}{8}{ + linewidth=2pt,linecolor=red]{-8}{8}{ 1 - 3876218985722260225*x^2/10892114744073986176 + 14975974793271450625*x^4/174273835905183778816 - 317095420958296875*x^6/26811359370028273664 diff --git a/Master/texmf-dist/tex/latex/hvextern/hvextern.sty b/Master/texmf-dist/tex/latex/hvextern/hvextern.sty index 9e3fbea8c0e..54a921e0a16 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.20} -\ProvidesFile{hvextern}[2022/04/27 v\hvexternFileversion: package for running external documents (HV)] +\def\hvexternFileversion{0.21} +\ProvidesFile{hvextern}[2022/04/30 v\hvexternFileversion: package for running external documents (HV)] \RequirePackage{shellesc,xkeyval,graphicx,marginnote,fancyvrb,tikz,listings,ifplatform} \RequirePackage{tcolorbox,xparse} @@ -78,13 +78,14 @@ \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,xetex,pdflatex,lualatex,xelatex,context}[pdflatex]{% -% \hv@typeout{>>>> Compiler type \nr}% +\define@choicekey*+{hv}{compiler}[\val\nr]{mpost,tex,latex,luatex,python3,perl,lua,java,% + xetex,pdflatex,lualatex,xelatex,context}[pdflatex]{% + \hv@typeout{>>>> Compiler type \nr}% \def\hv@extern@compiler{\val}% \edef\hv@extern@compilerNo{\nr}% }{\PackageWarning{hvextern}{erroneous input (#1) for compiler ignored. Using pdflatex.}% \def\hv@extern@compiler{pdflatex}% - \def\hv@extern@compilerNo{6}% + \def\hv@extern@compilerNo{9}% } \def\ResetKeys{% @@ -140,6 +141,9 @@ \NewDocumentCommand\run@hv@extern@cleanup{ m } { \clist_map_inline:nn {#1}{\ShellEscape{\hv@rm \hv@extern@ExamplesDir\hvExternDateiname.##1}} + \ifnum\hv@extern@compilerNo=0\relax % we have metapost + \hv@rm epsf.* + \fi } \NewDocumentCommand\run@hv@extern@sequenceList{ m } { @@ -157,9 +161,9 @@ \newcommand\BodyVerbatim[2][]{\begin{tcolorbox}\VerbatimInput[#1]{#2}\end{tcolorbox}} -\newcommand\PreambleListing[2][]{\begin{tcolorbox}\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}} +\newcommand\PreambleListing[2][]{\begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}} -\newcommand\BodyListing[2][]{\begin{tcolorbox}\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}} +\newcommand\BodyListing[2][]{\begin{tcolorbox}[top=-2pt]\expandafter\lstinputlisting\expandafter[#1]{#2}\end{tcolorbox}} \newcounter{hv@example@counter} @@ -168,7 +172,7 @@ \@namedef{#1@initPreambleFancy}{\edef\FancyVerbStartString{#4}\edef\FancyVerbStopString{#5}}% code \@namedef{#1@initText}{linerange={#2}-{#3},includerangemarker=false}% text \@namedef{#1@initPreamble}{linerange={#4}-{#5},includerangemarker=false}% code -}% ^^to prevent problems with lua comments +}% {} ^^to prevent problems with lua comments %%------------------ the config part -------------------- %\input{hvextern-mp.cfg} @@ -260,6 +264,14 @@ {--StopVisiblePreamble} +%---- Java +\hv@extern@ExampleType{java} + {//StartVisibleMain} + {//StopVisibleMain} + {//StartVisiblePreamble} + {//StopVisiblePreamble} + + %%%--------------------------------- end config part ------------------ %% @@ -368,11 +380,13 @@ \fi \ifhv@extern@code\else \ifhv@extern@showFilename + \hv@typeout{>>>> Set filename in the margin!}% \marginnote{\rotatebox{90}{\hvExternDateiname}}% \fi \fi \ifhv@extern@moveToExampleDir % \ShellEscape{mkdir\space\hv@extern@ExamplesDir/}% + \hv@typeout{>>>> Move file into example dir}% \ShellEscape{\hv@move \hvExternDateiname.*\space \hv@extern@ExamplesDir}% \fi \ifhv@extern@includegraphic @@ -380,8 +394,10 @@ \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}% \ifdim\hv@extern@mpwidth>\z@ \hfill\minipage[t]{\dimexpr\linewidth-\hv@extern@mpwidth-1em\relax}\vspace{0pt}% \else @@ -389,6 +405,7 @@ \fi \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}}% -- cgit v1.2.3