Re: strange problem with arithmetics



Victor Ivrii <vivrii@xxxxxxxxx> writes:
This works:
\documentclass[12pt]{article}
\pagestyle{empty}
\usepackage{ifthen}
\usepackage{graphicx,color}
\newcommand{\test}[1]{%
\underline{\hskip#1in}
}
[...]

This does not (I plugged #1*0.7in instead of #1in).

\documentclass[12pt]{article}
\pagestyle{empty}
\usepackage{ifthen}
\usepackage{graphicx,color}
\newcommand{\test}[1]{%
\underline{\hskip#1*0.7in}
}
[...]

How to fix it? I am more interested in something like

\usepackage{calc}
...
\newcommand{\test}[1]{%
\underline{\hspace{#1*0.7in}}%
}%

(note the correction of your use of %; and that the calc package will
operate on the argument of \hspace but not \hskip.

\newcolor{mycolor}{rgb}{0.03*#1, 0.5+0.0.1*#1,0.4-0.02*#1}

can't be done by the same technique; needs calculation of the values
as points in dimension registers, and then stripping the result as in

\edef\value{\expandafter\strip@pt\the\tempdimenreg}

so:

\usepackage{calc}
\newdimen\testdimen
...
\makeatletter
\newcommand\definecol[2]{% #1=factor, #2=name of colour to define
\setlength\testdimen{0.03pt*#1}%
\edef\@valuer{\expandafter\strip@pt\the\testdimen}%
...% analagously for green and blue
\newcolor{#2}{rgb}{\@valuer, \@valueg, \@valueb}%
}%

this can be done slightly more elegantly using \dimexpr, but i don't
have space in the margin to demonstrate that.
--
Robin Fairbairns, Cambridge
.