# Creating chapters by referencing parts of other chapters

I am trying to create a chapter or a section by referencing some parts of other sections.

For example:

“He goes to school”

Here “school” can be

• Law school,
• etc.

“She is going to watch a movie”

Here movie can be

• romantic/comedy
• horror,
• sci-fi,
• etc.

So here, I want to reference school and movie, so that they come up in a new chapter or section, like this

1. school - Business school, Law school, etc.
2. movie - romantic/comedy, horror, sci-fi, etc.

Since there are lot of these, doing it manually is tedious.

Is there any way of doing this automatically using some commands?

Any help is appreciated.

-
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. – lockstep Oct 18 '12 at 18:23
@PeterGrill sounds like an answer... – cmhughes Oct 18 '12 at 22:54

I am not sure I fully understand the question, but since at least two of us have a similar interpretations I am converting my comment to an answer.

You should define macros for each of the components that may change, and then use the values of these macros as needed.

## Method 1:

Using the example you gave, for instance you could define the macro \School to contain the school type, and use that in the sentence. So, here I initialize an empty value of \School and the sentence it is going to be used in:

\newcommand*{\School}{}
\newcommand*{\SchoolSentence}{He goes to \School.}


So, whenever you want to use this, you first ensure that the value of \School is set before using \SchoolSentence:

\renewcommand*{\School}{Business School}
\SchoolSentence

\renewcommand*{\School}{Harvard Law School}
\SchoolSentence


which produces

He goes to Harvard Law School.

You can construct expressions with more variables as well. For instance:

\newcommand*{\Movie}{}
\newcommand*{\Person}{}
\newcommand*{\MovieSentence}{\Person\ is going to watch \Movie.}


The you can use this as:

\renewcommand*{\Person}{Uncle Owen}
\renewcommand*{\Movie}{The Empire Strikes Back}
\MovieSentence


Uncle Owen is going to watch The Empire Strikes Back.

## Notes:

• The trailing backslash in \Person\ was needed to ensure that there is a space following the value of this macro.

## Method 2:

An alternate way of approaching this is to treat the school name as a parameter. So, the \SchoolSentence would be defined as accepting one parameter (the [1]), and to using # access the value of the first parameter:

\newcommand*{\SchoolSentence}[1]{He goes to #1.}


Similarly we can defined \MovieSentence to require two parameters:

\newcommand*{\MovieSentence}[2]{#1 is going to watch #2.}


The using this as follows yields results identical to above:

\SchoolSentence{Business School}

\SchoolSentence{Harvard Law School}

\MovieSentence{Uncle Owen}{The Empire Strikes Back}


## Code (Method 1):

\documentclass{article}

\newcommand*{\School}{}
\newcommand*{\SchoolSentence}{He goes to \School.}

\newcommand*{\Movie}{}
\newcommand*{\Person}{}
\newcommand*{\MovieSentence}{\Person\ is going to watch \Movie.}

\begin{document}
\SchoolSentence

\renewcommand*{\School}{Harvard Law School}
\SchoolSentence

\renewcommand*{\Person}{She}
\renewcommand*{\Movie}{The Shinning}
\MovieSentence

\renewcommand*{\Person}{Uncle Owen}
\renewcommand*{\Movie}{The Empire Strikes Back}
\MovieSentence

\end{document}


## Code (Method 2):

\documentclass{article}

\newcommand*{\SchoolSentence}[1]{He goes to #1.}
\newcommand*{\MovieSentence}[2]{#1 is going to watch #2.}

\begin{document}