Some quick notation questions about newcommand

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[flash] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Some quick notation questions about newcommand

Some quick notation questions about newcommand

by kaiserkarl13 » Thu Aug 31, 2023 8:17 pm

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:

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

Code: Select all

\newcommand*{\hello}{\relax
  Hello, world!}
That would do the same thing. I could also have left off the end-of-line character, like this:

Code: Select all

\newcommand*{\hello}{Hello, world!}

Some quick notation questions about newcommand

by topsquark » Thu Aug 31, 2023 6:22 pm

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).
Thank you!

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

Some quick notation questions about newcommand

by kaiserkarl13 » Thu Aug 31, 2023 3:03 pm

\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

by topsquark » Thu Aug 31, 2023 6:39 am

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

Top