I've made two major modifications and one minor tweak to your initial commands:Īt the ends of the lines, I've added & symbols that tell the shell: "only execute the next command if this previous one has returned successfully." This saves extra errors if you've specified a file.tex that doesn't exist, or if the latex command fails for some reason. Here's a first draft of a function that does what you want: function ltx(). Functions can be defined in your shell's startup files and so would not need any modification to your $PATH and could be executed from any directory you find yourself in.
Yet another option is to create a function. Aliases are limited, though, because the shell only expands them when they are the first word in your command, and don't have a way to refer back to the passed parameter multiple times (it just gets appended to your alias text).
#Compile latex file in terminal how to
jcoppens showed how to do this as one of the commenters pointed out, you can put this shell script somewhere more central ( ~/bin?) and update your $PATH to include that directory so that you can then type ltx file.tex anywhere there's a file.tex and it'll do what you want.Īnother option is to create an alias.
This is an artificial limitation, IMHO, as maybe next week you want to work on some different files in a different directory.Ĭreating a shell script is one obvious solution to the problem - you have multiple commands that you chain together all the time, and you don't want to type them every time you want to generate a new postscript file. syntax) that the ltx script exists in your current directory. I'll enter another Answer just to give some additional perspective for future efforts.