% \iffalse meta-comment
%
% Copyright 2017-2026 by Tibor Tómács
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Tibor Tómács.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{fgruler.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<package>\ProvidesPackage{fgruler}[2026/01/11 v1.7 Package for drawing rulers on the foreground or in the text]
%
%<*driver>
\documentclass{ltxdoc}
\OnlyDescription
\AddToHook{begindocument/before}[doc/hyperref]{\hypersetup{pdfstartview=FitH,allcolors=black}}% see in doc.sty and hypdoc.sty
\usepackage[a4paper,margin=25mm,marginparwidth=15mm,marginparsep=5mm,headsep=5mm,headheight=4mm,footskip=10mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{listings,fontawesome,stackengine}
\usepackage[type=none]{fgruler}

\setlength{\labelsep}{0pt}

\lstnewenvironment{examplelst}{\lstset{
gobble=2,
belowskip=\bigskipamount,
basicstyle=\ttfamily,
backgroundcolor=\color{blue!10},
framerule=0pt,
frame=trbl,
framesep=5pt,
columns=fullflexible,
xleftmargin=5pt,
xrightmargin=5pt,
keepspaces}}{}

\newcommand{\commandinline}{\lstinline[
literate={<}{{$\langle$}}1{>}{{$\rangle$}}1,
delim={[is][\color{green!50!black}\normalfont\itshape]{!}{!}},
basicstyle=\color{blue!80!black}\ttfamily,
columns=fullflexible,
keepspaces]}

\begin{document}
    \DocInput{./fgruler.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{fgruler.sty}
% 
% \title{The \texorpdfstring{{\bfseries\sffamily fgruler} package\\{\large v1.7 (2026/01/11)}}{fgruler package}}
% \author{Tibor Tómács\\{\normalsize\href{mailto:tomacs.tibor@gmail.com}{\texttt{tomacs.tibor@gmail.com}}}}
% \date{}
% \maketitle
% 
% \fgruler*[color=red!80!black]{upperleft}
% \noindent{\rulerparams{}{\scriptsize\sffamily\color{teal}}{blue}{}{}\ruler{taperight}{\textwidth}}
% 
% \section{Introduction}
% The |fgruler| package draws horizontal and vertical rulers on the foreground of every (or the current) page at absolute position.
% In this way, you can check the page layout dimensions.
% You can also draw various rulers in the text.
% 
% \medskip\noindent
% The |fgruler| package requires the services of the following packages: |kvoptions|, |etoolbox|, |xcolor|, |graphicx|, |eso-pic|.
% 
% \section{Loading package}
% Load the package with
% \begin{flushleft}
% \commandinline|\usepackage[!<package options>!]{fgruler}|
% \end{flushleft}
% or
% \begin{flushleft}
% \commandinline|\usepackage{fgruler}|\\
% \commandinline|\setfgruler{!<package options>!}|
% \end{flushleft}
% The |\setfgruler| command is usable in the document body, too.
% 
% \section{Package options}\label{sec:options}
% By default, the |fgruler| package draws a square ruler on the foreground of every page. 
% The following package options set the parameters of these rulers.
% \begin{description}
% \item\commandinline|unit=!<unit>!|\\
% Ruler unit. Possible \commandinline|!<unit>!| values:
% \begin{description}
% \item\commandinline|cm| Metric ruler (centimeter). Default value.
% \item\commandinline|in| English ruler (inch).
% \end{description}
% 
% \item\commandinline|type=!<type name>!|\\
% It determines the origin, directions, and lengths of the ruler. Possible \commandinline|!<type name>!| values:
% \begin{description}
% \item\commandinline|upperleft| Default value. Square ruler (origin: upper left corner of the paper; directions: down and right; lengths: paper sizes). See Example \ref{example:upperleft}.
% \item\commandinline|upperright| Square ruler (origin: upper right corner of the paper; directions: down and left; lengths: paper sizes). See Example \ref{example:upperright}.
% \item\commandinline|lowerleft| Square ruler (origin: lower left corner of the paper; directions: up and right; lengths: paper sizes). See Example \ref{example:lowerleft}.
% \item\commandinline|lowerright| Square ruler (origin: lower right corner of the paper; directions: up and left; lengths: paper sizes). See Example \ref{example:lowerright}.
% \item\commandinline|upperleftT| Square ruler (origin: upper left corner of the text area; directions: down and right; lengths: text area sizes). See Example \ref{example:upperleftT}.
% \item\commandinline|upperrightT| Square ruler (origin: upper right corner of the text area; directions: down and left; lengths: text area sizes). See Example \ref{example:upperrightT}.
% \item\commandinline|lowerleftT| Square ruler (origin: lower left corner of the text area; directions: up and right; lengths: text area sizes). See Example \ref{example:lowerleftT}.
% \item\commandinline|lowerrightT| Square ruler (origin: lower right corner of the text area; directions: up and left; lengths: text area sizes). See Example \ref{example:lowerrightT}.
% \item\commandinline|alledges| There are rulers on all edges of the paper. 
% Top ruler origin: upper left corner of the paper (direction: right). 
% Bottom ruler origin: lower left corner of the paper (direction: right). 
% Left ruler origin: upper left corner of the paper (direction: down). 
% Right ruler origin: upper right corner of the paper (direction: down). Lengths: paper sizes. See Example \ref{example:alledges}.
% \item\commandinline|alledges*| It is similar to |alledges| option, but bottom ruler origin is lower right corner of the paper (direction: left), 
% and left ruler origin is lower left corner of the paper (direction: up). 
% See Example \ref{example:alledges*}.
% \item\commandinline|alledgesT| It is similar to |alledges| option, but on the edges of the text area. See Example \ref{example:alledgesT}.
% \item\commandinline|alledgesT*| It is similar to |alledges*| option, but on the edges of the text area. See Example \ref{example:alledgesT*}.
% \item\commandinline|user| Each \commandinline|!<unit>!|--\commandinline|!<type name>!| pair activates an \commandinline|\fgrulertype{!<unit>!}{!<type name>!}| command.
% So the expansion of \commandinline|\fgrulertype{!<unit>!}{user}| determines the effect of this option.
% It will be \commandinline|!<code>!| after using the \commandinline|\fgrulerdefuser{!<code>!}| command, 
% where in the \commandinline|!<code>!| you have to referrence the unit as \commandinline|\fgrulerunit|.
% For example, after\\ |\fgrulerdefuser{\fgrulertype{\fgrulerunit}{alledges}}|\\ the |type=user| option will be equivalent to the |type=alledges|.
% See also Examples \ref{example:user-first}--\ref{example:user-last}.
% \item\commandinline|none| No ruler drawn.
% \end{description}
%
% \item\commandinline|type={!<type name list>!}|\\
% The \commandinline|!<type name list>!| is a list of valid type names separated by commas. 
% These types will be combined.
% For example |type={alledges,alledgesT}|.
% See the result in Example \ref{example:combining}.
% 
% \item\commandinline|hshift=!<length>!|\\
% Horizontal shift of the ruler, if the \commandinline|!<type name>!| is |upperleft|, |lowerleft|, |upperright|, or |lowerright|.
% The shift direction is right, if the \commandinline|!<type name>!| is |upperleft| or |lowerleft|.
% The shift direction is left, if the \commandinline|!<type name>!| is |upperright| or |lowerright|.
% Default: |hshift=0cm|.
% See Examples \ref{example:shift-first}--\ref{example:shift-last}.
% 
% \item\commandinline|vshift=!<length>!|\\
% Vertical shift of the ruler, if the \commandinline|!<type name>!| is |upperleft|, |lowerleft|, |upperright|, or |lowerright|.
% The shift direction is down, if the \commandinline|!<type name>!| is |upperleft| or |upperright|.
% The shift direction is up, if the \commandinline|!<type name>!| is |lowerleft| or |lowerright|.
% Default: |vshift=0cm|.
% See Examples \ref{example:shift-first}--\ref{example:shift-last}.
% 
% \item\commandinline|color=!<color name>!|\\
% Ruler color (see |xcolor| package). Default: |color=black|. 
% See Example \ref{example:showframe-color}.
% 
% \item\commandinline|numsep=!<length>!|\\
% Separation between number and ruler. Default: |numsep=3pt|.
% 
% \item\commandinline|markthick=!<length>!|\\
% Mark thickness. Default: |markthick=0.4pt|.
% 
% \item\commandinline|marklength=!<length>!|\\
% Mark length at integer units (see the red marks):
% {\fgrulernoborderline\fgrulercaptioncm{}\fgrulerthickcm{}{}{1pt}\fgrulercolorcm{}{}{red}\ruler{rightup}{3cm}}
% Default: |marklength=2mm|. See the length of the other marks in Section \ref{sec:additional}.
% 
% \item\commandinline|numfont=!<font type>!|\\
% Number font type. Default: |numfont=\scriptsize\sffamily|. You can use this option only in |\setfgruler| and |\fgruler*| (see Section \ref{sec:currentpage}) commands.
% 
% \item\commandinline|showframe| or \commandinline|showframe=true|\\
% It draws visible frames for the text and margin area, and lines for the head and foot.
% Their color and thickness are determined by the |color| and the |markthick| options.
% See Example \ref{example:showframe-color}.
% 
% \item\commandinline|showframe=false|\\
% It deactivates the |showframe| option.
% 
% \item\commandinline|nonefgrulers|\\
% It kills all of the rulers on the foreground, including also those, which are generated by |\fgruler| or |\fgruler*| (see Section \ref{sec:currentpage}).
% But the rulers, which were drawn by |\ruler| and |\squareruler| (see Section \ref{sec:intext}), do not disappear.
% Furthermore it deactivates the |showframe| option, too.
% In this case the |fgruler| package does not load the |eso-pic| package.
% This option works only in preamble.
% 
% It is recommended to use in two cases:
% \begin{itemize}
% \item To draw rulers only in text, there is no need for the checking function.
% \item To halt the checking function temporarily.
% \end{itemize}
% 
% The |type=none| is not identical with |nonefgrulers| option. The differences:
% \begin{itemize}
% \item |type=none| does not kill the |\fgruler| and |\fgruler*| commands and the |showframe| option.
% \item |type=none| is alterable in any point of the document.
% \item The |fgruler| package loads the |eso-pic| package, if you use the |type=none| option without |nonefgrulers|.
% \end{itemize}
% \end{description}
% 
% \section{Drawing rulers on the foreground of the current page}\label{sec:currentpage}
% \begin{description}
% \item\commandinline|\fgruler[!<unit!>]{!<type name>!}{!<hshift>!}{!<vshift>!}|\\
% It draws a square ruler on the foreground of that page, where this command is expanded.
% You can use more |\fgruler| commands in the same page.
% 
% The package options (see Section \ref{sec:options}) also work on this command, except for |type|, |hshift|, and |vshift|.
% 
% This command is effectless, if you use the |nonefgrulers| package option in the preamble.
% \begin{description}
% \item\commandinline|!<unit!>| options: 
% \commandinline|cm|, \commandinline|in| (see Section \ref{sec:options}).
% Its default value is the same as the value specified by the |unit=|\commandinline|!<unit!>| package option.
% 
% \item\commandinline|!<type name!>| parameters:
% \commandinline|upperleft|, \commandinline|upperright|, \commandinline|lowerleft|, \commandinline|lowerright| (see Section \ref{sec:options}).
% 
% \item\commandinline|!<hshift>!|
% Horizontal shift.
% The shift direction is right, if the \commandinline|!<type name>!| is |upperleft| or |lowerleft|, otherwise left.
% 
% \item\commandinline|!<vshift>!|
% Vertical shift.
% The shift direction is down, if the \commandinline|!<type name>!| is |upperleft| or |upperright|, otherwise up.
% \end{description}
% 
% Example: |\fgruler[in]{upperright}{1in}{2.5in}|
% \end{description}
% \begin{description}
% \item\commandinline|\fgruler*[!<package options!>]{!<type name>!}|\\
% It draws a ruler on the foreground of that page, where this command is expanded.
% You can use more |\fgruler*| commands in the same page.
% 
% The package options (see Section \ref{sec:options}) also work on this command, except for |type|.
% 
% This command is effectless, if you use the |nonefgrulers| package option in the preamble.
% \begin{description}
% \item\commandinline|!<package options!>|
% All options from Section \ref{sec:options}, except for |type|, |showframe|, and |nonefgrulers|.
% 
% \item\commandinline|!<type name!>| 
% All possible values of the |type| option from Section \ref{sec:options}, except for the |none| value.
% \end{description}
% 
% Example: |\fgruler*[color=red,type=in]{alledges}|
%
% Note that the following two commands are equivalent:\\
% |\fgruler*[unit=in,hshift=1in,vshift=2.5in]{upperright}|\\
% |\fgruler[in]{upperright}{1in}{2.5in}|
% \end{description}
% 
% \section{Drawing rulers in the text}\label{sec:intext}
% \begin{description}
% \item\commandinline|\ruler[!<unit!>]{!<type name>!}{!<length>!}|\\
% It draws a horizontal or a vertical ruler.
% The bottom of the ruler is aligned to the baseline of the surrounding text.
% The package options (see Section \ref{sec:options}) do not work on this command.
% \begin{description}
% \item\commandinline|!<unit!>| options:\\
% \commandinline|cm| Metric ruler (centimeter). Default option.\\
% \commandinline|in| English ruler (inch).
% 
% \item\commandinline|!<type name!>| parameters:\\
% \commandinline|downright | Direction: down. The numbers are on the right side.\\
% \commandinline|downleft  | Direction: down. The numbers are on the left side.\\
% \commandinline|upright   | Direction: up. The numbers are on the right side.\\
% \commandinline|upleft    | Direction: up. The numbers are on the left side.\\
% \commandinline|rightdown | Direction: right. The numbers are on the down side.\\
% \commandinline|rightup   | Direction: right. The numbers are on the up side.\\
% \commandinline|leftdown  | Direction: left. The numbers are on the down side.\\
% \commandinline|leftup    | Direction: left. The numbers are on the up side.\\
% \commandinline|taperight | Tape measure (direction: right). See Example \ref{example:tape}.\\
% \commandinline|tapeleft  | Tape measure (direction: left). See Example \ref{example:tape}.
% 
% \item\commandinline|!<length>!|
% Ruler length.
% \end{description}
% 
% Example: |\ruler{rightdown}{5cm}| \ruler{rightdown}{5cm}
% 
% \item\commandinline|\ruler*[!<unit!>]{!<type name>!}{!<length>!}|\\
% It works like |\ruler|, but the top of the ruler is aligned to the baseline of the surrounding text.
% 
% Example:
% |\ruler*{taperight}{5cm}|
% \ruler*{taperight}{5cm}
% 
% \item\commandinline|\squareruler[!<unit!>]{!<type name>!}{!<width>!}{!<height>!}|\\
% It draws a square ruler.
% The bottom of the square ruler is aligned to the baseline of the surrounding text.
% The package options (see Section \ref{sec:options}) do not work on this command.
% \begin{description}
% \item\commandinline|!<unit!>| options:\\
% \commandinline|cm| Metric ruler (centimeter). Default option.\\
% \commandinline|in| English ruler (inch).
% 
% \item\commandinline|!<type name!>| parameters:\\
% \commandinline|upperleft | Directions: down and right.\\
% \commandinline|upperright| Directions: down and left.\\
% \commandinline|lowerleft | Directions: up and right.\\
% \commandinline|lowerright| Directions: up and left.
% 
% \item\commandinline|!<width>!|
% Square ruler width.
% 
% \item\commandinline|!<height>!|
% Square ruler height.
% \end{description}
% 
% Example:
% |\squareruler{upperleft}{5cm}{1cm}|
% \squareruler{upperleft}{5cm}{1cm}
% 
% \item\commandinline|\squareruler*[!<unit!>]{!<type name>!}{!<width>!}{!<height>!}|\\
% It works like |\squareruler|, but the top of the square ruler is aligned to the baseline of the surrounding text.
% 
% Example:
% |\squareruler*{upperleft}{5cm}{1cm}|
% \squareruler*{upperleft}{5cm}{1cm}
% 
% \item\commandinline|\rulerparams{!<markthick>!}{!<numfont>!}{!<color>!}{!<marklength>!}{!<numsep>!}|\\
% It sets the parameters of the rulers, which are drawn by |\ruler| or |\squareruler|. 
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<markthick>!| Mark thickness. Default: |0.4pt|
% \item\commandinline|!<numfont>!| Number font type. Default: |\scriptsize\sffamily|
% \item\commandinline|!<color>!| Ruler line color. Default: |black|
% \item\commandinline|!<marklength>!| Mark length at integer units. Default: |2mm|
% \item\commandinline|!<numsep>!| Separation between number and ruler. Default: |3pt|
% \end{description}
%
% For example, |\rulerparams{}{}{red}{}{}| changes the ruler color to red.
% 
% \item\commandinline|\rulerparamsfromfg|\\
% It sets the ruler parameters from the current foreground ruler parameters.
% 
% \item\commandinline|\rulernorotatenum|\\
% By default, the numbers of the vertical rulers (which were generated by |\ruler| or |\squareruler|) are rotated by 90$^\circ$.
% It kills this action.
% This command can only be expanded in the document body.
% 
% Example: |{\rulernorotatenum\ruler{upright}{1cm}}| {\rulernorotatenum\ruler{upright}{1cm}}
% 
% \item\commandinline|\rulerrotatenum|\\
% After |\rulernorotatenum|, it reactivates the number rotating.
% This command can only be expanded in the document body.
% \end{description}
% 
% \section{Additional setting commands}\label{sec:additional}
% The following commands can work on all of the rulers, which are drawn by |fgruler| package.
% \begin{description}
% \item\commandinline|\fgrulerstartnum{!<num>!}|\\
% The \commandinline|!<num>!| is a nonnegative integer, which will be the starting number on the horizontal and vertical rulers.
% Default: |\fgrulerstartnum{0}|
% 
% Example: |{\fgrulerstartnum{5}\squareruler{lowerleft}{3cm}{1cm}}| {\fgrulerstartnum{5}\squareruler{lowerleft}{3cm}{1cm}}
% 
% \item\commandinline|\fgrulerstartnumh{!<num>!}|\\
% The \commandinline|!<num>!| is a nonnegative integer, which will be the starting number on the horizontal rulers.
% Default: |\fgrulerstartnumh{0}|
% 
% Example: |{\fgrulerstartnumh{5}\squareruler{lowerleft}{3cm}{1cm}}| {\fgrulerstartnumh{5}\squareruler{lowerleft}{3cm}{1cm}}
% 
% \item\commandinline|\fgrulerstartnumv{!<num>!}|\\
% The \commandinline|!<num>!| is a nonnegative integer, which will be the starting number on the vertical rulers.
% Default: |\fgrulerstartnumv{0}|
% 
% Example: |{\fgrulerstartnumv{5}\squareruler{lowerleft}{3cm}{1cm}}| {\fgrulerstartnumv{5}\squareruler{lowerleft}{3cm}{1cm}}
% 
% \item\commandinline|\fgrulernoborderline|\\
% By default, there is a borderline on one side of the ruler.
% It disappears by this command.
% 
% Example: |{\fgrulernoborderline\ruler{rightup}{3cm}}| {\fgrulernoborderline\ruler{rightup}{3cm}}
% 
% \item\commandinline|\fgrulerborderline|\\
% After |\fgrulernoborderline|, it reactivates the previous default effect.
% 
% \item\commandinline|\fgrulercaptioncm{!<caption>!}|\\
% Unit caption in metric ruler.
% Default: |\fgrulercaptioncm{cm}|
% 
% Example: |{\fgrulercaptioncm{}\ruler{rightup}{3cm}}| {\fgrulercaptioncm{}\ruler{rightup}{3cm}}
% 
% \item\commandinline|\fgrulercaptionin{!<caption>!}|\\
% Unit caption in English ruler.
% Default: |\fgrulercaptionin{inch}|
% 
% \item\commandinline|\fgrulerdefnum{!<definition>!}|\\
% The ruler numbers are determined by the \commandinline|fgrulernum| counter.
% Its current value is printed by the \commandinline|\thefgrulernum|.
% Its default definition is |\def\thefgrulernum{\arabic{fgrulernum}}|, which is equivalent to |\fgrulerdefnum{\arabic{fgrulernum}}|.
% 
% Example: |{\fgrulerdefnum{}\fgrulercaptioncm{}\ruler{rightdown}{2cm}}| {\fgrulerdefnum{}\fgrulercaptioncm{}\ruler{rightdown}{2cm}}
% 
% \item\commandinline|\fgrulerratiocm{!<ratio1>!}{!<ratio2>!}|\\
% Mark length ratios in metric rulers.
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<ratio1>!|
% Mark length ratio at $k/10$\,cm, where $k$ is positive integer and not divisible by 5.\\
% {\fgrulerthickcm{1pt}{}{}\fgrulercolorcm{red}{}{}\ruler{rightup}{3cm}}\\
% For example, if this ratio is 0.5 and the mark length at integer unit is 2\,mm, then this mark length will be $0.5\cdot 2\,\mathrm{mm}=1\,\mathrm{mm}$.
% 
% \item\commandinline|!<ratio2>!|
% Mark length ratio at $k/2$\,cm, where $k$ is positive odd integer.\\
% {\fgrulerthickcm{}{1pt}{}\fgrulercolorcm{}{red}{}\ruler{rightup}{3cm}}
% \end{description}
% 
% Default: |\fgrulerratiocm{0.5}{0.75}|
% 
% \item\commandinline|\fgrulerratioin{!<ratio1>!}{!<ratio2>!}{!<ratio3>!}{!<ratio4>!}|\\
% Mark length ratios in English rulers.
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<ratio1>!|
% Mark length ratio at $k/16$\,inch, where $k$ is positive odd integer.\\
% {\fgrulerthickin{1pt}{}{}{}{}\fgrulercolorin{red}{}{}{}{}\ruler[in]{rightup}{2in}}
% 
% \item\commandinline|!<ratio2>!|
% Mark length ratio at $k/8$\,inch, where $k$ is positive odd integer.\\
% {\fgrulerthickin{}{1pt}{}{}{}\fgrulercolorin{}{red}{}{}{}\ruler[in]{rightup}{2in}}
% 
% \item\commandinline|!<ratio3>!|
% Mark length ratio at $k/4$\,inch, where $k$ is positive odd integer.\\
% {\fgrulerthickin{}{}{1pt}{}{}\fgrulercolorin{}{}{red}{}{}\ruler[in]{rightup}{2in}}
% 
% \item\commandinline|!<ratio4>!|
% Mark length ratio at $k/2$\,inch, where $k$ is positive odd integer.\\
% {\fgrulerthickin{}{}{}{1pt}{}\fgrulercolorin{}{}{}{red}{}\ruler[in]{rightup}{2in}}
% \end{description}
% 
% Default: |\fgrulerratioin{0.25}{0.375}{0.625}{0.75}|
% 
% \item\commandinline|\fgrulerthickcm{!<thick1>!}{!<thick2>!}{!<thick3>!}|\\
% Mark thicknesses in metric rulers.
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<thick1>!|
% Mark thickness at $k/10$\,cm, where $k$ is positive integer and not divisible by 5.
% 
% \item\commandinline|!<thick2>!|
% Mark thickness at $k/2$\,cm, where $k$ is positive odd integer.
% 
% \item\commandinline|!<thick3>!|
% Mark thickness at integer units.
% \end{description}
% 
% The default values are given by \commandinline|!<markthick>!| of |\rulerparams|, respectively by |markthick| option.
% 
% Example:\\
% |{\fgrulerthickcm{}{}{2pt}|\\
% |\rulerparams{}{}{}{5mm}{}|\\
% |\fgrulernoborderline|\\
% |\ruler{rightdown}{3cm}}|\\[2mm]
% {\fgrulerthickcm{}{}{2pt}
% \rulerparams{}{}{}{5mm}{}
% \fgrulernoborderline
% \ruler{rightdown}{3cm}}
% 
% \item\commandinline|\fgrulerthickin{!<thick1>!}{!<thick2>!}{!<thick3>!}{!<thick4>!}{!<thick5>!}|\\
% Mark thicknesses in English rulers.
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<thick1>!|
% Mark thickness at $k/16$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<thick2>!|
% Mark thickness at $k/8$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<thick3>!|
% Mark thickness at $k/4$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<thick4>!|
% Mark thickness at $k/2$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<thick5>!|
% Mark thickness at integer units.
% \end{description}
% 
% The default values are given by \commandinline|!<markthick>!| of |\rulerparams|, respectively by |markthick| option.
% 
% Example:\\
% |{\fgrulerthickin{}{}{}{}{2pt}|\\
% |\rulerparams{}{}{}{5mm}{}|\\
% |\fgrulernoborderline|\\
% |\ruler[in]{rightdown}{3in}}|\\[2mm]
% {\fgrulerthickin{}{}{}{}{2pt}
% \rulerparams{}{}{}{5mm}{}
% \fgrulernoborderline
% \ruler[in]{rightdown}{3in}}
% 
% \item\commandinline|\fgrulercolorcm{!<color1>!}{!<color2>!}{!<color3>!}|\\
% Mark colors in metric rulers.
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<color1>!|
% Mark color at $k/10$\,cm, where $k$ is positive integer and not divisible by 5.
% 
% \item\commandinline|!<color2>!|
% Mark color at $k/2$\,cm, where $k$ is positive odd integer.
% 
% \item\commandinline|!<color3>!|
% Mark color at integer units.
% \end{description}
% 
% The default values are given by \commandinline|!<color>!| of |\rulerparams|, respectively by |color| option.
% 
% Example:\\
% |{\fgrulercolorcm{green}{blue}{red}|\\
% |\rulerparams{1pt}{}{}{5mm}{}|\\
% |\fgrulernoborderline|\\
% |\ruler{rightdown}{3cm}}|\\[2mm]
% {\fgrulernoborderline
% \fgrulercolorcm{green}{blue}{red}
% \rulerparams{1pt}{}{}{5mm}{}
% \ruler{rightdown}{3cm}}
% 
% \item\commandinline|\fgrulercolorin{!<color1>!}{!<color2>!}{!<color3>!}{!<color4>!}{!<color5>!}|\\
% Mark color in English rulers.
% If an argument is empty, then that parameter will not be changed.
% \begin{description}
% \item\commandinline|!<color1>!|
% Mark color at $k/16$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<color2>!|
% Mark color at $k/8$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<color3>!|
% Mark color at $k/4$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<color4>!|
% Mark color at $k/2$\,inch, where $k$ is positive odd integer.
% 
% \item\commandinline|!<color5>!|
% Mark color at integer units.
% \end{description}
% 
% The default values are given by \commandinline|!<color>!| of |\rulerparams|, respectively by |color| option.
% 
% Example:\\
% |{\fgrulercolorin{yellow}{orange}{green}{blue}{red}|\\
% |\rulerparams{1pt}{}{}{5mm}{}|\\
% |\fgrulernoborderline|\\
% |\ruler[in]{rightdown}{3in}}|\\[2mm]
% {\fgrulernoborderline
% \fgrulercolorin{yellow}{orange}{green}{blue}{red}
% \rulerparams{1pt}{}{}{5mm}{}
% \ruler[in]{rightdown}{3in}}
% 
% \item\commandinline|\fgrulerreset|\\
% It sets all options and parameters to default values.
% This command can only be expanded in the document body.
% \end{description}
% 
% \medskip\noindent
% \colorbox{red!10}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{red}{\faWarning}
% \itshape All setting commands obey the normal scoping rules, i.e.~if you use them inside a group, then the changing of the parameters is not valid outside the group.}}
% 
% \newpage\fgrulerreset
% \section{Examples}
% \subsection{Deafult case}\label{example:upperleft}
% \begin{examplelst}
% \documentclass{article}
% \usepackage{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{showframe} and \texttt{color} options}\label{example:showframe-color}
% \setfgruler{color=red,showframe}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[color=red,showframe]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=upperright} option}\label{example:upperright}
% \setfgruler{type=upperright}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=upperright]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=lowerleft} option}\label{example:lowerleft}
% \setfgruler{type=lowerleft}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=lowerleft]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=lowerright} option}\label{example:lowerright}
% \setfgruler{type=lowerright}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=lowerright]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Shift in default case}\label{example:shift-first}
% \setfgruler{hshift=1cm,vshift=2cm}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[hshift=1cm,vshift=2cm]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Shift in case \texttt{type=upperright} option}
% \setfgruler{type=upperright,hshift=1cm,vshift=2cm}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=upperright,hshift=1cm,vshift=2cm]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Shift in case \texttt{type=lowerleft} option}
% \setfgruler{type=lowerleft,hshift=1cm,vshift=2cm}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=lowerleft,hshift=1cm,vshift=2cm]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Shift in case \texttt{type=lowerright} option}\label{example:shift-last}
% \setfgruler{type=lowerright,hshift=1cm,vshift=2cm}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=lowerright,hshift=1cm,vshift=2cm]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=alledges} option}\label{example:alledges}
% \setfgruler{type=alledges}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=alledges]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=alledges*} option}\label{example:alledges*}
% \setfgruler{type=alledges*}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=alledges*]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=upperleftT} option}\label{example:upperleftT}
% \setfgruler{type=upperleftT}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=upperleftT]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=upperrightT} option}\label{example:upperrightT}
% \setfgruler{type=upperrightT}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=upperrightT]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=lowerleftT} option}\label{example:lowerleftT}
% \setfgruler{type=lowerleftT}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=lowerleftT]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=lowerrightT} option}\label{example:lowerrightT}
% \setfgruler{type=lowerrightT}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=lowerrightT]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=alledgesT} option}\label{example:alledgesT}
% \setfgruler{type=alledgesT}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=alledgesT]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{The \texttt{type=alledgesT*} option}\label{example:alledgesT*}
% \setfgruler{type=alledgesT*}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=alledgesT*]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
%
% \newpage\fgrulerreset
% \subsection{Combining type names}\label{example:combining}
% \setfgruler{type={alledges,alledgesT}}
% \fgrulerdefusercm{\fgrulertype{cm}{alledges}\fgrulertype{cm}{alledgesT}}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type={alledges,alledgesT}]{fgruler}
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Setting the \texttt{type=user} option}\label{example:user-first}
% In the next example the |type=user| option activates |type=upperright| or |type=upperleft|, depending on the page number is odd or even.
% \setfgruler{type=none}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=user]{fgruler}
% \fgrulerdefuser{
%     \ifodd\value{page}\fgrulertype{\fgrulerunit}{upperright}
%         \else\fgrulertype{\fgrulerunit}{upperleft}\fi
% }
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Setting the \texttt{type=user} option}
% In the next example the |type=user| option places a vertical ruler at the left border of the text area.
% \setfgruler{type=user}
%\fgrulerdefuser{\AtTextLowerLeft{\ignorespaces\rulerparamsfromfg\llap{\ruler[\fgrulerunit]{downleft}{\textheight}}}}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=user]{fgruler}
% \fgrulerdefuser{
%     \AtTextLowerLeft{% See eso-pic package!
%         \rulerparamsfromfg
%         \llap{\ruler[\fgrulerunit]{downleft}{\textheight}}
%     }
% }
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Setting the \texttt{type=user} option}
% In the next example the |type=user| option places rulers at the right and bottom borders of the text area.
% \setfgruler{type=user}
%\fgrulerdefuser{\AtTextLowerLeft{\ignorespaces\rulerparamsfromfg\rulernorotatenum\llap{\ruler[\fgrulerunit]{downleft}{\textheight}}\ruler*[\fgrulerunit]{rightdown}{\textwidth}}}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=user]{fgruler}
% \fgrulerdefuser{
%     \AtTextLowerLeft{% See eso-pic package!
%         \rulerparamsfromfg
%         \rulernorotatenum
%         \llap{\ruler[\fgrulerunit]{downleft}{\textheight}}%
%         \ruler*[\fgrulerunit]{rightdown}{\textwidth}
%     }
% }
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Setting the \texttt{type=user} option}\label{example:user-last}
% In the next example the |type=user| option places rulers at the right and top borders of the text area.
% \setfgruler{type=user}
%\fgrulerdefuser{\AtTextUpperLeft{\ignorespaces%
%\rulerparamsfromfg\ruler[\fgrulerunit]{rightup}{\textwidth}\ignorespaces%
%\rulernorotatenum\fgrulercaptioncm{}\ignorespaces\ruler*[\fgrulerunit]{downright}{\textheight}}}
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=user]{fgruler}
% \fgrulerdefuser{
%     \AtTextUpperLeft{% See eso-pic package!
%         \rulerparamsfromfg
%         \ruler[\fgrulerunit]{rightup}{\textwidth}%
%         \rulernorotatenum
%         \csname fgrulercaption\fgrulerunit\endcsname{}%
%         \ruler*[\fgrulerunit]{downright}{\textheight}
%     }
% }
% \begin{document}
% ...
% \end{document}
% \end{examplelst}
%
% \newpage\fgrulerreset
% \subsection{Rulers on the foreground of the current page and in the text}
% \setfgruler{color=blue}
% \fgruler{upperleft}{1cm}{1.5cm}\fgruler*[color=red,unit=in]{lowerrightT}
% \noindent
% text
% \rulerparams{}{\color{red}\tiny\ttfamily}{green}{}{}
% {\fgrulernoborderline\ruler{rightdown}{3cm}}
% text
% \ruler*{rightdown}{3cm}
% text
% \rotatebox[origin=tl]{30}{\ruler*{rightdown}{3cm}}
% 
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[color=blue]{fgruler}
% \begin{document}
%     \fgruler{upperleft}{1cm}{1.5cm}
%     \fgruler*[color=red,unit=in]{lowerrightT}
%     \noindent
%     text
%     \rulerparams{}{\color{red}\tiny\ttfamily}{green}{}{}
%     {\fgrulernoborderline\ruler{rightdown}{3cm}}
%     text
%     \ruler*{rightdown}{3cm}
%     text
%     \rotatebox[origin=tl]{30}{\ruler*{rightdown}{3cm}} 
%     % \rotatebox is defined in graphicx package
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Ruler types in the text}
% \setfgruler{type=none}
% \noindent
% \rulerparams{}{}{red}{}{3pt}
% \ruler{rightdown}{3cm}
% \hfill
% \ruler{rightup}{3cm}
% \hfill
% \ruler{leftup}{3cm}
% \hfill
% \ruler{leftdown}{3cm}
% 
% \bigskip\noindent
% \rulerparams{}{}{green}{}{}
% {\rulernorotatenum\ruler{upright}{3cm}}
% \hfill
% \ruler{downright}{3cm}
% \hfill
% \ruler{upleft}{3cm}
% \hfill
% \ruler{downleft}{3cm}
% 
% \bigskip\noindent
% \rulerparams{}{}{blue!50!black}{}{}
% {\rulernorotatenum\fgrulercaptioncm{}\squareruler{upperleft}{2cm}{3cm}}
% \hfill
% \squareruler{lowerright}{2cm}{3cm}
% \hfill
% \squareruler{lowerleft}{2cm}{3cm}
% \hfill
% \squareruler{upperright}{2cm}{3cm}
% \hfill
% {\rulerparams{}{\footnotesize\bfseries\color{red}}{}{5mm}{}\squareruler[in]{lowerleft}{2in}{3cm}}
% 
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[a4paper,margin=25mm]{geometry}
% \usepackage[nonefgrulers]{fgruler}
% \begin{document}
%     \noindent
%     \rulerparams{}{}{red}{}{3pt}
%     \ruler{rightdown}{3cm}
%     \hfill
%     \ruler{rightup}{3cm}
%     \hfill
%     \ruler{leftup}{3cm}
%     \hfill
%     \ruler{leftdown}{3cm}
%     
%     \bigskip\noindent
%     \rulerparams{}{}{green}{}{}
%     {\rulernorotatenum\ruler{upright}{3cm}}
%     \hfill
%     \ruler{downright}{3cm}
%     \hfill
%     \ruler{upleft}{3cm}
%     \hfill
%     \ruler{downleft}{3cm}
%     
%     \bigskip\noindent
%     \rulerparams{}{}{blue!50!black}{}{}
%     {\rulernorotatenum\fgrulercaptioncm{}\squareruler{upperleft}{2cm}{3cm}}
%     \hfill
%     \squareruler{lowerright}{2cm}{3cm}
%     \hfill
%     \squareruler{lowerleft}{2cm}{3cm}
%     \hfill
%     \squareruler{upperright}{2cm}{3cm}
%     \hfill
%     {\rulerparams{}{\footnotesize\bfseries\color{red}}{}{5mm}{}
%     \squareruler[in]{lowerleft}{2in}{3cm}}
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Measuring tapes}\label{example:tape}
% \setfgruler{type=none}
% 
%\noindent\ignorespaces\ruler{taperight}{\textwidth}\\[2pt]\rotatebox[origin=br]{-90}{\ruler{tapeleft}{3cm}}~\ruler{taperight}{10cm}
%\par\medskip\noindent{\fgrulerdefnum{}\ruler{taperight}{\textwidth}}
%\par\medskip\noindent{\fgrulerdefnum{}\fgrulercaptioncm{}\rulerparams{}{}{red}{}{0pt}\ruler{taperight}{\textwidth}}
%
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[a4paper,margin=25mm]{geometry}
% \usepackage[nonefgrulers]{fgruler}
% \begin{document}
%     \noindent
%     \ruler{taperight}{\textwidth}\\[2pt]
%     \rotatebox[origin=br]{-90}{\ruler{tapeleft}{3cm}}
%     \ruler{taperight}{10cm}
%
%     \medskip\noindent
%     {\fgrulerdefnum{}
%     \ruler{taperight}{\textwidth}}
%     
%     \medskip\noindent
%     {\fgrulerdefnum{}
%     \fgrulercaptioncm{}
%     \rulerparams{}{}{red}{}{0pt}
%     \ruler{taperight}{\textwidth}}
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Mark length and rotating}
% \setfgruler{type=none}
% \noindent
% {\fgrulerdefnum{\rotatebox{45}{\arabic{fgrulernum}\,cm}}
% \fgrulercaptioncm{}
% \rulerparams{}{\tiny\color{red}}{blue}{8mm}{}
% \fgrulercolorcm{}{}{black}
% \rotatebox{-45}{\ruler{rightup}{10cm}}\\
% \ruler{rightup}{5cm}}
% 
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[nonefgrulers]{fgruler}
% \begin{document}
%     \noindent
%     {\fgrulerdefnum{\rotatebox{45}{\arabic{fgrulernum}\,cm}}
%     \fgrulercaptioncm{}
%     \rulerparams{}{\tiny\color{red}}{blue}{8mm}{}
%     \fgrulercolorcm{}{}{black}
%     \rotatebox{-45}{\ruler{rightup}{10cm}}\\
%     \ruler{rightup}{5cm}}
% \end{document}
% \end{examplelst}
% 
% \newpage\fgrulerreset
% \subsection{Coordinate system}
% \setfgruler{type=none}
% \noindent
% \rulernorotatenum
% \fgrulercaptioncm{}
% \fgrulercolorcm{}{}{red}
% \rulerparams{}{\scriptsize\color{red}}{}{}{}
% {\fgrulerdefnum{$-\arabic{fgrulernum}$}\squareruler*{upperright}{3cm}{3cm}}\ignorespaces
% \squareruler{lowerleft}{13cm}{6cm}
% 
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[a4paper,margin=25mm]{geometry}
% \usepackage[nonefgrulers]{fgruler}
% \begin{document}
%     \noindent
%     \rulernorotatenum
%     \fgrulercaptioncm{}
%     \fgrulercolorcm{}{}{red}
%     \rulerparams{}{\scriptsize\color{red}}{}{}{}
%     {\fgrulerdefnum{$-\arabic{fgrulernum}$}\squareruler*{upperright}{3cm}{3cm}}%
%     \squareruler{lowerleft}{13cm}{6cm}
% \end{document}
% \end{examplelst}
%
% \newpage\fgrulerreset
% \subsection{A new square ruler type}
% \setfgruler{type=none}
% {\rulernorotatenum\fgrulercaptioncm{}\ruler*{downleft}{5cm}}\ruler{rightup}{3cm}
% 
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[type=none]{fgruler}
% \newcommand{\usersquareruler}[2]{%
%     {\rulernorotatenum\fgrulercaptioncm{}\ruler*{downleft}{#2}}%
%     \ruler{rightup}{#1}%
% }
% \begin{document}
% \usersquareruler{3cm}{5cm}
% \end{document}
% \end{examplelst}
%
% \newpage\fgrulerreset
% \subsection{Scale bars on the maps}
% \setfgruler{type=none}
% \def\Sstackgap{5pt}
% \fgrulerratiocm{0}{0}
% \fgrulercaptioncm{m}
% \fgrulerdefnum{\fpeval{\value{fgrulernum}*100}}
% \Shortstack{\ruler{rightup}{5cm} $1:10000$}
% \par\bigskip\noindent
% \fgrulerdefnum{\fpeval{\value{fgrulernum}*200}}
% \Shortstack{\ruler{rightup}{5cm} $1:20000$}
% \par\bigskip\noindent
% \fgrulercaptioncm{km}
% \fgrulerdefnum{\fpeval{\value{fgrulernum}*.5}}
% \Shortstack{\ruler{rightup}{5cm} $1:50000$}
% 
% \bigskip
% \begin{examplelst}
% \documentclass{article}
% \usepackage[nonefgrulers]{fgruler}
% \usepackage{stackengine}
% \def\Sstackgap{5pt}
% \fgrulerratiocm{0}{0}
% \fgrulercaptioncm{m}

% \begin{document}

% \fgrulerdefnum{\fpeval{\value{fgrulernum}*100}}
% \Shortstack{\ruler{rightup}{5cm} $1:10000$}

% \bigskip

% \fgrulerdefnum{\fpeval{\value{fgrulernum}*200}}
% \Shortstack{\ruler{rightup}{5cm} $1:20000$}

% \bigskip

% \fgrulercaptioncm{km}
% \fgrulerdefnum{\fpeval{\value{fgrulernum}*.5}}
% \Shortstack{\ruler{rightup}{5cm} $1:50000$}

% \end{document}
% \end{examplelst}
%
% \StopEventually
%
%    \begin{macrocode}
%%
\@ifpackageloaded{kvoptions}{}{\RequirePackage{kvoptions}}
\@ifpackageloaded{etoolbox}{}{\RequirePackage{etoolbox}}

\SetupKeyvalOptions{family=fgruler,prefix=fgruler@}
\DeclareStringOption[.4pt]{markthick}
\DeclareStringOption[\scriptsize\sffamily]{numfont}
\DeclareStringOption[black]{color}
\DeclareStringOption[2mm]{marklength}
\DeclareStringOption[3pt]{numsep}
\DeclareStringOption[0pt]{hshift}
\DeclareStringOption[0pt]{vshift}
\DeclareStringOption[upperleft]{type}
\DeclareStringOption[cm]{unit}
\DeclareBoolOption{nonefgrulers}
\DeclareBoolOption{showframe}
\ProcessKeyvalOptions{fgruler}

\newlength{\fgruler@marklth}
\newlength{\fgruler@sep}
\newlength{\fgruler@width}
\newlength{\fgruler@fg@width}
\newlength{\fgruler@fg@height}

\def\fgruler@set#1#2#3#4#5{%
\def\fgruler@markthickness{\linethickness{#1}}%
\def\fgruler@font{#2}%
\def\fgruler@rulercolor{\color{#3}}%
\setlength{\fgruler@marklth}{#4}%
\setlength{\fgruler@sep}{#5}%
\def\fgruler@font@{\normalfont\normalsize\fgruler@font}%
\addtolength{\fgruler@sep}{\fgruler@marklth}%
\ifx\thefgrulernum\@empty%
  \expandafter\ifx\csname fgruler@caption@\fgruler@unit\endcsname\@empty%
    \setlength{\fgruler@width}{\fgruler@marklth}%
  \else
    \settoheight{\fgruler@width}{\fgruler@font@\csname fgruler@caption@\fgruler@unit\endcsname}%
    \addtolength{\fgruler@width}{\fgruler@sep}%
  \fi
\else
  \settoheight{\fgruler@width}{\fgruler@font@\thefgrulernum}%
  \addtolength{\fgruler@width}{\fgruler@sep}%
\fi}

\def\rulerparams#1#2#3#4#5{%
\ifx#1\@empty\else\def\fgruler@markthick@{#1}\fi%
\ifx#2\@empty\else\def\fgruler@numfont@{#2}\fi%
\ifx#3\@empty\else\def\fgruler@color@{#3}\fi%
\ifx#4\@empty\else\def\fgruler@marklength@{#4}\fi%
\ifx#5\@empty\else\def\fgruler@numsep@{#5}\fi%
\ignorespaces}

\rulerparams{.4pt}{\scriptsize\sffamily}{black}{2mm}{3pt}

\def\rulerparamsfromfg{\rulerparams{\fgruler@markthick}{\fgruler@numfont}{\fgruler@color}{\fgruler@marklength}{\fgruler@numsep}}

\def\fgruler@fgsetting{%
\fgruler@set{\fgruler@markthick}{\fgruler@numfont}{\fgruler@color}{\fgruler@marklength}{\fgruler@numsep}%
\rulernorotatenum}

\def\fgruler@intextsetting{%
\fgruler@set{\fgruler@markthick@}{\fgruler@numfont@}{\fgruler@color@}{\fgruler@marklength@}{\fgruler@numsep@}}

\def\fgruler@activate@type{%
\def\fgruler@output{}%
\def\fgruler@check{cm}\ifx\fgruler@unit\fgruler@check\else%
\def\fgruler@check{in}\ifx\fgruler@unit\fgruler@check\else%
\PackageError{fgruler}{\fgruler@unit\space is invalid unit}{Valid units: cm, in}%
\fi\fi%
\def\do##1{%
\expandafter\def\expandafter\fgruler@type@item\expandafter{##1}%
\def\fgruler@check{upperleft}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{upperright}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{lowerleft}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{lowerright}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{upperleftT}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{upperrightT}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{lowerleftT}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{lowerrightT}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{alledges}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{alledges*}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{alledgesT}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{alledgesT*}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{none}\ifx\fgruler@type@item\fgruler@check\else%
\def\fgruler@check{user}\ifx\fgruler@type@item\fgruler@check\else%
\PackageError{fgruler}{\fgruler@type@item\space is invalid type}%
{Valid types:\MessageBreak
upperleft, upperright, lowerleft, lowerright,\MessageBreak
upperleftT, upperrightT, lowerleftT, lowerrightT,\MessageBreak
alledges, alledges*, alledgesT, alledgesT*, user, none}%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
\g@addto@macro\fgruler@output{\csname fgruler@\fgruler@unit @##1@fg\endcsname}}%
\expandafter\docsvlist\expandafter{\fgruler@type}}

\def\fgrulerratiocm#1#2{%
\ifx#1\@empty\else\def\fgruler@cm@ratio@i{#1}\fi%
\ifx#2\@empty\else\def\fgruler@cm@ratio@ii{#2}\fi%
\ignorespaces}

\fgrulerratiocm{.5}{.75}

\def\fgrulerratioin#1#2#3#4{%
\ifx#1\@empty\else\def\fgruler@in@ratio@i{#1}\fi%
\ifx#2\@empty\else\def\fgruler@in@ratio@ii{#2}\fi%
\ifx#3\@empty\else\def\fgruler@in@ratio@iii{#3}\fi%
\ifx#4\@empty\else\def\fgruler@in@ratio@iv{#4}\fi%
\ignorespaces}

\fgrulerratioin{.25}{.375}{.625}{.75}

\def\fgrulerthickcm#1#2#3{%
\ifx#1\@empty\else\def\fgruler@cm@thick@i{\linethickness{#1}}\fi%
\ifx#2\@empty\else\def\fgruler@cm@thick@ii{\linethickness{#2}}\fi%
\ifx#3\@empty\else\def\fgruler@cm@thick@iii{\linethickness{#3}}\fi%
\ignorespaces}

\def\fgruler@cm@thick@i{}
\def\fgruler@cm@thick@ii{}
\def\fgruler@cm@thick@iii{}

\def\fgrulerthickin#1#2#3#4#5{%
\ifx#1\@empty\else\def\fgruler@in@thick@i{\linethickness{#1}}\fi%
\ifx#2\@empty\else\def\fgruler@in@thick@ii{\linethickness{#2}}\fi%
\ifx#3\@empty\else\def\fgruler@in@thick@iii{\linethickness{#3}}\fi%
\ifx#4\@empty\else\def\fgruler@in@thick@iv{\linethickness{#4}}\fi%
\ifx#5\@empty\else\def\fgruler@in@thick@v{\linethickness{#5}}\fi%
\ignorespaces}

\def\fgruler@in@thick@i{}
\def\fgruler@in@thick@ii{}
\def\fgruler@in@thick@iii{}
\def\fgruler@in@thick@iv{}
\def\fgruler@in@thick@v{}

\def\fgrulercolorcm#1#2#3{%
\ifx#1\@empty\else\def\fgruler@cm@color@i{\color{#1}}\fi%
\ifx#2\@empty\else\def\fgruler@cm@color@ii{\color{#2}}\fi%
\ifx#3\@empty\else\def\fgruler@cm@color@iii{\color{#3}}\fi%
\ignorespaces}

\def\fgruler@cm@color@i{}
\def\fgruler@cm@color@ii{}
\def\fgruler@cm@color@iii{}

\def\fgrulercolorin#1#2#3#4#5{%
\ifx#1\@empty\else\def\fgruler@in@color@i{\color{#1}}\fi%
\ifx#2\@empty\else\def\fgruler@in@color@ii{\color{#2}}\fi%
\ifx#3\@empty\else\def\fgruler@in@color@iii{\color{#3}}\fi%
\ifx#4\@empty\else\def\fgruler@in@color@iv{\color{#4}}\fi%
\ifx#5\@empty\else\def\fgruler@in@color@v{\color{#5}}\fi%
\ignorespaces}

\def\fgruler@in@color@i{}
\def\fgruler@in@color@ii{}
\def\fgruler@in@color@iii{}
\def\fgruler@in@color@iv{}
\def\fgruler@in@color@v{}

\def\setfgruler#1{\setkeys{fgruler}{#1}\fgruler@activate@type\ignorespaces}

\newdimen\fgruler@tempdima
\newdimen\fgruler@tempdimb

\newcommand\fgruler@div[2]{%
\fgruler@tempdima=#1\relax\fgruler@tempdimb=\unitlength\relax
\fgruler@tempdimb=#2\fgruler@tempdimb\divide\fgruler@tempdima by \fgruler@tempdimb
\@tempcnta\fgruler@tempdima\advance\@tempcnta\@ne}

\def\fgruler@check@param#1#2{%
\expandafter\def\expandafter\fgruler@param\expandafter{#1}%
\def\fgruler@check{cm}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{in}\ifx\fgruler@param\fgruler@check\else%
\PackageError{fgruler}{\fgruler@param\space is invalid parameter}{Valid parameters: cm, in}%
\fi\fi%
\expandafter\def\expandafter\fgruler@param\expandafter{#2}%
\def\fgruler@check{rightdown}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{rightup}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{leftdown}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{leftup}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{downright}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{downleft}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{upright}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{upleft}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{taperight}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{tapeleft}\ifx\fgruler@param\fgruler@check\else%
\PackageError{fgruler}{\fgruler@param\space is invalid parameter}%
{Valid parameters:\MessageBreak
rightdown, rightup, leftdown, leftup,\MessageBreak
downright, downleft, upright, upleft, taperight, tapeleft}%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}

\def\fgruler@check@param@#1#2{%
\expandafter\def\expandafter\fgruler@param\expandafter{#1}%
\def\fgruler@check{cm}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{in}\ifx\fgruler@param\fgruler@check\else%
\PackageError{fgruler}{\fgruler@param\space is invalid parameter}{Valid parameters: cm, in}%
\fi\fi%
\expandafter\def\expandafter\fgruler@param\expandafter{#2}%
\def\fgruler@check{upperleft}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{upperright}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{lowerleft}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{lowerright}\ifx\fgruler@param\fgruler@check\else%
\PackageError{fgruler}{\fgruler@param\space is invalid parameter}%
{Valid parameters:\MessageBreak
upperleft, upperright, lowerleft, lowerright}%
\fi\fi\fi\fi}

\def\fgruler@check@param@@#1#2{%
\expandafter\def\expandafter\fgruler@param\expandafter{#1}%
\def\fgruler@check{cm}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{in}\ifx\fgruler@param\fgruler@check\else%
\PackageError{fgruler}{\fgruler@param\space is invalid parameter}{Valid parameters: cm, in}%
\fi\fi%
\expandafter\def\expandafter\fgruler@param\expandafter{#2}%
\def\fgruler@check{upperleft}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{upperright}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{lowerleft}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{lowerright}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{upperleftT}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{upperrightT}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{lowerleftT}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{lowerrightT}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{alledges}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{alledges*}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{alledgesT}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{alledgesT*}\ifx\fgruler@param\fgruler@check\else%
\def\fgruler@check{user}\ifx\fgruler@param\fgruler@check\else%
\PackageError{fgruler}{\fgruler@param\space is invalid type}%
{Valid types:\MessageBreak
upperleft, upperright, lowerleft, lowerright,\MessageBreak
upperleftT, upperrightT, lowerleftT, lowerrightT,\MessageBreak
alledges, alledges*, alledgesT, alledgesT*, user}%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}

\newcommand{\fgruler@ruler}[3][cm]{\fgruler@check@param{#1}{#2}\fgruler@intextsetting\csname fgruler@#1@#2@\endcsname{#3}}
\newcommand{\fgruler@ruler@}[3][cm]{\fgruler@check@param{#1}{#2}\fgruler@intextsetting\csname fgruler@#1@#2@@\endcsname{#3}}
\def\ruler{\@ifstar{\fgruler@ruler@}{\fgruler@ruler}}

\newcommand{\fgruler@squareruler}[4][cm]{\fgruler@check@param@{#1}{#2}\fgruler@intextsetting\csname fgruler@#1@#2@\endcsname{#3}{#4}}
\newcommand{\fgruler@squareruler@}[4][cm]{\fgruler@check@param@{#1}{#2}\fgruler@intextsetting\csname fgruler@#1@#2@@\endcsname{#3}{#4}}
\def\squareruler{\@ifstar{\fgruler@squareruler@}{\fgruler@squareruler}}

\newcommand{\fgruler@fgruler}[4][\fgruler@unit]{\fgruler@check@param@{#1}{#2}\g@addto@macro\fgruler@output@{\csname fgruler@#1@#2@fg@\endcsname{#3}{#4}}}
\newcommand{\fgruler@fgruler@}[2][]{\g@addto@macro\fgruler@output@{{\setkeys{fgruler}{#1}\fgruler@check@param@@{\fgruler@unit}{#2}\csname fgruler@\fgruler@unit @#2@fg\endcsname}}}
\def\fgruler{\@ifstar{\fgruler@fgruler@}{\fgruler@fgruler}}

\def\fgrulercaptioncm#1{\def\fgruler@caption@cm{#1}\ignorespaces}
\def\fgruler@caption@cm{cm}
\def\fgrulercaptionin#1{\def\fgruler@caption@in{#1}\ignorespaces}
\def\fgruler@caption@in{inch}

\newif\iffgruler@borderline
\def\fgrulernoborderline{\fgruler@borderlinefalse\ignorespaces}
\def\fgrulerborderline{\fgruler@borderlinetrue\ignorespaces}
\fgruler@borderlinetrue

\newcounter{fgrulernum}
\newcounter{fgruler@check}

\def\fgruler@ifnot@divisible@five#1{%
\setcounter{fgruler@check}{\value{fgrulernum}}%
\divide\value{fgruler@check}by5\relax%
\multiply\value{fgruler@check}by5\relax%
\ifnum\value{fgruler@check}=\value{fgrulernum}\else#1\fi\stepcounter{fgrulernum}}

\def\fgruler@ifodd#1{\ifodd\value{fgrulernum}#1\fi\stepcounter{fgrulernum}}

\def\fgrulerstartnum#1{\def\fgruler@startnumh{#1}\def\fgruler@startnumv{#1}\ignorespaces}
\def\fgrulerstartnumh#1{\def\fgruler@startnumh{#1}\ignorespaces}
\def\fgrulerstartnumv#1{\def\fgruler@startnumv{#1}\ignorespaces}
\def\fgruler@startnumh{0}
\def\fgruler@startnumv{0}

\def\fgrulerdefnum#1{\def\thefgrulernum{#1}\ignorespaces}

\def\fgruler@rotatebox#1#2{#2}%

\def\rulernorotatenum{%
\ifx\@onlypreamble\@notprerr%
\def\fgruler@rotatebox##1##2{##2}%
\else\PackageError{fgruler}{Don't use \protect\rulernorotatenum\space in preamble!}{}\fi%
\ignorespaces}

\def\rulerrotatenum{%
\ifx\@onlypreamble\@notprerr%
\def\fgruler@rotatebox##1##2{\rotatebox{##1}{##2}}%
\else\PackageError{fgruler}{Don't use \protect\rulerrotatenum\space in preamble!}{}\fi%
\ignorespaces}

\def\fgrulerreset{%
\ifx\@onlypreamble\@notprerr%
\def\fgruler@cm@ratio@i{.5}%
\def\fgruler@cm@ratio@ii{.75}%
\def\fgruler@in@ratio@i{.25}%
\def\fgruler@in@ratio@ii{.375}%
\def\fgruler@in@ratio@iii{.625}%
\def\fgruler@in@ratio@iv{.75}%
\def\fgruler@cm@thick@i{}%
\def\fgruler@cm@thick@ii{}%
\def\fgruler@cm@thick@iii{}%
\def\fgruler@in@thick@i{}%
\def\fgruler@in@thick@ii{}%
\def\fgruler@in@thick@iii{}%
\def\fgruler@in@thick@iv{}%
\def\fgruler@in@thick@v{}%
\def\fgruler@cm@color@i{}%
\def\fgruler@cm@color@ii{}%
\def\fgruler@cm@color@iii{}%
\def\fgruler@in@color@i{}%
\def\fgruler@in@color@ii{}%
\def\fgruler@in@color@iii{}%
\def\fgruler@in@color@iv{}%
\def\fgruler@in@color@v{}%
\def\fgruler@rotatebox##1##2{\rotatebox{##1}{##2}}%
\def\fgruler@markthick@{.4pt}%
\def\fgruler@numfont@{\scriptsize\sffamily}%
\def\fgruler@color@{black}%
\def\fgruler@marklength@{2mm}%
\def\fgruler@numsep@{3pt}%
\def\fgruler@type{upperleft}%
\def\fgruler@unit{cm}%
\def\fgruler@markthick{.4pt}%
\def\fgruler@numfont{\scriptsize\sffamily}%
\def\fgruler@color{black}%
\def\fgruler@marklength{2mm}%
\def\fgruler@hshift{0pt}%
\def\fgruler@vshift{0pt}%
\def\fgruler@numsep{3pt}%
\def\thefgrulernum{\arabic{fgrulernum}}%
\def\fgruler@caption@cm{cm}%
\def\fgruler@caption@in{inch}%
\def\fgruler@startnumh{0}%
\def\fgruler@startnumv{0}%
\fgruler@borderlinetrue%
\fgruler@showframefalse%
\def\fgruler@output{\csname fgruler@\fgruler@unit @\fgruler@type @fg\endcsname}%
\else\PackageError{fgruler}{Don't use \protect\fgrulerreset\space in preamble!}{}\fi%
\ignorespaces}

\AtEndPreamble{

\@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}
\@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}}

\def\fgruler@rotatebox#1#2{\rotatebox{#1}{#2}}

\iffgruler@nonefgrulers

\renewcommand{\fgruler@fgruler}[4][]{}
\renewcommand{\fgruler@fgruler@}[2][]{}

\else

\@ifpackageloaded{eso-pic}{}{\RequirePackage{eso-pic}[2020/10/14]}

\def\fgruler@frame{%
  \begingroup
    \fgruler@fgsetting
    \fgruler@rulercolor%
    \fgruler@markthickness%
    \AtPageLowerLeft{%
      \framebox(\paperwidth,\paperheight){}}%
    \AtTextLowerLeft{%
      \framebox(\textwidth,\textheight){}}%
    \AtTextUpperLeft{%
      \put(0,\headsep){%
        \framebox(\textwidth,\headheight){}}}%
    \AtTextLowerLeft{%
      \put(0,-\footskip){%
        \line(1,0){\textwidth}}}%
    \AtTextLowerLeft{%
      \fgruler@tempdima=\textwidth\advance\fgruler@tempdima\marginparsep%
      \if@twoside
        \ifodd\c@page\else
          \if@mparswitch
            \fgruler@tempdima=-\marginparsep\advance\fgruler@tempdima-\marginparwidth
          \fi
        \fi
      \fi
      \put(\fgruler@tempdima,0)%
        {\framebox(\marginparwidth,\textheight){}}%
    }%
  \endgroup
}

\def\fgruler@output@{}

\ESO@isMEMOIR{%
  \AddToHook{shipout/foreground}{%
    \ESO@MEMOIR@corr
    \put(\ESO@tempdima,\ESO@tempdimb){%
      \iffgruler@showframe\fgruler@frame\fi%
      \fgruler@output\fgruler@output@%
      \global\let\fgruler@output@\@empty%
    }%
  }%
}{%
  \AddToHook{shipout/foreground}{%
    \put(0,\ESO@yoffsetI){%
      \iffgruler@showframe\fgruler@frame\fi%
      \fgruler@output\fgruler@output@%
      \global\let\fgruler@output@\@empty%
    }%
  }%
}

\fgruler@activate@type

\fi
}

%% RIGHTDOWN CM
\def\fgruler@cm@rightdown#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(1,0){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(0,-1){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(5,0){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(0,-1){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(10,0){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(0,-1){\fgruler@marklth}}%
\iffgruler@borderline\put(-\@halfwidth,0){\line(1,0){#1+\@wholewidth}}\fi% \@wholewidth is current line thickness and \@halfwidth = 0.5\@wholewidth (see in latex.ltx)
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(10,-\fgruler@sep)(10,0){\fgruler@tempdima}{\makebox(0,0)[t]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@cm@rightdown@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,\fgruler@width)(0,-\fgruler@width)%
\fgruler@cm@rightdown{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5cm\put(5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@rightdown@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@cm@rightdown@{#1}}}

%% RIGHTDOWN IN
\def\fgruler@in@rightdown#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(1,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(0,-1){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(2,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(0,-1){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(4,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(0,-1){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(8,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(0,-1){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(16,0){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(0,-1){\fgruler@marklth}}%
\iffgruler@borderline\put(-\@halfwidth,0){\line(1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(16,-\fgruler@sep)(16,0){\fgruler@tempdima}{\makebox(0,0)[t]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@in@rightdown@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,\fgruler@width)(0,-\fgruler@width)%
\fgruler@in@rightdown{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5in\put(8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@rightdown@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@in@rightdown@{#1}}}

%% RIGHTUP CM
\def\fgruler@cm@rightup#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(1,0){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(0,1){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(5,0){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(0,1){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(10,0){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(0,1){\fgruler@marklth}}%
\iffgruler@borderline\put(-\@halfwidth,0){\line(1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(10,\fgruler@sep)(10,0){\fgruler@tempdima}{\makebox(0,0)[b]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@cm@rightup@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,\fgruler@width)%
\fgruler@cm@rightup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5cm\put(5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@rightup@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@cm@rightup@{#1}}}

%% RIGHTUP IN
\def\fgruler@in@rightup#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(1,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(0,1){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(2,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(0,1){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(4,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(0,1){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(8,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(0,1){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(16,0){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(0,1){\fgruler@marklth}}%
\iffgruler@borderline\put(-\@halfwidth,0){\line(1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(16,\fgruler@sep)(16,0){\fgruler@tempdima}{\makebox(0,0)[b]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@in@rightup@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,\fgruler@width)%
\fgruler@in@rightup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5in\put(8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@rightup@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@in@rightup@{#1}}}

%% LEFTDOWN CM
\def\fgruler@cm@leftdown#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-1,0){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(0,-1){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-5,0){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(0,-1){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(-10,0){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(0,-1){\fgruler@marklth}}%
\iffgruler@borderline\put(\@halfwidth,0){\line(-1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(-10,-\fgruler@sep)(-10,0){\fgruler@tempdima}{\makebox(0,0)[t]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@cm@leftdown@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,\fgruler@width)(-#1,-\fgruler@width)%
\fgruler@cm@leftdown{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5cm\put(-5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@leftdown@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@cm@leftdown@{#1}}}

%% LEFTDOWN IN
\def\fgruler@in@leftdown#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-1,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(0,-1){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-2,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(0,-1){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-4,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(0,-1){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-8,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(0,-1){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(-16,0){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(0,-1){\fgruler@marklth}}%
\iffgruler@borderline\put(\@halfwidth,0){\line(-1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(-16,-\fgruler@sep)(-16,0){\fgruler@tempdima}{\makebox(0,0)[t]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@in@leftdown@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,\fgruler@width)(-#1,-\fgruler@width)%
\fgruler@in@leftdown{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5in\put(-8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@leftdown@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@in@leftdown@{#1}}}

%% LEFTUP CM
\def\fgruler@cm@leftup#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-1,0){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(0,1){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-5,0){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(0,1){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(-10,0){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(0,1){\fgruler@marklth}}%
\iffgruler@borderline\put(\@halfwidth,0){\line(-1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(-10,\fgruler@sep)(-10,0){\fgruler@tempdima}{\makebox(0,0)[b]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@cm@leftup@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,\fgruler@width)(-#1,0)%
\fgruler@cm@leftup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5cm\put(-5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@leftup@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@cm@leftup@{#1}}}

%% LEFTUP IN
\def\fgruler@in@leftup#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-1,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(0,1){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-2,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(0,1){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-4,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(0,1){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(-8,0){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(0,1){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(-16,0){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(0,1){\fgruler@marklth}}%
\iffgruler@borderline\put(\@halfwidth,0){\line(-1,0){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumh}\stepcounter{fgrulernum}%
\multiput(-16,\fgruler@sep)(-16,0){\fgruler@tempdima}{\makebox(0,0)[b]{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}

\def\fgruler@in@leftup@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,\fgruler@width)(-#1,0)%
\fgruler@in@leftup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5in\put(-8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@leftup@@#1{\leavevmode\hbox{}\lower\fgruler@width\hbox{\fgruler@in@leftup@{#1}}}

%% DOWNRIGHT CM
\def\fgruler@cm@downright#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-1){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(1,0){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-5){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(1,0){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(0,-10){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,\@halfwidth){\line(0,-1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(\fgruler@sep,-10)(0,-10){\fgruler@tempdima}{\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@cm@downright@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(\fgruler@width,#1)(0,-#1)%
\fgruler@cm@downright{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5cm\put(\fgruler@sep,-5){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\fgruler@caption@cm}}}\fi%
\end{picture}}

\def\fgruler@cm@downright@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@cm@downright@{#1}}}

%% DOWNRIGHT IN
\def\fgruler@in@downright#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-1){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(1,0){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-2){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(1,0){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-4){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(1,0){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-8){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(1,0){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(0,-16){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,\@halfwidth){\line(0,-1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(\fgruler@sep,-16)(0,-16){\fgruler@tempdima}{\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@in@downright@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(\fgruler@width,#1)(0,-#1)%
\fgruler@in@downright{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5in\put(\fgruler@sep,-8){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\fgruler@caption@in}}}\fi%
\end{picture}}

\def\fgruler@in@downright@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@in@downright@{#1}}}

%% DOWNLEFT CM
\def\fgruler@cm@downleft#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-1){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(-1,0){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-5){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(-1,0){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(0,-10){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(-1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,\@halfwidth){\line(0,-1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(-\fgruler@sep,-10)(0,-10){\fgruler@tempdima}{\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@cm@downleft@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(\fgruler@width,#1)(-\fgruler@width,-#1)%
\fgruler@cm@downleft{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5cm\put(-\fgruler@sep,-5){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\fgruler@caption@cm}}}\fi%
\end{picture}}

\def\fgruler@cm@downleft@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@cm@downleft@{#1}}}

%% DOWNLEFT IN
\def\fgruler@in@downleft#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-1){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(-1,0){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-2){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(-1,0){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-4){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(-1,0){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,-8){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(-1,0){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(0,-16){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(-1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,\@halfwidth){\line(0,-1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(-\fgruler@sep,-16)(0,-16){\fgruler@tempdima}{\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@in@downleft@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(\fgruler@width,#1)(-\fgruler@width,-#1)%
\fgruler@in@downleft{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5in\put(-\fgruler@sep,-8){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\fgruler@caption@in}}}\fi%
\end{picture}}

\def\fgruler@in@downleft@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@in@downleft@{#1}}}

%% UPRIGHT CM
\def\fgruler@cm@upright#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,1){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(1,0){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,5){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(1,0){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(0,10){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,-\@halfwidth){\line(0,1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(\fgruler@sep,10)(0,10){\fgruler@tempdima}{\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@cm@upright@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(\fgruler@width,#1)%
\fgruler@cm@upright{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5cm\put(\fgruler@sep,5){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\fgruler@caption@cm}}}\fi%
\end{picture}}

\def\fgruler@cm@upright@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@cm@upright@{#1}}}

%% UPRIGHT IN
\def\fgruler@in@upright#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,1){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(1,0){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,2){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(1,0){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,4){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(1,0){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,8){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(1,0){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(0,16){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,-\@halfwidth){\line(0,1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(\fgruler@sep,16)(0,16){\fgruler@tempdima}{\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@in@upright@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(\fgruler@width,#1)%
\fgruler@in@upright{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5in\put(\fgruler@sep,8){\makebox(0,0)[l]{\fgruler@rotatebox{90}{\fgruler@font@\fgruler@caption@in}}}\fi%
\end{picture}}

\def\fgruler@in@upright@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@in@upright@{#1}}}

%% UPLEFT CM
\def\fgruler@cm@upleft#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,1){\@tempcnta}{\fgruler@ifnot@divisible@five{\fgruler@cm@thick@i\fgruler@cm@color@i\line(-1,0){\fgruler@cm@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{5}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,5){\@tempcnta}{\fgruler@ifodd{\fgruler@cm@thick@ii\fgruler@cm@color@ii\line(-1,0){\fgruler@cm@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{10}%
\multiput(0,0)(0,10){\@tempcnta}{\fgruler@cm@thick@iii\fgruler@cm@color@iii\line(-1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,-\@halfwidth){\line(0,1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(-\fgruler@sep,10)(0,10){\fgruler@tempdima}{\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@cm@upleft@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(\fgruler@width,#1)(-\fgruler@width,0)%
\fgruler@cm@upleft{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5cm\put(-\fgruler@sep,5){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\fgruler@caption@cm}}}\fi%
\end{picture}}

\def\fgruler@cm@upleft@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@cm@upleft@{#1}}}

%% UPLEFT IN
\def\fgruler@in@upleft#1{%
\fgruler@rulercolor%
\fgruler@markthickness%
\fgruler@div{#1}{1}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,1){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@i\fgruler@in@color@i\line(-1,0){\fgruler@in@ratio@i\fgruler@marklth}}}%
\fgruler@div{#1}{2}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,2){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@ii\fgruler@in@color@ii\line(-1,0){\fgruler@in@ratio@ii\fgruler@marklth}}}%
\fgruler@div{#1}{4}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,4){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iii\fgruler@in@color@iii\line(-1,0){\fgruler@in@ratio@iii\fgruler@marklth}}}%
\fgruler@div{#1}{8}%
\setcounter{fgrulernum}{0}%
\multiput(0,0)(0,8){\@tempcnta}{\fgruler@ifodd{\fgruler@in@thick@iv\fgruler@in@color@iv\line(-1,0){\fgruler@in@ratio@iv\fgruler@marklth}}}%
\fgruler@div{#1}{16}%
\multiput(0,0)(0,16){\@tempcnta}{\fgruler@in@thick@v\fgruler@in@color@v\line(-1,0){\fgruler@marklth}}%
\iffgruler@borderline\put(0,-\@halfwidth){\line(0,1){#1+\@wholewidth}}\fi%
\setcounter{fgrulernum}{\fgruler@startnumv}\stepcounter{fgrulernum}%
\multiput(-\fgruler@sep,16)(0,16){\fgruler@tempdima}{\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum\stepcounter{fgrulernum}}}}}

\def\fgruler@in@upleft@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(\fgruler@width,#1)(-\fgruler@width,0)%
\fgruler@in@upleft{#1}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\thefgrulernum}}}%
\ifdim#1>.5in\put(-\fgruler@sep,8){\makebox(0,0)[r]{\fgruler@rotatebox{-90}{\fgruler@font@\fgruler@caption@in}}}\fi%
\end{picture}}

\def\fgruler@in@upleft@@#1{\leavevmode\hbox{}\lower#1\hbox{\fgruler@in@upleft@{#1}}}

%% TAPERIGHT CM
\def\fgruler@cm@taperight@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,\fgruler@width+\fgruler@sep)%
\fgruler@cm@rightup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5cm\put(5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}\fi%
\def\thefgrulernum{}%
\put(0,\fgruler@width+\fgruler@sep){\fgruler@cm@rightdown{#1}}%
\end{picture}}

\def\fgruler@cm@taperight@@#1{\leavevmode\hbox{}\lower\dimexpr
\fgruler@width+\fgruler@sep\relax\hbox{\fgruler@cm@taperight@{#1}}}

%% TAPERIGHT IN
\def\fgruler@in@taperight@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,\fgruler@width+\fgruler@sep)%
\fgruler@in@rightup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5in\put(8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}\fi%
\def\thefgrulernum{}%
\put(0,\fgruler@width+\fgruler@sep){\fgruler@in@rightdown{#1}}%
\end{picture}}

\def\fgruler@in@taperight@@#1{\leavevmode\hbox{}\lower\dimexpr
\fgruler@width+\fgruler@sep\relax\hbox{\fgruler@in@taperight@{#1}}}

%% TAPELEFT CM
\def\fgruler@cm@tapeleft@#1{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,\fgruler@width+\fgruler@sep)(-#1,0)%
\fgruler@cm@leftup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5cm\put(-5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}\fi%
\def\thefgrulernum{}%
\put(0,\fgruler@width+\fgruler@sep){\fgruler@cm@leftdown{#1}}%
\end{picture}}

\def\fgruler@cm@tapeleft@@#1{\leavevmode\hbox{}\lower\dimexpr
\fgruler@width+\fgruler@sep\relax\hbox{\fgruler@cm@tapeleft@{#1}}}

%% TAPELEFT IN
\def\fgruler@in@tapeleft@#1{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,\fgruler@width+\fgruler@sep)(-#1,0)%
\fgruler@in@leftup{#1}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\ifdim#1>.5in\put(-8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}\fi%
\def\thefgrulernum{}%
\put(0,\fgruler@width+\fgruler@sep){\fgruler@in@leftdown{#1}}%
\end{picture}}

\def\fgruler@in@tapeleft@@#1{\leavevmode\hbox{}\lower\dimexpr
\fgruler@width+\fgruler@sep\relax\hbox{\fgruler@in@tapeleft@{#1}}}

%% UPPERLEFT CM
\def\fgruler@cm@upperleft@#1#2{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,#2)(0,-#2)%
\fgruler@cm@rightdown{#1}%
\fgruler@cm@downright{#2}%
\ifdim#1>.5cm\put(5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@upperleft@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@cm@upperleft@{#1}{#2}}}

\def\fgruler@cm@upperleft@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\put(#1,0){%
\fgruler@cm@upperleft@{\fgruler@fg@width}{\fgruler@fg@height}}}%
\endgroup}

\def\fgruler@cm@upperleft@fg{\fgruler@cm@upperleft@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% UPPERLEFT IN
\def\fgruler@in@upperleft@#1#2{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,#2)(0,-#2)%
\fgruler@in@rightdown{#1}%
\fgruler@in@downright{#2}%
\ifdim#1>.5in\put(8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@upperleft@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@in@upperleft@{#1}{#2}}}

\def\fgruler@in@upperleft@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\put(#1,0){%
\fgruler@in@upperleft@{\fgruler@fg@width}{\fgruler@fg@height}}}%
\endgroup}

\def\fgruler@in@upperleft@fg{\fgruler@in@upperleft@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% UPPERRIGHT CM
\def\fgruler@cm@upperright@#1#2{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,#2)(-#1,-#2)%
\fgruler@cm@leftdown{#1}%
\fgruler@cm@downleft{#2}%
\ifdim#1>.5cm\put(-5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@upperright@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@cm@upperright@{#1}{#2}}}

\def\fgruler@cm@upperright@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\fgruler@cm@upperright@{\fgruler@fg@width}{\fgruler@fg@height}}%
\endgroup}

\def\fgruler@cm@upperright@fg{\fgruler@cm@upperright@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% UPPERRIGHT IN
\def\fgruler@in@upperright@#1#2{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,#2)(-#1,-#2)%
\fgruler@in@leftdown{#1}%
\fgruler@in@downleft{#2}%
\ifdim#1>.5in\put(-8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@upperright@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@in@upperright@{#1}{#2}}}

\def\fgruler@in@upperright@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\fgruler@in@upperright@{\fgruler@fg@width}{\fgruler@fg@height}}%
\endgroup}

\def\fgruler@in@upperright@fg{\fgruler@in@upperright@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% LOWERLEFT CM
\def\fgruler@cm@lowerleft@#1#2{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,#2)%
\fgruler@cm@rightup{#1}%
\fgruler@cm@upright{#2}%
\ifdim#1>.5cm\put(5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@lowerleft@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@cm@lowerleft@{#1}{#2}}}

\def\fgruler@cm@lowerleft@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\put(#1,#2){%
\fgruler@cm@lowerleft@{\fgruler@fg@width}{\fgruler@fg@height}}}%
\endgroup}

\def\fgruler@cm@lowerleft@fg{\fgruler@cm@lowerleft@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% LOWERLEFT IN
\def\fgruler@in@lowerleft@#1#2{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,#2)%
\fgruler@in@rightup{#1}%
\fgruler@in@upright{#2}%
\ifdim#1>.5in\put(8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@lowerleft@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@in@lowerleft@{#1}{#2}}}

\def\fgruler@in@lowerleft@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\put(#1,#2){%
\fgruler@in@lowerleft@{\fgruler@fg@width}{\fgruler@fg@height}}}%
\endgroup}

\def\fgruler@in@lowerleft@fg{\fgruler@in@lowerleft@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% LOWERRIGHT CM
\def\fgruler@cm@lowerright@#1#2{%
\setlength{\unitlength}{1mm}%
\begin{picture}(#1,#2)(-#1,0)%
\fgruler@cm@leftup{#1}%
\fgruler@cm@upleft{#2}%
\ifdim#1>.5cm\put(-5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}\fi%
\end{picture}}

\def\fgruler@cm@lowerright@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@cm@lowerright@{#1}{#2}}}

\def\fgruler@cm@lowerright@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\put(0,#2){%
\fgruler@cm@lowerright@{\fgruler@fg@width}{\fgruler@fg@height}}}%
\endgroup}

\def\fgruler@cm@lowerright@fg{\fgruler@cm@lowerright@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% LOWERRIGHT IN
\def\fgruler@in@lowerright@#1#2{%
\setlength{\unitlength}{.0625in}%
\begin{picture}(#1,#2)(-#1,0)%
\fgruler@in@leftup{#1}%
\fgruler@in@upleft{#2}%
\ifdim#1>.5in\put(-8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}\fi%
\end{picture}}

\def\fgruler@in@lowerright@@#1#2{\leavevmode\hbox{}\lower#2\hbox{\fgruler@in@lowerright@{#1}{#2}}}

\def\fgruler@in@lowerright@fg@#1#2{%
\begingroup%
\setlength{\fgruler@fg@width}{\paperwidth}%
\addtolength{\fgruler@fg@width}{-#1}%
\setlength{\fgruler@fg@height}{\paperheight}%
\addtolength{\fgruler@fg@height}{-#2}%
\fgruler@fgsetting%
\AtPageLowerLeft{\put(0,#2){%
\fgruler@in@lowerright@{\fgruler@fg@width}{\fgruler@fg@height}}}%
\endgroup}

\def\fgruler@in@lowerright@fg{\fgruler@in@lowerright@fg@{\fgruler@hshift}{\fgruler@vshift}}

%% UPPERLEFTT CM
\def\fgruler@cm@upperleftT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,-\textheight)%
\fgruler@cm@rightup{\textwidth}%
\fgruler@cm@downleft{\textheight}%
\put(5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% UPPERLEFTT IN
\def\fgruler@in@upperleftT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,-\textheight)%
\fgruler@in@rightup{\textwidth}%
\fgruler@in@downleft{\textheight}%
\put(8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% UPPERRIGHTT CM
\def\fgruler@cm@upperrightT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(-\textwidth,-\textheight)%
\fgruler@cm@leftup{\textwidth}%
\fgruler@cm@downright{\textheight}%
\put(-5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% UPPERRIGHTT IN
\def\fgruler@in@upperrightT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(-\textwidth,-\textheight)%
\fgruler@in@leftup{\textwidth}%
\fgruler@in@downright{\textheight}%
\put(-8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% LOWERLEFTT CM
\def\fgruler@cm@lowerleftT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,0)%
\fgruler@cm@rightdown{\textwidth}%
\fgruler@cm@upleft{\textheight}%
\put(5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% LOWERLEFTT IN
\def\fgruler@in@lowerleftT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,0)%
\fgruler@in@rightdown{\textwidth}%
\fgruler@in@upleft{\textheight}%
\put(8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% LOWERRIGHTT CM
\def\fgruler@cm@lowerrightT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(-\textwidth,0)%
\fgruler@cm@leftdown{\textwidth}%
\fgruler@cm@upright{\textheight}%
\put(-5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% LOWERRIGHTT IN
\def\fgruler@in@lowerrightT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(-\textwidth,0)%
\fgruler@in@leftdown{\textwidth}%
\fgruler@in@upright{\textheight}%
\put(-8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% ALLEDGES CM
\def\fgruler@cm@alledges@fg{%
\AtPageLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\paperwidth,\paperheight)(0,-\paperheight)%
\fgruler@cm@rightdown{\paperwidth}%
\fgruler@cm@downright{\paperheight}%
\put(0,-\paperheight){\fgruler@cm@rightup{\paperwidth}}
\put(\paperwidth,0){\fgruler@cm@downleft{\paperheight}}
\put(5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}
\end{picture}}}

%% ALLEDGES IN
\def\fgruler@in@alledges@fg{%
\AtPageLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\paperwidth,\paperheight)(0,-\paperheight)%
\fgruler@in@rightdown{\paperwidth}%
\fgruler@in@downright{\paperheight}%
\put(0,-\paperheight){\fgruler@in@rightup{\paperwidth}}
\put(\paperwidth,0){\fgruler@in@downleft{\paperheight}}
\put(8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}
\end{picture}}}

%% ALLEDGES* CM
\@namedef{fgruler@cm@alledges*@fg}{%
\AtPageLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\paperwidth,\paperheight)(0,-\paperheight)%
\fgruler@cm@rightdown{\paperwidth}%
\fgruler@cm@downright{\paperheight}%
\put(\paperwidth,-\paperheight){%
\fgruler@cm@leftup{\paperwidth}%
\fgruler@cm@upleft{\paperheight}}
\put(5,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@cm}}
\end{picture}}}

%% ALLEDGES* IN
\@namedef{fgruler@in@alledges*@fg}{%
\AtPageLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\paperwidth,\paperheight)(0,-\paperheight)%
\fgruler@in@rightdown{\paperwidth}%
\fgruler@in@downright{\paperheight}%
\put(\paperwidth,-\paperheight){%
\fgruler@in@leftup{\paperwidth}%
\fgruler@in@upleft{\paperheight}}
\put(8,-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\fgruler@caption@in}}
\end{picture}}}

%% ALLEDGEST CM
\def\fgruler@cm@alledgesT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,-\textheight)%
\fgruler@cm@rightup{\textwidth}%
\fgruler@cm@downleft{\textheight}%
\put(0,-\textheight){\fgruler@cm@rightdown{\textwidth}}
\put(\textwidth,0){\fgruler@cm@downright{\textheight}}
\put(5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\put(0,-\textheight-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\put(\textwidth+\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% ALLEDGEST IN
\def\fgruler@in@alledgesT@fg{%
\AtTextLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,-\textheight)%
\fgruler@in@rightup{\textwidth}%
\fgruler@in@downleft{\textheight}%
\put(0,-\textheight){\fgruler@in@rightdown{\textwidth}}
\put(\textwidth,0){\fgruler@in@downright{\textheight}}
\put(8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\put(0,-\textheight-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\put(\textwidth+\fgruler@sep,0){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% ALLEDGEST* CM
\@namedef{fgruler@cm@alledgesT*@fg}{%
\AtTextLowerLeft{%
\setlength{\unitlength}{1mm}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,-\textheight)%
\fgruler@cm@rightup{\textwidth}%
\fgruler@cm@downleft{\textheight}%
\put(\textwidth,-\textheight){\fgruler@cm@leftdown{\textwidth}}
\put(\textwidth,-\textheight){\fgruler@cm@upright{\textheight}}
\put(5,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@cm}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\put(\textwidth,-\textheight-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\put(\textwidth+\fgruler@sep,-\textheight){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% ALLEDGEST* IN
\@namedef{fgruler@in@alledgesT*@fg}{%
\AtTextLowerLeft{%
\setlength{\unitlength}{.0625in}%
\fgruler@fgsetting%
\begin{picture}(\textwidth,\textheight)(0,-\textheight)%
\fgruler@in@rightup{\textwidth}%
\fgruler@in@downleft{\textheight}%
\put(\textwidth,-\textheight){\fgruler@in@leftdown{\textwidth}}
\put(\textwidth,-\textheight){\fgruler@in@upright{\textheight}}
\put(8,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\fgruler@caption@in}}%
\setcounter{fgrulernum}{\fgruler@startnumh}%
\put(0,\fgruler@sep){\makebox(0,0)[b]{\fgruler@font@\thefgrulernum}}%
\put(\textwidth,-\textheight-\fgruler@sep){\makebox(0,0)[t]{\fgruler@font@\thefgrulernum}}%
\setcounter{fgrulernum}{\fgruler@startnumv}%
\put(-\fgruler@sep,0){\makebox(0,0)[r]{\fgruler@font@\thefgrulernum}}%
\put(\textwidth+\fgruler@sep,-\textheight){\makebox(0,0)[l]{\fgruler@font@\thefgrulernum}}%
\end{picture}}}

%% USER
\def\fgruler@cm@user@fg{}
\def\fgruler@in@user@fg{}
\def\fgrulertype#1#2{\csname fgruler@#1@#2@fg\endcsname}

\def\fgrulerdefusercm#1{\def\fgruler@cm@user@fg{#1}} % for old versions
\def\fgrulerdefuserin#1{\def\fgruler@in@user@fg{#1}} % for old versions

\def\fgrulerdefuser#1{%
\expandafter\def\expandafter\fgrulerunit\expandafter{\fgruler@unit}%
\@namedef{fgruler@\fgruler@unit @user@fg}{#1}}

%    \end{macrocode}
% \Finale
\endinput