40

I wrote the following LaTeX documents.

\documentclass[11pt]{book}

\newlength{\mywidth}
\newlength{\myheight}
\setlength{\mywidth}{85mm}
\setlength{\myheight}{112mm}

\newcommand{\setpagesize}[2]{%
  \special{papersize=#1,#2}%
}

\setpagesize{\mywidth}{\myheight}

\begin{document}
The quick brown fox jumps over the lazy dog
\end{document}

I got following error messages from dvipdfmxand failed.

$ latex abc.tex
$ dvipdfmx abc.dvi 
abc.dvi -> abc.pdf

** WARNING ** Reading special command failed: "papersize=\mywidth ,\myheight "
[1
** WARNING ** Reading special command failed: "papersize=\mywidth ,\myheight "
]
4327 bytes written

When I use \def in place of \newlength and \setlength, it worked.

\documentclass[11pt]{book}

\def\mywidth{85mm}
\def\myheight{112mm}

\newcommand{\setpagesize}[2]{%
  \special{papersize=#1,#2}%
}
% ...


$ latex abc.tex
$ dvipdfmx abc.dvi 
abc.dvi -> abc.pdf
[1]
4331 bytes written

Why?

4
  • I can't reproduce that with my version of dvipdfmx. Perhaps try changing \setpagesize{\mywidth}{\myheight} to \setpagesize{\the\mywidth}{\the\myheight}? Apr 13, 2011 at 14:50
  • @Bruno: I didn't get an error too, but I didn't get a sensible pagesize either. \the is certainly needed. Apr 13, 2011 at 15:30
  • Thank you for your response. My version of dvipdfmx is "dvipdfmx-20110311 by the DVIPDFMx project team, an extended version of dvipdfm-0.13.2c developed by Mark A. Wicks". Apr 13, 2011 at 21:45
  • 2
    Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). May 12, 2011 at 0:15

2 Answers 2

51

\newlength is a LaTeX macro which defines a new length register, which holds a length as number and can be used for calculations (e.g. using \addtolength). The \def macro is the primitive version of \(re)newcommand and simply defines the content as string.

In your case you want to place the length as string inside the \special which is written into the DVI file. However, if you use the length register like \mywidth directly it doesn't return its value as string but awaits some operation like an assignment. You need to write \the\mywidth to get the string representation of the length register. However, a macro defined using \def is simply expanded by \special and its string content is simply added to the DVI.

23

\mywidth is a length register, not a value. In some places it can be used as if it were a value, but if e.g. you would use simply \mywidth in the middle of your text you would get an error. You get the value of a length register with \the. So try \setpagesize{\the\mywidth}{\the\myheight}

You must log in to answer this question.

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