Skip to content

Commit

Permalink
feat:新增自动化编译脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
wrm244 committed Dec 22, 2023
1 parent 9d76ad0 commit 695fc53
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 68 deletions.
Binary file added build/main.pdf
Binary file not shown.
Binary file modified main.pdf
Binary file not shown.
9 changes: 5 additions & 4 deletions main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
% 欢迎使用桂林电子科技大学本科毕业论文LaTex模板(v3.0)
% 项目:https://github.com/wrm244/GUEThesis
% 请参考项目目录下的docs文件夹额外说明
%编译指导:请下载MiKTeX软件后,运行根目录下的makefile.bat即可自动编译
% --------------------------------------------------------
\special{dvipdfmx:config z 1}
% 修改数值是否压缩,1:压缩,0:不压缩,不压缩会加快编译速度,但会增加PDF体积
Expand Down Expand Up @@ -35,10 +36,10 @@
\begin{document}
\makecover % 封面
%也可使用另外添加PDF文件作为封面,如盲审封面 \bindpdfcover{盲审学位论文封面(示例).pdf}
\originalitydeclaration % 独创性声明
\originalitydeclaration % 独创性声明
%也可使用已签字的扫面版独创性声明PDF文件 \signatureofdeclaration{./docs/独创性声明(示例).pdf}
\input{chapters/abstract} % 摘要
\thesistableofcontents % 目录
\input{chapters/abstract} % 摘要
\thesistableofcontents % 目录

% -------------------------------------------------
% 论文各章节(详见目录下chapter文件夹)
Expand All @@ -47,7 +48,7 @@
\input{chapters/chapter2}
\input{chapters/chapter3}
\input{chapters/chapter4}
\input{chapters/chapter5} % 可根据需求自行添加章节数
\input{chapters/chapter5} % 可根据需求自行添加章节数
\input{chapters/conclusion} % 总结与展望
% --------------------------------------------------
% 参考文献
Expand Down
180 changes: 180 additions & 0 deletions makefile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
: 设置编码为utf-8,解决中文显示问题
chcp 65001

@echo off

:: 设置标题
title %date% %time% makefile
:: 基本设置
set File_Name=main
set TeX_Name=xelatex
set Bib_Name=bibtex

:: 计算开始时间
set Start_Time=%time%
:: ==========================================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 清除辅助文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
:: clear aux files
del /q %File_Name%.pdf %File_Name%.synctex *.aux *.bbl *.blg *.log *.out *.toc *.bcf *.xml *.nlo *.nls *.bak *.ind *.idx *.ilg *.lof *.lot *.ent-x *.tmp *.ltx *.los *.lol *.loc *.listing *.gz *.synctex(busy) *.nav *.snm *.vrb *.fls *.xdv *.fdb_latexmk

:: ==========================================================================================
echo.
echo.
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始一次 %TeX_Name% 编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
:: compile the tex file nonstopmode batchmode 批处理运行模式,无日志显示,利于提速
%TeX_Name%.exe -no-pdf -shell-escape -file-line-error -halt-on-error -interaction=batchmode --synctex=-1 %File_Name%.tex
echo.
echo.
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始文献编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
:: compile bibliography
%Bib_Name% %File_Name%
echo.
echo.
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始目录编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
set Catalogs=没有插入任何索引
:: 编译目录和符号说明索引
:: 判断是否存在 .gls 文件,判断是否采用glossaries宏包生成符号说明表
if exist "%File_Name%.glo" (
:: 执行 makeindex 命令
makeindex -s %File_Name%.ist -o %File_Name%.gls %File_Name%.glo
set Catalogs=采用glossaries宏包生成符号说明表
) else (
:: 判断是否存在 .nls 文件,判断是否采用nomencl宏包生成符号说明表
if exist "%File_Name%.nlo" (
:: 执行 makeindex 命令
makeindex -s nomencl.ist -o %File_Name%.nls %File_Name%.nlo
set Catalogs=采用nomencl宏包生成符号说明表
) else (
:: 判断是否存在 .xdv 文件,判断是否需要生成索引
if exist "%File_Name%.xdv" (
:: 执行 makeindex 命令
makeindex %File_Name%.xdv
set Catalogs=有目录但没符号说明表
) else (
:: 打印该文章没有插入任何索引
set Catalogs=没有插入任何索引
)
)
)
echo.
echo.
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始二次 %TeX_Name% 编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
:: compile the tex file batchmode nonstopmode
%TeX_Name%.exe -no-pdf -shell-escape -file-line-error -halt-on-error -interaction=batchmode --synctex=-1 %File_Name%.tex
echo.
echo.
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始三次 %TeX_Name% 编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
:: compile the tex file nonstopmode batchmode: 不输出过程信息,提高速度
%TeX_Name%.exe -shell-escape -file-line-error -halt-on-error -interaction=batchmode --synctex=-1 %File_Name%.tex
echo.
echo.
echo ================================================================================
echo ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 完成所有编译 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
echo ================================================================================
echo.
echo.

