generator.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. global $options;
  3. global $preamble;
  4. $preamble = "";
  5. global $existing_commands;
  6. global $included_usepackages;
  7. $included_usepackages = [];
  8. global $additional_usepackages;
  9. $additional_usepackages = [];
  10. $steps = 10;
  11. function user_consent($msg,$defaultyes = null,$defaultno = null)
  12. {
  13. global $options;
  14. if (isset($options["-n"]))
  15. return false;
  16. if ($defaultyes !== null && isset($options[$defaultyes]))
  17. return true;
  18. if ($defaultno !== null && isset($options[$defaultno]))
  19. return false;
  20. $response = false;
  21. do
  22. {
  23. echo "$msg (y/n)\n";
  24. $response = rtrim(fgets(STDIN));
  25. if ($response === "n" || $response == "N")
  26. return false;
  27. } while ($response !== "y" && $response !== "Y" && $response !== "");
  28. return true;
  29. }
  30. function user_prompt($msg,$default)
  31. {
  32. global $options;
  33. echo "$msg [Default: $default]\n";
  34. $response = "";
  35. if (!isset($options["-n"]))
  36. $response = rtrim(fgets(STDIN));
  37. if ($response == "")
  38. $response = $default;
  39. echo "You entered: '$response'\n";
  40. return $response;
  41. }
  42. function print_help()
  43. {
  44. $name = basename(__FILE__);
  45. echo<<<END
  46. Usage: php $name /path/folder1/main.tex /path/folder2/article.tex ... /path/folderN/paper.tex\n
  47. Generate a thesis template from the provided paper tex files and folders.
  48. The absolute minimum for a cumulative thesis is currently 3 papers first-authored and 6 in total.
  49. --force-overwrite overwrite files and folders
  50. --no-overwrite do not overwrite files and folders
  51. --no-compile-check do not perform a compile check
  52. --use-backups restore backups before making changes
  53. --not-sloppy disable use of sloppypar around places that struggle without
  54. (mainly the bibliographies)
  55. --cv add a CV
  56. (unusual for PhD theses, required for habilitation theses)
  57. --no-stat-declaration do not add the statutory declaration
  58. (required for PhD thesis, unusual for habilitation theses)
  59. -n skip all prompts (implies --no-overwrite)
  60. --help display this help and exit
  61. END;
  62. exit(0);
  63. }
  64. function error_exit($msg,$usage = false)
  65. {
  66. echo "ERROR: $msg\n";
  67. if ($usage)
  68. echo "Usage: php ".basename(__FILE__)." /path/folder1/main.tex /path/folder2/article.tex ... /path/folderN/paper.tex\n";
  69. exit(-1);
  70. }
  71. function check_software()
  72. {
  73. if (strpos(shell_exec("latexmk --version"),"Latexmk,") === false)
  74. error_exit("latexmk not installed");
  75. if (!str_starts_with(shell_exec("pdftotext --help 2>&1"),"pdftotext version"))
  76. error_exit("pdftotext not installed");
  77. }
  78. function rrmdir($dir) {
  79. if (is_dir($dir)) {
  80. $files = scandir($dir);
  81. foreach ($files as $file)
  82. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  83. rmdir($dir);
  84. }
  85. else if (file_exists($dir)) unlink($dir);
  86. }
  87. function rcopy($src, $dst) {
  88. if (file_exists($dst)) rrmdir($dst);
  89. if (is_dir($src)) {
  90. mkdir($dst);
  91. $files = scandir($src);
  92. foreach ($files as $file)
  93. if ($file != "." && $file != "..") rcopy("$src/$file", "$dst/$file");
  94. }
  95. else if (file_exists($src)) copy($src, $dst);
  96. }
  97. function rscandir($dir,$extensions = []) {
  98. $result = [];
  99. if (!str_ends_with($dir,"/"))
  100. $dir .= "/";
  101. if (str_ends_with($dir,"latex.out/"))
  102. return $result;
  103. $array = scandir($dir);
  104. foreach ($array as $item) {
  105. if (!str_starts_with($item,"."))
  106. {
  107. if (!is_dir($dir.$item))
  108. {
  109. $extension_match = true;
  110. if ($extensions != [])
  111. {
  112. $extension_match = false;
  113. foreach ($extensions as $e)
  114. {
  115. if (str_ends_with($item,"$e"))
  116. {
  117. $extension_match = true;
  118. }
  119. }
  120. }
  121. if ($extension_match)
  122. $result[] = $dir.$item;
  123. }
  124. else
  125. $result = array_merge($result, rscandir($dir.$item,$extensions));
  126. }
  127. }
  128. return $result;
  129. }
  130. function unique_targets($targets)
  131. {
  132. $parts_required = 1;
  133. $unique_targets = [];
  134. while (count($unique_targets) != count($targets))
  135. {
  136. foreach ($targets as $t)
  137. {
  138. $tparts = explode("/",$t);
  139. $tpcount = count($tparts);
  140. $tparts = array_splice($tparts,$tpcount-$parts_required,$parts_required);
  141. $t = implode("_",$tparts);
  142. if (isset($unique_targets[$t]))
  143. {
  144. $parts_required++;
  145. $unique_targets = [];
  146. break;
  147. }
  148. $unique_targets[$t] = 1;
  149. }
  150. }
  151. return array_keys($unique_targets);
  152. }
  153. function check_folders($argv)
  154. {
  155. $args = array_slice($argv,1);
  156. $sourcedirs = [];
  157. foreach ($args as $a)
  158. {
  159. if (!str_starts_with($a,"-"))
  160. $sourcedirs[] = $a;
  161. }
  162. if (count($sourcedirs) < 1)
  163. {
  164. error_exit("Too few papers. Need at least one paper to run this.",true);
  165. }
  166. if (count($sourcedirs) < 3)
  167. {
  168. echo "Warning: Too few papers. The statutes require as an absolute minimum for a cumulative thesis at least 3 first-author papers and at least 6 in total.";
  169. }
  170. if (count($sourcedirs) < 5)
  171. {
  172. echo "Warning: Few papers. Check your institute guidelines to see how many papers are recommended. Also the statutes require as an absolute minimum for a cumulative thesis at least 6 papers in total.";
  173. }
  174. $texfiles = [];
  175. for ($i = 0; $i < count($sourcedirs); $i++)
  176. {
  177. $texfiles[$i] = basename($sourcedirs[$i]);
  178. $sourcedirs[$i] = dirname($sourcedirs[$i]);
  179. }
  180. $targets = unique_targets($sourcedirs);
  181. return [$targets,$texfiles,$sourcedirs];
  182. }
  183. function check_and_copy_folders($argv)
  184. {
  185. [$targets,$texfiles,$sourcedirs] = check_folders($argv);
  186. //echo "Source -> Target Directory Mapping:\n";
  187. $n = count($sourcedirs);
  188. //print_r($mapping);
  189. for ($i = 0; $i < $n; $i++)
  190. {
  191. $s = $sourcedirs[$i];
  192. $t = $targets[$i];
  193. $f = $texfiles[$i];
  194. if (str_ends_with($f,".pdf"))
  195. {
  196. if (!file_exists("$s/$f"))
  197. error_exit("$s/$f not found");
  198. if (file_exists("$t/$f.pdf") && !user_consent("$t/$f.pdf already exists... overwrite?","--force-overwrite","--no-overwrite"))
  199. {
  200. echo "Skipping $s/$f, $t/$f.pdf already exists...\n";
  201. }
  202. else
  203. {
  204. echo "Copying $s/$f to $t/$f...\n";
  205. if (!file_exists($t)) mkdir($t);
  206. rcopy("$s/$f","$t/$f");
  207. }
  208. }
  209. else
  210. {
  211. if (!file_exists($s))
  212. error_exit("$s not found");
  213. if (file_exists($t) && !user_consent("$t already exists... overwrite?","--force-overwrite","--no-overwrite"))
  214. {
  215. echo "Skipping ".$s.", ".$t." already exists...\n";
  216. }
  217. else
  218. {
  219. echo "Copying ".$s." to ".$t."...\n";
  220. rcopy($s,$t);
  221. }
  222. }
  223. }
  224. return array_combine($targets,$texfiles);
  225. }
  226. function file_get_and_backup($f,$bak = ".orig_bak")
  227. {
  228. global $options;
  229. if (isset($options["--use-backups"]))
  230. {
  231. if (file_exists("$f$bak"))
  232. copy("$f$bak", $f);
  233. }
  234. $content = file_get_contents("$f");
  235. if (!file_exists("$f$bak"))
  236. file_put_contents("$f$bak",$content);
  237. return $content;
  238. }
  239. function adjust_references($papers,$extensions = [])
  240. {
  241. $bibresources = [];
  242. foreach ($papers as $d => $f)
  243. {
  244. if (str_ends_with($f,".pdf"))
  245. continue;
  246. $files = rscandir($d,$extensions);
  247. foreach ($files as $file)
  248. {
  249. if (str_ends_with($file,".bib"))
  250. {
  251. $bib = file_get_and_backup($file);
  252. $bib = preg_replace("/(^\s*@\s*[a-z]+\s*\{\s*)((?!$d)\S)/i",'${1}'.$d.':${2}',$bib);
  253. $bib = preg_replace("/(\n\s*@\s*[a-z]+\s*\{\s*)((?!$d)\S)/i",'${1}'.$d.':${2}',$bib);
  254. file_put_contents($file,$bib);
  255. $bibresources[$d] = $file;
  256. }
  257. else
  258. {
  259. $tex = file_get_and_backup($file);
  260. // labels of lstlistings etc
  261. $tex = preg_replace("/([\[,]\s*label\s*=\s*)((?!$d)[^\[,]+[\[,])/i",'${1}'.$d.':${2}',$tex);
  262. // normal labels
  263. $tex = preg_replace("/(\\\label\s*\{\s*)((?!$d)[^}]+\})/i",'${1}'.$d.':${2}',$tex);
  264. // cref ref autoref
  265. $refs = [];
  266. preg_match_all("/\\\(cref|ref|autoref)\s*\{\s*[^}]+\}/i",$tex,$refs);
  267. foreach ($refs[0] as $ref)
  268. {
  269. $oldref = $ref;
  270. $ref = preg_replace("/([{,])\s*((?!$d)[^,}]+[},])/i",'${1}'.$d.':${2}',$ref);
  271. $ref = preg_replace("/([{,])\s*((?!$d)[^,}]+[},])/i",'${1}'.$d.':${2}',$ref);
  272. $tex = str_replace($oldref,$ref,$tex);
  273. }
  274. // cite citeA citeauthor etc
  275. $cites = [];
  276. preg_match_all("/\\\([a-z]*cite[a-z]*)\s*\{\s*[^}]+\}/i",$tex,$cites);
  277. foreach ($cites[0] as $cite)
  278. {
  279. $oldcite = $cite;
  280. $cite = preg_replace("/([{,])\s*((?!$d)[^,}]+[},])/i",'${1}'.$d.':${2}',$cite);
  281. $cite = preg_replace("/([{,])\s*((?!$d)[^,}]+[},])/i",'${1}'.$d.':${2}',$cite);
  282. $tex = str_replace($oldcite,$cite,$tex);
  283. }
  284. file_put_contents($file,$tex);
  285. }
  286. }
  287. }
  288. return $bibresources;
  289. }
  290. function stripformatting($tex)
  291. {
  292. return str_ireplace(['\Large ','\bf ','\rm ','\\\\'],[' ',' ',' ',' '],$tex);
  293. }
  294. function getusepackages($tex)
  295. {
  296. $packages = [];
  297. preg_match_all("/\n\s*(\\\\usepackage([^{}]*)(?<R>{((?:[^{}]+|(?&R))*)}))/i",$tex,$packages);
  298. if (isset($packages[1]))
  299. {
  300. return [$packages[1],$packages[4]];
  301. }
  302. return [[],[]];
  303. }
  304. function getmathops($tex)
  305. {
  306. $mathops = [];
  307. preg_match_all("/\n\s*(\\\\DeclareMathOperator([^{}]*)(?<R>{((?:[^{}]+|(?&R))*)})([^{}]*)(?<P>{((?:[^{}]+|(?&P))*)}))/i",$tex,$mathops);
  308. if (isset($mathops[4]))
  309. return [$mathops[1],$mathops[4]];
  310. return [];
  311. }
  312. function getnewcommands($tex)
  313. {
  314. $newcommands = [];
  315. preg_match_all("/\n\s*(\\\\newcommand([^{}]*)(?<R>{((?:[^{}]+|(?&R))*)})([^{}]*)(?<P>{((?:[^{}]+|(?&P))*)}))/i",$tex,$newcommands);
  316. if (isset($newcommands[4]))
  317. return $newcommands[4];
  318. return [];
  319. }
  320. function adjust_papers($papers,$extensions = [])
  321. {
  322. foreach ($papers as $d => $f)
  323. {
  324. $tex = "";
  325. $paper_fulltitle = "";
  326. $authors = "";
  327. if (str_ends_with($f,".pdf"))
  328. {
  329. $paper_fulltitle = trim(user_prompt("Please enter the full title for the paper in folder '$d'","TODO"));
  330. $paper_shorttitle = trim(user_prompt("Please enter a short title for the paper in folder '$d'","TODO"));
  331. $authors = trim(user_prompt("Please enter the author list for paper '$d'","TODO"));
  332. $header=<<<END
  333. \chapter[$paper_shorttitle]{{$paper_fulltitle}}\label{chapter:$d}
  334. \section*{Publication Data}
  335. \\fullcite{TODO}
  336. \section*{Contributions}
  337. TODO
  338. \includepdf[pages=-]{{$d}/{$f}}
  339. END;
  340. file_put_contents("$d/main.tex",$header);
  341. }
  342. $files = rscandir($d,$extensions);
  343. foreach ($files as $file)
  344. {
  345. if (!str_ends_with($file,"main.tex"))
  346. continue;
  347. $tex = file_get_and_backup($file,".interm_bak");
  348. if ($authors == "" && preg_match("/\n\s*\\\\author/i",$tex) == 1)
  349. {
  350. $authors = [];
  351. preg_match_all("/\n\s*\\\\author\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",$tex,$authors);
  352. if (isset($authors[2]) && isset($authors[2][0]))
  353. $authors = trim(stripformatting($authors[2][0]));
  354. }
  355. if ($paper_fulltitle == "" && preg_match("/\n\s*\\\\title/i",$tex) == 1)
  356. {
  357. $title = [];
  358. preg_match_all("/\n\s*\\\\title\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",$tex,$title);
  359. if (isset($title[2]) && isset($title[2][0]))
  360. $title = trim(stripformatting($title[2][0]));
  361. else
  362. $title = $d;
  363. $shorttitle = $title;
  364. if (strpos($title,":") !== false)
  365. $shorttitle = trim(explode(":",$title)[0]);
  366. $paper_fulltitle = trim(user_prompt("Please enter the full title for the paper in folder '$d'","$title"));
  367. $paper_shorttitle = trim(user_prompt("Please enter a short title for the paper in folder '$d'","$shorttitle"));
  368. }
  369. $header = "";
  370. if ($paper_fulltitle != "" && $authors != "")
  371. {
  372. $header=<<<END
  373. \chapter[$paper_shorttitle]{$paper_fulltitle}\label{chapter:$d}
  374. \section*{Publication Data}
  375. \\fullcite{TODO}
  376. \section*{Contributions}
  377. TODO
  378. \\newpage
  379. \begin{center}
  380. {\Large \\textbf{
  381. $paper_fulltitle%
  382. }}\\\\\
  383. \\vspace{0.6cm}
  384. {\large $authors%
  385. } % TODO: check author list
  386. \\end{center}
  387. END;
  388. }
  389. $tex = preg_replace("/\\\documentclass.*\\n/i",'',$tex);
  390. $tex = preg_replace("/\\\begin{document}/i",$header,$tex);
  391. $tex = preg_replace("/\\\begin{abstract}/i",'\section*{Abstract}',$tex);
  392. $tex = preg_replace("/\\\\end{abstract}/i",'',$tex);
  393. $tex = preg_replace("/\\\\thispagestyle{empty}/i",'',$tex);
  394. $tex = preg_replace("/\\\\bibliographystyle\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  395. $tex = preg_replace("/\n\s*\\\\bibliography\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  396. $tex = preg_replace("/\\\\end{document}/i",'',$tex);
  397. $tex = preg_replace("/\n\s*\\\\author\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  398. $tex = preg_replace("/\n\s*\\\\title\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  399. $tex = preg_replace("/\n\s*\\\\date\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  400. $tex = preg_replace("/\n\s*\\\\maketitle/i","",$tex);
  401. [$ups,$ps] = getusepackages($tex);
  402. global $included_usepackages;
  403. global $additional_usepackages;
  404. foreach (array_diff($ps,$included_usepackages) as $k => $v) {
  405. if ($v != "usenix,epsfig,endnotes" && $v != "cite" && !($v == 'floatrow' && in_array('float',$included_usepackages)))
  406. {
  407. $additional_usepackages[] = $ups[$k];
  408. $included_usepackages[] = $v;
  409. }
  410. }
  411. $additional_usepackages = array_unique($additional_usepackages);
  412. sort($additional_usepackages);
  413. $tex = preg_replace("/\n\s*\\\\usepackage([^{}]*)(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  414. $newcommands = getnewcommands($tex);
  415. global $existing_commands;
  416. $rmcommands = array_intersect($newcommands,$existing_commands);
  417. foreach ($rmcommands as $rmc)
  418. {
  419. $tex = preg_replace("/\n\s*\\\\newcommand([^{}]*)({\s*\\".$rmc."\s*}.*\n)/i","\n",$tex);
  420. }
  421. [$mathopsfull,$mathops] = getmathops($tex);
  422. global $existing_mathops;
  423. global $preamble;
  424. $addmathops = array_diff($mathops,$existing_mathops);
  425. foreach ($addmathops as $k => $v)
  426. {
  427. $preamble .= $mathopsfull[$k] . "\n";
  428. $existing_mathops[] = $v;
  429. }
  430. $rmmathops = array_intersect($mathops,$existing_mathops);
  431. foreach ($rmmathops as $rmo)
  432. {
  433. $tex = preg_replace("/\n\s*\\\\DeclareMathOperator([^{}]*)({\s*\\".$rmo."\s*}.*\n)/i","\n",$tex);
  434. }
  435. $matches = [];
  436. $tex = preg_replace("/\n\s*\\\\pgfplotsset\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
  437. $tex = preg_replace("/\n\s*\\\\setlength{\s*\\\marginparwidth.*\n/i","\n",$tex);
  438. file_put_contents($file,$tex);
  439. }
  440. }
  441. return;
  442. }
  443. function check_options($argv)
  444. {
  445. $options = [];
  446. foreach ($argv as $a)
  447. {
  448. if (str_starts_with($a,"-"))
  449. $options[$a] = 1;
  450. if ($a == "-n")
  451. $options["--no-overwrite"] = 1;
  452. }
  453. return $options;
  454. }
  455. function compile_check($papers,$precopy = false)
  456. {
  457. array_shift($papers);
  458. if ($precopy)
  459. $papers = array_combine($papers,$papers);
  460. foreach ($papers as $p => $f)
  461. {
  462. if (str_ends_with($f,".pdf"))
  463. {
  464. echo "======= Skipping PDF: $f =======\n";
  465. continue;
  466. }
  467. echo "======= Paper $p -> $f START =======\n";
  468. if ($precopy)
  469. {
  470. echo "$p\n";
  471. if (strpos($p,"/") === false || str_starts_with($p,".") || !is_dir(dirname($p)))
  472. continue;
  473. $f = basename($p);
  474. $p = dirname($p);
  475. }
  476. else
  477. {
  478. shell_exec("cd $p; latexmk -c 2>/dev/null; latexmk -C 2>/dev/null; rm -f *.bbl");
  479. }
  480. $str = shell_exec("cd $p; latexmk -latexoption=\"-shell-escape\" -g -pdf $f 2>&1");
  481. $lines = explode("\n",$str);
  482. $skip = true;
  483. $failed = false;
  484. foreach($lines as $l)
  485. {
  486. if (str_starts_with($l,"Latexmk: ====List of undefined refs and citations:"))
  487. $skip = false;
  488. if ($skip)
  489. continue;
  490. if (stripos($l,"fail") !== false)
  491. $failed = true;
  492. echo "$l\n";
  493. }
  494. if ($failed || user_consent("Please check the PDF file. Are there any problems with invalid references to figures, tables or with the bibliography?","--","--no-overwrite"))
  495. error_exit("The paper did not compile properly, please fix the errors next before continuing.");
  496. echo "======= Paper $p -> $f END =======\n";
  497. }
  498. }
  499. check_software();
  500. $options = check_options($argv);
  501. if (isset($options["--help"]))
  502. print_help();
  503. echo "\n=== Step 1/$steps: Check Folders ===\n\n";
  504. [$targets,$texfiles,$sourcedirs] = check_folders($argv);
  505. echo "\n=== Step 2/$steps: Pre-Copy Compile Check ===\n\n";
  506. $targets_exist = true;
  507. foreach ($targets as $t)
  508. if (!is_dir($t))
  509. $targets_exist = false;
  510. if (isset($options["--no-compile-check"]) || $targets_exist)
  511. echo "Skipping...\n";
  512. else
  513. compile_check($argv,true);
  514. echo "\n=== Step 3/$steps: Copying Files ===\n\n";
  515. $papers = check_and_copy_folders($argv);
  516. echo "\n=== Step 4/$steps: Adjusting References (in *.bib *.tex *.tikz) ===\n\n";
  517. $bibresources = adjust_references($papers,[".bib",".tex",".tikz"]);
  518. echo "\n=== Step 5/$steps: Compile Check ===\n\n";
  519. if (isset($options["--no-compile-check"]))
  520. echo "Skipping...\n";
  521. else
  522. compile_check($papers);
  523. [$_t,$usepackages1] = getusepackages(file_get_contents("main.tex.php"));
  524. [$_t,$usepackages2] = getusepackages(file_get_contents("tugraz_defaults.sty"));
  525. global $included_usepackages;
  526. $included_usepackages = array_unique(array_merge($usepackages1, $usepackages2));
  527. sort($included_usepackages);
  528. $cmds1 = getnewcommands(file_get_contents("main.tex.php"));
  529. $cmds2 = getnewcommands(file_get_contents("tugraz_defaults.sty"));
  530. global $existing_commands;
  531. $existing_commands = array_unique(array_merge($cmds1, $cmds2));
  532. [$del,$mathops1] = getmathops(file_get_contents("main.tex.php"));
  533. [$del,$mathops2] = getmathops(file_get_contents("tugraz_defaults.sty"));
  534. global $existing_mathops;
  535. $existing_mathops = array_unique(array_merge($mathops1, $mathops2));
  536. echo "\n=== Step 5/$steps: Adjusting Papers (checking only *.tex files) ===\n\n";
  537. adjust_papers($papers,[".tex"]);
  538. foreach ($papers as $k => $v)
  539. {
  540. if (str_ends_with($papers[$k],".pdf"))
  541. $papers[$k] = 'main.tex';
  542. }
  543. echo "\n=== Step 6/$steps: Generate main.tex ===\n\n";
  544. $thesis_type = user_prompt("Enter Thesis Type ","PhD Thesis");
  545. $thesis_title = user_prompt("Enter Thesis Title ","Security of TODO");
  546. $thesis_part1_title = user_prompt("Enter Introductory Part Title ","Introduction to the Security of TODO");
  547. $thesis_author = user_prompt("Enter Your Name ","Harry Potter");
  548. $thesis_date = user_prompt("Enter Prospective Defense Month", "July 1998");
  549. $thesis_institute = user_prompt("Enter Your Institute","Institute for Applied Information Processing and Communications");
  550. $thesis_assessors = user_prompt("Enter Names of your Assessors (comma-separated)","Severus Snape, Minerva McGonagall");
  551. $num_publications_in_thesis = count($papers);
  552. $num_publications = user_prompt("How many publications did you co-author during your PhD? (6 is the absolute minimum for a cumulative thesis)","6");
  553. $sloppy_begin = "";
  554. $sloppy_end = "";
  555. if (!isset($options["--no-sloppy"]))
  556. {
  557. $sloppy_begin = '\begin{sloppypar}';
  558. $sloppy_end = '\end{sloppypar}';
  559. }
  560. ob_start();
  561. require "main.tex.php";
  562. $maintex_content = ob_get_contents();
  563. ob_end_clean();
  564. //if (!file_exists("main.tex") || user_consent("main.tex already exists. overwrite?")) // TODO: enable this check
  565. file_put_contents("main.tex",$maintex_content);
  566. if (!file_exists("mypreamble.sty"))
  567. file_put_contents("mypreamble.sty","\ProvidesPackage{mypreamble}\n\n".implode("\n",$additional_usepackages)."\n\n".$preamble);
  568. @mkdir("tikz");
  569. if (!file_exists("abstract.tex"))
  570. file_put_contents("abstract.tex","");
  571. if (!file_exists("intro.tex"))
  572. file_put_contents("intro.tex","");
  573. if (!file_exists("main.bib"))
  574. file_put_contents("main.bib","");
  575. if (isset($options["--cv"]))
  576. {
  577. if (!file_exists("cv.bib"))
  578. file_put_contents("cv.bib","");
  579. if (!file_exists("cv.tex"))
  580. file_put_contents("cv.tex","This is my CV! Thanks for checking it out!");
  581. }
  582. echo "=== done ===\nNext step, run this command:\nlatexmk -latexoption=\"-shell-escape\" -g -pdf main.tex\n";
  583. ?>