summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/hitszthesis/compile.bat
blob: 3ef4d414633348825a39cd6d2ed158dfbaabcf32 (plain)
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
@echo off
chcp 65001 >nul

set THESIS=main
set PACKAGE=hitszthesis

set flag=%1
if %flag%x == x (
	set flag=thesis
)

if %flag%x == thesisx (
	call :cleanall
	call :thesis
	if ERRORLEVEL 1 (
		echo Error! Please check the 'main.log' for more details...
		pause
	) else (
		call :clean
		echo Finished!
	)
	goto :EOF
)

if %flag%x == clsx (
	call :cls
	goto :EOF
)

if %flag%x == allx (
	echo Compile thesis and documentation...
	call :doc
	call :thesis
	goto :EOF
)

if %flag%x == docx (
	call :doc
	goto :EOF
)

if %flag%x == cleanx (
	call :clean
	goto :EOF
)

if %flag%x == cleanallx (
	call :cleanall
	goto :EOF
)

if %flag%x == wordcountx (
	call :wordcounty
	goto :EOF
)

:help
	echo This is the compile batch script for hitszhesis.
	echo Usage:
	echo     compile.bat [option]
	echo options:
	echo   thesis    Compile the thesis (default)
	echo   doc       Compile the documentation
	echo   all       Compile the thesis and documentation
	echo   clean     Clean all work files
	echo   cleanall  Clean all work files and pdf files
	echo   wordcount Count words in main.pdf
	echo   help      Print this help message
goto :EOF

:thesis
	echo Compile thesis...
	latex %PACKAGE%.ins
	xelatex -shell-escape %THESIS%.tex
	bibtex %THESIS%.tex
	xelatex -shell-escape %THESIS%.tex
	xelatex -shell-escape %THESIS%.tex
	splitindex %THESIS% -- -s hitszthesis.ist
	xelatex -shell-escape %THESIS%.tex
goto :EOF

:cls
	echo Split cls file...
	xetex %PACKAGE%.ins
goto :EOF

:doc
	echo Compile documentation...
	latex %PACKAGE%.ins
	xelatex %PACKAGE%.dtx
	makeindex -s gind.ist -o %PACKAGE%.ind %PACKAGE%.idx
	makeindex -s gglo.ist -o %PACKAGE%.gls %PACKAGE%.glo
	xelatex %PACKAGE%.dtx
	xelatex %PACKAGE%.dtx
goto :EOF

:clean
	echo Clean auxiliary files...
	latexmk -c %PACKAGE%.dtx
	latexmk -c %THESIS%
	del *.xdv *.hd *.aux front\*.aux body\*.aux back\*.aux >nul 2>nul
goto :EOF

:cleanall
	echo Clean pdf files...
	del /Q %PACKAGE%.pdf %THESIS%.pdf >nul 2>nul
	goto :clean
goto :EOF

:wordcountx
	set found=0
	setlocal enabledelayedexpansion

	findstr "\\documentclass\[[^\[]*english" %THESIS%.tex > nul
	if %errorlevel% equ 0 (
		for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -char-only  2^>nul') do (
			if !found! equ 1 (
				echo 英文字符数:		!%%i!
				goto :total
			)
			echo %%i | findstr "total" > nul && set found=1
		)
	) else (
		for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -ch-only  2^>nul') do (
			if !found! equ 1 (
				echo 纯中文字数:		!%%i!
				goto :total
			)
			echo %%i | findstr "total" > nul && set found=1
		)
	)

:total
	set found=0
	for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -chinese 2^>nul') do (
		if !found! equ 1 (
			echo 总字数^(英文单词+中文字^):!%%i!
			goto :EOF
		)
		echo %%i | findstr "total" > nul && set found=1
	)
goto :EOF

:wordcounty
	texcount %THESIS%.tex -inc -chinese
goto :EOF