Generalusing a newcommand before it's stated or other fix

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
PGScooter
Posts: 31
Joined: Mon Jul 14, 2008 2:47 pm

using a newcommand before it's stated or other fix

Post by PGScooter »

Hi, having programmed a bit before, I got in the routine of having my outline up top and then the subroutines down at the problem. Is it possible in LaTeX to do something like this:

Section 1: \asection1

Section 2: \asection2

Section 3: \asection3

\newcommand{\asection1}{This contains the contents of section 1.....}
etc.

Does that make sense? Is there a better way to do this than using \newcommand? I understand that I can place the \newcommand above and it will work, but I would prefer to do it this way for some irrational idiosyncratic reason :)

Thank you!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

using a newcommand before it's stated or other fix

Post by phi »

This won't work at all because digits are not allowed in command names. The preferred way to structure documents is to write one file per chapter and to \include those files in the master file.
PGScooter
Posts: 31
Joined: Mon Jul 14, 2008 2:47 pm

Re: using a newcommand before it's stated or other fix

Post by PGScooter »

Hi phi,

thank you for the reply and suggestion. I am still looking for a way to structure it in my own preferred way :) (well, without the numbered command names).

thanks
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: using a newcommand before it's stated or other fix

Post by Juanjo »

If I've understood your goal, you pretend first to use a command, say \asectionOne, and later write its definition. This will never work, since TeX commands should be defined before they are used. If you want a "clean" code, not disturbed by definitions and other stuff, put all that in a package and load it in the preamble of the main tex file.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
PGScooter
Posts: 31
Joined: Mon Jul 14, 2008 2:47 pm

Re: using a newcommand before it's stated or other fix

Post by PGScooter »

Juanjo,

Thanks for the reply. I understand that it would never work in the case of the \necommand command. However, I thought there might be some package to do what I wanted. The table of contents, to me, is an example of a command which uses information that is processed later. Of course, it requires more than one pass to get things right, but to me, that would be a meaningless sacrifice.

In any case, thank you Juanjo and phi for your help! I still have much to learn about what is and what is not possible in LaTeX. Now that I know what I want to do will never work, I can move on to thinking about more productive things :)
Post Reply