4

I have a dozen or so course notes that I am writing. I have one 'styling file' (call it Master.tex) containing the header, and begin/end document - it specifies fonts, included packages, defined environments, etc. I then include the body of the document I want to compile. This way, all of my notes have the same styling, formatting, and feel.

However, the title of the document is declared in the header, which is in Master.tex. I would like to have a way to have this title be read off of the included body file - is this or something similar possible?

1
  • 1
    Yes it is possible. However this all depends on how you specify the title and how you want to access it. So, really need you to compose a MWE that shows how the title is specified as a complete file, and how you want to use it. Feb 24, 2013 at 20:49

1 Answer 1

4

Here's a solution using the fancyhdr package. (Edited to fix header formatting and to move \title to master file.)

% Master.tex
%
\documentclass{article}

\newcommand{\thisdocument}{to be replaced}

\title{\thisdocument}

\usepackage{fancyhdr}
\pagestyle{fancy} 
\fancyhead{} % clear defaults
\fancyhead[C]{\thisdocument}

\begin{document}

% included file contains the next lines
\renewcommand{\thisdocument}{What is the title of this lecture?}

\maketitle
\newpage
Header on this page is what it should be.

Some lecture notes here ...
% end of included material

\end{document}
1
  • Thanks, this worked. I changed the pagestyle to plain, though, as fancy was printing the title three times at the top of every other page.
    – vgty6h7uij
    Feb 24, 2013 at 21:08

You must log in to answer this question.

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