I'm playing a bit of catch up on my questions.
There are a couple of quick questions I have. I have seen a couple of \newcommand codes:
1. \newcommand\routine[4]{
2. \newcommand*\routine[4]{
3. \newcommand\rountine{%
As usual, I can't find anything on the net about a distinction. For all of the applications I've been working with, they seem to work identically, but I'm sure there's some kind of difference between them.
Thanks!
-Dan
LaTeX Beginner's Guide ⇒ Some quick notation questions about newcommand
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Some quick notation questions about newcommand
\newcommand\routine[4]{}
will define a "long" command "\routine" that has four arguments. The starred version does the same except the command is not "long" (i.e., the four arguments cannot contain paragraph breaks). If your command works with the star, you should use the star.Your last example simply defines "\rountine" but expects no arguments (and thus it won't eat the four arguments following it like the other two will).
Some quick notation questions about newcommand
Thank you!kaiserkarl13 wrote:\newcommand\routine[4]{}
will define a "long" command "\routine" that has four arguments. The starred version does the same except the command is not "long" (i.e., the four arguments cannot contain paragraph breaks). If your command works with the star, you should use the star.
Your last example simply defines "\rountine" but expects no arguments (and thus it won't eat the four arguments following it like the other two will).
Actually, I had meant to ask about
\newcommand\routine[4]{%
My question was about why we would need the %. All it does is tell the compiler that what follows on the line is not code, right? So why does it keep cropping up? I would think that \newcommand\routine[4]{ would be enough.
Thanks again!
-Dan
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Some quick notation questions about newcommand
Here's a reason for the percent sign (i.e., a comment, which has the effect of eating the spaces until the next line); compare the following:
See how the first one has a space, even though I didn't put one in the text? That's why the % signs are used. I could also have ended the line with a command, like so:
That would do the same thing. I could also have left off the end-of-line character, like this:
Code: Select all
\documentclass{article}
\newcommand*{\hello}{
Hello, world!}
\newcommand*{\goodbye}{%
Goodbye, world!}
\begin{document}
\noindent
This is the \hello\ command. Saying\hello\ is what we are doing.
This is the \goodbye\ command. Saying\goodbye\ is what we are doing.
\end{document}
Code: Select all
\newcommand*{\hello}{\relax
Hello, world!}
Code: Select all
\newcommand*{\hello}{Hello, world!}