I have noticed that makefiles sometimes do their job (they compile the document) and sometimes they don't (then, they claim nothing has changed). In the latter case, depending on how the makefile looks, there is no output at all or a message is prompted stating that there was nothing to do. In one of my examples, it tells "„example.pdf“ ist bereits aktuell." (translates to: "„example.pdf“ is already up-to-date.")
The latter is, I suppose, a feature (not a bug) to save time in case make is called when the source code did not change (because then, of course, there is in fact nothing to do). However, sometimes this behavior is wrong, because the LaTeX source code did change.
I was wondering (and investigating for some time) the precise reasons and circumstances when and why the make script does not recompile although the code has changed. The main reason for wondering about this is, of course, that I want to be able to force the script to recompile. In the course of writing this question I finally figured that out(!), but there are still open questions.
First, my observations and answers, then the open questions.
Consider the following MWE:
\documentclass{beamer}
\begin{document}
\begin{frame}
frame 1
\end{frame}
\end{document}
Now, consider two variants of makefiles, both are named "makefile". Careful: the lines following the label must be preceded by a tabulator, not by whitespaces.
Variant 1:
example.pdf:
pdflatex example.tex
pdflatex example.tex
Variant 2:
example:
pdflatex example.tex
pdflatex example.tex
To verify my observations, you will need to run both makefile variants. For convenience (i.e., to prevent renaming the files all the time) you can just call the first variant makefile1, the second makefile2, and then run either make -f makefile1 or make -f makefile2.
Apparently, the label used in the makefile (i.e. "example.pdf:" vs. "example:") determines whether they might not work. That is, variant 2 of the makefile (not using the ".pdf" ending in the label) will always recompile, no matter what (this can easily be verified via just calling the script multiple times without touching any tex files in between). Only variant 1 does sometimes (or always(?), see below) claim that nothing is to do.
This already answers my question of how to force recompiling (namely by just using a makecript label without the ending .pdf). Still, I still have the following questions:
(A) Why is this the case? What is the semantics of the label ending ".pdf"? More importantly, how were I supposed to find out about that? I really gave my best finding a manual for LaTeX makefiles or related stackoverlow questions but really couldn't find anything! Nobody even seemed to have my problem that the script did not run although the LaTeX source code did indeed change.
(B) I did my best finding a MWE example which proves that the makescript variant 1 sometimes does recompile, but not in all cases in which it should. Still, I failed. When creating this post, I was not able to reproduce this behavior. Instead, makefile variant 1 did always claim that nothing was to do as long as the PDF existed -- not matter how (extremely) severe the changes in the code were (even if I deleted all content present in the compiled PDF and created completely new content it still did not recompile). Thus my question: Did I just remember/recognize it incorrectly before that also variant 1 does sometimes recompile (even when a PDF exists) or does it really never recompile as long as the result PDF exists? If it does sometimes recompile (which is what I believed prior to writing this) I'd be happy for a MWE, just out of curiosity.
Thank you!
example.pdfisn't present. Change your rule toexample.pdf: example.tex. – David Purton Nov 03 '18 at 03:47exampleis ever produced. So it always tries to run it. – David Purton Nov 03 '18 at 03:49makefile tutorialor something similar to learn how they work in general. You might also be interested inlatexmkwhich is often better suited to building latex files. – David Purton Nov 03 '18 at 03:54