diff options
author | Karl Berry <karl@freefriends.org> | 2012-03-30 22:59:00 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-03-30 22:59:00 +0000 |
commit | d82e1c23973fd0271f93686f487bd1cee8dcd947 (patch) | |
tree | aa2b560201147b7fa4c9a307309855ed5c7ef6a6 /Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex | |
parent | 0c2a4b76e6f5683bb95ad5a176f157745fd78dc7 (diff) |
FAQ-en (30mar12)
git-svn-id: svn://tug.org/texlive/trunk@25791 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex')
-rw-r--r-- | Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex | 63 |
1 files changed, 52 insertions, 11 deletions
diff --git a/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex b/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex index b71fbaece6d..b6b706555aa 100644 --- a/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex +++ b/Master/texmf-dist/doc/generic/FAQ-en/faq-mac-prog.tex @@ -1,4 +1,4 @@ -% $Id: faq-mac-prog.tex,v 1.25 2011/09/09 19:35:14 rf10 Exp rf10 $ +% $Id: faq-mac-prog.tex,v 1.28 2012/02/18 19:28:56 rf10 Exp rf10 $ \section{Macro programming} @@ -503,19 +503,20 @@ what's left: \begin{narrowversion} \begin{verbatim} \def\testnum#1{\afterassignment\testresult - \count255=#1 \end} + \count255=0#1 \end} \def\testresult#1\end{\ifx\end#1\end} -\def\IsInteger#1{TT\fi \testnum{#1}} \end{verbatim} \end{narrowversion} \begin{wideversion} \begin{verbatim} -\def\testnum#1{\afterassignment\testresult\count255=#1 \end} +\def\testnum#1{\afterassignment\testresult\count255=0#1 \end} \def\testresult#1\end{\ifx\end#1\end\isanumtrue\else\isanumfalse\fi} \end{verbatim} \end{wideversion} \end{quote} -(which technique is due to David Kastrup); this can provoke errors. +(which technique is due to David Kastrup; the trick for avoiding the +errors, noted in an earlier version of this answer, was suggested by +Andreas Matthias). In a later thread on the same topic, Michael Downes offered: \begin{quote} \begin{wideversion} @@ -863,7 +864,7 @@ accurately. \item[keyval.sty]Distributed as part of \CTANref{graphics}[keyval] \end{ctanrefs} - * faq-mac-prog.tex (q-keyval): tweak words about getoptk + * faq-mac-prog.tex (q-keyval): tweak words about getoptk \Question[Q-keyval]{Key-value input for macros and package options} @@ -1508,7 +1509,7 @@ for you. They all create a \tex{} conditional command: These \tex{} commands may be used within the \latex{} conditional framework, as (for example): \begin{quote} - \csx{ifthenelse}\texttt{\char`\{}\cmdinvoke{boolean}{pdf}\texttt{\char`\}\char`\{\meta{if pdf}\char`\}\char`\{\meta{not pdf}\char`\}} + \csx{ifthenelse}\texttt{\obracesymbol{}}\cmdinvoke{boolean}{pdf}\texttt{\cbracesymbol{}}\texttt{\obracesymbol{}}\meta{if pdf}\texttt{\cbracesymbol{}}\texttt{\obracesymbol{}}\meta{if not pdf}\texttt{\cbracesymbol{}} \end{quote} The \Package{ifxetex} package also provides a command @@ -1598,6 +1599,7 @@ output, you also need to know about the value of \csx{pdfoutput}: \CTANref{oberdiek}[ifluatex] \item[ifxetex.sty]\CTANref{ifxetex} \end{ctanrefs} +\LastEdit{2012-02-13} \Question[Q-subverttoks]{Subverting a token register} @@ -2359,10 +2361,49 @@ definition like: \WithSuffix\gdef\mycommand*{starred version} \end{verbatim} \end{quote} + +For those of an adventurous disposition, a further option is to use +the \Package{xparse} package from the \Package{l3packages} +distribution. The package defines a bunch of commands (such as +\csx{NewDocumentCommand}) which are somewhat analagous to +\csx{newcommand} and the like, in \latexe{}. The big difference is +the specification of command arguments; for each argument, you have a +set of choices in the command specification. So, to create a +*-command (in \latexe{} style), one might write: +\begin{quote} +\begin{verbatim} +\NewDocumentCommand \foo { s m } {% + % #1 is the star indicator + % #2 is a mandatory argument + ... +} +\end{verbatim} +\end{quote} +The ``star indicator'' (\texttt{s}) argument appears as \texttt{\#1} +and will take values \csx{BooleanTrue} (if there was a star) or +\csx{BooleanFalse} (otherwise); the other (\texttt{m}) argument is a +normal \tex{}-style mandatory argument, and appears as \texttt{\#2}. + +While \Package{xparse} provides pleasing command argument +specifications, it \emph{is} part of the % ! line break +\Qref*{\latex{}~3 experimental harness}{Q-LaTeX3}, and +simply loading the package ``pulls in'' a large bunch of other package +files via the \Package{expl3} package: these packages provide the rest +of the harness. +% original suggestion was to offer: +% \NewDocumentCommand{\mycommand}{s}{% +% % macro contents where #1 refers to *-variant (true) or not (false) +% \IfBooleanTF{#1}% Condition on * +% {}% TRUE: \mycommand* +% {}% FALSE: \mycommand +% } \begin{ctanrefs} \item[ifthen.sty]Part of the \LaTeX{} distribution \item[suffix.sty]Distributed as part of \CTANref{bigfoot}[suffix] +\item[xparse.sty]Distributed as part of \CTANref{l3packages}[xparse] +\item[expl3.sty]Distributed as part of \CTANref{l3kernel}[expl3] \end{ctanrefs} +\LastEdit{2012-02-07} \nothtml{\hrule height 0pt \nobreak\vskip0pt plus2.5in\vskip 0pt\relax} \Question[Q-ltxabbrv]{\LaTeX{} internal ``abbreviations'', etc.} @@ -2517,7 +2558,7 @@ So, using \Package{printlen}, we could say: \end{quote} and get: \begin{quote} -\verb|\foo| is 12pt +\csx{foo} is 12pt \end{quote} while, if we say: \begin{quote} @@ -2525,17 +2566,17 @@ while, if we say: \newlength{\foo} \setlength{\foo}{12pt} \uselengthunit{mm} -\verb|\foo| is \printlength{\foo} +\verb|foo| is \printlength{\foo} \end{verbatim} \end{quote} we get: \begin{quote} -\verb|\foo| is 4.21747mm +\csx{foo} is 4.21747mm \end{quote} \begin{ctanrefs} \item[printlen.sty]\CTANref{printlen} \end{ctanrefs} -\LastEdit*{2011-09-08} +\LastEdit{2012-03-16} \Question[Q-labelcount]{Using labels as counter values} |