4

I have not been using latex in a while and I would like to try to implement the tips & tricks given in this video during the TUG conference by Jean Luc Doumont : http://www.youtube.com/watch?v=vkBCeOBbAmM

I tried to implement the first trick: xy positioning

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}

\def\xy#1#2#3{\setbox0=\hbox to\z@{%
\kern#1\raise#2\hbox{#3}\hss}%
\ht0=\z@\dp0=\z@\box0}


%testing the command
\xy 1 5 b


\end{document}

unfortunately I get the following error log

! Undefined control sequence.
\xy #1#2#3->\setbox 0=\hbox to\z 
                                 @{\kern #1\raise #2\hbox {#3}\hss }\ht 0=\z...
l.29 \xy 1 5 b

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.

! Missing number, treated as zero.
<to be read again> 
                   @
l.29 \xy 1 5 b

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   @
l.29 \xy 1 5 b

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Missing { inserted.
<to be read again> 
                   @
l.29 \xy 1 5 b

A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \raise 
l.29 \xy 1 5 b

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \hbox 
l.29 \xy 1 5 b

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Undefined control sequence.
\xy ...{\kern #1\raise #2\hbox {#3}\hss }\ht 0=\z 
                                                  @\dp 0=\z @\box 0
l.29 \xy 1 5 b

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.

! Missing number, treated as zero.
<to be read again> 
                   @
l.29 \xy 1 5 b

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   @
l.29 \xy 1 5 b

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Undefined control sequence.
\xy ...raise #2\hbox {#3}\hss }\ht 0=\z @\dp 0=\z 
                                                  @\box 0
l.29 \xy 1 5 b

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.

! Missing number, treated as zero.
<to be read again> 
                   @
l.29 \xy 1 5 b

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   @
l.29 \xy 1 5 b

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Missing } inserted.
<inserted text> 
                }
l.32 \end{document}

and I can't figure out what is the mistake since I never programmed macros before.

4

1 Answer 1

6

You need to enclose the definition pf \xy inside \makeatletter, \makeatother due to the @ character (See What do \makeatletter and \makeatother do?); also, in ots present form, the first and second arguments should be lengths (numbers plus a valid unit), and not simply numbers:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}

\makeatletter
\def\xy#1#2#3{\setbox0=\hbox to\z@{%
\kern#1\raise#2\hbox{#3}\hss}%
\ht0=\z@\dp0=\z@\box0}
\makeatother

%testing the command
\xy{1cm}{-5cm}{b}


\end{document}

If you want the first two arguments to be numbers instead of lengths, you could say (as percusse suggested in a comment):

\makeatletter
\def\xy#1#2#3{{\setbox0=\hbox to\z@{%
\kern#1\p@\raise#2\p@\hbox{#3}\hss}%
\ht0=\z@\dp0=\z@\box0}}
\makeatother

(the unit is now pt) and then use \xy in the form

\xy{10}{-70}{b}

Notice also the braces enclosing the definition; this grouping will prevent problems that might occur when used in other macros (suggestion by Heiko Oberdiek).

6
  • 1
    I think appending \p@ to #1 and #2 is a plausable shortcut to avoid the explicit dimensions.
    – percusse
    Apr 23, 2013 at 22:31
  • 1
    A space after \box0 prevents the macro from looking for further digits. Even is box 0 is a scratch register I would put it in a group to avoid trouble with the internals of other macros. Apr 23, 2013 at 22:39
  • @percusse I incorporated your suggestion to my answer. Apr 23, 2013 at 23:33
  • @HeikoOberdiek I incorporated your suggestion to my answer. Apr 23, 2013 at 23:34
  • @GonzaloMedina The group should start before \setbox and not before \box; in this way you're doing all the business in a group which doesn't influence possibly existent incarnations of \box0.
    – egreg
    Apr 23, 2013 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .