TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following Task todo: I have made me a default structure for lecture notes and now I want to compile my notes into separate PDFs for learning.

So my goal is to have for every course a separate tex file, and have only one single template file. The problem is that I just can't do a \input{myfile} because I want to set the title, fancy page heads and stuff like that. Or is this also possible with the \input{} function?

Or is there another way to go?

share|improve this question
up vote 5 down vote accepted

You can set up the header/footer without the the actual contents defined. So create a MyTemplate.sty which contains your setup. Note here, that CourseNumber, \CourseTitle and \CourseTitle are not yet defined. This file should have all the packages that you want to use and the basic setup of the style is done here.


% Other generic packages

% Setup style for fancyheader
\lhead{\bfseries \CourseNumber} 
\rhead{\bfseries \CourseTitle} 
\rfoot{Page \thepage} 

% Other generic settings

% Following is only so that I can capture the image below in a small height. 
% Do not use in real document

The for each course you have a separate file which includes \usepackage{MyTemplate}. Here is an example file where you define the values of the macros needed to fill in the contents of the header/footer. Note that this file should only contain the content, all the formatting info is contained in the MyTemplate.sty



\usepackage{lipsum}% for dummy text

\newcommand{\CourseNumber}{Math 101}%
\newcommand{\CourseTitle}{Intro to Mathematics}%
\newcommand{\Author}{Prof. Reox}%

\section{Section Header}

This way each course will have a common format:

enter image description here

share|improve this answer

If your intent is to include only a single course .tex file with your template, then you set all your titles, headings, etc. in the course .tex file and use \input{<filename>} in your template file. Here's a brief illustration of what I'm talking about (you would have a number of course.tex files):


% Course preamble
\usepackage{<packages>}% Course-specific package(s)
% Course body/content


\documentclass{article}% Main document class
% Template preamble
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\usepackage{<packages>}% Generic packages used throughout all courses
% Other generic packages
% Other generic settings

The \input{<filename>} command extracts the contents of <filename>.tex verbatim and inserts it in a document where it is called. As such, you're able to include anything in <filename>.tex that you would normally in your main .tex template file. Just as long as the sequence of commands follow the regular/required document structure:


You'll note that, when \input{course} is replaced with the contents of course.tex in the first example, the above document structure will result, leading to a successful compile that is course specific.

As mentioned, this does not allow you to mix courses together and compile (say) course1.tex and course2.tex into your main template, since the each would have a preamble that would conflict with the regular document structure. If you do want this setup (for whatever reason), the you need to consider using something like the standalone package/document class or the subfiles package.

As an interesting side-note, consider reading When should I use \input vs \include ?

share|improve this answer

It sounds like you'd be best off (i) collecting all of your specialized code into a so-called LaTeX "style file" -- a text file that has the extension .sty, say, reox.sty -- and (ii) loading this package from each of your driver files. One loads a package with the \usepackage command, as in:

\documentclass{article} % or "report", or whatever
% further commands to set document's tile, page headers, etc
% body of document.
share|improve this answer

You can use in your template command names e.g. \mytitle in the definitions for the headers etc. And then give in the course files this commands a sensible content — you only must make sure that you give the commands the correct content before using them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.