![LaTeX XY 定位](https://linux22.com/image/267061/LaTeX%20XY%20%E5%AE%9A%E4%BD%8D.png)
我已经有一段时间没有使用乳胶了,我想尝试实施 Jean Luc Doumont 在 TUG 会议期间在此视频中给出的提示和技巧:http://www.youtube.com/watch?v=vkBCeOBbAmM
我尝试实现第一个技巧:xy定位
\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}
不幸的是我收到以下错误日志
! 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}
由于我之前从未编写过宏,所以我无法弄清楚错误是什么。
答案1
您需要将定义 pf 括\xy
在 内\makeatletter
,\makeatother
因为@
字符(参见\makeatletter 和 \makeatother 起什么作用?); 此外,以 ots 的当前形式,第一个和第二个参数应该是长度(数字加上有效单位),而不仅仅是数字:
\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}
如果你希望前两个参数是数字而不是长度,你可以这样说(如敲击在评论中建议):
\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
(单位为现在pt
),然后\xy
以形式使用
\xy{10}{-70}{b}
还要注意括住定义的括号;这种分组将避免在其他宏中使用时可能出现的问题(建议海科·奥伯迪克)。