0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.145.152.49


Current Path : /proc/self/root/usr/bin/X11/X11/X11/
Upload File :
Current File : //proc/self/root/usr/bin/X11/X11/X11/tex4ebook

#!/usr/bin/env texlua
-- Package tex4ebook. Author Michal Hoftich <michal.h21@gmail.com>
-- This package is subject of LPPL license, version 1.3 
--
kpse.set_program_name("luatex")
require("lapp-mk4")
-- require("ebookutils")
local ebookutils = require "mkutils"
local mkparams = require "mkparams"

-- Setting
local latex_cmd="latex"
local copy_cmd="copy"
local move_cmd="move"
local env_param="%%" 
local htlatex_call=""
-- These correspond to htlatex parameters
local tex4ht_sty_par=""
local tex4ht_par=""
local t4ht_par=""
local latex_par=""
local output_formats={epub=true,mobi=true,epub3=true}
local executor=nil
local tidy = false
local include_fonts = false
local arg_message = [[
tex4ebook - ebook generation support for LaTeX
Usage:
tex4ebook [switches] filename ["tex4ht.sty op." "tex4ht op." "t4ht op" "latex op"]
-c,--config (default xhtml) Custom config file
-e,--build-file (default nil)  If build file is different than `filename`.mk4
-f,--format (default epub) Output format. Supported values: epub, epub3, mobi
-h,--help  Display help message
-l,--lua  Runs htlualatex instead of htlatex
-m,--mode (default default) Switch which can be used in the makefile
-r,--resolution (default 167)
-s,--shell-escape  Enable shell escape in htlatex run
-t,--tidy Run html tidy on html output. May result in wrong spacing!
-v,--version  Display version number
<filename> (string) Input file name
]]

-- This option is no longer available, all files must be unicode
-- -u,--utf8 
local args=lapp(arg_message)

if args["filename"] == nil and args["version"] == false then
  print(arg_message) 
  return
else
  input_file=args["filename"]
end

if args.version then
  print "tex4ebook v0.1e"
  return 
end

if args.lua then
  latex_cmd="dvilualatex"
end


if args["shell-escape"] then 
  latex_par = latex_par .. " -shell-escape"
end

if args["include-fonts"] then 
  include_fonts = true
end

-- local mathml = ","
-- if args["mathml"] then
--   -- mathml = ",mathml,"
--   tex4ht_sty_par = tex4ht_sty_par .. ",mathml"
-- end
local   mode = args.mode or "default"

if os.type=="unix" then
  env_param="$"
  copy_cmd="cp"
  move_cmd="mv"
  t4ht_dir_format="%s/"
else 
  env_param="%%"
  copy_cmd="copy"
  move_cmd="move"
  t4ht_dir_format="%s"
end

if args.tidy then 
  tidy = true
else
  tidy = false
end
-- Env file copying 

--[[if not ebookutils.file_exists("tex4ht.env") then
local env_file = kpse.find_file("epub2.env")
ebookutils.copy_filter(env_file,"tex4ht.env",function(s) return s % {
move = move_cmd,
copy = copy_cmd,
resolution = args.resolution
} end)
end--]]

--print ("nazdar ${world}" % {world="svete"})
--print(args.config)

local input = ebookutils.remove_extension(input_file)
local config=ebookutils.remove_extension(args.config)
-- local tex4ht_sty_par = config ..tex4ht_sty_par..","+args.format
--local sty_args =  args[2] and ", " .. args[2]  or ""
local sty_args = ""
if args[2] then 
  sty_args = "," .. args[2]
end
local tex4ht_sty_par = tex4ht_sty_par + sty_args --args[2]
local tex4ht_par = tex4ht_par +args[3]
local t4ht_par = t4ht_par + args[4]
local latex_par = latex_par + args[5]

-- use default parameter processing from make4ht
-- add some needed args
args.filename=input_file
local params = mkparams.process_args(args)

-- but also support tex4ebook!s own parameters
local oldparams = {
  -- htlatex=latex_cmd
  -- ,input=input 
  -- ,tex_file = tex_file
  format=args.format
  -- ,latex_par=latex_par
  -- ,tex4ht_sty_par=tex4ht_sty_par
  -- ,tex4ht_par=tex4ht_par
  -- ,t4ht_par=t4ht_par
  -- ,mode = mode
  ,t4ht_dir_format=t4ht_dir_format
  ,tidy = tidy
  ,include_fonts = include_fonts
  ,resolution=args.resolution
  ,mathml=mathml
  ,packages="\\RequirePackage{tex4ebook}"
}  

-- extend params
for k,v in pairs(oldparams) do
  params[k] = v
end

params.tex4ht_sty_par=params.tex4ht_sty_par .. ",charset=utf-8,"..args.format
params.tex4ht_par= " -cmozhtf -utf8" .. params.tex4ht_par

if output_formats[args.format] then
  executor=require("exec_"..args.format)
  params=executor.prepare(params)
else
  print("Unknown output format: "..args.format)
  return
end

local build_file = input.. ".mk4"

if args["build-file"] and args["build-file"] ~= "nil"  then 
	build_file = args["build-file"] 
end

local config_file = ebookutils.load_config(params, build_file)

params["config_file"] = config_file
--config_file.Make:run()
print("${htlatex} ${input} \"${tex4ht_sty_par}\" \"${tex4ht_par}\" \"${t4ht_par}\" \"${latex_par}\"" % params)
executor.run(input,params)
executor.writeContainer()
executor.clean()
--print(args[1])