编译时出现错误这个模板和pdflatex -output-directory=./_out thesis.tex
:
! I can't write on file `text/abbreviations.aux'.
\@include ...\immediate \openout \@partaux #1.aux
\immediate \write \@partau...
l.187 \include{text/abbreviations}
(Press Enter to retry, or Control-D to exit; default file extension is `.tex')
Please type another output file name: ^D
! Emergency stop.
\@include ...\immediate \openout \@partaux #1.aux
\immediate \write \@partau...
l.187 \include{text/abbreviations}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on _out/thesis.log.
这通常是我使用该选项的方式-output-directory
,以前我从未遇到过这种使用问题,但我一定是做错了什么,因为没有这个选项,编译工作仍然正常。
文件树
ls -R
来自项目根目录的结果:
_README.txt _out figures ociamthesis.cls references.bib splitcolor.py text thesis.tex
./_out:
thesis.aux thesis.bcf thesis.lof thesis.mtc thesis.out
thesis.bbl thesis.blg thesis.log thesis.mtc0 thesis.toc
./figures:
beltcrest.pdf sample
./figures/sample:
Gray498.png
./text:
abbreviations.tex abstract.tex acknowledgements.tex appendix-1.tex ch1-intro.tex ch2-litreview.tex
版本
我在 OSX 上,pdflatex 手册没有显示任何选项-aux_directory
,我的版本是:
pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015)
kpathsea version 6.2.1
Copyright 2015 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.17; using libpng 1.6.17
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with xpdf version 3.04
答案1
@DavidCarlisle 在 OP 的评论中提出了一个解决方案。似乎只需创建一个子目录_out/text
即可使编译成功。
答案2
我遇到了同样的问题,并通过编写构建脚本解决了该问题,该脚本在我的构建文件夹中创建子目录,这些子目录在编译之前镜像我的源文件夹中的子目录:
#!/bin/sh
for OUTPUT in $(find src -type d)
do
mkdir dist/$OUTPUT
done
pdflatex -output-directory=./dist ./src/main.tex
这样就免去了每次添加子目录时手动创建子目录的麻烦。
答案3
灵感来自这答案 我编写了一个正确的 shell 脚本1来自动创建所有需要的输出目录。它可以正确处理包含空格的文件名 - 但它无法处理包含换行符的文件名2。
用法
将下面的代码保存为create_output_dirs.sh
(或任何你喜欢的名称)并使用使其可执行chmod +x create_output_dirs.sh
。
确保您位于 Latex 项目的根目录中并执行该脚本。
例如,如果脚本保存在你的主目录中:
~/.create_output_dirs.sh outdir
这将创建一个outdir
目录并在其中复制当前目录的目录结构。如果没有给出参数,它将用作dst
目标目录。
在寻找要创建的目录时,它不会递归目标目录 - 您可以多次运行它而不删除输出目录。
代码
#!/bin/sh
# if no parameter is given, use 'dst' as destination directory
if [ -z "$1" ]; then
dst=dst
else
dst="$1"
fi
# find all directories which are not the destination dir or inside it
find . -type d -not -name "$dst" -not -path "./$dst/*" -printf '%P\n' \
| while IFS= read -r dir
do
mkdir -p "$dst/$dir"
done
1 这意味着 POSIX shell。此外它需要find
2 您真的不应该有这些文件名!
答案4
这是我的解决方案,与凯尔·米尼汉,但使用起来更复杂一些Makefile
:
#!/usr/bin/make -f
# https://stackoverflow.com/questions/7123241/makefile-as-an-executable-script-with-shebang
ECHOCMD:=/bin/echo -e
SHELL := /bin/bash
# The main latex file
THESIS_MAIN_FILE := main
# This will be the pdf generated
THESIS_OUTPUT_NAME := thesis
# This is the directory where the temporary files are going to be
CACHE_DIRECTORY := cache
THESIS_MAIN_FILE_PATH := $(CACHE_DIRECTORY)/$(THESIS_MAIN_FILE).pdf
# Find all files ending with `main.tex`
LATEX_SOURCE_FILES := $(wildcard *main.tex)
# Create a new variable within all `LATEX_SOURCE_FILES` file names ending with `.pdf`
LATEX_PDF_FILES := $(LATEX_SOURCE_FILES:.tex=.pdf)
# https://stackoverflow.com/questions/55642491/how-to-check-whether-a-file-exists-outside-a-makefile-rule
FIND_EXEC := $(if $(wildcard /bin/find),,/usr)/bin/find
.PHONY: all help latex thesis verbose clean biber_hook biber_hook1 pdflatex_hook \
pdflatex_hook1 pdflatex_hook2 pdflatex_hook3 pdflatex_hook4
# http://stackoverflow.com/questions/1789594/how-do-i-write-the-cd-command-in-a-makefile
.ONESHELL:
# Default target
# https://stackoverflow.com/questions/46135614/how-to-call-makefile-recipe-rule-multiple-times
all: pdflatex_hook1 biber_hook1 pdflatex_hook2 pdflatex_hook3 pdflatex_hook4 biber
# https://tex.stackexchange.com/questions/91592/where-to-find-official-and-extended-documentation-for-tex-latexs-commandlin
# https://tex.stackexchange.com/questions/52988/avoid-linebreaks-in-latex-console-log-output-or-increase-columns-in-terminal
PDF_LATEX_COMMAND = pdflatex --synctex=1 -halt-on-error -file-line-error
PDF_LATEX_COMMAND += $(if $(shell pdflatex --help | grep time-statistics),--time-statistics,)
PDF_LATEX_COMMAND += $(if $(shell pdflatex --help | grep max-print-line),--max-print-line=10000,)
LATEX = $(PDF_LATEX_COMMAND) --interaction=batchmode
LATEX += $(if $(shell pdflatex --help | grep aux-directory),-aux-directory="$(CACHE_DIRECTORY)",)
LATEX += $(if $(shell pdflatex --help | grep output-directory),-output-directory="$(CACHE_DIRECTORY)",)
# Copies the PDF to the current directory
# https://stackoverflow.com/questions/55671541/how-define-a-makefile-condition-and-reuse-it-in-several-build-rules/
define copy_resulting_pdf=
if [[ -f "${THESIS_MAIN_FILE_PATH}" ]]; \
then \
printf 'Coping PDF...\n'; \
cp "${THESIS_MAIN_FILE_PATH}" "${current_dir}/${THESIS_OUTPUT_NAME}.pdf"; \
else \
printf "\\nError: The PDF "${THESIS_MAIN_FILE_PATH}" was not generated!\\n"; \
exit 1; \
fi
endef
# https://stackoverflow.com/questions/4210042/exclude-directory-from-find-command
DIRECTORIES_TO_CREATE := $(shell "${FIND_EXEC}" -not -path "./**.git**" \
-not -path "./pictures**" -type d \
-not -path "./${CACHE_DIRECTORY}**" -type d)
# https://stackoverflow.com/questions/11469989/how-can-i-strip-first-x-characters-from-string-using-sed
define setup_envinronment =
$(eval current_dir := $(shell pwd)) echo $(current_dir) > /dev/null
printf "\\n";
readarray -td' ' DIRECTORIES_TO_CREATE_ARRAY <<<"$(DIRECTORIES_TO_CREATE) "; \
unset 'DIRECTORIES_TO_CREATE_ARRAY[-1]'; \
declare -p DIRECTORIES_TO_CREATE_ARRAY; \
for directory_name in "$${DIRECTORIES_TO_CREATE_ARRAY[@]}"; \
do \
full_cache_directory="${CACHE_DIRECTORY}/$${directory_name:2}"; \
printf "Creating %s\\n" "$${full_cache_directory}"; \
mkdir -p "$${full_cache_directory}"; \
done
printf "\\n";
endef
# Run pdflatex, biber, pdflatex
biber: setup_things biber_hook pdflatex_hook
$(copy_resulting_pdf)
setup_things:
$(setup_envinronment)
# Call biber to process the bibliography and does not attempt to show the elapsed time
# https://www.mankier.com/1/biber --debug
biber_hook biber_hook1:
$(setup_envinronment)
echo "Running biber quietly..."
biber --quiet --input-directory="$(CACHE_DIRECTORY)" --output-directory="$(CACHE_DIRECTORY)" $(THESIS_MAIN_FILE).bcf
# https://stackoverflow.com/questions/46135614/how-to-call-makefile-recipe-rule-multiple-times
pdflatex_hook pdflatex_hook1 pdflatex_hook2 pdflatex_hook3 pdflatex_hook4: setup_things
@$(LATEX) $(LATEX_SOURCE_FILES)
# This rule will be called for every latex file and pdf associated
latex: $(LATEX_PDF_FILES)
$(setup_envinronment)
# Dynamically generated recipes for all PDF and latex files
%.pdf: %.tex
$(setup_envinronment)
@$(LATEX) $<
clean:
$(RM) -rv $(CACHE_DIRECTORY)
$(RM) -v $(THESIS_OUTPUT_NAME).pdf
原文及全文请见Makefile
此处: