summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-03-20 21:10:21 +0000
committerKarl Berry <karl@freefriends.org>2022-03-20 21:10:21 +0000
commit6f2024c5e1a601cf624c7206b24b160311ebc123 (patch)
tree4f12e5c02708c2a7c8a6a4b3208bfa6eda10734f
parentacdc7a5666799ac5ac8ae3c90d20246a7002d9c4 (diff)
luaaddplot (20mar22) (branch)
git-svn-id: svn://tug.org/texlive/branches/branch2021.final@62830 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/luatex/luaaddplot/README.md34
-rw-r--r--Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.pdfbin0 -> 258501 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.tex25
-rw-r--r--Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.dtx300
-rw-r--r--Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.ins19
-rw-r--r--Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.lua60
-rw-r--r--Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.sty23
-rw-r--r--Master/tlpkg/tlpsrc/collection-luatex.tlpsrc1
-rw-r--r--Master/tlpkg/tlpsrc/luaaddplot.tlpsrc0
9 files changed, 462 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/luatex/luaaddplot/README.md b/Master/texmf-dist/doc/luatex/luaaddplot/README.md
new file mode 100644
index 00000000000..ce4f4448e35
--- /dev/null
+++ b/Master/texmf-dist/doc/luatex/luaaddplot/README.md
@@ -0,0 +1,34 @@
+luaaddeplot
+===========
+
+Version
+-------
+1.0
+
+Author
+------
+Reinhard Kotucha <a href="mailto:Reinhard.Kotucha@gmx.de">Reinhard.Kotucha@gmx.de</a>
+
+License
+-------
+LPPL v1.3 or any later version.
+
+Description
+-----------
+luaaddplot is an extension to pgfplots which extends the `\addplot`
+macro by a facility which allows modification of data files while they
+are read. With luaaddplot it's not necessary anymore to pre-process
+data files generated by measuring devices with external scripts.
+
+This package can be used with plain LuaTeX or LuaLaTeX.
+
+Installation
+------------
+Copy
+
+`luaaddplot.tex` and `luaaddplot.lua` to `tex/generic/luaaddplot`
+
+and
+
+`luaaddplot.sty` to `tex/latex/luaaddplot`.
+
diff --git a/Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.pdf b/Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.pdf
new file mode 100644
index 00000000000..875fac11570
--- /dev/null
+++ b/Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.tex b/Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.tex
new file mode 100644
index 00000000000..8225d53d193
--- /dev/null
+++ b/Master/texmf-dist/doc/luatex/luaaddplot/luaaddplot.tex
@@ -0,0 +1,25 @@
+%% File 'luaaddplot.tex', generated from luaaddplot.dtx'.
+%%
+%% luaaddplot.dtx
+%% Copyright 2022 Reinhard Kotucha <reinhard.kotucha@gmx.net>
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% 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.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `maintained'.
+%%
+%% The Current Maintainer of this work is Reinhard Kotucha.
+%%
+%% This work consists of the files luaaddplot.dtx and luaaddplot.ins
+%% and the derived files luaaddplot.tex, luaaddplot.sty, and luaaddplot.lua.
+\directlua{require('luaaddplot')}
+\def\luaaddplot#1file#2;{
+ \directlua{luaaddplot.opts('#1')luaaddplot.readfile(#2)}}
+\endinput
+%%
+%% End of file `luaaddplot.tex'.
diff --git a/Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.dtx b/Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.dtx
new file mode 100644
index 00000000000..7d3e4bf8c24
--- /dev/null
+++ b/Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.dtx
@@ -0,0 +1,300 @@
+% \iffalse meta-comment
+%
+% $Id: luaaddplot.dtx 3 2022-03-19 23:12:51Z reinhard $
+%
+%<*driver>
+\documentclass[a4paper,11pt]{ltxdoc}
+\MakeShortVerb{\|}
+
+\advance\textheight by 2\baselineskip
+\usepackage[english]{babel}
+\usepackage{tgpagella}
+\usepackage[dvipsnames]{xcolor}
+\usepackage{parskip}
+\usepackage{siunitx}
+\usepackage[colorlinks,bookmarksopen,bookmarksnumbered]{hyperref}
+\hypersetup{linkcolor=BrickRed}
+
+\author{Reinhard Kotucha}
+\title{\textsf{luaaddplot}}
+\begin{document}
+\maketitle
+\vspace*{1cm}
+
+\begin{abstract}
+ \parindent=0pt \parskip=1ex
+ \noindent The \textsf{pgfplots} package supports plotting data from files.
+ If these files are generated by measuring devices they almost always
+ have to be pre-processed.
+
+ This packge provides a macro |\luaaddplot| which extends the
+ functionality of |\addplot| by an optional argument containing
+ a $\lambda$- expression which is evaluated for each line of the data
+ file.
+
+ The package requires Lua\TeX\ or Lua\LaTeX.
+\end{abstract}
+\vspace*{1cm}
+\tableofcontents
+\vspace*{\fill}
+
+\newpage
+
+\section{Introduction}
+When plotting files generated by measuring devices the data files
+often have to be pre-processed before they can be passed to \textsf{pgfplots}.
+In most cases a header describing the device configuration must be
+removed, column delimiters have to be changed, and units have to be
+scaled (\si{\hertz} to \si{\mega\hertz}, \si{\volt} to
+\si{\micro\volt}, etc\ldots). In some cases more complex operations
+are required.
+
+\subsection{Usage}
+
+\verb| \luaaddplot|\oarg{options}| file "|%
+$\langle$\textit{filename}$\rangle$|"|[|, |$\langle$\textit{$\lambda$-expression}$\rangle$]|;|
+
+Everything between \cs{luaaddplot} and the keyword |file| is passed to
+\cs{addplot}, everything between |file| and the semicolon is
+processed by Lua and valid Lua syntax is required here. You can
+consider code between |file| and the terminating semicolon as
+arguments of a Lua function with braces omitted.
+
+\subsection{Reading the data file}
+
+Data files generated by measuring devices usually have an ASCII
+header describing the settings. These lines are often preceded by
+comment characters but not always. In order to avoid pre-processing
+with another tool, all lines which do not begin with a number are
+ignored.
+
+Different devices use different column delimiters. Therefore tabs,
+colons, semicolons, and commas are replaced by a space. With other
+words, various datafile formats are converted to a format specified by
+\textsc{Matlab}.
+
+\subsection{\texorpdfstring{$\lambda$}{lambda}-Expressions}
+
+A $\lambda$-expression is an anonymous function and looks like this:
+\begin{verbatim}
+ function (a)
+ return a[1], a[2]
+ end
+\end{verbatim}
+
+The formal parameter |a| (its name can be chosen arbitrarily) is
+replaced by an ordered list of columns for each line in the data file.
+The return values are the $x$ and $y$ values to be plotted and are
+passed to \cs{addplot}. Always two values must be returned. Please
+note that the index of the first column is 1 in Lua and not 0, as in
+many other programming languages.
+
+In the example above the first and second column of the data file
+will be plotted. This is the default if the $\lambda$-expression is
+omitted.
+
+\newpage
+
+\section{Examples}
+
+\subsection{Scaling}
+
+The following is an excerpt of a data file generated by a spectrum analyzer.
+
+\begin{verbatim}
+x-Unit;Hz;
+y-Unit;dBm;
+Preamplifier;OFF;
+Transducer;OFF;
+Values;501;
+0;43.660163879394531;
+6000000;-53.616184234619141;
+12000000;-60.31707763671875;
+18000000;-62.548038482666016;
+54000000;-66.722061157226563;
+\end{verbatim}
+
+Frequencies are in \si{\hertz} but for the plot we prefer
+\si{\mega\hertz}. The solution is
+\begin{verbatim}
+\luaaddplot[blue] file "spectrum.data", function (col)
+ return col[1]/1e6, col2
+ end;
+\end{verbatim}
+
+
+\subsection{Processing}
+
+The following is an excerpt of a data file generated by a vector
+network analyzer.
+
+\begin{verbatim}
+%% Date: 2021-02-25 11:36:04
+%% Data & Calibration Information:
+%% Trc1:S11(Full One Port)
+%%freq[Hz] re:Trc1_S11 im:Trc1_S11
+6.650000000000000E+008,3.684957681171731E-001,-9.205383204111828E-001,
+6.652500000000000E+008,3.717039523633851E-001,-9.215835251874305E-001,
+6.655000000000000E+008,3.687706454916999E-001,-9.207422307051146E-001,
+6.657500000000000E+008,3.574212650433284E-001,-9.176705980253278E-001,
+6.660000000000000E+008,3.453552411257967E-001,-9.254690887689956E-001,
+\end{verbatim}
+
+The first column denotes the frequency in \si{\hertz}, the second and
+third column denote the real and imaginary part of the impedance
+$s_{11}$ respectively.
+
+Now we want to plot
+\begin{displaymath}
+ 20 \log_{10} \sqrt{(\text{Re\,} s_{11})^2 + (\text{Im\,} s_{11})^2}
+\end{displaymath}
+with frequencies in \si{\mega\hertz}.
+
+The solution is
+\begin{verbatim}
+\luaaddplot[green] file "s11.data",
+ function (col)
+ return col[1]/1e6, 20*math.log10(math.sqrt(col[2]^2 + col[3]^2))
+ end;
+\end{verbatim}
+
+
+\newpage
+\section{Implementation}
+\DocInput{luaaddplot.dtx}
+\end{document}
+%<*tex|sty|lua>
+%</tex|sty|lua>
+
+%</driver>
+% \fi
+% \begin{macrocode}
+%<tex>%% File 'luaaddplot.tex', generated from luaaddplot.dtx'.
+%<sty>%% File 'luaaddplot.sty', generated from luaaddplot.dtx'.
+%<lua>-- File 'luaaddplot.lua', generated from luaaddplot.dtx'.
+%<lua>--[[
+%%
+%% luaaddplot.dtx
+%% Copyright 2022 Reinhard Kotucha <reinhard.kotucha@gmx.net>
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% 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.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `maintained'.
+%%
+%% The Current Maintainer of this work is Reinhard Kotucha.
+%%
+%% This work consists of the files luaaddplot.dtx and luaaddplot.ins
+%% and the derived files luaaddplot.tex, luaaddplot.sty, and luaaddplot.lua.
+%<lua>--]]
+% \end{macrocode}
+% \subsection{luaaddplot.tex}
+% \begin{macrocode}
+%<*tex>
+\directlua{require('luaaddplot')}
+\def\luaaddplot#1file#2;{
+ \directlua{luaaddplot.opts('#1')luaaddplot.readfile(#2)}}
+%</tex>
+% \end{macrocode}
+% \subsection{luaaddplot.sty}
+% \begin{macrocode}
+%<*sty> \ProvidesPackage{luaaddplot}[2022/03/18/ v1.0]
+\input luaaddplot.tex
+%</sty>
+% \end{macrocode}
+% \subsection{luaaddplot.lua}
+% \begin{macrocode}
+%<*lua>
+
+module('luaaddplot', package.seeall)
+
+% \end{macrocode}
+% \DescribeMacro{readfile()}
+% Read and pre-process file \verb|file| and apply
+% $\lambda$-expression. If the second argument is \verb|nil| the
+% first and second column is returned.
+% \begin{macrocode}
+function readfile (file, lambda)
+% \end{macrocode}
+% Check whether datafile exists.
+% \begin{macrocode}
+ if not lfs.isfile(file) then
+ error('\nERROR: File "'..file..'" not found.')
+ end
+
+ local data = io.open(file)
+
+ for line in data:lines() do
+% \end{macrocode}
+% Remove all spaces at the beginning of a line.
+% \begin{macrocode}
+ line = line:gsub('^%s+', '')
+% \end{macrocode}
+% Ignore all lines which don't begin with a number. All comments
+% and empty lines in data files are ignored.
+% \begin{macrocode}
+ if line:match('^%-?%.?[0-9]') then
+% \end{macrocode}
+% Replace possible non-space delimiters by spaces. This allows to
+% process various datafile formats the same way as \textsc{Matlab}
+% files without manual interaction.
+% \begin{macrocode}
+ line = line:gsub('[\t:;,]', ' ')
+% \end{macrocode}
+% The result must be a table with two columns. If no $\lambda$
+% expression is provided, the first two colums of the data file are
+% returned. With a $\lambda$ expression as second argument arbitrary
+% columns can be selected from a data file and can be pre-processed in
+% any way possible.
+% \begin{macrocode}
+ local a, b
+ local cols = line:explode (' +')
+% \end{macrocode}
+% Convert strings to numbers. Because $\lambda$ expressions can
+% access any column we convert all table entries from strings
+% to numbers, if possible, instead of only the return values.
+% Numbers are returned to \TeX\ as floating point numbers.
+% \begin{macrocode}
+ for i, col in ipairs(cols) do
+ cols[i] = tonumber(cols[i])
+ end
+
+ if lambda then
+ a, b = lambda(cols)
+ if a and b then
+ tex.print(string.format('%g %g', a, b))
+ end
+ else
+ tex.print(string.format('%g %g', cols[1], cols[2]))
+ end
+ end
+ end
+ tex.print('};')
+ data:close()
+end
+% \end{macrocode}
+% \DescribeMacro{opts()}
+% Pass optional arguments from \verb|\luaaddplot| to \verb|\addplot|.
+% \begin{macrocode}
+
+function opts (s)
+ tex.print('\\addplot'..s..' table {')
+end
+
+% </lua>
+% \end{macrocode}
+
+%\endinput
+% Local Variables:
+% mode: LaTeX
+% TeX-master: t
+% TeX-engine: luatex
+% indent-tabs-mode: nil
+% coding: utf-8-unix
+% End:
+% vim:set tabstop=2 expandtab:
diff --git a/Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.ins b/Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.ins
new file mode 100644
index 00000000000..e6258a3a70c
--- /dev/null
+++ b/Master/texmf-dist/source/luatex/luaaddplot/luaaddplot.ins
@@ -0,0 +1,19 @@
+
+% $Id: luaaddplot.ins 2 2022-03-19 23:02:47Z reinhard $
+
+\input docstrip
+
+\nopreamble
+\askforoverwritefalse
+
+\usedir{tex/latex/luaaddplot}
+
+ \generate{\file{luaaddplot.sty}{\from{luaaddplot.dtx}{sty}}}
+
+\usedir{tex/generic/luaaddplot}
+
+ \generate{\file{luaaddplot.tex}{\from{luaaddplot.dtx}{tex}}}
+ \nopostamble
+ \generate{\file{luaaddplot.lua}{\from{luaaddplot.dtx}{lua}}}
+
+\endbatchfile
diff --git a/Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.lua b/Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.lua
new file mode 100644
index 00000000000..3bb75b26970
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.lua
@@ -0,0 +1,60 @@
+-- File 'luaaddplot.lua', generated from luaaddplot.dtx'.
+--[[
+%%
+%% luaaddplot.dtx
+%% Copyright 2022 Reinhard Kotucha <reinhard.kotucha@gmx.net>
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% 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.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `maintained'.
+%%
+%% The Current Maintainer of this work is Reinhard Kotucha.
+%%
+%% This work consists of the files luaaddplot.dtx and luaaddplot.ins
+%% and the derived files luaaddplot.tex, luaaddplot.sty, and luaaddplot.lua.
+--]]
+
+module('luaaddplot', package.seeall)
+
+function readfile (file, lambda)
+ if not lfs.isfile(file) then
+ error('\nERROR: File "'..file..'" not found.')
+ end
+
+ local data = io.open(file)
+
+ for line in data:lines() do
+ line = line:gsub('^%s+', '')
+ if line:match('^%-?%.?[0-9]') then
+ line = line:gsub('[\t:;,]', ' ')
+ local a, b
+ local cols = line:explode (' +')
+ for i, col in ipairs(cols) do
+ cols[i] = tonumber(cols[i])
+ end
+
+ if lambda then
+ a, b = lambda(cols)
+ if a and b then
+ tex.print(string.format('%g %g', a, b))
+ end
+ else
+ tex.print(string.format('%g %g', cols[1], cols[2]))
+ end
+ end
+ end
+ tex.print('};')
+ data:close()
+end
+
+function opts (s)
+ tex.print('\\addplot'..s..' table {')
+end
+
+
diff --git a/Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.sty b/Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.sty
new file mode 100644
index 00000000000..7eb3c3ba18e
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/luaaddplot/luaaddplot.sty
@@ -0,0 +1,23 @@
+%% File 'luaaddplot.sty', generated from luaaddplot.dtx'.
+%%
+%% luaaddplot.dtx
+%% Copyright 2022 Reinhard Kotucha <reinhard.kotucha@gmx.net>
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% 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.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `maintained'.
+%%
+%% The Current Maintainer of this work is Reinhard Kotucha.
+%%
+%% This work consists of the files luaaddplot.dtx and luaaddplot.ins
+%% and the derived files luaaddplot.tex, luaaddplot.sty, and luaaddplot.lua.
+\input luaaddplot.tex
+\endinput
+%%
+%% End of file `luaaddplot.sty'.
diff --git a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
index 49c631b73dd..f3a8569ef1f 100644
--- a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
+++ b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
@@ -30,6 +30,7 @@ depend lua-uni-algos
depend lua-ul
depend lua-visual-debug
depend lua-widow-control
+depend luaaddplot
depend luacensor
depend luacode
depend luacolor
diff --git a/Master/tlpkg/tlpsrc/luaaddplot.tlpsrc b/Master/tlpkg/tlpsrc/luaaddplot.tlpsrc
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/Master/tlpkg/tlpsrc/luaaddplot.tlpsrc