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

  • Business school,
  • 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.

share|improve this question
    
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
    
Not sure I understand your question, but how about defining \newcommand{\School}{Business school}, and using \School instead of school. The,n when you need a different version you redefine it with \renewcommand{\School}{Law school} to change the definition? I would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up how you actually want to use this. This will help to clarify what you are trying to do. –  Peter Grill Oct 18 '12 at 18:34
    
@PeterGrill sounds like an answer... –  cmhughes Oct 18 '12 at 22:54

1 Answer 1

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 Business School.

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}
\renewcommand*{\School}{Business School}
\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}
\SchoolSentence{Business School}

\SchoolSentence{Harvard Law School}

\MovieSentence{She}{The Shinning}

\MovieSentence{Uncle Owen}{The Empire Strikes Back}
\end{document}
share|improve this answer

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.