:: ==========================================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 清除辅助文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo.
echo.
:: call makeclear
del /q *.aux *.bbl *.blg *.log *.out *.toc *.bcf *.xml *.nlo *.nls *.bak *.ind *.idx *.ilg *.lof *.lot *.ent-x *.tmp *.ltx *.los *.lol *.loc *.listing *.gz *.synctex(busy) *.nav *.snm *.vrb *.fls *.xdv *.fdb_latexmk

:: ==========================================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 清除已有结果文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
:: 处理上次生成的结果文件
set Build_Path="./build/"
:: 检查是否存在./Build/文件夹
if exist %Build_Path% (
:: 存在./Build/文件夹,则删除
rd /s /q %Build_Path%
echo 删除上次生成的结果文件
mkdir %Build_Path%
echo 创建 Build 文件夹
) else (
:: 不存在./Build/文件夹,则创建
mkdir %Build_Path%
echo 创建 Build 文件夹
)
echo.
echo.
:: ==========================================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 移动生成文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
:: 移动结果文件到指定文件夹
if exist "%File_Name%.pdf" (
move "%File_Name%.pdf" %Build_Path%
move "%File_Name%.synctex" %Build_Path%
echo 移动生成文件到 Build 文件夹中
) else (
echo 未检索到生成的pdf文件
)
echo.
echo.
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 目录生成情况 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo %Catalogs%
echo.
echo.
:: ==========================================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 统计编译时长 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
:: 计算结束时间
set End_Time=%time%
:: 格式化时间
set options="tokens=1-4 delims=:.,"
for /f %options% %%a in ("%Start_time%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%End_time%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%
:: 计算时间并输出
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
echo 编译时长为:%hours% 小时 %mins%%secs%%ms% 毫秒 (%totalsecs%.%ms%s total)
echo.

:: 结束
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 查看生成文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo 请在 "%Build_Path%" 文件夹中查看编译后的文件。
pause
exit /b
170 changes: 170 additions & 0 deletions makefile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@

#!/bin/bash

# 基本设置
File_Name="main"
TeX_Name="xelatex"
Bib_Name="biber"

# 计算开始时间
Start_Time=$(date +"%s")
#==========================================================================
echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 清除辅助文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
# 清除辅助文件
rm -r $File_Name.pdf $File_Name.synctex *.aux *.bbl *.blg *.log *.out *.toc *.bcf *.xml *.synctex *.nlo *.nls *.bak *.ind *.idx *.ilg *.lof *.lot *.ent-x *.tmp *.ltx *.los *.lol *.loc *.listing *.gz *.userbak *.nav *.snm *.vrb *.fls *.xdv *.fdb_latexmk

#==========================================================================
echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始一次 $TeX_Name 编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
# 编译 Tex 文件 nonstopmode batchmode 批处理运行模式,无日志显示,利于提速
$TeX_Name -no-pdf -shell-escape -file-line-error -halt-on-error -interaction=batchmode --synctex=-1 $File_Name.tex

echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始文献编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
# 编译参考文献
$Bib_Name $File_Name
echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始目录编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
Catalogs="没有插入任何索引"
# 编译目录和符号说明索引
# 判断是否存在 .gls 文件,判断是否采用 glossaries 宏包生成符号说明表
if [[ -f "$File_Name.glo" ]]; then
# 执行 makeindex 命令
makeindex -s $File_Name.ist -o $File_Name.gls $File_Name.glo
Catalogs="采用 glossaries 宏包生成符号说明表"
# 判断是否存在 .nls 文件,判断是否采用 nomencl 宏包生成符号说明表
elif [[ -f "$File_Name.nlo" ]]; then
# 执行 makeindex 命令
makeindex -s nomencl.ist -o $File_Name.nls $File_Name.nlo
Catalogs="采用 nomencl 宏包生成符号说明表"
# 判断是否存在 .idx 文件,判断是否需要生成索引
elif [[ -f "$File_Name.xdv" ]]; then
# 执行 makeindex 命令
makeindex "$File_Name.xdv"
Catalogs="有目录 没符号说明表"
else
# 打印该文章没有插入任何索引
Catalogs="没有插入任何索引"
fi

echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始二次 $TeX_Name 编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
# 编译 Tex 文件
$TeX_Name -no-pdf -shell-escape -file-line-error -halt-on-error -interaction=batchmode --synctex=-1 $File_Name.tex

echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXX 开始三次 $TeX_Name 编译 XXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
# 编译 Tex 文件
$TeX_Name -shell-escape -file-line-error -halt-on-error -interaction=batchmode --synctex=-1 $File_Name.tex

echo ""
echo ""
echo ================================================================================
echo ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 完成所有编译 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
echo ================================================================================
echo ""
echo ""

#==========================================================================

echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 清除辅助文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo ""
echo ""
# 清除辅助文件
rm -r *.aux *.bbl *.blg *.log *.out *.toc *.bcf *.xml *.nlo *.nls *.bak *.ind *.idx *.ilg *.lof *.lot *.ent-x *.tmp *.ltx *.los *.lol *.loc *.listing *.gz *.userbak *.nav *.snm *.vrb *.fls *.xdv *.fdb_latexmk

#==========================================================================

echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 清除已有结果文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
# 处理上次生成的结果文件
Build_Path="./Build/"
# 检查是否存在 ./Build/ 文件夹
if [[ -d "$Build_Path" ]]; then
# 存在 ./Build/ 文件夹,则删除
rm -rf "$Build_Path"
echo "删除上次生成的结果文件"
mkdir $Build_Path
echo "创建 Build 文件夹"
else
# 不存在 ./Build/ 文件夹,则创建
mkdir $Build_Path
echo "创建 Build 文件夹"
fi
echo ""
echo ""
#==========================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 移动生成文件 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
# 移动结果文件到指定文件夹
if [[ -f "$File_Name.pdf" ]]; then
mv "$File_Name.pdf" $Build_Path
mv "$File_Name.synctex" $Build_Path
echo "移动结果文件到 Build 文件夹中"
else
echo "未生成结果文件"
fi
echo ""
echo ""
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 目录生成情况 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
echo $Catalogs
echo ""
echo ""
#==========================================================================
echo ================================================================================
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 统计编译时长 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo ================================================================================
# 计算结束时间
End_Time=$(date +"%s")
# 计算运行时长
Run_Time=$(($End_Time - $Start_Time))
Hours=$((Run_Time / 3600))
Minutes=$(((Run_Time % 3600)/60))
Seconds=$((Run_Time % 60))

echo "编译时长为:$Hours 小时 $Minutes$Seconds 秒 (($Run_Time)s total)"
echo ""

# 延时关闭 5s
# sleep 5
Loading

0 comments on commit 695fc53

Please sign in to comment.