登录
/
注册
首页
论坛
其它
首页
科技
业界
安全
程序
广播
Follow
关于
签到
每天签到奖励2-10圆
导读
排行榜
TG频道
发帖说明
登录
/
注册
账号
自动登录
找回密码
密码
登录
立即注册
搜索
搜索
关闭
CSDN热搜
程序园
精品问答
技术交流
资源下载
本版
帖子
用户
软件
问答
教程
代码
写记录
VIP申请
VIP网盘
网盘
联系我们
发帖说明
每日签到
道具
勋章
任务
淘帖
动态
分享
留言板
导读
设置
我的收藏
退出
腾讯QQ
微信登录
返回列表
首页
›
业界区
›
科技
›
$\LaTeX{}$之快速编译和删除中间文件
$\LaTeX{}$之快速编译和删除中间文件
[ 复制链接 ]
施婉秀
2025-10-1 13:38:05
本文介绍了在 \(\LaTeX{}\) 中如何使用批处理文件和Makefile来实现快速编译和删除中间文件,保持工作目录的清爽整洁。
批处理文件
在Windows下可以使用批处理文件来处理,也可以使用Makefile(但需配置make环境)。这里为了操作简单性,在Windows下只介绍如何使用批处理文件来实现快速删除中间文件和快速编译。
快速删除中间文件(辅助文件)
步骤如下:
新建文本文件命名为clean.bat;
复制下面的代码放到文本文件中;
@echo off
echo Cleaning auxiliary files...
del /s /q "*.aux" "*.log" "*.out" "*.bbl" "*.blg" "*.toc" "*.lof" "*.lot" "*.synctex.gz"
echo Cleaning completed!
pause
复制代码
将文件放入主文件(.tex)所在文件夹中,双击运行即可删除中间文件以及子文件夹中的中间文件。
快速编译并删除中间文件
步骤如下:
新建文本文件命名为compile.bat;
复制下面的代码放到文本文件中;
@echo off
:: ==============================================
:: LaTeX Compile Automation Script (XeLaTeX + BibTeX)
:: Usage: Drag and drop the .tex file onto this script or manually specify the file name
:: ==============================================
:: set variable
set TEX_COMPILER=xelatex
set BIB_COMPILER=bibtex
set MAX_ATTEMPTS=3
set LOG_EXTENSIONS=*.aux *.log *.out *.bbl *.blg *.toc *.lof *.lot *.synctex.gz
:: Check whether the file is obtained by dragging
if "%~1"=="" (
echo Error: Please drag the .tex file onto this script or manually specify the file name
pause
exit /b 1
)
:: Extract the file name (without extension)
set "TEX_FILE=%~1"
set "BASE_NAME=%~n1"
:: Compile function definition
:compile
echo.
echo =============== Start Compiling... ===============
echo Compiling document: %TEX_FILE%
:: First XeLaTeX Compilation
echo.
echo [1/4] First %TEX_COMPILER% compiling...
%TEX_COMPILER% -interaction=nonstopmode -synctex=1 "%BASE_NAME%.tex"
if %ERRORLEVEL% neq 0 (
echo Error: First %TEX_COMPILER% Compilation failed
goto error_handling
)
:: BibTeX Compilation
echo.
echo [2/4] %BIB_COMPILER% compiling reference...
%BIB_COMPILER% "%BASE_NAME%.aux"
if %ERRORLEVEL% neq 0 (
echo Warning: %BIB_COMPILER% There may be issues with the compilation (check the .blg file)
)
:: Second XeLaTeX Compilation
echo.
echo [3/4] Second %TEX_COMPILER% compiling...
%TEX_COMPILER% -interaction=nonstopmode -synctex=1 "%BASE_NAME%.tex"
if %ERRORLEVEL% neq 0 (
echo Error: Second %TEX_COMPILER% Compilation failed
goto error_handling
)
:: Third XeLaTeX Compilation (Ensure correct cross-referencing)
echo.
echo [4/4] Third %TEX_COMPILER% compiling...
%TEX_COMPILER% -interaction=nonstopmode -synctex=1 "%BASE_NAME%.tex"
if %ERRORLEVEL% neq 0 (
echo Error: Third %TEX_COMPILER% Compilation failed
goto error_handling
)
:: Cleaning auxiliary files (Optional)
echo.
echo Cleaning auxiliary files...
del /s /q %LOG_EXTENSIONS% 2>nul
:: Completed Successfully
echo.
echo =============== Compilation Completed Successfully ===============
echo Final output file: %BASE_NAME%.pdf
start "" "%BASE_NAME%.pdf" :: Automatically open the generated PDF
goto end
:: Error Handling
:error_handling
set /a ATTEMPTS+=1
if %ATTEMPTS% lss %MAX_ATTEMPTS% (
echo.
echo Attempting to fix the issue (attempt %ATTEMPTS%/3)...
goto compile
)
echo.
echo =============== Compilation Failed ===============
echo After %MAX_ATTEMPTS% attempts, it has not been successful. Please check the logs:
type "%BASE_NAME%.log" | more
goto end
:end
pause
复制代码
将文件放入主文件(.tex)所在文件夹中,拖动主文件到该脚本上,或者命令行运行:compile.bat main.tex。
注意事项:
TEX_COMPILER可更换为pdflatex或lualatex编译命令,且删除辅助文件的命令可选择删除掉,避免每次都需要重新生成中间文件浪费时间。
Makefile
常规编译方法
[code]# 定义编译器LATEX = xelatex# 定义需要清理的辅助文件扩展名AUX_FILES = *.aux *.log *.out *.toc *.lof *.lot *.bbl *.blg *.synctex.gz *.fls *.fdb_latexmk *.run.xml *.nav *.snm *.vrb *.bcf *.idx *.ilg *.ind *.xdv# 获取当前目录下所有 .tex 文件(排除带空格的文件名)TEX_FILES = $(wildcard *.tex)PDF_FILES = $(TEX_FILES:.tex=.pdf)# 默认目标:编译所有 .tex 文件all: $(PDF_FILES) @echo "编译完成!"# 模式规则:从 .tex 生成 .pdf%.pdf: %.tex $(LATEX) -interaction=nonstopmode -halt-on-error $< #@# 如果有参考文献,运行 biber 或 bibtex #@if [ -f $(basename $
LaTeX
快速
编译
删除
中间
相关帖子
Ubuntu 20下PostgreSQL 17.6 源码编译安装
微软.net表达式编译居然有bug?
Oracle清理:如何安全删除trace, alert和archivelog文件?
快速幂算法的基础和扩展
独立开发经验谈:用视频快速讲解你的产品核心竞争力
Avalonia实战之Native AOT编译
Claude Code MCP 快速高效使用指南
记一次ADL导致的C++代码编译错误
Kafka如何快速的入个门呢?
PostgreSQL 18 源码编译安装体验
vip免费申请,1年只需15美金$
回复
使用道具
举报
提升卡
置顶卡
沉默卡
喧嚣卡
变色卡
千斤顶
照妖镜
相关推荐
安全
Ubuntu 20下PostgreSQL 17.6 源码编译安装
0
763
晖顶蝇
2025-10-01
业界
微软.net表达式编译居然有bug?
0
964
司空娅玲
2025-10-01
安全
Oracle清理:如何安全删除trace, alert和archivelog文件?
0
275
越蔓蔓
2025-10-01
业界
快速幂算法的基础和扩展
0
798
忙贬
2025-10-03
业界
独立开发经验谈:用视频快速讲解你的产品核心竞争力
0
237
孜稞
2025-10-05
安全
Avalonia实战之Native AOT编译
0
807
歇凛尾
2025-10-06
科技
Claude Code MCP 快速高效使用指南
0
510
劳怡月
2025-10-06
业界
记一次ADL导致的C++代码编译错误
0
528
陈兰芳
2025-10-06
安全
Kafka如何快速的入个门呢?
0
567
炳裘垦
2025-10-07
安全
PostgreSQL 18 源码编译安装体验
0
252
懵崭
2025-10-08
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
回复
本版积分规则
回帖并转播
回帖后跳转到最后一页
浏览过的版块
安全
签约作者
程序园优秀签约作者
发帖
施婉秀
2025-10-1 13:38:05
关注
0
粉丝关注
26
主题发布
板块介绍填写区域,请于后台编辑
财富榜{圆}
anyue1937
9999501
dage888
999994
富账慕
10013
4
匝抽
9986
5
孙淼淼
9992
6
筒濂
9985
7
柴古香
9993
8
凌彦慧
9991
9
崔瑜然
9984
10
慢秤
9979
查看更多