LaTeX forum ⇒ LaTeX Beginner's GuideSome quick notation questions about newcommand Topic is solved

Questions and answers about the LaTeX Beginner's Guide
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

Some quick notation questions about newcommand

Postby 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

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Some quick notation questions about newcommand

Postby 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).

topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

Some quick notation questions about newcommand

Postby 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

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Some quick notation questions about newcommand  Topic is solved

Postby 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:
\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:
\newcommand*{\hello}{\relax
  Hello, world!}

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


Return to “LaTeX Beginner's Guide”

Who is online

Users browsing this forum: No registered users and 3 guests