| 1 |
|
| 2 |
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5 |
| 3 |
% Bundled source file for the IFMTARG package |
| 4 |
%--------1---------2---------3---------4---------5 |
| 5 |
% Please see the accompanying README for author, |
| 6 |
% license, documentation and installation information |
| 7 |
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5 |
| 8 |
|
| 9 |
\RequirePackage{filecontents} |
| 10 |
\begin{filecontents*}{ifmtarg.sty} |
| 11 |
\NeedsTeXFormat{LaTeX2e} |
| 12 |
\ProvidesPackage{ifmtarg}[2018/04/16 v1.2b check for an empty argument] |
| 13 |
\begingroup |
| 14 |
\catcode`\Q=3 |
| 15 |
\long\gdef\@ifmtarg#1{\@xifmtarg#1QQ\@secondoftwo\@firstoftwo\@nil} |
| 16 |
\long\gdef\@xifmtarg#1#2Q#3#4#5\@nil{#4} |
| 17 |
\long\gdef\@ifnotmtarg#1{\@xifmtarg#1QQ\@firstofone\@gobble\@nil} |
| 18 |
\endgroup |
| 19 |
\endinput |
| 20 |
\end{filecontents*} |
| 21 |
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5 |
| 22 |
|
| 23 |
|
| 24 |
% Conditionally compile the documentation & generate the .ins file: |
| 25 |
\providecommand\documentationCompile{Y} |
| 26 |
\makeatletter |
| 27 |
\if\documentationCompile N |
| 28 |
\expandafter\@@end |
| 29 |
\fi |
| 30 |
|
| 31 |
|
| 32 |
\begin{filecontents*}{ifmtarg.ins} |
| 33 |
%&latex |
| 34 |
\def\documentationCompile{N} |
| 35 |
\input ifmtarg.tex |
| 36 |
\csname@@end\endcsname |
| 37 |
\end{filecontents*} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
\makeatletter |
| 43 |
\documentclass[twocolumn]{ltxdoc} |
| 44 |
|
| 45 |
\usepackage{shortvrb} |
| 46 |
\MakeShortVerb\| |
| 47 |
\usepackage[it,medium]{titlesec} |
| 48 |
|
| 49 |
\usepackage{array,ifmtarg,bigfoot,fancyvrb} |
| 50 |
\usepackage[svgnames]{xcolor} |
| 51 |
\usepackage[colorlinks,linktocpage]{hyperref} |
| 52 |
|
| 53 |
\usepackage{geometry} |
| 54 |
\geometry{margin=2cm} |
| 55 |
|
| 56 |
\usepackage{tocloft,varwidth} |
| 57 |
\setcounter{tocdepth}{1} |
| 58 |
\def\tocwidthA{0.55} |
| 59 |
\def\tocwidthB{0.44} |
| 60 |
\def\cftpartfont{\scshape} |
| 61 |
\def\cftsecfont{\small} |
| 62 |
\cftbeforesecskip=0pt |
| 63 |
\def\cftpartleader{} |
| 64 |
\def\cftpartafterpnum{\cftparfillskip} |
| 65 |
\def\cftsecleader{} |
| 66 |
\def\cftsecafterpnum{\cftparfillskip} |
| 67 |
|
| 68 |
\DeclareRobustCommand\pkg{\textsf} |
| 69 |
\def\pkgopt#1{\texttt{[#1]}} |
| 70 |
\newcommand\chng[1]{\marginpar{\footnotesize\raggedright\textsf{#1}}} |
| 71 |
|
| 72 |
\def\PDF{\textsc{pdf}} |
| 73 |
\def\PS{\textsc{ps}} |
| 74 |
\def\DVI{\textsc{dvi}} |
| 75 |
\def\EPS{\textsc{eps}} |
| 76 |
|
| 77 |
\usepackage{amsmath,listings} |
| 78 |
\lstset{basicstyle=\ttfamily,columns=fullflexible} |
| 79 |
|
| 80 |
\usepackage{changepage} |
| 81 |
\usepackage[T1]{fontenc} |
| 82 |
\usepackage{microtype} |
| 83 |
\usepackage{lmodern} |
| 84 |
\usepackage[sc,osf]{mathpazo} |
| 85 |
\linespread{1.1} |
| 86 |
\frenchspacing |
| 87 |
|
| 88 |
\GetFileInfo{ifmtarg.sty} |
| 89 |
\begin{document} |
| 90 |
{\addtocontents{toc}{\protect\begin{varwidth}[t]{\tocwidthA\linewidth}}} |
| 91 |
|
| 92 |
\title{The \pkg{ifmtarg} package} |
| 93 |
\author{% |
| 94 |
Author: Donald Arseneau, and Peter Wilson, Herries Press\\ |
| 95 |
Maintainer: Will Robertson\\ |
| 96 |
\texttt{will dot robertson at latex-project dot org}% |
| 97 |
} |
| 98 |
\date{\fileversion \qquad \filedate} |
| 99 |
|
| 100 |
\maketitle |
| 101 |
|
| 102 |
\section{Documentation} |
| 103 |
|
| 104 |
The \pkg{ifmtarg} package provides an if--then--else programmer's command \verb|\@ifmtarg| for testing for an empty macro argument. |
| 105 |
`Empty' here refers to an argument of zero or more spaces only.\footnote{If you need a command to test for emptiness that doesn't include spaces, use the \verb|\tl_if_empty:nTF| conditional from the \pkg{expl3} package. \verb|\@ifmtarg| is equivalent to \pkg{expl3}'s \verb|\tl_if_blank:nTF|.} |
| 106 |
The command is fully expandable; its syntax is: |
| 107 |
\begin{quote} |
| 108 |
\cmd{\@ifmtarg}\marg{arg}\marg{Code for arg empty} |
| 109 |
\\\null\hfill |
| 110 |
\marg{Code for arg not empty} |
| 111 |
\end{quote} |
| 112 |
|
| 113 |
A variation is provided, \cmd{\@ifnotmtarg}, to be used when only the `false' branch is required. |
| 114 |
It is slightly more efficient when code is only required for a non-empty argument. |
| 115 |
\begin{quote} |
| 116 |
\cmd{\@ifnotmtarg}\marg{arg}\marg{Code for not empty} |
| 117 |
\end{quote} |
| 118 |
|
| 119 |
\section{Examples} |
| 120 |
|
| 121 |
\begin{verbatim} |
| 122 |
\newcommand\isempty[1]{\@ifmtarg{#1}{YES}{NO}} |
| 123 |
\end{verbatim} |
| 124 |
\nobreak |
| 125 |
\begin{tabular}{@{\hspace{1.8em}}>{\color{SeaGreen}}l@{$\quad\to\quad$}>{\ttfamily}l@{}} |
| 126 |
\verb+\isempty{}+ & YES \\ |
| 127 |
\verb+\isempty{ }+ & YES \\ |
| 128 |
\verb+\isempty{E}+ & NO \\ |
| 129 |
\verb+\isempty{ E }+ & NO |
| 130 |
\end{tabular} |
| 131 |
|
| 132 |
\begin{verbatim} |
| 133 |
\newcommand\isnotempty[1]{\@ifnotmtarg{#1}{YES}} |
| 134 |
\end{verbatim} |
| 135 |
\nobreak |
| 136 |
\begin{tabular}{@{\hspace{1.8em}}>{\color{SeaGreen}}l@{$\quad\to\quad$}>{\ttfamily}l@{}} |
| 137 |
\verb+\isnotempty{}+ & \\ |
| 138 |
\verb+\isnotempty{ }+ & \\ |
| 139 |
\verb+\isnotempty{E}+ & YES \\ |
| 140 |
\verb+\isnotempty{ E }+ & YES |
| 141 |
\end{tabular} |
| 142 |
|
| 143 |
\newpage |
| 144 |
\section{History} |
| 145 |
|
| 146 |
(\emph{Peter's comments follow.}) In an Email to me on 13 March 2000, Donald Arseneau pointed out some |
| 147 |
failings with my original definition of the \cmd{\@ifmtarg} command: |
| 148 |
% |
| 149 |
\begin{verbatim} |
| 150 |
\newcommand{\@ifmtarg}[3]{% |
| 151 |
\edef\@mtarg{\zap@space#1 \@empty}% |
| 152 |
\ifx\@empty\@mtarg\relax #2\else #3\fi} |
| 153 |
\end{verbatim} |
| 154 |
% |
| 155 |
It works most of the time correctly but Donald showed that it can |
| 156 |
give unexpected results |
| 157 |
under conditions that I had not thought of. He suggested the coding |
| 158 |
that now appears in the package above for the \cmd{\@ifmtarg} and |
| 159 |
\cmd{\@ifnotmtarg} commands. For a discussion on detecting empty arguments |
| 160 |
see \href{http://www.ctan.org/pub/tex-archive/info/aro-bend/answer.002}{\texttt{CTAN/info/aro-bend/answer.002}} |
| 161 |
|
| 162 |
|
| 163 |
\section*{Change History} |
| 164 |
|
| 165 |
\begin{itemize} |
| 166 |
\item[v1.2a] New maintainer (Will Robertson) |
| 167 |
\item[v1.2b] Typo in documentation example code |
| 168 |
\end{itemize} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
\section*{Licence and copyright} |
| 173 |
|
| 174 |
This work may be modified and/or distributed under the terms and |
| 175 |
conditions of the \LaTeX\ Project Public License\footnote{\url{http://www.latex-project.org/lppl.txt}}, version~1.3c or later (your choice). |
| 176 |
The current maintainer of this work is Will Robertson. |
| 177 |
|
| 178 |
\bigskip |
| 179 |
\noindent |
| 180 |
Copyright Peter Wilson, 1996 \\ |
| 181 |
Copyright Peter Wilson and Donald Arseneau, 2000 |
| 182 |
|
| 183 |
{\addtocontents{toc}{\protect\end{varwidth}\protect\hfill}} |
| 184 |
{\addtocontents{toc}{\protect\begin{varwidth}[t]{\protect\tocwidthB\protect\linewidth}}} |
| 185 |
\clearpage |
| 186 |
\parindent=0pt |
| 187 |
|
| 188 |
\section{Implementation} |
| 189 |
\VerbatimInput{ifmtarg.sty} |
| 190 |
|
| 191 |
{\addtocontents{toc}{\protect\end{varwidth}}} |
| 192 |
|
| 193 |
\end{document} |