I really like LaTex. I much prefer to typset my papers, rather than manufacture them in word. But every once in a while, I find little things that make using LaTex a PITA.
For example, in my document, I have text that often needs to be repeated. For example, I need the title on the titlepage (duh), the copyright page, the signature page and etc… Same goes for actor. I spent countless hours searching how to extract data from the built in variables initialized via the standard \author and \title calls. I even emailed my old mentor in all things LaTex and he also had no clue.
So I decided to fake it:
\newcommand{\printtitle}{Title of My Paper}
Now wherever I need to put title, I just use \printtitle and I’m done. This is not a perfect solution, but it works. At least as long as you don’t start nesting functions. For example if you do:
\uppercase{\printtitle}
You get lowercase letters. Why? Latex does not have a proper stack, and so nesting functions may or may not work depending on circumstances. At least that’s what I have been told.
This is annoying as shit. Anyone knows the proper way to do this? I know that the answer must be locked up somewhere deap within article.cls which includes the implementation of the \maketitle call. But for the life of me, I can’t decipher how to extract title and author from there.
Regarding your title problem, this will get you the text:
\makeatletter\@title\makeatother
but it still barfs if you try to use \uppercase
hope this helps.
Wow! Thanks for the tip! I couldn’t figure that out.
I’m wondering if \protect will do anything in this case…
Use the LaTeX rather than the TeX form:
\MakeUppercase{\printtitle}
and it will be in uppercase. ;)
Another command to know is TeX’s \edef which expands the definition before it is stored. However, as with \def, you have to be careful as it will not warn you if an existing command is overwritten.
Thanks! This thing was driving me nuts!
I forgot to mention one more trick. This:
\expandafter\uppercase\expandafter{\printtitle}
will also work. All of this is related the problem of how far TeX should expand a macro before performing an operation on it. It isn’t so much a design flaw or limitation of TeX, but rather a difficulty in specifying to it exactly what you want to do. Obviously, \uppercase, unlike \MakeUppercase, does not do an expansion on its argument before it operates on it.
Thanks! Those are really great tips.
See, sometimes I miss this kind of insights – I have functional understanding of LaTex but every once in a while I run into a problem that reminds me that I still have tons to learn about it. :)
I want to write the Heading: “References” in place of “Bibliography” for the heading of Bibliography. How can i do that?
Surajit – try this:
This should do the trick.
Many many thanks Luke, it worked!
Glad to help. :)
I dont want to put the page number of the bibliography in the content of my report. How can i do that?
Not sure what you mean. Can you explain?
Can i use the “.sty” files while i am in windows Xp platform? If so, then how can i do that? I want to use the Sty files such as fancyheadings.sty, nomencl.sty etc.
Why wouldn’t you? If you have a fancy custom style you can just drop it in the same directory as the file you are working on. If you want to install a package for a system wide use you should probably consult instructions for your latex distribution as the paths may vary.