GeneralTrouble with \newcommand

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ThermanMerman
Posts: 3
Joined: Fri Jan 11, 2008 5:51 pm

Trouble with \newcommand

Post by ThermanMerman »

I'm using LaTeX for math assignments, and I ran into a problem with the following.

The desired effect is (making two lines under the answer)

Code: Select all

\underline{\underline{250}}
Not wanting to punch in all that every time (I mean, it takes like 4 seconds!) I tried this

Code: Select all

\newcommand{\ans}{\underline\underline}
-and-

Code: Select all

\newcommand{\ans}{\underline{\underline}}
but both give the error message

Code: Select all

! Argument of underline has an extra }
How do I make this little b*st*rd work? I'm grateful for any help. :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Trouble with \newcommand

Post by gmedina »

Try

Code: Select all

\newcommand\ans[1]{\underline{\underline{#1}}}
and use it in the usual way:

Code: Select all

\ans{250}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: Trouble with \newcommand

Post by Juanjo »

Perhaps you may find useful the \uuline or even the \uwave commands in the ulem package. Put \usepackage{ulem} in the preamble and try these commands instead of your \ans command.
ThermanMerman
Posts: 3
Joined: Fri Jan 11, 2008 5:51 pm

Trouble with \newcommand

Post by ThermanMerman »

gmedina wrote: Try

Code: Select all

\newcommand\ans[1]{\underline{\underline{#1}}}
and use it in the usual way:

Code: Select all

\ans{250}


I'm afraid it didn't work properly. It returned 0250 with the double lines only under the first 0.
Juanjo wrote: Perhaps you may find useful the \uuline or even the \uwave commands in the ulem package. Put \usepackage{ulem} in the preamble and try these commands instead of your \ans command.


Yes, this did the trick. Thank you! :)
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Trouble with \newcommand

Post by gmedina »

ThermanMerman wrote:
gmedina wrote: Try

Code: Select all

\newcommand\ans[1]{\underline{\underline{#1}}}
and use it in the usual way:

Code: Select all

\ans{250}


I'm afraid it didn't work properly. It returned 0250 with the double lines only under the first 0.

??
Can you please explain that?

Code: Select all

\documentclass{article}
\newcommand\ans[1]{\underline{\underline{#1}}}

\begin{document}

\ans{0250}

\end{document}
Seems to work fine for me.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
ThermanMerman
Posts: 3
Joined: Fri Jan 11, 2008 5:51 pm

Re: Trouble with \newcommand

Post by ThermanMerman »

The last one worked for me as well. Maybe I just typed wrong on the first attempt. Anyway, it's working now so thanks to both of you! :)
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: Trouble with \newcommand

Post by balfonsi »

It didn't work because a pair of brackets was missing. The exact syntax is:
\newcommand{\ans}[1]{\underline{\underline{#1}}}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Trouble with \newcommand

Post by gmedina »

balfonsi wrote: It didn't work because a pair of brackets was missing. The exact syntax is:
\newcommand{\ans}[1]{\underline{\underline{#1}}}

I disagree with you. This two commands

Code: Select all

\newcommand{\ans}[1]{\underline{\underline{#1}}}
and

Code: Select all

\newcommand\ans[1]{\underline{\underline{#1}}}
are equivalent. I know that not using the brackets is a TeX syntax feature, but it doesn't cause any troubles in this case and even the LaTeX companion suggests this practice with \newcommand.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply