-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_figures.bat
173 lines (142 loc) · 3.68 KB
/
make_figures.bat
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
@REM Display help text
IF "%~1"=="-h" GOTO :help
IF "%~1"=="-help" GOTO :help
@REM Set global variables
@REM Script name
SET scriptname=%~nx0
@REM Script mode
SET /A file=0
SET /A recursive=0
@REM Options
SET /A verbose=0
SET /A open=0
SET /A tex="a"
@REM Set mode
IF "%1"=="" GOTO :noMode
IF "%1"=="recursive" (
SET recursive=1
) ELSE (
IF "%1"=="file" (
SET file=1
) ELSE (
GOTO :invalidMode
)
)
SHIFT
SET directory=%~1
SHIFT
IF %file%==1 (
SET tex=%~1
SHIFT
)
@REM If no parameters, build without opening
IF "%1"=="" GOTO :default
@REM Loop through all parameters
SET /A numP=0
:loop
@REM Use numP to test each parameter for validity
SET numP=0
@REM Check options
IF "%1"=="-v" (
SET numP=1
SET verbose=1
) ELSE (
IF "%1"=="-verbose" (
SET numP=1
SET verbose=1
)
)
IF "%1"=="-o" (
SET numP=1
SET open=1
) ELSE (
IF "%1"=="-open" (
SET numP=1
SET open=1
)
)
@REM If current option is not valid
IF !numP!==0 GOTO :invalidOption
@REM Shift variables and loop if another option exists
SHIFT
IF NOT "%1"=="" GOTO :loop
:: Default
:default
IF NOT EXIST "%directory%" GOTO :invalidDirectory
IF %recursive%==1 (
FOR /R "%directory%" %%i IN (*.TIKZ) DO (
SET tex=%%~ni
CALL :main
)
) ELSE (
CALL :main
)
@REM Finally:
GOTO :EOF
:: Main function
:main
@REM Verbose options
IF %verbose%==0 (
CALL :buildPDF
) ELSE (
CALL :buildPDFv
)
@REM Open options
IF %open%==1 (
CALL :openPDF
)
EXIT /B
:: Build PDF
:buildPDF
ECHO -- Building PDF --
latexmk -aux-directory=Debug -shell-escape -file-line-error -interaction=nonstopmode -halt-on-error -output-directory=figures -silent -xelatex %directory%/%tex%.tikz
EXIT /B
:: Build PDF verbose
:buildPDFv
ECHO -- Building PDF -- (v)
latexmk -aux-directory=Debug -shell-escape -file-line-error -interaction=nonstopmode -halt-on-error -output-directory=figures -verbose -xelatex %directory%/%tex%.tikz
EXIT /B
:: Open PDF
:openPDF
ECHO -- Opening PDF --
figures\%tex%.pdf
EXIT /B
:: Help
:help
ECHO %scriptname% compile tikz diagrams using XeLaTeX.
ECHO.
ECHO Usage: %scriptname% file [directory] [filename] [options]
ECHO %scriptname% recursive [directory] [options]
ECHO.
ECHO Available options:
ECHO %scriptname% [-h ^| -help] Provides help information.
ECHO %scriptname% [filename] [-v ^| -verbose] Show compiler output.
ECHO %scriptname% [filename] [-o ^| -open] Open the PDF after compilation.
GOTO :EOF
:: No Mode
:noMode
ECHO No mode provided. [file ^| recursive] expected.
ECHO Try "%scriptname% -h" for more information.
GOTO :EOF
:: Invalid Option
:invalidOption
ECHO Unknown option: %1
ECHO Try "%scriptname% -h" for more information.
GOTO :EOF
:: Invalid Mode
:invalidMode
ECHO Invalid mode provided. [file ^| recursive] expected.
ECHO Try "%scriptname% -h" for more information.
GOTO :EOF
:: No Directory
:noDirectory
ECHO No directory was supplied.
ECHO Try "%scriptname% -h" for more information.
GOTO :EOF
:: Invalid Directory
:invalidDirectory
ECHO Directory "%directory%" is invalid.
ECHO Try "%scriptname% -h" for more information.
GOTO :EOF