Last active
December 21, 2015 09:09
-
-
Save akafael/6283303 to your computer and use it in GitHub Desktop.
Conjunto de Macros usando o Lua e Latex para montar tabelas e figuras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% use lualatex to compile | |
%% \luaTable{'numberOfColumns'}{'dataFile.dat'}{'legend'} | |
%% {'First Line of table (title)'} | |
\usepackage{luacode} %% Package to use the enviroment luacode | |
\begin{luacode} | |
numC = 3 | |
function readfileDat(filename) | |
local filename = "../data/"..filename | |
for line in io.lines(filename) do | |
local numl = {} | |
for n in string.gmatch(line,"[\%d\%.]+") do | |
numl[#numl+1] = tostring(n) | |
end | |
numC = #numl -- rever esta parte | |
tex.sprint(table.concat(numl," & "),"\\\\") | |
end | |
end | |
function readfileDat0(filename) | |
local tableData = {} | |
tableData,numC = readfileDat0(filename) | |
tex.sprint(table.concat(tableData,"\\\\")) | |
end | |
\end{luacode} | |
\newcommand{\luaTable}[5][\directlua{tex.print(numC)}] | |
{ | |
\begin{table}[H] | |
\centering | |
\label{#4} | |
\caption{#3} | |
\begin{tabular}{*{#1}{c}} | |
\hline | |
#5\\ | |
\hline | |
\directlua{readfileDat('#2')} | |
\hline | |
\end{tabular} | |
\end{table} | |
} | |
% Sample: | |
% \luaTable[3]{teste.dat}{legenda}{x&y&z} | |
% ----------------------------------------------------------------- | |
\newcounter{cGraph} | |
\setcounter{cGraph}{1} | |
\newcommand{\plotedFigure}[2][\thecGraph]{ | |
\begin{figure}[H] | |
\centering | |
\label{fig:g#1} | |
\includegraphics[width=10cm]{../image/graph#1.png} | |
\caption{#2} | |
\end{figure} | |
\stepcounter{cGraph} | |
} | |
% Sample: | |
% \plotedFigure{numberOfGraph}{'legend'} | |
% ----------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a macro for LuaLatex to build formatted tables by .dat files