Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?
share|improve this question

1 Answer 1

up vote 7 down vote accepted

\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.

share|improve this answer
    
Thank you very much! :) –  Viktor Kleen Mar 7 '13 at 0:59
1  
@ViktorKleen Welcome to TeX.sx! –  egreg Mar 7 '13 at 1:01
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.