LatexMk

t

After installing the TeX distribution and having created a project folder with a .tex file in it, you can simply enter your project directory and invoke it using the following command:

latexmk [file]

If you want to use pdflatex instead, use

latexmk -pdf [file]

If you have only one tex file in the current directory, you can omit ‘[file]’ in both cases. But that’s not the end of the feature list! Use the following command to open the resulting PDF file in your system’s PDF viewer.

latexmk -pdf -pvc [file]

If you appear to be not an utterly ultimate LaTeX guru or you are using the tikzDevice with R, or similar, you might want to get rid of pdflatex’s interactive mode, which prompts on every error. Use the following command line to keep pdflatex quiet.

latexmk -pdf -pvc -silent [file]

If you appear to have Skim on Mac OS X, you might want to add the following lines to your ${HOME}/.latexmkrc (which you might need to create):

$pdf_previewer = 'osascript -e "set theFile to POSIX file \"%S\" as alias" -e "set thePath to POSIX path of theFile" -e "tell application \"Skim\"" -e "open theFile" -e "end tell"';
$pdf_update_method = 4;
$pdf_update_command = '/usr/bin/osascript -e "set theFile to POSIX file \"%S\" as alias" -e "set thePath to POSIX path of theFile" -e "tell application \"Skim\"" -e  "  set theDocs to get documents whose path is thePath" -e "  try" -e "    if (count of theDocs) > 0 then revert theDocs" -e "  end try" -e "  open theFile" -e "end tell"';
$latex = 'latex --shell-escape';
$pdflatex = 'pdflatex --shell-escape';

# added for using glossaries
add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
sub makeglo2gls {
  system("makeindex -s '$_[0]'.ist -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo");
}

# automatically convert R to .tex
# (needs to use tikzDevice and R file needs to have the same file base as tex file)
add_cus_dep( 'R', 'tex', 0, 'CallRscript');
sub CallRscript {
    system("cd `dirname $_[0].R` && Rscript `basename $_[0].R` `basename $_[0].tex`");
}

These lines make sure, that latexmk opens the PDF file in Skim (ignoring your system default settings) and tells Skim to reload the file every time the PDF is updated. Note that the update command may not be necessary depending on your Skim version. Besides that, the configuration adds some magic in case you are using the tikzDevice, R and glossaries.

Cheers, iss

Flattr: