diff options
Diffstat (limited to 'Master/texmf-doc/doc/english/FAQ-en/html/FAQ-patch.html')
-rw-r--r-- | Master/texmf-doc/doc/english/FAQ-en/html/FAQ-patch.html | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-patch.html b/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-patch.html new file mode 100644 index 00000000000..d5d61403e57 --- /dev/null +++ b/Master/texmf-doc/doc/english/FAQ-en/html/FAQ-patch.html @@ -0,0 +1,76 @@ +<head> +<title>UK TeX FAQ -- question label patch</title> +</head><body> +<h3>Patching existing commands</h3> +<p>In the general case (possibly sticking something in the middle of an +existing command) this is difficult. However, the common requirement, +to add some code at the beginning or the end of an existing command, +is conceptually quite easy. Suppose we want to define a version of a +command that does some small extension of its original definition: we +would naturally write: +<blockquote> +<pre> +\renewcommand{\splat}{\mumble\splat} +</pre> +</blockquote> +However, this would not work: a call to <code>\</code><code>splat</code> would execute +<code>\</code><code>mumble</code>, and the call the redefined <code>\</code><code>splat</code> again; this is an +infinite recursive loop, that will quickly exhaust TeX's memory. +<p>Fortunately, the TeX primitive <code>\</code><code>let</code> command comes to our +rescue; it allows us to take a "snapshot" of the current state of a +command, which we can then use in the redefinition of the command. +So: +<blockquote> +<pre> +\let\OldSmooth\smooth +\renewcommand{\smooth}{\mumble\OldSmooth} +</pre> +</blockquote> +effects the required patch, safely. Adding things at the end of a +command works similarly. If <code>\</code><code>smooth</code> takes arguments, one must +pass them on: +<blockquote> +<pre> +\renewcommand{\smooth}[2]{\mumble\OldSmooth{#1}{#2}} +</pre> + +</blockquote> +<p>The general case may be achieved in two ways. First, one can use the +LaTeX command <code>\</code><code>CheckCommand</code>; this compares an existing command +with the definition you give it, and issues a warning if two don't +match. Use is therefore: +<blockquote> + <code>\CheckCommand{\complex}{</code><<i>original definition</i>><code>}</code><br> + <code>\renewcommand{\complex}{</code><<i>new definition</i>><code>}</code> +</blockquote> +This technique is obviously somewhat laborious, but if the original +command comes from a source that's liable to change under the control +of someone else, it does at least warn you that your patch is in +danger of going wrong. +<p>Otherwise, LaTeX users may use one of the <i>patch</i> or +<i>patchcmd</i> systems. +<p><i>Patch</i> gives you an ingenious (and difficult to understand) +mechanism, and comes as an old-style LaTeX documented macro file. +Sadly the old-style <i>doc</i> macros are no longer available, but +the file (<i>patch.doc</i>) may be input directly, and the +documentation may be read (un-typeset). Roughly speaking, one gives +the command a set of instructions analagous to <i>sed</i> +substitutions, and it regenerates the command thus amended. The +author of this FAQ has (slightly reluctantly) given up using +<i>patch</i>... +<p>The <i>patchcmd</i> package addresses a slightly simpler task, by +restricting the set of commands that you may patch; you mayn't patch +any command that has an optional argument, though it does deal with +the case of commands defined with <code>\</code><code>DeclareRobustCommand</code>. The +package defines a <code>\</code><code>patchcommand</code> command, that takes three +arguments: the command to patch, stuff to stick at the front of its +definition, and stuff to stick on the end of its definition. So, if +<code>\</code><code>b</code> contains "<code>b</code>", then +<code>\</code><code>patchcommand</code><code>\</code><code>b{a}{c}</code> +will produce a new version of <code>\</code><code>b</code> that contains "<code>abc</code>". +<dl> +<dt><tt><i>patch.doc</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/macros/generic/patch.doc">macros/generic/patch.doc</a> +<dt><tt><i>patchcommand.sty</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/patchcmd.zip">macros/latex/contrib/patchcmd</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/patchcmd.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/patchcmd/">browse</a>) +</dl> +<p><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=patch">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=patch</a> +</body> |