# Macros in \special

I tried to compute a bounding box in LaTeX and pass the value on to dvisvgm via DVI specials. The resulting code (which I copy-and-pasted together from all over the internet) looked as follows:

``````\newlength{\mywidth}
\newlength{\myheight}
% ...
\special{dvisvgm:bbox a 0 0 \the\mywidth \the\myheight}
``````

This resulted (predictably after the fact) in the following output in the DVI file:

``````dvisvgm:bbox a 0 0 147.00748pt26.3999pt
``````

After considerable amounts of googling I came up with the following workaround:

``````\newtoks\spacetoken
\spacetoken={ }
\special{dvisvgm:bbox a 0 0 \the\mywidth\the\spacetoken\the\myheight}
``````

However, that just looks horridly wrong to my eyes. Hence, my questions:

1. How does `\special` work?
2. Is there any better way to do this?
-

`\special` is like `\write`: it expands its argument until finding unexpandable tokens and then it writes the result to the DVI file.

Since in `\the\mywidth \the\myheight` there's no space (the apparent one is ignored during tokenization, as it follows a control sequence), the result is what you found out.

There's a simpler solution, though:

``````\the\mywidth\space\the\myheight
``````

because the expansion of `\space` is exactly a space token.

As Joseph Wright remarks in a comment, TeX takes no responsibility in what's contained in the argument of `\special`: as long as it's "fully expandable" and balanced with respect to braces, it can be anything and it's a job for the printer/previewer driver to interpret it.

-
Thank you very much! :) – Viktor Kleen Mar 7 '13 at 0:59
@ViktorKleen Welcome to TeX.sx! – egreg Mar 7 '13 at 1:01
I think it might be worth adding that the whole point of `\special` is that TeX knows nothing about the 'internal' structure of the argument: it's entirely arbitrary. – Joseph Wright Mar 7 '13 at 8:47