[texhax] \newcommand

Roger Mason rmason at sparky2.esd.mun.ca
Fri Sep 26 11:51:42 CEST 2003

Thanks to all who replied.

I put the command in a .sty file and that worked flawlessly.  Others have
tested and discussed the makeatletter ... makeatother method.

The FAQ mentioned by Barbara Beeton does indeed contain relevant
information, it is under "Macro Programming" -> "LaTeX Macros", that
directs the reader to the appropriate part of The LaTeX Companion.

Thanks again
Roger Mason

On Thu, 25 Sep 2003, Barbara Beeton wrote:

> roger,
> you've fallen into a most common patch of quicksand.
>
> control sequences containing @ signs are "internal" ones,
> and must be given special attention.  the fix, fortunately,
> is simple.  two possibilities:
>
>  - put your new command in a file named whatever.sty and
>    then \usepackage{whatever}
>
>  - leave the definition in the preamble of your document
>    and surround it by the commands
>      \makeatletter
>      ...
>      \makeatother
>
> this is almost certainly described in the very fine uktug
> faq; i think the url is
>     http://www.tex.ac.uk/faq/
> (you really should become acquainted with the faq -- it's
> 							-- bb
>
> ---------- Original message ----------
> Date: Thu, 25 Sep 2003 16:45:33 -0230 (NDDT)
> From: Roger Mason <rmason at sparky2.esd.mun.ca>
> To: texhax at tug.org
> Subject: [texhax] \newcommand
>
> Hello,
>
> I am trying to define a command in latex with this code in the preamble:
>
> \newcommand{\mybox}[2]{%
>   \setlength{\unitlength}{1pt}
>   \makeatletter
>   \begin{picture}(\strip at pt\linewidth,#1)
>     \put(0,0){\framebox(\strip at pt\linewidth,#1)[tl]{#2}}
>   \end{picture}
>   \makeatother}
>
> It is designed to produce a box that is the width of the \linewidth
> currently in use at height #1 containing text #2.  The code in the
> definition was obtained from the archives of this list and runs fine when
> embeded in a LaTeX document (with numbers for #1 & #2).  When I define the
> command above and invoke it using (for example)
>
> \mybox{72}{Zn}
>
> in the body of the document, compilation fails and the log file says:
>
> ! Undefined control sequence.
> <argument> \strip
>                   @pt\linewidth
> l.90 \mybox{72}{Zn}
>
> The control sequence at the end of the top line
> of your error message was never \def'ed. If you have
> misspelled it (e.g., \hobx'), type I' and the correct
> spelling (e.g., I\hbox'). Otherwise just continue,
> and I'll forget about whatever was undefined.
>
> Is there some simple step I am missing?
>
> Thanks for any replies,
>
> Roger Mason
>
> P.S. Is it considered good etiquette on this list to thank responders on
> the list or should that be done privately?
> _______________________________________________
> TeX FAQ: http://faq.tug.org/
`