String constants in LaTeX

When we write computer programs we use constants instead of repeating the same value over and over again in the program. Why not do the same in LaTeX – why repeat titles and other names that are used many times in the same document?

LaTeX may not be your favorite programming language but defining and using constants is very simple and does not require reading a thick manual. To define a command \DocTitle that gets replaced with it’s value wherever it’s being used simply type

\newcommand{\DocTitle}{My title}

About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to String constants in LaTeX

  1. Yurii says:

    But here is a problem; try later in Latex

    \DocTitle is the doc title

    There will be no space separating “My title” and “is”… Redefining

    \newcommand{\DocTitle}{My title }

    Will make a problem for say

    \DocTitle, that is the doc title
    :(

  2. Example LaTeX use…
    To get around the space problem, keep the original version, but put a slash after \DocTitle\ like this, when you want a space after it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s