I have a file structured like this: we can call it input.tex
begin{document}
import{./}{Capitolo1.tex}
import{./}{Capitolo2.tex}
end{document}
Using this function I can perform a serger operation, replacing the import command with the content of the desired file (Chapter 1, Chapter 2)
function search_for_import(tex)
print(tex)
local temp= tex..".mirror"
local tbl = {}
for j = 1, #rows_from(tex) do
if string.sub(rows[j],1,7) == "\import" then
table.insert(tbl,{
[1] = j,
[2] = string.sub(rows[j],13,-2),
})
print(string.sub(rows[j],13,-2))
search_for_import(string.sub(rows[j],13,-2))
end
end
if #tbl > 0 then
temp = tex..".mirror"
io.output(temp)
local line
row = rows_from(tex)
print(#row)
for i = 1, #row do
line = row[i]
for key, value in pairs(tbl) do
if i == value[1] then
print(value[2])
line = row[i+1]
for j = 1, #rows_from(value[2]) do
io.write(rows_from(value[2])[j], "n")
end
end
end
io.write(line, "n")
end
io.close()
end
os.execute("move "..temp.." "..tex)
end
This function works fine. But what if the imported file itself had an import command? My attempt is to use the recursive function
for j = 1, #rows_from(tex) do
if string.sub(rows[j],1,7) == "\import" then
table.insert(tbl,{
[1] = j,
[2] = string.sub(rows[j],13,-2),
})
print(string.sub(rows[j],13,-2))
search_for_import(string.sub(rows[j],13,-2)) --this
end
end
But this end with an infinite loop.
Ant ideas?