I want to draw a trimmed ruler, for example, from 2.3cm to 3.9cm where the distance between two consecutive marks is 1mm.
I have difficulty to efficiently check whether or not the counter is a multiple of 5 or 10. If the counter is a multiple of 5 then the mark is 6pt long else if the counter is a multiple of 10 then the mark is 9pt long plus printing the quotient as a label.
The following is my complete code.
\documentclass[pstricks,border=12pt]{standalone}
\usepackage[nomessages]{fp}
\usepackage{multido}
\newcommand\Ruler[2]{%
\FPeval\start{round(10*#1:0)}%
\FPeval\stop{round(10*#2:0)}%
\FPeval\width{round(stop-start:0)}%
\FPeval\count{round(\width+1:0)}
\psset{xunit=\dimexpr\psxunit/10}
\begin{pspicture}[linecap=2](\width,1)
\psline(\width,0)
\multido{\ix=0+1,\i=\start+1}{\count}{%
\FPeval\quo{trunc(\i/5:0)}
\FPeval\rem{round(\i-5*quo:0)}
\psline(\ix,0)(\ix,3pt)
\FPifzero\rem
\psline(\ix,0)(\ix,6pt)% if \i can be defined by 5
\fi
\FPeval\quo{trunc(\i/10:0)}
\FPeval\rem{round(\i-10*quo:0)}
\FPifzero\rem
\psline(\ix,0)(\ix,9pt)% if \i can be defined by 10
\uput[90](\ix,6pt){\quo}% if \i can be defined by 10 and put the result of \i divided by 10
\fi
}
\end{pspicture}\ignorespaces
}
\begin{document}
\Ruler{2.3}{3.9}
\end{document}

Is there a better way to check divisibility in LaTeX?





\int_compare:nTF{\int_mod:nn {#1}{5} = 0}{true}{false}. I don't think that using fixed point numbers for doing integer arithmetic is the best way to proceed. – egreg Sep 29 '13 at 17:57