I'm teaching Math Methods of Physics this fall, and want to provide written notes after class for the students to use. I'd like for them to be individual lectures, but combinable into one document with page numbers and a table of contents. (I'm currently using the article class, sections, subsections and subsubsections.) Naturally, I'll be using images, mathematical equations, arrays, and all that sweet LaTeX goodness.

I've read over the descriptions of how to use \input and \include, as well as the packages \standalone and \subfiles. What's the cleanest way to get continuous page numbering and the ability to create a ToC from a bunch of individual files? I'm still not sure of the relative strengths and weaknesses of these approaches. Importantly, will the page numbers carry over from one lecture to the next? If not, a ToC will be fairly useless.

My headers for an individual lecture (clearly needs editing to get to where I want to go):

\documentclass[11pt, letterpaper]{article}
\lhead{Mathematical Methods of Physics}                
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\graphicspath{ {./graphics/} }

\newcommand{\bull}{\, \vcenter{\hbox{\tiny$\bullet$}} \,} % middle sized dot, between \cdot and \bullet, in math mode
\newcommand{\inv}{\:\!{\text -}1}
\newcommand{\dx}{\dfrac{\mathrm{d}}{\mathrm{d} x}}

\title{Mathematical Methods of Physics}
\author{Martin F. Melhus}


Physics 309 covers the mathematical methods of physics.  The class meets on Monday, Wednesday, and Friday, from 1:00 PM to 1:50 PM, in Kirkbride Hall, room xxx.  The instructor is Professor Martin Melhus.  Dr. Melhus's office is in Kirkbride Hall, room 246, and his campus phone extension is 4377.



We begin the course by examining the fundamental mathematical principles that we already know, ...

Additionally, I'd be happy to get any comments on better ways to do the stuff I'm doing (I thought I earned a Ph.D. in LaTeX when wrote the thesis for my actual Ph.D. in Physics, but it seems I still have much more to learn).

  • 1
    Please can you add one simple code or minimal code (minimal working example)?
    – Sebastiano
    Aug 16, 2018 at 7:28
  • Sebastiano, not sure how it will help, but the header for my first (so far only) set of notes is now included in the question.
    – Martin
    Aug 16, 2018 at 13:40
  • I think that with your code you have received the answer. :-) Good work and good LaTeX.
    – Sebastiano
    Aug 16, 2018 at 19:02
  • Using subfiles is certainly one way to go. For a similar use-case I wrote a small python script to automatically extract the pages for each lecture/week using hooks that I had LaTeX put in the aux file...
    – user30471
    Aug 17, 2018 at 4:40

1 Answer 1


Using subfiles you can get correct page numbering by using the zref-xr package.

Assuming your main file is main.tex:










and your subfile is called chap2.tex:

% !TeX root = chap2.tex






This will give you the whole document with a table of contents and a subdocument with the correct page numbering. You need to first compile the main document and then the subfile.

  • Samcarter, thanks. This seems to work fine. Playing with a few other page numbering commands, I was able to get the main body to start with page 1, and the table of contents to be indexed in roman numerals. And the individual compilation of files also works fine. Thanks a lot for the help, it's working great.
    – Martin
    Aug 16, 2018 at 18:26
  • Found a small error - i was still using \setcounterpageref{page}{main-chap2} when my subdocument was called N01M.tex, and the page numbering was starting with 0 when I typeset the subfile. I changed the argument to the proper filename, and now main won't compile, giving me a File ended while scanning use of \@xs@reserved@A. I can post both headers in a new question if that would help.
    – Martin
    Aug 16, 2018 at 19:30
  • @Martin replace chap2 with the label of the chapter, not with the filename Aug 16, 2018 at 19:38
  • Still doesn't work, same error. Going to look into whether there's a package conflict. Any other advice? I didn't have labels before, added them in. My format is an article, does that matter?
    – Martin
    Aug 16, 2018 at 21:04
  • @Martin If you can make a minimal working example (MWE) I could take a look. Aug 16, 2018 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .