I want to add a bash command that does the following:
Currently, I need to run this:
$ pdflatex <filename>.tex | open <filename>.pdf
Is there any way to convert that into something like
$ complatex <filename>
and have both commands executed?
I want to add a bash command that does the following:
Currently, I need to run this:
$ pdflatex <filename>.tex | open <filename>.pdf
Is there any way to convert that into something like
$ complatex <filename>
and have both commands executed?
How about this for a start:
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
}
Oneline version:
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 ;}
This function tests for an argument, if there is one it just runs pdflatex saving the output files in the argument's directory (instead of the current one) and opens the output .pdf in the default PDF viewer. If you call it without an argument, it goes through every .tex file in the current directory, tests whether there's a .pdf with the same name and only if not does the same as above.
To make the complatex command available on your system, just copy one of the two versions from above into either your ~/.bash_aliases (create it if necessary) or your ~/.bashrc file and open up a new terminal or source the changed file in an existing one with e.g. source ~/.bash_aliases.
$ 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