8

The following code does not compile with the following error message

Missing = inserted for \ifnum

\documentclass[pstricks,border=4pt]{standalone}
\usepackage{multido}

\psset{linewidth=.5\pslinewidth}
\psset{xunit=2cm}

\newcommand\FixedScale[1]{%
    \multips(0,0)(.1,0){\the\numexpr10*#1+1\relax}{\psline(0,0)(0,-3pt)}
    \multips(0,0)(.5,0){\the\numexpr2*#1+1\relax}{\psline(0,0)(0,-6pt)}
    \multips(0,0)(1,0){\the\numexpr#1+1\relax}{\psline(0,0)(0,-9pt)}
    \multido{\i=0+1}{\the\numexpr#1+1\relax}{\uput[-90](\i,-5pt){$\i$}}
}

\newcommand\VernierScale[2][0.09]{%
    \rput(#2,0){%
    \psset{xunit=#1,linecolor=red}%
    \multips(0,0)(1,0){11}{\psline(0,0)(0,3pt)}%
    \multips(5,0)(5,0){1}{\psline(0,0)(0,6pt)}%
    \multips(0,0)(10,0){2}{\psline(0,0)(0,9pt)}%
    \ifnum#1=0.11\relax
        \multido{\i=0+5}{3}{\uput[90](\i,8pt){\tiny$\the\numexpr10-\i\relax$}}
    \else
        \multido{\i=0+5}{3}{\uput[90](\i,8pt){\tiny$\i$}}
    \fi
    }
}

\begin{document}
\multido{\n=0.00+0.01}{21}{%
\begin{pspicture}(0,-.5)(2,.55)
\FixedScale{2}
\VernierScale[0.09]{\n}
\end{pspicture}}
\end{document}

What is wrong with \ifnum#1=0.09\relax?

  • there is no need for using decimals here. – user2478 Sep 28 '13 at 16:45
  • @Herbert: Yes. But the value passed to \VernierScale semantically represents the length of two consecutive marks on the vernier scale. I have to adopt this convention to avoid confusion. – kiss my armpit Sep 28 '13 at 16:49
14

I think you should be able to do something like

\ifdim#1pt=0.09pt\relax

As mentioned in the other answers, \ifnum tests integer values.

So

\documentclass{article}
\def\testing#1{%%
  \ifdim#1pt<0.09pt\relax
    SMALL!
  \else
    not so small
  \fi
}
\pagestyle{empty}
\begin{document}

  \testing{10}

  \testing{0.001}

\end{document}

results in

enter image description here

  • Thanks for other answers (with up votes done). But the last in won! – kiss my armpit Sep 28 '13 at 16:42
  • 1
    +1 although I'm not sure offering helpful advice as opposed to answering the question as posted is really allowed:-) – David Carlisle Sep 28 '13 at 16:43
  • 1
    (+1) I don't care if this answered the question - it answered mine! – cfr Sep 30 '14 at 16:53
16
\ifnum#1=0.09\relax?

tests if the number passed as #1 is 0 and if it is, it expands to .09\relax

A number is an integer.

6

Read \if_integer_number#1=another_integer_ and not floating point numbers. Use values as percentage:

\documentclass[pstricks,border=4pt]{standalone}
\usepackage{multido}
\psset{linewidth=.5\pslinewidth,xunit=2cm}

\newcommand\FixedScale[1]{%
    \multips(0,0)(.1,0){\the\numexpr10*#1+1\relax}{\psline(0,0)(0,-3pt)}
    \multips(0,0)(.5,0){\the\numexpr2*#1+1\relax}{\psline(0,0)(0,-6pt)}
    \multips(0,0)(1,0){\the\numexpr#1+1\relax}{\psline(0,0)(0,-9pt)}
    \multido{\i=0+1}{\the\numexpr#1+1\relax}{\uput[-90](\i,-5pt){$\i$}}%
}

\newcommand\VernierScale[2][9]{%
    \rput(#2,0){%
    \psset{xunit=\dimexpr#1\psunit/100,linecolor=red}%
    \multips(0,0)(1,0){11}{\psline(0,0)(0,3pt)}%
    \multips(5,0)(5,0){1}{\psline(0,0)(0,6pt)}%
    \multips(0,0)(10,0){2}{\psline(0,0)(0,9pt)}%
    \ifnum#1=11\relax
        \multido{\i=0+5}{3}{\uput[90](\i,8pt){\tiny$\the\numexpr10-\i\relax$}}
    \else
        \multido{\i=0+5}{3}{\uput[90](\i,8pt){\tiny$\i$}}
    \fi
    }%
}

\begin{document}
\multido{\n=0.00+0.01}{21}{%
\begin{pspicture}(0,-.5)(2,.55)
\FixedScale{2}
\VernierScale[9]{\n}
\end{pspicture}}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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