防止 tex 目录被构建输出弄乱的 Makefile

防止 tex 目录被构建输出弄乱的 Makefile

我正在使用xelatexbibermakeglossaries来生成我的学士论文。它们都创建了大量的临时文件,这些文件不仅使我的根文档目录变得杂乱无章,而且使我的论文的整个目录结构也变得杂乱无章。以前,我曾大量使用和,目的findrm摆脱所有垃圾。cleanMakefile

目前我的想法是将构建论文所需的所有内容复制到.build子目录中,然后cd复制到 Makefile 中的该目录中,然后再开始编译。我尝试使用output-directoryxelatex 和 biber 开关(makeglossaries 没有),但没有成功。这就是为什么我想在子目录中生成 pdf,这样在编译和复制创建的 之后,我可以安全地删除其中包含所有内容的 pdf pdfs,使用rm -rf .build/*

这里是 Makefile(screen或者print目标中有趣的部分,正如你所看到的):

#
# Makefile for Bachelorthesis
#
# @ supresses command output
#
# conditionals are not allowed to have a starting tab, 
# otherwise they will be sent to the shell
#
DEBUG='true'
ROOT_DIR=$(shell pwd)
BUILD_DIR=$(ROOT_DIR)/.build
XELATEX_OPTS=-output-directory=$(BUILD_DIR)
BIBER_OPTS=--output_directory=$(BUILD_DIR)
.PHONY : clearscr clean screen print

all: copy_sources screen print copy_output

copy_sources:
    rsync --verbose --checksum --recursive --human-readable --progress --exclude=output --exclude=.git* $(ROOT_DIR)/ $(ROOT_DIR)/.build

copy_output:
    cp --update $(BUILD_DIR)/*.pdf $(ROOT_DIR)/output

screen:
    @echo "Building screen version ..."
    @cd $(BUILD_DIR)
ifeq ($(DEBUG) , 'true')
    @echo "\n------------------ xelatex --------------------\n"     
    xelatex thesis $(XELATEX_OPTS) | grep --ignore-case warning
    @echo "\n------------------- biber ---------------------\n" 
    biber thesis $(BIBER_OPTS)
    @echo "\n--------------- makeglossaries ----------------\n"         
    makeglossaries thesis
    @echo "\n------------------ xelatex --------------------\n" 
    xelatex thesis $(XELATEX_OPTS) | grep --ignore-case warning     
else
    xelatex thesis $(XELATEX_OPTS) > /dev/null  
    biber thesis $(BIBER_OPTS) > /dev/null          
    makeglossaries thesis > /dev/null   
    xelatex thesis $(XELATEX_OPTS) > /dev/null          
endif

print:
    @echo "Building print version ..."
    cd $(BUILD_DIR)
ifeq ($(DEBUG) , 'true')
    @echo "\n------------------ xelatex --------------------\n" 
    xelatex thesis_print $(XELATEX_OPTS) | grep --ignore-case warning
    @echo "\n------------------- biber ---------------------\n"     
    biber thesis_print $(BIBER_OPTS)        
    @echo "\n--------------- makeglossaries ----------------\n" 
    makeglossaries thesis_print
    @echo "\n------------------ xelatex --------------------\n"     
    xelatex thesis_print $(XELATEX_OPTS) | grep --ignore-case warning       
else
    xelatex thesis_print $(XELATEX_OPTS) > /dev/null            
    biber thesis_print $(BIBER_OPTS) > /dev/null            
    makeglossaries thesis_print > /dev/null 
    xelatex thesis_print $(XELATEX_OPTS) > /dev/null            
endif

clean:
    @echo "I will clean up this mess ..."
    @rm -rf $(BUILD_DIR)/*
    # remove the following commands, if the build was started in the BUILD_DIR successfully
    @rm -f *.out *.nav *.snm *.toc *.log *.bcf *.bbl *.blg *.lof *.lol *.lot *.run.xml *.xdy *.glo *.glg *.gls *.idx *.ist *-blx.bib .*.bbl.swp *.mtc* *.maf
    @find . -name \*.aux  -type f -delete
    @find . -name \*.bbl  -type f -delete
    @find . -name \*.bak  -type f -delete
    @find . -name \*.blg  -type f -delete
    @find . -name \*.fls  -type f -delete
    @find . -name \*.fdb_latexmk  -type f -delete
    @find . -name \*.vsdx  -type f -delete
    @find $(ROOT_DIR) -name '*in Konflikt stehende*' -delete

clearscreen:
    clear

这是编译后的文档根目录,有大量的临时垃圾:

    abstract.aux     _dump        synctooutput.sh   thesis.lol   thesis.mtc6       thesis_print.gls   thesis_print.mtc2  thesis_print.run.xml
abstract.tex     frontpage    synctooutput.sh~  thesis.lot   thesis.mtc7       thesis_print.ist   thesis_print.mtc3  thesis_print.tex
affidavit.aux    header       thesis.aux        thesis.maf   thesis.mtc8       thesis_print.lof   thesis_print.mtc4  thesis_print.toc
affidavit.tex    LICENSE      thesis.bcf        thesis.mtc   thesis.mtc9       thesis_print.log   thesis_print.mtc5  thesis.run.xml
appendix         license.aux  thesis.glg        thesis.mtc0  thesis.out        thesis_print.lol   thesis_print.mtc6  thesis.tex
attachments      license.tex  thesis.glo        thesis.mtc1  thesis.pdf        thesis_print.lot   thesis_print.mtc7  thesis.toc
bibliography     Makefile     thesis.gls        thesis.mtc2  thesis_print.aux  thesis_print.maf   thesis_print.mtc8  tikz_pgf
bibtexEntry.tex  output       thesis.ist        thesis.mtc3  thesis_print.bcf  thesis_print.mtc   thesis_print.mtc9  todos.sh
content          README       thesis.lof        thesis.mtc4  thesis_print.glg  thesis_print.mtc0  thesis_print.out   variables
document.tex     resources    thesis.log        thesis.mtc5  thesis_print.glo  thesis_print.mtc1  thesis_print.pdf

看来 xelatex 和 co 没有使用由输出目录-switch,而是使用工作目录的 Makefile。我甚至cd在开始编译之前尝试过使用命令仅使用 /wo 选项,结果相同。

请帮我删除所有临时文件:)

答案1

我明白了,也许这对其他人有帮助,或者可以作为创建 Makefile 的灵感。问题在于命令cd以及如何make执行命令,就像我在上面的评论中提到的那样。

生成文件:

#
# Makefile for Bachelorthesis
#
#   Andreas Linz -- 10INB-T
#   HTWK-Leipzig, Fakultaet IMN
#   [email protected]
#
# @ supresses command output
#
# conditionals are not allowed to have a starting tab, 
# otherwise they will be sent to the shell
#
DEBUG='true'
ROOT_DIR=$(shell pwd)
BUILD_DIR=$(ROOT_DIR)/.build
OUTPUT_DIR=$(ROOT_DIR)/output
#.PHONY : clearscr clean screen print

all: copy_sources screen print copy_output

copy_sources:
    @echo "Copying sources to build folder: $(BUILD_DIR)"
    @rsync --verbose --checksum --recursive --human-readable --progress --exclude=.build --exclude=.build_scripts --exclude=output --exclude=.git --exclude=.gitignore $(ROOT_DIR)/ $(ROOT_DIR)/.build

copy_output:
    @echo "Copying generated PDFs to output folder: $(OUTPUT_DIR)"
    @cp -f $(BUILD_DIR)/*.pdf $(OUTPUT_DIR)

screen:
    @echo "Building screen version ..."
ifeq ($(DEBUG) , 'true')
    .build_scripts/screen.sh $(BUILD_DIR) $(DEBUG) 
else
    .build_scripts/screen.sh $(BUILD_DIR) $(DEBUG)
endif

print:
    @echo "Building print version ..."
ifeq ($(DEBUG) , 'true')
    .build_scripts/print.sh $(BUILD_DIR) $(DEBUG)       
else
    .build_scripts/print.sh $(BUILD_DIR) $(DEBUG)
endif

clean_conflicts:
    @find $(ROOT_DIR) -name '*in Konflikt stehende*' -delete
    @find $(ROOT_DIR) -name '*conflicted copy*' -delete

clean: clean_conflicts
    @echo "I will clean up this mess ..."
    @cd $(BUILD_DIR); rm -r *

clean_all: clean
    @rm $(OUTPUT_DIR)/*

clearscreen:
    clear

# remove the following commands, if the build was started in the BUILD_DIR successfully
#   @rm -f *.out *.nav *.snm *.toc *.log *.bcf *.bbl *.blg *.lof *.lol *.lot *.run.xml *.xdy *.glo *.glg *.gls *.idx *.ist *-blx.bib .*.bbl.swp *.mtc* *.maf
#   @find . -name \*.aux  -type f -delete
#   @find . -name \*.bbl  -type f -delete
#   @find . -name \*.bak  -type f -delete
#   @find . -name \*.blg  -type f -delete
#   @find . -name \*.fls  -type f -delete
#   @find . -name \*.fdb_latexmk  -type f -delete
#   @find . -name \*.vsdx  -type f -delete
#   @find $(ROOT_DIR) -name '*in Konflikt stehende*' -delete

构建脚本:

屏幕.sh:

#!/bin/bash
#
# script for generating the print pdfs
# this script should be called from the Makefile in the document root
#
# check number of arguments with `$# -eq 0`
#

if [ $# == 2 ]; then
    echo "Changing directory to: $1"
    cd $1
    if [ $2 = 'true' ]; then
        echo "12345: $XELATEX_OPTS"
        echo -e "\n------------------ xelatex --------------------\n"     
        xelatex $XELATEX_OPTS thesis #|grep --ignore-case --extended-regex "info|warning|error|^\([A-Za-z0-9]*\)"
        echo -e "\n------------------- biber ---------------------\n" 
        biber $BIBER_OPTS thesis
        echo -e "\n--------------- makeglossaries ----------------\n"         
        makeglossaries thesis
        echo -e "\n------------------ xelatex --------------------\n" 
        xelatex $XELATEX_OPTS thesis > /dev/null
    else
        xelatex $XELATEX_OPTS thesis > /dev/null  
        biber $BIBER_OPTS thesis > /dev/null          
        makeglossaries thesis > /dev/null   
        xelatex $XELATEX_OPTS thesis > /dev/null
    fi
else
    echo "Number of arguments given: $#"
    echo "Usage: ./screen.sh path_to_build_dir [true/false]"
fi

打印.sh:

#!/bin/bash
#
# script for generating the print pdfs
# this script should be called from the Makefile in the document root
#
# check number of arguments with `$# -eq 0`
#

XELATEX_OPTS=""
BIBER_OPTS=""

if [ $# == 2 ]; then
    echo "Changing directory to: $1"
    cd $1
    if [ $2 = 'true' ]; then
        echo -e "\n------------------ xelatex --------------------\n"     
        xelatex $XELATEX_OPTS thesis_print > /dev/null
        echo -e "\n------------------- biber ---------------------\n" 
        biber $BIBER_OPTS thesis_print 
        echo -e "\n--------------- makeglossaries ----------------\n"         
        makeglossaries thesis_print
        echo -e "\n------------------ xelatex --------------------\n" 
        xelatex $XELATEX_OPTS thesis_print | grep --ignore-case --extended-regex "info|warning|error|^\([A-Za-z0-9]*\)"
    else
        xelatex $XELATEX_OPTS thesis_print > /dev/null  
        biber $BIBER_OPTS thesis_print > /dev/null          
        makeglossaries thesis_print > /dev/null   
        xelatex $XELATEX_OPTS thesis_print > /dev/null
    fi
else
    echo "Number of arguments given: $#"
    echo "Usage: ./screen.sh path_to_build_dir [true/false]"
fi

答案2

pdflatex正在使用

-aux-directory=

临时文件的选项,看起来xelatex有相同的选项但未经测试。

答案3

我真的不明白为什么 TeX 社区会觉得所有“输入”文件都必须在每个文件内硬编码一个“几乎完整的路径”是理所当然的。如果有一些 \inputrelativetome 输入命令,比如

#include "local_file.h"

在 C 语言中,那么重命名子目录就几乎毫不费力了。我遵循的原则是,事物应该尽可能本地化。

我喜欢使用 build/ 目录。我使用一个名为答案生成书末练习的答案(我的书)。我终于找到了一个简单的“构建目录”问题解决方案。我只需调用:

TEXINPUTS=".:../build/:$TEXINPUTS" xelatex -output-directory=../build/ topologia_geral.tex

顺序“.:../build/”或“../build/:.”不应该成为问题,除非您打算生成名称与源目录中的文件冲突的文件。但无论如何,这不是一个好主意...

相关内容