Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
add comment

4 Answers 4

up vote 4 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.

MyTemplate.sty:

\usepackage{fancyhdr}
% Other generic packages

% Setup style for fancyheader
\pagestyle{fancy}
\lhead{\bfseries \CourseNumber} 
\chead{} 
\rhead{\bfseries \CourseTitle} 
\lfoot{\today} 
\cfoot{\Author} 
\rfoot{Page \thepage} 
\renewcommand{\headrulewidth}{0.4pt} 
\renewcommand{\footrulewidth}{0.4pt}

% Other generic settings

% Following is only so that I can capture the image below in a small height. 
% Do not use in real document
%\renewcommand{\textheight}{4cm}

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

Math101:

\documentclass{article}

\usepackage{lipsum}% for dummy text
\usepackage{MyTemplate}

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

\begin{document}
\section{Section Header}
\lipsum[1-4]
\end{document}

This way each course will have a common format:

enter image description here

share|improve this answer
add comment

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.tex

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

template.tex

\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
\input{course}

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:

\documentclass{<class>}
%preamble
\begin{document}
%body
\end{document}

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
add comment

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
\usepackage{reox}
% further commands to set document's tile, page headers, etc
\begin{document}
% body of document.
\end{document}
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.