diff --git a/.gitignore b/.gitignore index fe9bea0..79b20f8 100644 --- a/.gitignore +++ b/.gitignore @@ -305,6 +305,7 @@ TSWLatexianTemp* *.csv *.tsv *.xlsl +*.zip # Silence *.sil diff --git a/csv_fixer.lua b/csv_fixer.lua new file mode 100644 index 0000000..0d60f41 --- /dev/null +++ b/csv_fixer.lua @@ -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() diff --git a/main.tex b/main.tex index e34c691..31b0cff 100644 --- a/main.tex +++ b/main.tex @@ -18,10 +18,12 @@ % 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} %------ Paquetes base +% amsmath tiene que cargarse antes que cleverref, y datatool lo requiere +\usepackage{amsmath, mathtools} \usepackage{datetime} \usepackage{xcolor} @@ -39,20 +41,28 @@ % Leer datos de csv \usepackage{datatool} -\DTLloaddb{propuestas}{propuestas.csv} \DTLsetup{ io = { delimiter = {"}, separator = {,}, 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}, - pdftitle={Temas para los Seminarios Borromeos, Edición 2026--2027}, + pdftitle={Propuestas de temas para los Seminarios Borromeos, Edición 2026--2027}, 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} \newdate{today}{\day}{\month}{\year} %\today @@ -104,7 +114,7 @@ \item[Otras observaciones] \myothers \end{description} - + \newpage }