diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/interval |
Initial commit
Diffstat (limited to 'macros/latex/contrib/interval')
-rw-r--r-- | macros/latex/contrib/interval/README | 32 | ||||
-rw-r--r-- | macros/latex/contrib/interval/interval.pdf | bin | 0 -> 323101 bytes | |||
-rw-r--r-- | macros/latex/contrib/interval/interval.sty | 88 | ||||
-rw-r--r-- | macros/latex/contrib/interval/interval.tex | 199 |
4 files changed, 319 insertions, 0 deletions
diff --git a/macros/latex/contrib/interval/README b/macros/latex/contrib/interval/README new file mode 100644 index 0000000000..0ae8b8be21 --- /dev/null +++ b/macros/latex/contrib/interval/README @@ -0,0 +1,32 @@ +% (C) Lars Madsen, daleif@math.au.dk, 2019/03/06 +% This material is subject to the LaTeX Project Public License. +% See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html +% for the details of that license. + + +This small package use the pgfkeys pacakge to solve the problem of +using the ]a,b[ syntax for indicating an open interval. Instead of +having to type this as \mathopen{]}a,b\mathclose{[} users can simply +use + + \interval[open]{a}{b} (= ]a,b[ with proper spacing) + +Other usages include + + \interval[open left]{a}{b} (= ]a,b]) + \interval{a}{b} (= [a,b]) + +We also provide a simple interface to switch to the more convenient +(a,b) tradition for specifying an open interval. + +See the manual for details. + +* v0.4: + Added \ointerval, \linterval, \rinterval short hands (suggested by Frank Mittelbach). + They are just shots ways to say, say, \interval[open]{a}{b}, etc. + + Removed \intervalsetup (now gives an error if used, was set to equal \intervalconfig) + +* v0.3: added the colorize option +* v0.2: typo in manual + diff --git a/macros/latex/contrib/interval/interval.pdf b/macros/latex/contrib/interval/interval.pdf Binary files differnew file mode 100644 index 0000000000..1095061d6f --- /dev/null +++ b/macros/latex/contrib/interval/interval.pdf diff --git a/macros/latex/contrib/interval/interval.sty b/macros/latex/contrib/interval/interval.sty new file mode 100644 index 0000000000..1aa4ae5234 --- /dev/null +++ b/macros/latex/contrib/interval/interval.sty @@ -0,0 +1,88 @@ +\ProvidesPackage{interval}[2019/03/06 v0.4] + +\newcommand\INTVversion{v0.4} + +%% +%% This package can 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 2003/12/01 or later. +%% +%% This work has the LPPL maintenance status "maintained". +%% +%% The Current Maintainer of this work is Lars Madsen (daleif@math.au.dk). +%% + + +\RequirePackage{pgfkeys} + +\newcommand\INTV@scaler[1]{ + \def\INTV@auto{auto} + \def\INTV@arg{#1} + \ifx\INTV@auto\INTV@arg + \def\INTV@openfence{\mathopen{}\mathclose\bgroup\left\INTV@leftfence} + \def\INTV@closefence{\aftergroup\egroup\right\INTV@rightfence} + \else + \def\INTV@openfence{\mathopen{#1\INTV@leftfence}} + \def\INTV@closefence{\mathclose{#1\INTV@rightfence}} + \fi +} + + +% setup +\pgfkeys{% + /interval/.is family,% + /interval,% + left open fence/.initial={]},% + left closed fence/.initial={[},% + right open fence/.initial={[},% + right closed fence/.initial={]},% + left fence/.link=/interval/left closed fence,% + right fence/.link=/interval/right closed fence,% + separator symbol/.initial={,},% + open left/.style={ left fence/.link=/interval/left open fence },% + open right/.style={ right fence/.link=/interval/right open fence },% + open/.style={open left,open right},% + scaled/.code={\INTV@scaler{#1}},% + scaled/.default=auto,% + soft open fences/.style={% + left open fence={(},% + right open fence={)},% + },% + colorize/.initial=,% +} + +% user configuation +\newcommand\intervalconfig[1]{\pgfkeys{/interval,#1}} + +\newcommand\intervalsetup{ + \PackageError{interval}{The \string\intervalsetup\space macro has + been removed. Please use \string\intervalconfig\space instead}{} +} + + +\newcommand\interval[3][]{% + \begingroup% + \def\INTV@openfence{\mathopen{\INTV@leftfence}}% + \def\INTV@closefence{\mathclose{\INTV@rightfence}}% +% \let\INTV@extra\relax% + \pgfkeys{interval,#1}% + \pgfkeysgetvalue{/interval/left fence}{\INTV@leftfence}% + \pgfkeysgetvalue{/interval/right fence}{\INTV@rightfence}% + \pgfkeysgetvalue{/interval/colorize}{\INTV@colorize}% + \INTV@colorize% + \INTV@openfence% + #2% + \pgfkeysvalueof{/interval/separator symbol} + #3% + \INTV@closefence% + \endgroup% +} + +\newcommand\ointerval[3][]{\interval[open,#1]{#2}{#3}} +\newcommand\linterval[3][]{\interval[open left,#1]{#2}{#3}} +\newcommand\rinterval[3][]{\interval[open right,#1]{#2}{#3}} + diff --git a/macros/latex/contrib/interval/interval.tex b/macros/latex/contrib/interval/interval.tex new file mode 100644 index 0000000000..42ebc81f1f --- /dev/null +++ b/macros/latex/contrib/interval/interval.tex @@ -0,0 +1,199 @@ +\documentclass[a4paper,article]{memoir} +\usepackage[T1]{fontenc} +\usepackage{amsmath,enumitem,showexpl} +%\usepackage[scaled]{beramono} +\title{The \textsf{interval} package} +\author{Lars Madsen\thanks{Email: daleif@math.au.dk, version: \INTVversion}\\ \small (on behalf of By the Danish \TeX\ collective)} +\setsecnumdepth{none} + +%\setlength\overfullrule{5pt} + +\usepackage{interval} + +\begin{document} + +\maketitle + + + +\section{Motivation} +\label{sec:motivation} + +In mathematics there are two syntax' when it comes to specifying open +and closed intervals. + +The first use parantheses to mark an open end +\begin{align*} + [a,b] \qquad (a,b] \qquad [a,b)\qquad (a,b), +\end{align*} +while the other use brackets throughout +\begin{align*} + [a,b] \qquad ]a,b] \qquad [a,b[\qquad ]a,b[, +\end{align*} + +The former poses no problem in \TeX, but the later does, as, e.g., a +closing bracket is being used in place of an opening fence, and thus +have the wrong category when it comes to spacing: +\begin{align*} + ]-a,b[+c \qquad\text{versus}\qquad \mathopen{]}-a,b\mathclose{[}+c. +\end{align*} + +One could use +\begin{verbatim} +\mathopen{]}-a,b\mathclose{[}+c +\end{verbatim} +to solve the problem, but then \cs{left}\dots\cs{right} can no longer +be used to auto scale the fences. + + + + +\section{The \cs{interval} command} +\label{sec:csinterval-command} + +The following is the result of a discussion on the Danish \TeX\ Users +groups mailing list. Kudos to Martin Heller, for proposing the +original version using \textsf{pgfkeys}. + +We provide a macro and a way to globally configure it +\begin{quote} + \cs{interval}\oarg{options}\marg{start}\marg{end}\\ + \cs{intervalconfig}\marg{options} +\end{quote} +We note that the interval separator symbol is hidden inside the +\cs{interval} macro and can be changed using an option. + +\subsection{Configuration options} +\label{sec:options} + +\begin{description}[style=nextline,font=\sffamily\bfseries] +\item[separator symbol] + symbol that separates the start and end of the interval. Default: + \texttt{\{,\}}, note that as comma is the separating character in the + options specification, the symbol is enclosed in braces, these are + automatically removed. +\item[left open fence] + Default: \texttt{]} +\item[left closed fence] + Default: \texttt{[} +\item[right open fence] + Default: \texttt{[} +\item[right closed fence] + Default: \texttt{]} +\item[soft open fences] + This is just a fast way of saying + \begin{quote} + \ttfamily\obeylines + left open fence=(, + right open fence=) + \end{quote} +\item[colorize] + Default: \meta{empty}. When rewriting an existing document into + using the \textsf{interval} package, it turns out to be \emph{very} + handy to color the result of the \cs{interval} macro to keep track + of which have been rewritten and which has not. + This can be done using +\begin{lstlisting}[basicstyle=\ttfamily,columns=flexible] + \usepackage{xcolor} + \intervalconfig{ colorize=\color{red} } +\end{lstlisting} +It will colorize the entire interval including the fences. + +\end{description} + +\subsection{Usage options} + +By default \cs{interval}\marg{start}\marg{end} will produce a closed +interval. Other types are provided via options: + +\begin{description}[style=nextline,font=\sffamily\bfseries] +\item[open] + an open interval +\item[open left] + interval open on the left side +\item[open right] + interval open on the right side +\item[scaled] + auto scale interval fences +\item[scaled=\meta{scaler}] + scale fences using \meta{scaler}, i.e.\ using \texttt{scaled=\cs{Big}} +\end{description} + +\fancybreak{} + +As some might be guessed, the \texttt{interval} package depends on the +\textsf{pgfkeys} package to handle its key-value configuration. + + +\subsection{Short hands} +\label{sec:shorthands} + +For convenience the following short hands are provided as of version 0.4. +\begin{description}[style=nextline,font=\normalfont] +\item[\cs{ointerval}\oarg{options}\marg{start}\marg{end}] + is short for \cs{interval}\texttt{[open,}\meta{options}\texttt{]}\marg{start}\marg{end} +\item[\cs{linterval}\oarg{options}\marg{start}\marg{end}] + is short for \cs{interval}\texttt{[open left,}\meta{options}\texttt{]}\marg{start}\marg{end} +\item[\cs{rinterval}\oarg{options}\marg{start}\marg{end}] + is short for \cs{interval}\texttt{[open right,}\meta{options}\texttt{]}\marg{start}\marg{end} +\end{description} + +%\newpage + +\section{Examples} +\label{sec:examples} + +% used for showexpl +\lstset{ + explpreset={ + xleftmargin=0em, + columns=fixed, + }, + pos=r, + width=-99pt, + overhang=0pt, + hsep=2\columnsep, + vsep=\bigskipamount, + rframe=x, + basicstyle=\footnotesize\ttfamily, +} + + + +\begin{LTXexample}[varwidth=true] +\begin{align*} +& A\in\interval{a}{b} \\ +& A\in\interval[open]{a}{b} \\ +& A\in\interval[open left]{a}{b} \\ +& A\in\interval[open right, + scaled]{a}{\frac{1}{2}b}=B \\ +& A\in\interval[scaled=\big]{a}{b} \\ +& A\in\ointerval[scaled]{% + \tfrac{1}{3}}{\tfrac{1}{2}} +\end{align*} +\end{LTXexample} +And using soft open fences: +\begin{LTXexample}[varwidth=true] +\intervalconfig{ + soft open fences, + separator symbol=;, +} +\begin{align*} +& A\in\interval{a}{b} \\ +& A\in\interval[open]{a}{b} \\ +& A\in\interval[open left]{a}{b} \\ +& A\in\interval[open right, + scaled]{a}{\frac{1}{2}b}=B \\ +& A\in\interval[scaled=\big]{a}{b} \\ +& A\in\rinterval{a}{b} +\end{align*} +\end{LTXexample} + + + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: |