[Tex/LaTex] Using latexmk with multiple tex files in the directory

compilingincludeinputlatexmkmultiple files

edit

solution to compile :

latexmk -pdf mainfile.tex

I have left this example up as it might contain language used by others unfamiliar with this area 🙂

At the very least it provides a Minimal Working example of compiling a master file which includes a sub file, as well as a bibliography. All these are in the same directory for this example (I'm sure there are more pragmatic solutions to file management, "an exercise to the reader…").

Here is a bash alias that I use as I always have the main file called main.tex

# latex compile if files called main
alias ltmk="latexmk -bibtex -pdf -pvc ./main.tex"

I can't vouch for that being best practice – it works for me though.


I can compile a document using latexmk -pdf

If i have a tex file as a master that includes other tex files latexmk seems to get confused, I'm just wondering what the best practice is here?

I've tried to specify the master file with something like latexmk master.tex -pdf

thanks

Here's a MWE (I think!)

Main File

\documentclass[11pt,a4paper,oneside]{book}
%------------------------------------------------------------
\usepackage[style=authoryear-comp]{biblatex}
\addbibresource{invest_bib.bib}
%------------------------------------------------------------

\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Something that I have written }\label{introduction}


This will be a citaion: \parencite{WinNT}
Here is another citation!(with parens) : \parencite{WinNT}
have another go \parencite{WinNT}

% this is the file that I would like to be input at this 
% location
\input{test}

\backmatter

\printbibliography

\end{document}

File to be included

\section{Something else}

This is something that's being included. 

Can I still cite things from the bib file that's in the 
directory? 

Like \parencite{WinNT}

I'm not sure....

Bib file

@online{WinNT,
  author = {MultiMedia LLC},
  title = {{MS Windows NT} Kernel Description},
  year = 1999,
  url = {http://web.archive.org/web/20080207010024/http://www.808multimedia.com/winnt/kernel.htm},
  urldate = {2010-09-30}
}

Best Answer

The problem here is that if you do not specify any files on latexmk's command line, it will, by default, try to compile all the tex files in the current directory. But if some of the files are input by others instead of being compilable by themselves, there will be errors, as the OP found.

The simplest work-around is, as observed in the question, to put the desired primary filename on the command line.

But it is nevertheless a convenience just to type latexmk and have the program figure out what to do. There are two configuration variables that can change latexmk's default behavior: See the documentation for @default_files and @default_excluded_files. [The second variable was only documented starting in v. 4.43a, which is the current version when I write this answer.]

In the example in the problem, putting the following lines in one of latexmk's configuration rc files will allow the simple command line latexmk to work

@default_excluded_files = ( 'test.tex' );
$pdf_mode = 1; $dvi_mode = $postscript_mode = 0;

As a bonus, I've added the second line so that just pdf files will be made, without the need to include -pdf on the command line, which I find convenient.

Related Question