-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2pdf.lua
More file actions
executable file
·39 lines (30 loc) · 1.35 KB
/
2pdf.lua
File metadata and controls
executable file
·39 lines (30 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env luajit
package.path = (arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)")) .. "lib" .. package.config:sub(1, 1) .. "?.lua;" .. package.path
local utility = require "utility"
local argparse = utility.require("argparse")
local parser = argparse():description("Converts everything in the local directory to pdf, placed in \"./2pdf-output\".")
local options = parser:parse()
if utility.OS == "Windows" then
local config = utility.get_config()
if not (config["2pdf.lua"] and config["2pdf.lua"].first_run) then
print("The first time pandoc is run on Windows, a dialog box may open.")
print(" If it does, uncheck \"always show this\" and click \"Install\".")
print("Press enter to continue. This warning will not appear again.")
io.read("*line")
config["2pdf.lua"] = config["2pdf.lua"] or {}
config["2pdf.lua"].first_run = true
utility.save_config()
end
end
utility.required_program("pandoc")
utility.required_program("xelatex")
local for_files = utility.ls()
os.execute("mkdir 2pdf-output")
for_files(function(file_name)
if file_name == "." or file_name == ".." then return end
local _, name, extension = utility.split_path_components(file_name)
if extension then
name = name:sub(1, -(#extension + 2))
end
os.execute("pandoc --pdf-engine xelatex \"" .. file_name .. "\" -o \"2pdf-output/" .. name .. ".pdf\"")
end)