Làm thế nào về điều này để bắt đầu:
complatex ()
{
if [[ -n $1 ]]; then
pdflatex -output-directory $(dirname "$1") "$1" &&
xdg-open "${1%%.tex}.pdf"
else
for i in *.tex; do
if [[ ! -f ${i%%.tex}.pdf ]]; then
pdflatex "$i" &&
xdg-open "${i%%.tex}.pdf"
fi
done
fi
}
Phiên bản trực tuyến:
complatex(){ if [[ $1 ]]; then pdflatex -output-directory $(dirname "$1") "$1" && xdg-open "${1%%.tex}.pdf"; else for i in *.tex; do if [[ ! -f ${i%%.tex}.pdf ]]; then pdflatex "$i" && xdg-open "${i%%.tex}.pdf"; fi; done; fi ;}
Hàm này kiểm tra một đối số, nếu có một đối số, nó chỉ chạy pdflatexlưu các tệp đầu ra trong thư mục của đối số (thay vì hiện tại) và mở đầu ra .pdftrong trình xem PDF mặc định. Nếu bạn gọi nó mà không có đối số, nó sẽ đi qua mọi .textệp trong thư mục hiện tại, kiểm tra xem có một .pdftên nào có cùng tên không và chỉ khi không thực hiện giống như trên.
Để complatexcung cấp lệnh trên hệ thống của bạn, chỉ cần sao chép một trong hai phiên bản ở trên vào tệp của bạn ~/.bash_aliases(tạo nếu cần) hoặc ~/.bashrcmở một thiết bị đầu cuối mới hoặc lấy nguồn đã thay đổi trong tệp hiện có với ví dụ source ~/.bash_aliases.
Chạy ví dụ
$ tree -A --noreport
.
├── dummy.pdf
├── dummy.tex
├── other\ dir
└── test.tex
$ complatex test.tex &>/dev/null # opens test.pdf in PDF viewer
$ tree -A --noreport
.
├── dummy.pdf
├── dummy.tex
├── other\ dir
├── test.aux
├── test.log
├── test.pdf
└── test.tex
$ rm -f test.!(tex) # removes the output files that were just created
$ cd other\ dir/
$ complatex ../test.tex &>/dev/null # opens test.pdf in PDF viewer
$ ls # other dir stays empty
$ cd ..
$ tree -A --noreport
.
├── dummy.pdf
├── dummy.tex
├── other\ dir
├── test.aux
├── test.log
├── test.pdf
└── test.tex
$ rm -f test.!(tex) # removes the output files that were just created
$ complatex &>/dev/null # opens test.pdf in PDF viewer, doesn't process dummy.tex as there's a dummy.pdf already
$ tree -A --noreport
.
├── dummy.pdf
├── dummy.tex
├── other\ dir
├── test.aux
├── test.log
├── test.pdf
└── test.tex
{}một cú pháp trongfindlệnh?