|
2 | 2 |
|
3 | 3 | chcp 65001 >nul |
4 | 4 |
|
5 | | -REM Basename of thesis |
6 | 5 | set THESIS=main |
7 | 6 |
|
8 | | -REM Parse command line arguments |
9 | | -set TARGET=%1 |
10 | | -if "%TARGET%"=="" set TARGET=all |
11 | | - |
12 | | -REM Engine handling |
13 | | -set ENGINES=-xelatex -lualatex |
14 | | -set ENGINE=-xelatex |
15 | | -if not "%~2"=="" ( |
16 | | - if "%~2"=="-xelatex" ( |
17 | | - set ENGINE=-xelatex |
18 | | - ) else if "%~2"=="-lualatex" ( |
19 | | - set ENGINE=-lualatex |
| 7 | +if "%~1" == "" ( |
| 8 | + set flag=thesis |
| 9 | +) else ( |
| 10 | + set flag=%1 |
| 11 | +) |
| 12 | + |
| 13 | +if not "%~2" == "-xelatex" ( |
| 14 | + if not "%~2" == "-lualatex" ( |
| 15 | + echo Expected ENGINE in {-xelatex, -lualatex}, Got "%~2" |
| 16 | + Set default ENGINE to "-xelatex" |
20 | 17 | ) else ( |
21 | | - echo Error: Expected $$ENGINE in {-xelatex, -lualatex}, Got "%~2" |
22 | | - echo Setting default $$ENGINE to "-xelatex" |
| 18 | + set ENGINE=-lualatex |
23 | 19 | ) |
| 20 | +) else ( |
| 21 | + set ENGINE=-xelatex |
24 | 22 | ) |
25 | 23 |
|
26 | | -REM LaTeXmk options |
27 | | -set LATEXMK_OPT=-quiet -file-line-error -halt-on-error -interaction=nonstopmode -shell-escape -synctex=1 -recorder %ENGINE% |
| 24 | +if %flag% == thesis ( |
| 25 | + call :cleanall |
| 26 | + call :thesis |
| 27 | + if ERRORLEVEL 1 ( |
| 28 | + echo. |
| 29 | + echo Error! Please check the %THESIS%.log for more details . . . |
| 30 | + pause |
| 31 | + ) else ( |
| 32 | + call :clean |
| 33 | + echo Finished! |
| 34 | + pause |
| 35 | + ) |
| 36 | + goto :EOF |
| 37 | +) |
28 | 38 |
|
29 | | -REM LaTeXmk options for preview continuous mode |
30 | | -set LATEXMK_OPT_PVC=%LATEXMK_OPT% -pvc |
| 39 | +if %flag% == clean ( |
| 40 | + call :clean |
| 41 | + goto :EOF |
| 42 | +) |
31 | 43 |
|
32 | | -REM Check for required programs |
33 | | -where latexmk >nul 2>&1 |
34 | | -if %ERRORLEVEL% NEQ 0 ( |
35 | | - echo Error: latexmk not found in PATH |
36 | | - exit /b 1 |
| 44 | +if %flag% == cleanall ( |
| 45 | + call :cleanall |
| 46 | + goto :EOF |
37 | 47 | ) |
38 | 48 |
|
39 | | -where texcount >nul 2>&1 |
40 | | -if %ERRORLEVEL% NEQ 0 ( |
41 | | - echo Error: texcount not found in PATH |
42 | | - exit /b 1 |
| 49 | +if %flag% == wordcount ( |
| 50 | + call :wordcount |
| 51 | + goto :EOF |
43 | 52 | ) |
44 | 53 |
|
45 | | -REM Execute the requested target |
46 | | -if "%TARGET%"=="all" goto :all |
47 | | -if "%TARGET%"=="pvc" goto :pvc |
48 | | -if "%TARGET%"=="view" goto :view |
49 | | -if "%TARGET%"=="wordcount" goto :wordcount |
50 | | -if "%TARGET%"=="clean" goto :clean |
51 | | -if "%TARGET%"=="cleanall" goto :cleanall |
52 | | -if "%TARGET%"=="help" goto :help |
53 | | -if "%TARGET%"=="thesis" goto :thesis |
54 | | - |
55 | | -echo Unknown target: %TARGET% |
56 | | -goto :help |
57 | | - |
58 | | -:all |
59 | | - call :thesis |
60 | | - if ERRORLEVEL 1 ( |
61 | | - echo. |
62 | | - echo Error! Please check the %THESIS%.log for more details... |
63 | | - pause |
64 | | - ) else ( |
65 | | - echo Finished! |
66 | | - ) |
67 | | - goto :EOF |
| 54 | +:help |
| 55 | + echo This is the compile batch script for tongji-undergrad-thesis. |
| 56 | + echo Usage: |
| 57 | + echo make.bat [option] |
| 58 | + echo options: |
| 59 | + echo thesis Compile the thesis (default) |
| 60 | + echo clean Clean all work files |
| 61 | + echo cleanall Clean all work files and main.pdf |
| 62 | + echo wordcount Count words in main.pdf |
| 63 | + echo help Print this help message |
| 64 | +goto :EOF |
68 | 65 |
|
69 | 66 | :thesis |
70 | | - echo Building %THESIS%.pdf with %ENGINE%... |
71 | | - latexmk %LATEXMK_OPT% %THESIS%.tex |
72 | | - goto :EOF |
73 | | - |
74 | | -:pvc |
75 | | - echo Starting preview continuous mode... |
76 | | - latexmk %LATEXMK_OPT_PVC% %THESIS% |
77 | | - goto :EOF |
78 | | - |
79 | | -:view |
80 | | - echo Opening %THESIS%.pdf... |
81 | | - if exist %THESIS%.pdf ( |
82 | | - start "" "%THESIS%.pdf" |
83 | | - ) else ( |
84 | | - echo Error: %THESIS%.pdf does not exist. Build it first with 'make all' |
85 | | - ) |
86 | | - goto :EOF |
87 | | - |
88 | | -:wordcount |
89 | | - echo Counting words in %THESIS%.tex... |
90 | | - set found=0 |
91 | | - setlocal enabledelayedexpansion |
92 | | - |
93 | | - findstr "\\documentclass\[[^\[]*en" %THESIS%.tex >nul 2>&1 |
94 | | - if %ERRORLEVEL% EQU 0 ( |
95 | | - for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -char-only 2^>nul') do ( |
96 | | - if !found! equ 1 ( |
97 | | - echo 英文字符数 (Latin characters) :%%i |
98 | | - goto :count_total |
99 | | - ) |
100 | | - echo %%i | findstr "total" >nul && set found=1 |
101 | | - ) |
102 | | - ) else ( |
103 | | - for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -ch-only 2^>nul') do ( |
104 | | - if !found! equ 1 ( |
105 | | - echo 纯中文字数 (Chinese characters) :%%i |
106 | | - goto :count_total |
107 | | - ) |
108 | | - echo %%i | findstr "total" >nul && set found=1 |
109 | | - ) |
110 | | - ) |
111 | | - |
112 | | -:count_total |
113 | | - set found=0 |
114 | | - for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -chinese 2^>nul') do ( |
115 | | - if !found! equ 1 ( |
116 | | - echo 总字数 (Total characters) :%%i |
117 | | - endlocal |
118 | | - goto :EOF |
119 | | - ) |
120 | | - echo %%i | findstr "total" >nul && set found=1 |
121 | | - ) |
122 | | - endlocal |
123 | | - goto :EOF |
| 67 | + echo Compile . . . |
| 68 | + latexmk %ENGINE% -synctex=1 -quiet -interaction=nonstopmode -file-line-error -halt-on-error -shell-escape %THESIS% 2>nul |
| 69 | +goto :EOF |
124 | 70 |
|
125 | 71 | :clean |
126 | | - echo Cleaning auxiliary files... |
127 | | - latexmk -c -bibtex -silent %THESIS%.tex styledef.tex 2>nul |
128 | | - echo Clean complete. |
129 | | - goto :EOF |
| 72 | + echo Clean files . . . |
| 73 | + latexmk -quiet -c %THESIS% 2>nul |
| 74 | +goto :EOF |
130 | 75 |
|
131 | 76 | :cleanall |
132 | | - echo Cleaning all generated files... |
133 | | - latexmk -C -bibtex -silent %THESIS%.tex styledef.tex 2>nul |
134 | | - if exist %THESIS%.pdf ( |
135 | | - echo Close the file: '%THESIS%.pdf'! |
136 | | - pause |
137 | | - goto :cleanall |
138 | | - ) |
139 | | - echo Clean complete. |
140 | | - goto :EOF |
| 77 | + echo Clean all files . . . |
| 78 | + latexmk -quiet -C %THESIS% 2>nul |
| 79 | + if exist %THESIS%.pdf ( |
| 80 | + echo Close the file: '%THESIS%.pdf'! |
| 81 | + pause |
| 82 | + call :cleanall |
| 83 | + ) |
| 84 | +goto :EOF |
141 | 85 |
|
142 | | -:help |
143 | | - echo Available targets: |
144 | | - echo all - Build PDF (default) |
145 | | - echo pvc - Preview continuously |
146 | | - echo view - Open PDF |
147 | | - echo wordcount - Count words in Chinese and English |
148 | | - echo clean - Remove auxiliary files |
149 | | - echo cleanall - Remove all generated files |
150 | | - echo help - Show this help message |
151 | | - echo thesis - Legacy alias for 'all' |
152 | | - echo. |
153 | | - echo Available engines (use as second parameter): |
154 | | - echo -xelatex (default) |
155 | | - echo -lualatex |
156 | | - echo. |
157 | | - echo Example usage: |
158 | | - echo make |
159 | | - echo make all -lualatex |
160 | | - echo make pvc |
161 | | - goto :EOF |
| 86 | +:wordcount |
| 87 | + set found=0 |
| 88 | + setlocal enabledelayedexpansion |
| 89 | + |
| 90 | + findstr "\\documentclass\[[^\[]*en" %THESIS%.tex > nul |
| 91 | + if %errorlevel% equ 0 ( |
| 92 | + for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -char-only 2^>nul') do ( |
| 93 | + if !found! equ 1 ( |
| 94 | + echo 英文字符数 :!%%i! |
| 95 | + goto :total |
| 96 | + ) |
| 97 | + echo %%i | findstr "total" > nul && set found=1 |
| 98 | + ) |
| 99 | + ) else ( |
| 100 | + for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -ch-only 2^>nul') do ( |
| 101 | + if !found! equ 1 ( |
| 102 | + echo 纯中文字数 :!%%i! |
| 103 | + goto :total |
| 104 | + ) |
| 105 | + echo %%i | findstr "total" > nul && set found=1 |
| 106 | + ) |
| 107 | + ) |
| 108 | + |
| 109 | +:total |
| 110 | + set found=0 |
| 111 | + for /f "delims=" %%i in ('texcount %THESIS%.tex -inc -chinese 2^>nul') do ( |
| 112 | + if !found! equ 1 ( |
| 113 | + echo 总字数(英文单词 + 中文字) :!%%i! |
| 114 | + goto :EOF |
| 115 | + ) |
| 116 | + echo %%i | findstr "total" > nul && set found=1 |
| 117 | + ) |
| 118 | +goto :EOF |
162 | 119 |
|
163 | 120 | exit /B 0 |
0 commit comments