Added a lua helper function to fix the csv file.
This commit is contained in:
parent
4d7001ea40
commit
a063d278a6
1
.gitignore
vendored
1
.gitignore
vendored
@ -305,6 +305,7 @@ TSWLatexianTemp*
|
|||||||
*.csv
|
*.csv
|
||||||
*.tsv
|
*.tsv
|
||||||
*.xlsl
|
*.xlsl
|
||||||
|
*.zip
|
||||||
|
|
||||||
# Silence
|
# Silence
|
||||||
*.sil
|
*.sil
|
||||||
|
|||||||
95
csv_fixer.lua
Normal file
95
csv_fixer.lua
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
local input = arg[1]
|
||||||
|
local output = arg[2]
|
||||||
|
|
||||||
|
local f = assert(io.open(input, "r"))
|
||||||
|
local s = f:read("*a")
|
||||||
|
f:close()
|
||||||
|
|
||||||
|
local delim = ","
|
||||||
|
local out, row = {}, {}
|
||||||
|
local i, n = 1, #s
|
||||||
|
|
||||||
|
local function csv_escape(cell)
|
||||||
|
local needs_quotes =
|
||||||
|
cell:find(delim, 1, true) or cell:find('"', 1, true) or
|
||||||
|
cell:find("\\ ", 1, true) or cell:find("[\r\n]", 1, true)
|
||||||
|
if needs_quotes then
|
||||||
|
cell = cell:gsub('"','""')
|
||||||
|
return '"' .. cell .. '"'
|
||||||
|
end
|
||||||
|
return cell
|
||||||
|
end
|
||||||
|
|
||||||
|
local function push_cell(cell) row[#row+1] = cell end
|
||||||
|
local function end_row() out[#out+1] = row; row = {} end
|
||||||
|
|
||||||
|
while i <= n do
|
||||||
|
local c = s:sub(i,i)
|
||||||
|
|
||||||
|
if c == '"' then
|
||||||
|
i = i + 1
|
||||||
|
local buf = {}
|
||||||
|
while i <= n do
|
||||||
|
c = s:sub(i,i)
|
||||||
|
if c == '"' then
|
||||||
|
local nextc = s:sub(i+1,i+1)
|
||||||
|
if nextc == '"' then
|
||||||
|
buf[#buf+1] = '"'
|
||||||
|
i = i + 2
|
||||||
|
else
|
||||||
|
i = i + 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
else
|
||||||
|
buf[#buf+1] = c
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local cell = table.concat(buf)
|
||||||
|
cell = cell:gsub("\r\n","\\\\{}")
|
||||||
|
cell = cell:gsub("\n","\\\\{}")
|
||||||
|
cell = cell:gsub("\r","\\\\{}")
|
||||||
|
push_cell(cell)
|
||||||
|
|
||||||
|
local c2 = s:sub(i,i)
|
||||||
|
if c2 == delim then i = i + 1
|
||||||
|
elseif c2 == "\n" then i = i + 1; end_row()
|
||||||
|
elseif c2 == "\r" then
|
||||||
|
if s:sub(i+1,i+1) == "\n" then i = i + 2 else i = i + 1 end
|
||||||
|
end_row()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local buf = {}
|
||||||
|
while i <= n do
|
||||||
|
c = s:sub(i,i)
|
||||||
|
if c == delim or c == "\n" or c == "\r" then break end
|
||||||
|
buf[#buf+1] = c
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
local cell = table.concat(buf)
|
||||||
|
cell = cell:gsub("\r\n","\\\\{}")
|
||||||
|
cell = cell:gsub("\n","\\\\{}")
|
||||||
|
cell = cell:gsub("\r","\\\\{}")
|
||||||
|
push_cell(cell)
|
||||||
|
|
||||||
|
if i <= n and s:sub(i,i) == delim then i = i + 1
|
||||||
|
elseif i <= n and s:sub(i,i) == "\n" then i = i + 1; end_row()
|
||||||
|
elseif i <= n and s:sub(i,i) == "\r" then
|
||||||
|
if s:sub(i+1,i+1) == "\n" then i = i + 2 else i = i + 1 end
|
||||||
|
end_row()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #row > 0 then end_row() end
|
||||||
|
|
||||||
|
local fo = assert(io.open(output, "w"))
|
||||||
|
for r = 1, #out do
|
||||||
|
local cells = out[r]
|
||||||
|
for k = 1, #cells do
|
||||||
|
if k > 1 then fo:write(delim) end
|
||||||
|
fo:write(csv_escape(cells[k] or ""))
|
||||||
|
end
|
||||||
|
if r < #out then fo:write("\n") end
|
||||||
|
end
|
||||||
|
fo:close()
|
||||||
22
main.tex
22
main.tex
@ -18,10 +18,12 @@
|
|||||||
% includefoot, % Incluir el pie en el área del texto
|
% includefoot, % Incluir el pie en el área del texto
|
||||||
}
|
}
|
||||||
|
|
||||||
\usepackage[main=spanish,es-noshorthands,es-lcroman]{babel} % selecciona idioma
|
\usepackage[spanish,es-noshorthands,es-lcroman]{babel} % selecciona idioma
|
||||||
\usepackage[autostyle=true]{csquotes}
|
\usepackage[autostyle=true]{csquotes}
|
||||||
|
|
||||||
%------ Paquetes base
|
%------ Paquetes base
|
||||||
|
% amsmath tiene que cargarse antes que cleverref, y datatool lo requiere
|
||||||
|
\usepackage{amsmath, mathtools}
|
||||||
\usepackage{datetime}
|
\usepackage{datetime}
|
||||||
\usepackage{xcolor}
|
\usepackage{xcolor}
|
||||||
|
|
||||||
@ -39,20 +41,28 @@
|
|||||||
|
|
||||||
% Leer datos de csv
|
% Leer datos de csv
|
||||||
\usepackage{datatool}
|
\usepackage{datatool}
|
||||||
\DTLloaddb{propuestas}{propuestas.csv}
|
|
||||||
\DTLsetup{
|
\DTLsetup{
|
||||||
io = {
|
io = {
|
||||||
delimiter = {"},
|
delimiter = {"},
|
||||||
separator = {,},
|
separator = {,},
|
||||||
format = {csv},
|
format = {csv},
|
||||||
csv-content = no-parse
|
csv-content = tex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
% Código de Lua que preprocesa el csv para eliminar saltos de línea
|
||||||
|
\directlua{
|
||||||
|
arg = {"propuestas.csv","propuestas_fixed.csv"}
|
||||||
|
dofile("csv_fixer.lua")
|
||||||
|
}
|
||||||
|
|
||||||
|
\DTLloaddb{propuestas}{propuestas_fixed.csv}
|
||||||
|
|
||||||
|
|
||||||
\hypersetup{pdfauthor={Despacho tórico y amigos},
|
\hypersetup{pdfauthor={Despacho tórico y amigos},
|
||||||
pdftitle={Temas para los Seminarios Borromeos, Edición 2026--2027},
|
pdftitle={Propuestas de temas para los Seminarios Borromeos, Edición 2026--2027},
|
||||||
pdflang=es}
|
pdflang=es}
|
||||||
\title{\Large{\textbf{Temas para los Seminarios Borromeos}\\{Edición 2026--2027}}}
|
\title{\Large{\textbf{Propuestas de temas para los Seminarios Borromeos}\\{Edición 2026--2027}}}
|
||||||
\author{Despacho tórico y amigos}
|
\author{Despacho tórico y amigos}
|
||||||
|
|
||||||
\newdate{today}{\day}{\month}{\year} %\today
|
\newdate{today}{\day}{\month}{\year} %\today
|
||||||
@ -104,7 +114,7 @@
|
|||||||
|
|
||||||
\item[Otras observaciones] \myothers
|
\item[Otras observaciones] \myothers
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
||||||
\newpage
|
\newpage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user