Commit f32dd6dd authored by liziwl's avatar liziwl
Browse files

fix: 修复批处理脚本在 PowerShell 中的兼容性问题



将 build.bat 和 clean.bat 重写为使用 goto 标签而非 else if 语法,
修复了嵌套括号导致的解析错误,使脚本在 cmd 和 PowerShell 中
都能正常工作。

Co-Authored-By: default avatarClaude <noreply@anthropic.com>
parent 41d0c50b
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@echo off
setlocal

REM Build the SUSTech thesis document
echo Building SUSTech Thesis...

REM Generate class files if needed
if not exist "sustechthesis.cls" (
  echo Generating class files...
  xetex sustechthesis.ins
)

REM Check command line argument to determine what to build
if "%~1"=="" goto build_thesis
if /I "%~1"=="thesis" goto build_thesis
if /I "%~1"=="report" goto build_report
if /I "%~1"=="all" goto build_all
if /I "%~1"=="doc" goto build_doc
goto usage

:build_thesis
echo Building thesis document...
latexmk sustechthesis-example
goto success

:build_report
echo Building report document...
latexmk sustechthesis-example-report
goto success

:build_all
echo Building all documents...
latexmk sustechthesis-example
if exist "sustechthesis-example-report.tex" (
  latexmk sustechthesis-example-report
)
goto success

:build_doc
echo Building documentation...
latexmk sustechthesis.dtx
goto success

:usage
echo Invalid argument. Usage:
echo   build.bat          - Build thesis (default)
echo   build.bat thesis   - Build thesis
echo   build.bat report   - Build report
echo   build.bat all      - Build all documents
echo   build.bat doc      - Build documentation
goto end

:success
echo Build completed successfully!

:end
pause
 No newline at end of file
+98 −2
Original line number Diff line number Diff line
@echo off
setlocal EnableDelayedExpansion

REM Check command line argument to determine cleanup level
if /I "%~1"=="all" goto cleanall
if /I "%~1"=="help" goto usage
if /I "%~1"=="?" goto usage

REM Default: basic clean behavior (like Makefile clean target)
echo Performing basic cleanup...

REM Clean auxiliary files generated by LaTeX using latexmk
if exist "sustechthesis-example.tex" (
  latexmk -c sustechthesis-example
del /Q *~ main-survey.* main-translation.* _markdown_thuthesis* thuthesis.markdown.*
 No newline at end of file
)

if exist "sustechthesis-example-report.tex" (
  latexmk -c sustechthesis-example-report
)

if exist "sustechthesis.dtx" (
  latexmk -c sustechthesis.dtx
)

REM Delete common auxiliary files that might remain
call :delete_files *.aux *.bbl *.blg *.toc *.lof *.lot *.out *.fls *.fdb_latexmk *.synctex.gz *.bcf *.run.xml *.xdv *.idv *.lg *.xwm

REM Delete minted temporary directories
call :delete_dirs _minted-*

REM Delete temporary files with tilde
call :delete_files *~

REM Delete markdown-related temporary files
call :delete_files *_markdown_*.tex *_markdown_* *.markdown.*

goto completed

:cleanall
echo Performing full cleanup (cleanall)...

REM Clean auxiliary files generated by LaTeX using latexmk
if exist "sustechthesis-example.tex" (
  latexmk -c sustechthesis-example
)

if exist "sustechthesis-example-report.tex" (
  latexmk -c sustechthesis-example-report
)

if exist "sustechthesis.dtx" (
  latexmk -c sustechthesis.dtx
)

REM Delete common auxiliary files that might remain
call :delete_files *.aux *.bbl *.blg *.toc *.lof *.lot *.out *.fls *.fdb_latexmk *.synctex.gz *.bcf *.run.xml *.xdv *.idv *.lg *.xwm

REM Delete minted temporary directories
call :delete_dirs _minted-*

REM Delete temporary files with tilde
call :delete_files *~

REM Delete markdown-related temporary files
call :delete_files *_markdown_*.tex *_markdown_* *.markdown.*

REM Additionally delete generated class files and PDFs (cleanall behavior)
call :delete_files sustechthesis.cls dtx-style.sty

call :delete_files sustechthesis.pdf sustechthesis-example.pdf sustechthesis-example-report.pdf

REM Delete test-related directories
call :delete_dirs public-test dist

:completed
echo Cleanup operation completed.
goto end

:delete_files
del /Q %* 2>nul
goto :eof

:delete_dirs
for /d %%d in (%*) do (
  if exist "%%d" (
    rmdir /s /q "%%d" 2>nul
  )
)
goto :eof

:usage
echo Usage:
echo   clean.bat        - Basic cleanup (default)
echo   clean.bat all    - Full cleanup (removes generated files too)
echo   clean.bat help   - Show this help

:end
pause
 No newline at end of file