Debian Codegraph @

texmf-dist/tex/luatex/luaaddplot/luaaddplot.lua

raw
1 -- File 'luaaddplot.lua', generated from luaaddplot.dtx'.
2 --[[
3 %%
4 %% luaaddplot.dtx
5 %% Copyright 2022 Reinhard Kotucha <[email protected]>
6 %%
7 %% This work may be distributed and/or modified under the
8 %% conditions of the LaTeX Project Public License, either version 1.3
9 %% of this license or (at your option) any later version.
10 %% The latest version of this license is in
11 %% http://www.latex-project.org/lppl.txt
12 %% and version 1.3 or later is part of all distributions of LaTeX
13 %% version 2005/12/01 or later.
14 %%
15 %% This work has the LPPL maintenance status `maintained'.
16 %%
17 %% The Current Maintainer of this work is Reinhard Kotucha.
18 %%
19 %% This work consists of the files luaaddplot.dtx and luaaddplot.ins
20 %% and the derived files luaaddplot.tex, luaaddplot.sty, and luaaddplot.lua.
21 --]]
22
23 module('luaaddplot', package.seeall)
24
25 function readfile (file, lambda)
26 if not lfs.isfile(file) then
27 error('\nERROR: File "'..file..'" not found.')
28 end
29
30 local data = io.open(file)
31
32 for line in data:lines() do
33 line = line:gsub('^%s+', '')
34 if line:match('^%-?%.?[0-9]') then
35 line = line:gsub('[\t:;,]', ' ')
36 local a, b
37 local cols = line:explode (' +')
38 for i, col in ipairs(cols) do
39 cols[i] = tonumber(cols[i])
40 end
41
42 if lambda then
43 a, b = lambda(cols)
44 if a and b then
45 tex.print(string.format('%g %g', a, b))
46 end
47 else
48 tex.print(string.format('%g %g', cols[1], cols[2]))
49 end
50 end
51 end
52 tex.print('};')
53 data:close()
54 end
55
56 function opts (s)
57 tex.print('\\addplot'..s..' table {')
58 end
59
60