summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-10-09 21:44:19 +0000
committerKarl Berry <karl@freefriends.org>2018-10-09 21:44:19 +0000
commitf3266b6d92494d20f968cba7b17804fddc8ac409 (patch)
tree7a5db15bd3ed22c8b2b79b67bf7046dd1d281b83 /Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua
parent65e4272f74f437a899e7dd52c5ab52501dca02db (diff)
cluttex (9oct18)
git-svn-id: svn://tug.org/texlive/trunk@48871 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua')
-rw-r--r--Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua71
1 files changed, 71 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua b/Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua
new file mode 100644
index 00000000000..0c69eefd136
--- /dev/null
+++ b/Master/texmf-dist/doc/support/cluttex/src/texrunner/auxfile.lua
@@ -0,0 +1,71 @@
+--[[
+ Copyright 2016 ARATA Mizuki
+
+ This file is part of ClutTeX.
+
+ ClutTeX is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ClutTeX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ClutTeX. If not, see <http://www.gnu.org/licenses/>.
+]]
+
+local string_match = string.match
+local pathutil = require "texrunner.pathutil"
+local filesys = require "lfs"
+local fsutil = require "texrunner.fsutil"
+local message = require "texrunner.message"
+
+-- for LaTeX
+local function parse_aux_file(auxfile, outdir, report, seen)
+ report = report or {}
+ seen = seen or {}
+ seen[auxfile] = true
+ for l in io.lines(auxfile) do
+ local subauxfile = string_match(l, "\\@input{(.+)}")
+ if subauxfile then
+ if fsutil.isfile(subauxfile) then
+ parse_aux_file(pathutil.join(outdir, subauxfile), outdir, report, seen)
+ else
+ local dir = pathutil.join(outdir, pathutil.dirname(subauxfile))
+ if not fsutil.isdir(dir) then
+ assert(fsutil.mkdir_rec(dir))
+ report.made_new_directory = true
+ end
+ end
+ end
+ end
+ return report
+end
+
+-- \citation, \bibdata, \bibstyle and \@input
+local function extract_bibtex_from_aux_file(auxfile, outdir, biblines)
+ biblines = biblines or {}
+ for l in io.lines(auxfile) do
+ local name = string_match(l, "\\([%a@]+)")
+ if name == "citation" or name == "bibdata" or name == "bibstyle" then
+ table.insert(biblines, l)
+ if CLUTTEX_VERBOSITY >= 2 then
+ message.info("BibTeX line: ", l)
+ end
+ elseif name == "@input" then
+ local subauxfile = string_match(l, "\\@input{(.+)}")
+ if subauxfile and fsutil.isfile(subauxfile) then
+ extract_bibtex_from_aux_file(pathutil.join(outdir, subauxfile), outdir, biblines)
+ end
+ end
+ end
+ return biblines
+end
+
+return {
+ parse_aux_file = parse_aux_file,
+ extract_bibtex_from_aux_file = extract_bibtex_from_aux_file,
+}