###前提・実現したい事
Texで書いた文章をptex2pdfでタイプセットしたかったのですが、途中で処理が止まってしまい、タイプセットできませんでした。そこでptex2pdfを実行するスクリプトを調べてみると、おそらくos.executeのところでエラーというか0以外(今回は-1)を返してしまっているので、上手く行かないのだと考えました。os.executeについて調べると0以外を返すときはシェルが利用可能な時だと書いてありました。スクリプト自体はTexをインストールした時についてきたものなので間違ってはいないと思います。どうすればptex2pdfでスクリプトが実行できるのかご教授頂けたら幸いです。
###発生している問題・エラーメッセージ
コマンドプロンプトで
ptex2pdf test.tex
と実行すると
This is ptex2pdf[.lua] version 20181212.0. Processing test.tex ptex2pdf processing of test.tex failed.
となり処理が止まります。
###該当のソースコード
lua
1#!/usr/bin/env texlua 2 3function usage() 4 print(USAGE) 5end 6 7function makereadme() 8 print("# " .. NAME .. " #") 9 print() 10 print("**Author:** " .. AUTHOR .. " ") 11 print("**Website:** http://www.preining.info/blog/software-projects/ptex2pdf/ (in Japanese) ") 12 print("**License:** GPLv2") 13 print() 14 print(SHORTDESC) 15 print() 16 print("## Description ##") 17 print() 18 print(LONGDESC) 19 print("## Usage ##") 20 print() 21 print("`````") 22 print(USAGE) 23 print("`````") 24 print() 25 print("## Installation ##") 26 print() 27 print(INSTALLATION) 28 print("## TeXworks setup ##") 29 print() 30 print(TEXWORKS) 31 print() 32 print("## Development place ##") 33 print() 34 print(DEVELPLACE) 35 print() 36 print("## Changelog ##") 37 print() 38 print(CHANGELOG) 39 print("## Copyright and License ##") 40 print() 41 print(LICENSECOPYRIGHT) 42end 43 44function help() 45 print(NAME .. ": " .. SHORTDESC) 46 print() 47 print("Author: " .. AUTHOR) 48 print() 49 print(LONGDESC) 50 print(USAGE) 51end 52 53function fullhelp() 54 help() 55 print("Installation") 56 print("------------") 57 print(INSTALLATION) 58 print("TeXworks setup") 59 print("--------------") 60 print(TEXWORKS) 61 print("Development place") 62 print("-----------------") 63 print(DEVELPLACE) 64 print() 65 print("Copyright and License") 66 print("---------------------") 67 print(LICENSECOPYRIGHT) 68end 69 70function whoami () 71 print("This is " .. NAME .. " version ".. VERSION .. ".") 72end 73 74function print_ifdebug(message) -- for debugging: accepts only one argument 75 --print("DEBUG: " .. message) -- uncomment for debugging 76end 77 78function slashify(str) -- replace "\" with "/", mainly for path strings on cp932 windows 79 return (tostring(str):gsub("[\x81-\x9f\xe0-\xfc]?.", { ["\"] = "/" })) 80end 81 82if #arg == 0 then 83 usage() 84 os.exit(0) 85end 86 87-- defaults: 88tex = "ptex" 89texopts = "" 90dvipdf = "dvipdfmx" 91dvipdfopts = "" 92intermediate = 1 93 94use_eptex = 0 95use_uptex = 0 96use_latex = 0 97outputdir = "." 98prefilename = "" 99filename = "" 100bname = "" 101exit_code = 0 102narg = 1 103repeat 104 this_arg = arg[narg] 105 -- replace double dash by single dash at the beginning 106 this_arg = string.gsub(this_arg, "^%-%-", "-") 107 108 if this_arg == "-v" then 109 whoami() 110 os.exit(0) 111 elseif this_arg == "-readme" then 112 makereadme() 113 os.exit(0) 114 elseif this_arg == "-output-directory" then 115 narg = narg+1 116 outputdir = arg[narg] 117 elseif (string.sub(this_arg, 1, 18) == "-output-directory=") then 118 outputdir = string.sub(this_arg, 19, -1) 119 elseif this_arg == "-print-version" then 120 print(VERSION) 121 os.exit(0) 122 elseif this_arg == "-h" then 123 help() 124 os.exit(0) 125 elseif this_arg == "-help" then 126 fullhelp() 127 os.exit(0) 128 elseif this_arg == "-e" then 129 use_eptex = 1 130 elseif this_arg == "-u" then 131 use_uptex = 1 132 elseif this_arg == "-l" then 133 use_latex = 1 134 elseif this_arg == "-s" then 135 dvipdf = "" 136 elseif this_arg == "-i" then 137 intermediate = 0 138 elseif this_arg == "-ot" then 139 narg = narg+1 140 texopts = arg[narg] 141 elseif (string.sub(this_arg, 1, 4) == "-ot=") then 142 texopts = string.sub(this_arg, 5, -1) 143 elseif this_arg == "-od" then 144 narg = narg+1 145 dvipdfopts = arg[narg] 146 elseif (string.sub(this_arg, 1, 4) == "-od=") then 147 dvipdfopts = string.sub(this_arg, 5, -1) 148 else 149 if filename == "" then 150 filename = this_arg 151 else 152 -- when emacs tex-mode is used, this will help store "\nonstopmode\input" 153 print("Multiple filename arguments? OK, I'll take the latter one.") 154 prefilename = prefilename .. " \"" .. filename .. "\"" 155 filename = this_arg 156 end 157 end --if this_arg == ... 158 narg = narg+1 159until narg > #arg 160 161whoami() 162 163if use_eptex == 1 then 164 if use_uptex == 1 then 165 if use_latex == 1 then 166 tex = "uplatex" -- uplatex already as etex extension 167 else 168 tex = "euptex" 169 end 170 else 171 if use_latex == 1 then 172 tex = "platex" -- latex needs etex anyway 173 else 174 tex = "eptex" 175 end 176 end 177else 178 if use_uptex == 1 then 179 if use_latex == 1 then 180 tex = "uplatex" 181 else 182 tex = "uptex" 183 end 184 else 185 if use_latex == 1 then 186 tex = "platex" 187 else 188 tex = "ptex" 189 end 190 end 191end 192 193-- initialize kpse 194kpse.set_program_name(tex) 195 196-- filename searching 197-- first search for the file as is, 198-- if not found, try file .tex, if that not found, file .ltx 199 200if ( filename == "" ) then 201 print("No filename argument given, exiting.") 202 os.exit(1) 203else 204 filename = slashify(filename) 205 if ( kpse.find_file(filename) == nil ) then 206 -- try .tex extension 207 if ( kpse.find_file(filename .. ".tex") == nil ) then 208 -- last try .ltx 209 if ( kpse.find_file(filename .. ".ltx") == nil ) then 210 print("File cannot be found with kpathsea: ", filename .. "[.tex, .ltx]") 211 os.exit(1) 212 else 213 bname = filename 214 filename = filename .. ".ltx" 215 end 216 else 217 bname = filename 218 filename = filename .. ".tex" 219 end 220 else 221 -- if it has already an extension, we need to drop it to get the dvi name 222 bname = string.gsub(filename, "^(.*)%.[^./]+$", "%1") 223 end 224 -- filename may contain "/", but the intermediate output is written 225 -- in current directory, so we need to drop it 226 -- note that all "\" has been replaced with "/" 227 bname = string.gsub(bname, "^.*/(.*)$", "%1") 228end 229 230-- we are still here, so we found a file 231-- make sure that on Windows/uptex we are using utf8 as command line encoding 232if os.type == 'windows' then 233 if use_uptex == 1 then 234 os.setenv('command_line_encoding', 'utf8') 235 else 236 os.setenv('command_line_encoding', 'none') 237 end 238end 239if (outputdir ~= ".") then 240 texopts = "-output-directory \"" .. outputdir .. "\" " .. texopts 241 bname = outputdir .. "/" .. bname 242 dvipdfopts = "-o \"" .. bname .. ".pdf\"" 243end 244print("Processing ".. filename) 245if (os.execute(tex .. " " .. texopts .. prefilename .. " \"" .. filename .. "\"") == 0) and 246 (dvipdf == "" or (os.execute(dvipdf .. " " .. dvipdfopts .. " \"" .. bname .. ".dvi" .. "\"") == 0)) then 247 if dvipdf ~= "" then 248 print(bname .. ".pdf generated by " .. dvipdf .. ".") 249 end 250 if intermediate == 1 then -- clean-up: 251 if dvipdf ~= "" then 252 os.remove( bname .. ".dvi" ) 253 end 254 end 255else 256 print("ptex2pdf processing of " .. filename .. " failed.\n") 257 print_ifdebug("tex = " .. tex) 258 print_ifdebug("dvipdf = " .. dvipdf) 259 os.exit(2) 260end 261 262-- all done ... exit with success 263os.exit( 0 ) 264 265 266 267-- Local Variables: 268-- lua-indent-level: 2 269-- tab-width: 2 270-- indent-tabs-mode: nil 271-- End: 272-- vim:set tabstop=2 expandtab: #
###試したこと
一応コマンドプロンプトで
platex test.tex dvipdfmx test.dvi
とコマンドを分けて打つと上手く行きます。
ptex2pdfでまとめてやろうとすると、処理が止まります。
###Texのソースコード
%!TEX encoding = UTF-8 % ビルドレシピは「pLaTeX」を選択する \documentclass[11pt,a4j]{jsbook} \begin{document} \chapter{はじめに} \section{げぇ要} これは \LaTeX が Visual Studio Code でビルドできるかどうかのテスト文章である。 \chapter{おわりに} これが表示されていれば成功である。 \end{document}
###補足
TexLive2019
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/13 06:10 編集
2020/01/13 09:00
2020/01/13 11:51
2020/01/13 12:25