| 1 |
structure TeXEngine : sig |
| 2 |
type engine_type |
| 3 |
type run_options = { engine_executable : string option |
| 4 |
, halt_on_error : bool |
| 5 |
, interaction : InteractionMode.interaction option |
| 6 |
, file_line_error : bool |
| 7 |
, synctex : string option |
| 8 |
, shell_escape : ShellEscape.shell_escape option |
| 9 |
, jobname : string option |
| 10 |
, output_directory : string option |
| 11 |
, extra_options : string list |
| 12 |
, output_format : OutputFormat.format |
| 13 |
, draftmode : bool (* pdfTeX / XeTeX / LuaTeX *) |
| 14 |
, fmt : string option |
| 15 |
, lua_initialization_script : string option (* LuaTeX only *) |
| 16 |
} |
| 17 |
type engine = { name : string |
| 18 |
, executable : string |
| 19 |
, supports_pdf_generation : bool |
| 20 |
, dvi_extension : string |
| 21 |
, supports_draftmode : bool |
| 22 |
, engine_type : engine_type |
| 23 |
} |
| 24 |
val isLuaTeX : engine -> bool |
| 25 |
val isPdfTeX : engine -> bool |
| 26 |
val isXeTeX : engine -> bool |
| 27 |
val buildCommand : engine * string * run_options -> string |
| 28 |
val get : string -> engine option |
| 29 |
end = struct |
| 30 |
datatype engine_type = PDFTEX | XETEX | LUATEX | OTHER |
| 31 |
type run_options = { engine_executable : string option |
| 32 |
, halt_on_error : bool |
| 33 |
, interaction : InteractionMode.interaction option |
| 34 |
, file_line_error : bool |
| 35 |
, synctex : string option |
| 36 |
, shell_escape : ShellEscape.shell_escape option |
| 37 |
, jobname : string option |
| 38 |
, output_directory : string option |
| 39 |
, extra_options : string list |
| 40 |
, output_format : OutputFormat.format |
| 41 |
, draftmode : bool (* pdfTeX / XeTeX / LuaTeX *) |
| 42 |
, fmt : string option |
| 43 |
, lua_initialization_script : string option (* LuaTeX only *) |
| 44 |
} |
| 45 |
type engine = { name : string |
| 46 |
, executable : string |
| 47 |
, dvi_extension : string |
| 48 |
, supports_pdf_generation : bool |
| 49 |
, supports_draftmode : bool |
| 50 |
, engine_type : engine_type |
| 51 |
} |
| 52 |
fun isLuaTeX ({ engine_type, ... } : engine) = engine_type = LUATEX |
| 53 |
fun isPdfTeX ({ engine_type, ... } : engine) = engine_type = PDFTEX |
| 54 |
fun isXeTeX ({ engine_type, ... } : engine) = engine_type = XETEX |
| 55 |
fun buildCommand (engine : engine, inputline, options : run_options) |
| 56 |
= let val executable = Option.getOpt (#engine_executable options, #executable engine) |
| 57 |
val revCommand = ["-recorder", executable] |
| 58 |
val revCommand = case #fmt options of |
| 59 |
NONE => revCommand |
| 60 |
| SOME fmt => "-fmt=" ^ fmt :: revCommand |
| 61 |
val revCommand = case #halt_on_error options of |
| 62 |
false => revCommand |
| 63 |
| true => "-halt-on-error" :: revCommand |
| 64 |
val revCommand = case #interaction options of |
| 65 |
NONE => revCommand |
| 66 |
| SOME mode => "-interaction=" ^ InteractionMode.toString mode :: revCommand |
| 67 |
val revCommand = case #file_line_error options of |
| 68 |
false => revCommand |
| 69 |
| true => "-file-line-error" :: revCommand |
| 70 |
val revCommand = case #synctex options of |
| 71 |
NONE => revCommand |
| 72 |
| SOME synctex => "-synctex=" ^ ShellUtil.escape synctex :: revCommand |
| 73 |
val revCommand = case #shell_escape options of |
| 74 |
NONE => revCommand |
| 75 |
| SOME ShellEscape.FORBIDDEN => "-no-shell-escape" :: revCommand |
| 76 |
| SOME ShellEscape.RESTRICTED => "-shell-restricted" :: revCommand |
| 77 |
| SOME ShellEscape.ALLOWED => "-shell-escape" :: revCommand |
| 78 |
val revCommand = case #jobname options of |
| 79 |
NONE => revCommand |
| 80 |
| SOME jobname => "-jobname=" ^ ShellUtil.escape jobname :: revCommand |
| 81 |
val revCommand = case #output_directory options of |
| 82 |
NONE => revCommand |
| 83 |
| SOME dir => "-output-directory=" ^ ShellUtil.escape dir :: revCommand |
| 84 |
val revCommand = case #engine_type engine of |
| 85 |
OTHER => revCommand |
| 86 |
| PDFTEX => let val revCommand = if #draftmode options then |
| 87 |
"-draftmode" :: revCommand |
| 88 |
else |
| 89 |
revCommand |
| 90 |
in case #output_format options of |
| 91 |
OutputFormat.DVI => "-output-format=dvi" :: revCommand |
| 92 |
| OutputFormat.PDF => revCommand |
| 93 |
end |
| 94 |
| XETEX => if #draftmode options orelse #output_format options = OutputFormat.DVI then |
| 95 |
"-no-pdf" :: revCommand |
| 96 |
else |
| 97 |
revCommand |
| 98 |
| LUATEX => let val revCommand = case #lua_initialization_script options of |
| 99 |
NONE => revCommand |
| 100 |
| SOME script => "--lua=" ^ ShellUtil.escape script :: revCommand |
| 101 |
val revCommand = if #draftmode options then |
| 102 |
"--draftmode" :: revCommand |
| 103 |
else |
| 104 |
revCommand |
| 105 |
in case #output_format options of |
| 106 |
OutputFormat.DVI => "--output-format=dvi" :: revCommand |
| 107 |
| OutputFormat.PDF => revCommand |
| 108 |
end |
| 109 |
val revCommand = List.revAppend (#extra_options options, revCommand) |
| 110 |
val revCommand = ShellUtil.escape inputline :: revCommand |
| 111 |
in String.concatWith " " (List.rev revCommand) |
| 112 |
end |
| 113 |
val pdftex_or_pdflatex = { supports_pdf_generation = true |
| 114 |
, dvi_extension = "dvi" |
| 115 |
, supports_draftmode = true |
| 116 |
, engine_type = PDFTEX |
| 117 |
} |
| 118 |
val pdftex : engine = { name = "pdftex", executable = "pdftex", ... = pdftex_or_pdflatex } |
| 119 |
val pdflatex : engine = { name = "pdflatex", executable = "pdflatex", ... = pdftex_or_pdflatex } |
| 120 |
val luatex_or_lualatex = { supports_pdf_generation = true |
| 121 |
, dvi_extension = "dvi" |
| 122 |
, supports_draftmode = true |
| 123 |
, engine_type = LUATEX |
| 124 |
} |
| 125 |
val luatex : engine = { name = "luatex", executable = "luatex", ... = luatex_or_lualatex } |
| 126 |
val lualatex : engine = { name = "lualatex", executable = "lualatex", ... = luatex_or_lualatex } |
| 127 |
val luajittex : engine = { name = "luajittex", executable = "luajittex", ... = luatex_or_lualatex } |
| 128 |
val xetex_or_xelatex = { supports_pdf_generation = true |
| 129 |
, dvi_extension = "xdv" |
| 130 |
, supports_draftmode = true |
| 131 |
, engine_type = XETEX |
| 132 |
} |
| 133 |
val xetex : engine = { name = "xetex", executable = "xetex", ... = xetex_or_xelatex } |
| 134 |
val xelatex : engine = { name = "xelatex", executable = "xelatex", ... = xetex_or_xelatex } |
| 135 |
val other_engine = { supports_pdf_generation = false |
| 136 |
, dvi_extension = "dvi" |
| 137 |
, supports_draftmode = false |
| 138 |
, engine_type = OTHER |
| 139 |
} |
| 140 |
val tex : engine = { name = "tex", executable = "tex", ... = other_engine } |
| 141 |
val etex : engine = { name = "etex", executable = "etex", ... = other_engine } |
| 142 |
val latex : engine = { name = "latex", executable = "latex", ... = other_engine } |
| 143 |
val ptex : engine = { name = "ptex", executable = "ptex", ... = other_engine } |
| 144 |
val eptex : engine = { name = "eptex", executable = "eptex", ... = other_engine } |
| 145 |
val platex : engine = { name = "platex", executable = "platex", ... = other_engine } |
| 146 |
val uptex : engine = { name = "uptex", executable = "uptex", ... = other_engine } |
| 147 |
val euptex : engine = { name = "euptex", executable = "euptex", ... = other_engine } |
| 148 |
val uplatex : engine = { name = "uplatex", executable = "uplatex", ... = other_engine } |
| 149 |
fun get "pdftex" = SOME pdftex |
| 150 |
| get "pdflatex" = SOME pdflatex |
| 151 |
| get "luatex" = SOME luatex |
| 152 |
| get "lualatex" = SOME lualatex |
| 153 |
| get "luajittex" = SOME luajittex |
| 154 |
| get "xetex" = SOME xetex |
| 155 |
| get "xelatex" = SOME xelatex |
| 156 |
| get "tex" = SOME tex |
| 157 |
| get "etex" = SOME etex |
| 158 |
| get "latex" = SOME latex |
| 159 |
| get "ptex" = SOME ptex |
| 160 |
| get "eptex" = SOME eptex |
| 161 |
| get "platex" = SOME platex |
| 162 |
| get "uptex" = SOME uptex |
| 163 |
| get "euptex" = SOME euptex |
| 164 |
| get "uplatex" = SOME uplatex |
| 165 |
| get _ = NONE |
| 166 |
end; |