summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/rulerbox
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/rulerbox
Initial commit
Diffstat (limited to 'macros/latex/contrib/rulerbox')
-rw-r--r--macros/latex/contrib/rulerbox/README.md36
-rw-r--r--macros/latex/contrib/rulerbox/rulerbox.pdfbin0 -> 59280 bytes
-rw-r--r--macros/latex/contrib/rulerbox/rulerbox.sty153
-rw-r--r--macros/latex/contrib/rulerbox/rulerbox.tex104
4 files changed, 293 insertions, 0 deletions
diff --git a/macros/latex/contrib/rulerbox/README.md b/macros/latex/contrib/rulerbox/README.md
new file mode 100644
index 0000000000..bdcc3a7034
--- /dev/null
+++ b/macros/latex/contrib/rulerbox/README.md
@@ -0,0 +1,36 @@
+rulerbox
+=======
+
+`rulerbox` is a LaTeX package for drawing rulers around a box. This might be useful when showing the absolute size of something in electronic documents, or designating the relative scale in printed materials.
+
+Contributing
+------------
+
+This package is developed and maintained by Yuchang Yang < yang.yc.allium@gmail.com >.
+
+Discussions and questions are welcome.
+
+Copyright and Licence
+---------------------
+
+ Copyright (C) 2019 by Yuchang Yang < yang.yc.allium@gmail.com >
+ ----------------------------------------------------------------------
+
+ This work may be distributed and/or modified under the
+ conditions of the LaTeX Project Public License, either
+ version 1.3c of this license or (at your option) any later
+ version. This version of this license is in
+ http://www.latex-project.org/lppl/lppl-1-3c.txt
+ and 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 Yuchang Yang.
+
+ This work consists of the files rulerbox.sty,
+ rulerbox.tex,
+ rulerbox.pdf, and
+ README.md.
diff --git a/macros/latex/contrib/rulerbox/rulerbox.pdf b/macros/latex/contrib/rulerbox/rulerbox.pdf
new file mode 100644
index 0000000000..86f188c61b
--- /dev/null
+++ b/macros/latex/contrib/rulerbox/rulerbox.pdf
Binary files differ
diff --git a/macros/latex/contrib/rulerbox/rulerbox.sty b/macros/latex/contrib/rulerbox/rulerbox.sty
new file mode 100644
index 0000000000..cd4537b91d
--- /dev/null
+++ b/macros/latex/contrib/rulerbox/rulerbox.sty
@@ -0,0 +1,153 @@
+%% rulerbox.sty
+%% Copyright 2019 Yuchang Yang < yang.yc.allium@gmail.com >
+%
+% 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 Yuchang Yang.
+%
+% This work consists of the files rulerbox.sty, rulerbox.tex and
+% the generated manual file rulerbox.pdf.
+%%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{rulerbox}[2019/04/18 v1.01 package rulerbox]
+\makeatletter
+\def\vb@xt@{\vbox to}
+\newdimen\rulerunit
+ \rulerunit=1mm
+\newdimen\rulerwidth
+ \rulerwidth=7pt
+\newdimen\rulersep
+ \rulersep=3pt
+\newdimen\rtickrule
+ \rtickrule=.4pt
+\newdimen\dim@margin
+\newdimen\dim@total@height
+\newdimen\dim@depth
+\def\ruler@vcells#1#2{%
+ \leaders\vb@xt@#1\rulerunit{%
+ \kern-.5\rtickrule
+ \hrule\@height\rtickrule\@width#2\rulerwidth
+ \vss}%
+ \vfill\kern-#1\rulerunit}
+\def\ruler@hcells#1#2{%
+ \leaders\hb@xt@#1\rulerunit{%
+ \kern-.5\rtickrule
+ \vrule\@width\rtickrule\@height#2\rulerwidth
+ \hss}%
+ \hfill\kern-#1\rulerunit}
+\newif\ifrulertop
+ \rulertoptrue
+\newif\ifrulerbottom
+ \rulerbottomtrue
+\newif\ifrulerleft
+ \rulerlefttrue
+\newif\ifrulerright
+ \rulerrighttrue
+\newif\ifruler@t
+\newif\ifruler@b
+\newif\ifruler@l
+\newif\ifruler@r
+\newbox\box@content
+\newbox\box@ruler@left
+\newbox\box@ruler@right
+\newbox\box@ruler@top
+\newbox\box@ruler@bottom
+\def\rulerbox{%
+ \let\ifruler@t\ifrulertop
+ \let\ifruler@b\ifrulerbottom
+ \let\ifruler@l\ifrulerleft
+ \let\ifruler@r\ifrulerright
+ \@ifnextchar[%]
+ {\ruler@box@option}{\ruler@box}}
+\def\ruler@box@option[#1]{%
+ \ruler@tfalse
+ \ruler@bfalse
+ \ruler@lfalse
+ \ruler@rfalse
+ \@tfor\@iterator:=#1\do{\csname ruler@\@iterator true\endcsname}%
+ \ruler@box}
+\long\def\ruler@box#1{%
+ \leavevmode
+ \setbox\box@content=\hbox{#1}%
+ \dim@margin=\rulerwidth
+ \advance\dim@margin\rulersep
+ \dim@total@height=\ht\box@content
+ \advance\dim@total@height\dp\box@content
+ \dim@depth=\dp\box@content
+ \ifruler@b
+ \advance\dim@depth\dim@margin
+ \fi
+ \rulers@prepare
+ \ruler@box@
+}
+\def\rulers@prepare{%
+ \ifruler@l\setbox\box@ruler@left=\hbox{\lower\dp\box@content\hbox{%
+ \ooalign{%
+ \vb@xt@\dim@total@height{\ruler@vcells{10}{1. }}\cr
+ \hidewidth\vb@xt@\dim@total@height{\ruler@vcells{ 5}{ .75}}\cr
+ \hidewidth\vb@xt@\dim@total@height{\ruler@vcells{ 1}{ .5 }}\cr
+ }%
+ }}\fi%
+ \ifruler@r\setbox\box@ruler@right=\hbox{\lower\dp\box@content\hbox{%
+ \ooalign{%
+ \vb@xt@\dim@total@height{\ruler@vcells{10}{1. }}\cr
+ \vb@xt@\dim@total@height{\ruler@vcells{ 5}{ .75}}\hidewidth\cr
+ \vb@xt@\dim@total@height{\ruler@vcells{ 1}{ .5 }}\hidewidth\cr
+ }%
+ }}\fi%
+ \ifruler@t\setbox\box@ruler@top=\hbox{%
+ \ooalign{%
+ \hb@xt@\wd\box@content{\ruler@hcells{10}{1 }}\cr
+ \hb@xt@\wd\box@content{\ruler@hcells{ 5}{ .75}}\cr
+ \hb@xt@\wd\box@content{\ruler@hcells{ 1}{ .5 }}\cr
+ }%
+ }\fi%
+ \ifruler@b\setbox\box@ruler@bottom=\hbox{%
+ \ooalign{%
+ \vb@xt@\rulerwidth{\hb@xt@\wd\box@content{\ruler@hcells{10}{1 }}\vss}\cr
+ \vb@xt@\rulerwidth{\hb@xt@\wd\box@content{\ruler@hcells{ 5}{ .75}}\vss}\cr
+ \vb@xt@\rulerwidth{\hb@xt@\wd\box@content{\ruler@hcells{ 1}{ .5 }}\vss}\cr
+ }%
+ }\fi}
+\def\ruler@box@{%
+ \lower\dim@depth\hbox{%
+ \ifruler@l\kern\dim@margin\fi
+ \vbox{%
+ \ifruler@t
+ \box\box@ruler@top
+ \nointerlineskip
+ \kern\rulersep
+ \fi
+ \hbox{%
+ \ifruler@l
+ \kern-\dim@margin
+ \box\box@ruler@left
+ \kern\rulersep
+ \fi
+ \box\box@content
+ \ifruler@r
+ \kern\rulersep
+ \box\box@ruler@right
+ \kern-\dim@margin
+ \fi
+ }%
+ \ifruler@b
+ \nointerlineskip
+ \kern\rulersep
+ \box\box@ruler@bottom
+ \fi
+ \kern\z@
+ }%
+ \ifruler@r\kern\dim@margin\fi
+ }}
+\makeatother
+%%
+%% End of file `rulerbox.sty'
diff --git a/macros/latex/contrib/rulerbox/rulerbox.tex b/macros/latex/contrib/rulerbox/rulerbox.tex
new file mode 100644
index 0000000000..887a633c22
--- /dev/null
+++ b/macros/latex/contrib/rulerbox/rulerbox.tex
@@ -0,0 +1,104 @@
+%% rulerbox.tex
+%% Copyright 2019 Yuchang Yang < yang.yc.allium@gmail.com >
+%
+% 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 Yuchang Yang.
+%
+% This work consists of the files rulerbox.sty, rulerbox.tex and
+% the generated manual file rulerbox.pdf.
+
+\documentclass[a4paper,11pt]{article}
+
+\usepackage{rulerbox}
+\usepackage{fontspec}
+\usepackage{color}
+\definecolor{darkmiku}{RGB}{19, 149, 139}
+
+\newdimen\sidelength
+ \sidelength=2cm
+\newdimen\boxkern
+ \boxkern=2mm
+\newdimen\mydimen
+\mydimen=\sidelength
+\advance\mydimen-.8pt
+
+\def\lan{\ensuremath{\langle}}
+\def\ran{\ensuremath{\rangle}}
+\def\param#1{\textrm{\lan\textit{#1}\ran}}
+\def\texttt#1{{\ttfamily\color{darkmiku}#1}}
+\def\cbox#1{\rulerbox[#1]{\ooalign{%
+ \rule{\sidelength}{\sidelength}\cr
+ \hidewidth\raisebox{.4pt}{\color{white}\rule{\mydimen}{\mydimen}}\hidewidth\cr
+ \hidewidth\vbox to \sidelength{\vss\hbox to \sidelength{\hss\texttt{[#1]}\hss}\vss}\hidewidth\cr
+ }}}
+
+\title{\hspace*{1cm}The \textsf{rulerbox} package\footnotemark[1]\hspace*{1cm}}
+\author{Yuchang \textsc{Yang}{\fontspec{SimSun}(杨宇昌)\kern-5pt\footnotemark[2]}}
+\date{April 18\textsuperscript{th}, 2019\qquad ver.~1.01}
+
+\begin{document}
+
+\parskip=1ex
+
+\begin{centering}
+ \vspace*{-2em}
+ \rulersep=5pt
+ \rulerwidth=5mm
+ \let\newpage\relax
+ \rulerbox{\parbox{.7\linewidth}{\vspace*{-2em}\maketitle\vspace*{-1.5em}}}\par
+ \vskip1.5em
+ \def\thefootnote{\fnsymbol{footnote}}
+ \footnotetext[1]{Github repository: \texttt{https://github.com/Mikumikunisiteageru/rulerbox}}
+ \footnotetext[2]{Email address: \texttt{yang.yc.allium@gmail.com}}
+\end{centering}
+
+\section{Introduction}
+ \textsf{rulerbox} is an independent \LaTeX\ package providing macro \texttt{\string\rulerbox}, which draws rulers along edges of an object, in the following style:\par
+ \vskip-1mm
+ \centerline{{\rulersep=-.4pt\rulerwidth=5mm\rulerbox[b]{\rule{10cm}{0pt}}}}
+ \smallskip
+ This might be useful when showing the absolute size of something in electronic documents, or designating the relative scale in printed materials.
+
+\section{Usage}
+
+% \subsection{Basic syntax}
+ \texttt{\string\rulerbox\{\param{content}\}} somewhat resembles the macro \texttt{\string\fbox\{\param{content}\}} defined by \LaTeX. The one mandatory parameter that they receive is the content to be wrapped inside a box. Then \texttt{\string\rulerbox} decorates the box edges with rulers, whereas \texttt{\string\fbox} frames the box by solid lines. Neither of them affects the vertical alignment.\par
+ \medskip
+ \centerline{\fontsize{50}{50}\selectfont ra\rulerbox{g}ge\fbox{d}ri\fbox{g}\rulerbox{h}t}
+
+\subsection{Edge selection}
+ \texttt{\string\rulerbox[\param{edges}]\{\param{content}\}} also accepts an optional parameter, telling \LaTeX{} which edges to be decorated with rulers. \texttt{\param{edges}} is any subset of \texttt{t}, \texttt{b}, \texttt{l}, and \texttt{r}, controlling the top, bottom, left, and right edges respectively. So \texttt{\string\rulerbox[tblr]\{\param{content}\}} behaves identically the same as \texttt{\string\rulerbox\{\param{content}\}} (unless default switches are turned off, see below), while \texttt{\string\rulerbox[]\{\param{content}\}} regresses to \texttt{\string\hbox\{\param{content}\}}.\par
+ \medskip
+ \centerline{\vbox{%
+ \hbox{\cbox{tl}\kern\boxkern\cbox{t}\kern\boxkern\cbox{tr}}%
+ \nointerlineskip\kern\boxkern
+ \hbox{\cbox{l}\kern\boxkern\cbox{}\kern\boxkern\cbox{r}}%
+ \nointerlineskip\kern\boxkern
+ \hbox{\cbox{bl}\kern\boxkern\cbox{b}\kern\boxkern\cbox{br}}%
+ }}
+ \smallskip
+ Default status of each edge can be set separately and globally by switching \texttt{\textbackslash ifrulertop}, \texttt{\textbackslash ifrulerbottom}, \texttt{\textbackslash ifrulerleft}, and \texttt{\textbackslash ifrulerright}. For example, \texttt{\string\rulerleftfalse} suppresses all left rulers (except required explicitly by \texttt{\param{edges}}), until a \texttt{\string\rulerlefttrue} is seen.\par
+
+\subsection{Dimensions}
+ Four dimensions are involved in the \textsf{rulerbox} package. They can be redefined locally by \texttt{\param{dimen name}=\param{dimen express}\string\relax} in \TeX\ style, or globally by \texttt{\string\setlength\{\param{dimen name}\}\{\param{dimen express}\}} in \LaTeX\ style.
+ \begin{itemize}
+ \item \texttt{\string\rulerunit}: The \textsl{least count} of rulers, \textit{i.e.}\ distance between adjacent ticks in rulers. Default is \texttt{1mm}, one millimetre, which produces rulers of metric length system. \texttt{\string\rulerunit} may be redefined to adapt to other \textsl{decimal} length systems, or draw rulers of relative scales.\par
+ For example, if one wants to switch to Chinese length units, he may define \texttt{\string\rulerunit=1cm\string\divide\string\rulerunit3\string\relax}, which makes the least count 10/3 mm, namely one \textit{fen}{\fontspec{SimSun}(分)}\kern-4pt, or one tenth \textit{cun}{\fontspec{SimSun}(寸)}\kern-4pt.\par
+ \vskip-6mm
+ \hbox{}\hfill{\rulerunit=1cm\divide\rulerunit3\relax\rulersep=-6pt\rulerwidth=5mm\rulerbox[b]{\rule{10cm}{0pt}}}\hfill\hbox{}\par
+ \smallskip
+ \item \texttt{\string\rulersep}: Distance between box edges and rulers. Default is \texttt{3pt}.
+ \item \texttt{\string\rulerwidth}: Length of longest ticks in rulers. Default is \texttt{7pt}.
+ \item \texttt{\string\rtickrule}: Width of tick lines in rulers. Default is \texttt{0.4pt}.
+ \end{itemize}
+
+\end{document}