forked from wbuchanan/eda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maketexcomp.ado
111 lines (78 loc) · 3.3 KB
/
maketexcomp.ado
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
********************************************************************************
* Description of the Program - *
* Utility to build a LaTeX compilation script. *
* *
* Program Output - *
* Bash/Batch script calling pdflatex on a given LaTeX source code file *
* *
* Lines - *
* 110 *
* *
********************************************************************************
*! maketexcomp
*! v 0.0.0
*! 29OCT2015
// Drop program from memory if it is already loaded
cap prog drop maketexcomp
// Define program
prog def maketexcomp, rclass
// Version Stata should use to interpret the code
version 14
// Define syntax structure for subroutine
syntax anything(name=filenm id="Name of LaTeX Source Code File"), ///
SCRiptname(string) root(string) [ PDFlatex(string asis) ]
// Check for null PDFLaTeX argument
if `"`pdflatex'"' == "" {
// If null use the binary name
loc pdflatex pdflatex
} // End IF Block for null pdflatex binary reference
// Check if user is running on Windoze
if `"`c(os)'"' == "Windows" {
loc compile `scriptname'.bat
// Write a Windoze batch script to compile a given LaTeX document
file open comp using `"`scriptname'.bat"', w replace
file write comp "::Batch file to compile LaTeX source" _n
file write comp `"`pdflatex'.exe `filenm'.tex"' _n
file write comp `"`pdflatex'.exe `filenm'.tex"' _n
file write comp `"`pdflatex'.exe `filenm'.tex"' _n
// Loop over ancillary file extensions
foreach v in aux lof log lot out toc {
// Delete ancillary files
file write comp `"DEL "`filenm'.`v'""' _n
} // End Loop over ancillary file extensions
file write comp "" _n
file write comp "" _n
file close comp
} // End IF Block for Windoze-based systems
// For all other computer systems on the planet
else {
loc compile `scriptname'.sh
// Write a bash script to compile the LaTeX document
file open comp using `"`scriptname'.sh"', w replace
file write comp "#!/bin/bash" _n
file write comp `"cd "`root'""' _n
file write comp `"`pdflatex' `filenm'.tex"' _n
file write comp `"`pdflatex' `filenm'.tex"' _n
file write comp `"`pdflatex' `filenm'.tex"' _n
// Loop over ancillary file extensions
foreach v in aux lof log lot out toc {
// Delete ancillary files
file write comp `"sudo rm "`filenm'.`v'""' _n
} // End Loop over ancillary file extensions
file write comp "" _n
file close comp
// Make the bash script executable
! sudo chmod a+x "`scriptname'.sh"
} // End of ELSE Block for non Windoze based systems
// Check for OSX
if `"`c(os)'"' == "MacOSX" {
// Return a version of the shell out for OSX
ret loc comp ! open -a Terminal.app `scriptname'.sh
} // End IF Block for OSX
// For other OS
else {
// Return the name of the script to execute
ret loc comp ! `compile'
} // End ELSE Block for other OS
// End of subroutine definition
end