Last active
September 7, 2020 22:13
-
-
Save HBelusca/eb5640ae2129a8f85c531c1ffb3c2d71 to your computer and use it in GitHub Desktop.
pdf-LaTeX Compilation Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: | |
:: pdf-LaTeX Compilation Script | |
:: (C) 2020 Hermès Bélusca-Maïto | |
:: | |
@echo off | |
setlocal enableextensions | |
if "%1"=="" ( | |
:Usage | |
echo. | |
echo Syntax: | |
echo %~nx0 build[-fast] name_of_tex_file | |
echo %~nx0 clean [name_of_tex_file] | |
exit /B | |
) | |
set "OPTION=%1" | |
if /I "%OPTION:~0,5%" EQU "build" ( | |
if NOT "%OPTION:~5%"=="" ( | |
if /I "%OPTION:~5%" NEQ "-fast" goto UnknownOpt | |
) | |
set "ACTION=Compiling" | |
) else if /I "%OPTION%" EQU "clean" ( | |
set "ACTION=Cleaning" | |
) else ( | |
:UnknownOpt | |
echo Unknown option '%OPTION%' | |
goto Usage | |
) | |
set "FILENAME=%~n2" | |
echo %ACTION% %FILENAME% | |
if /I "%OPTION:~0,5%" EQU "build" ( | |
if "%FILENAME%"=="" ( | |
echo. | |
echo No file name has been specified! | |
goto Usage | |
) | |
) | |
:: Delete the temporary files only if not doing the -fast build. | |
if /I "%OPTION:~5%" NEQ "-fast" ( | |
echo. | |
echo Deleting temporary files... | |
echo. | |
del *.aux | |
del *.bbl | |
del *.blg | |
del *.log | |
del *.out | |
if NOT "%FILENAME%"=="" (del %FILENAME%.pdf) | |
) | |
:: If we just wanted to clean the files, stop now. | |
if /I "%OPTION:~0,5%" NEQ "build" exit /B | |
:: Otherwise start compilation. | |
:: Do only one pass in -fast build. | |
if /I "%OPTION:~5%" NEQ "-fast" ( | |
set NUMPASSES=3 | |
) else ( | |
set NUMPASSES=1 | |
) | |
echo. | |
echo Compiling (Pass 1/%NUMPASSES%)... | |
echo. | |
pdflatex %FILENAME%.tex | |
:: Go directly to the end if we do the -fast build. | |
if /I "%OPTION:~5%" EQU "-fast" ( | |
goto Finish | |
) | |
echo. | |
echo Building bibliography... | |
echo. | |
for %%f in (*.aux) do bibtex %%f | |
echo. | |
echo Compiling (Pass 2/%NUMPASSES%)... | |
echo. | |
pdflatex %FILENAME%.tex | |
echo. | |
echo Compiling (Pass 3/%NUMPASSES%)... | |
echo. | |
pdflatex %FILENAME%.tex | |
:Finish | |
echo. | |
echo Done! | |
choice /C YN /M "Open the PDF file?" | |
if %errorlevel% EQU 1 (%FILENAME%.pdf) | |
exit /B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment