summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/memoir/mempatch.dtx
blob: 8888e87e9721c74875f8c20947757272487af06b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
% \iffalse meta-comment
%
% mempatch.dtx
% Author: Peter Wilson (Herries Press) herries dot press at earthlink dot net
% Maintainer: Lars Madsen (daleif+memoir at imf dot au dot dk)
% Copyright 2001 --- 2010 Peter R. Wilson
%
% 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 the 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/06/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% This work consists of the files listed in the README file.
%
% 
% \fi
% \CheckSum{514}
%
% \def\dtxfile{\texttt{mempatch.dtx}}
% \def\fileversion{v1.0} \def\filedate{2003/10/04}
% \def\fileversion{v1.1} \def\filedate{2003/10/07}
% \def\fileversion{v1.2} \def\filedate{2003/11/16}
% \def\fileversion{v2.0a} \def\filedate{2004/02/19}
% \def\fileversion{v2.1} \def\filedate{2004/03/01}
% \def\fileversion{v2.3} \def\filedate{2004/03/28}
% \def\fileversion{v2.4} \def\filedate{2004/04/26}
% \def\fileversion{v2.5} \def\filedate{2004/04/27}
% \def\fileversion{v2.6} \def\filedate{2004/04/30}
% \def\fileversion{v2.7} \def\filedate{2004/05/10}
% \def\fileversion{v2.8} \def\filedate{2004/05/13}
% \def\fileversion{v3.0} \def\filedate{2004/12/14}
% \def\fileversion{v3.1} \def\filedate{2004/12/19}
% \def\fileversion{v3.2} \def\filedate{2005/01/01}
% \def\fileversion{v3.3} \def\filedate{2005/01/17}
% \def\fileversion{v3.4} \def\filedate{2005/01/18}
% \def\fileversion{v3.5} \def\filedate{2005/02/01}
% \def\fileversion{v3.6} \def\filedate{2005/02/07}
% \def\fileversion{v3.7} \def\filedate{2005/02/26}
% \def\fileversion{v3.8} \def\filedate{2005/03/06}
% \def\fileversion{v3.9} \def\filedate{2005/03/23}
% \def\fileversion{v3.10} \def\filedate{2005/05/16}
% \def\fileversion{v3.11} \def\filedate{2005/05/23}
% \def\fileversion{v3.12} \def\filedate{2005/06/06}
% \def\fileversion{v4.1} \def\filedate{2005/10/06}
% \def\fileversion{v4.1h} \def\filedate{2005/11/15}
% \def\fileversion{v4.2} \def\filedate{2005/11/21}
% \def\fileversion{v4.3} \def\filedate{2005/12/13}
% \def\fileversion{v4.4} \def\filedate{2006/01/21}
% \def\fileversion{v4.4a} \def\filedate{2006/01/23}
% \def\fileversion{v4.5} \def\filedate{2006/08/08}
% \def\fileversion{v4.6} \def\filedate{2006/12/11}
% \def\fileversion{v4.7} \def\filedate{2006/12/23}
% \def\fileversion{v4.8} \def\filedate{2007/01/22}
% \def\fileversion{v4.9} \def\filedate{2007/12/14}
% \def\fileversion{v4.9a} \def\filedate{2007/12/24}
% \def\fileversion{v4.9a+} \def\filedate{2007/12/31}
% \def\fileversion{v5.0} \def\filedate{2008/05/26}
% \def\fileversion{v5.0} \def\filedate{2008/06/02}
% \def\fileversion{v5.1} \def\filedate{2008/07/11}
% \def\fileversion{v6.0} \def\filedate{2008/07/23}
% \def\fileversion{v6.0a} \def\filedate{2008/08/23}
% \def\fileversion{v6.0b} \def\filedate{2009/01/18}
% \def\fileversion{v6.0c} \def\filedate{2009/02/06}
% \def\fileversion{v6.0d} \def\filedate{2009/07/12}
% \def\fileversion{v6.0e} \def\filedate{2009/07/21}
% \def\fileversion{v6.0f} \def\filedate{2009/07/24}
% \def\fileversion{v6.0g} \def\filedate{2010/04/19}
%
% \title{The LaTeX \Lpack{memoir} class for configurable book 
%        typesetting: Code patches\thanks{This
%        file (\dtxfile) has version number \fileversion, last revised
%        \filedate.}}
%
% \author{%
% Peter Wilson\thanks{\texttt{herries dot press at earthlink dot net}}\\
% The Herries Press
% }
% \date{\filedate}
% \maketitle
%
%  ^^A \MakeShortVerb{\=}
%
% \begin{abstract}
% The \Lpack{memoir} class is designed for typesetting
% general books such as novels, biographies, histories, 
% and so on, although as it supports all the functionality of the 
% standard \Lpack{book} class it can also be used for technical writing.
% It provides more functions than the standard class as well as 
% presenting a more friendly interface for the book designer.
% It can also simulate the typesetting style of the standard \Lpack{article}
% class.
%
%    Because of its newness not all packages work well with \Lpack{memoir}.
% Also, as more users beat on it, subtle flaws are discovered in \Lpack{memoir}
% itself. Patching code is supplied to resolve known problems.
%
%    Code is also provided for new functionality that will later be 
% folded into the class code.
% \end{abstract}
%
% \tableofcontents
% \listoftables
%
% \StopEventually{}
%
% 
%
% \section{Introduction}
%
% This document provides the commented source for packages that patch
% the LaTeX \Lpack{memoir} class~\cite{MEMOIR}. 
% This class is designed for typesetting
% general books such as novels, biographies, histories, 
% and so on. It has all the functionality of the standard \Lpack{book}
% class and, as well as providing some extra functions, also provides
% a more friendly interface for the document designer. As it can encompass
% everything that the \Lpack{book} class provides it may also be used
% for technical writing.
%
%
%    Section~\ref{sec:docstrip} describes some
% administrative elements and code for general use later in the 
% specification.
% The macros forming the package files are defined in section~\ref{sec:hyper}
% and in section~\ref{sec:class} onwards.
% 
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%
% \section{A driver for this document} \label{sec:docstrip}
%
% The next series of code contains the documentation driver file for
% \LaTeX, i.e., the file that will produce the documentation you are
% currently reading. This will be extracted from this file by the 
% \textsc{docstrip} program.
%
%    \begin{macrocode}
%<*driver>
\documentclass[twoside]{ltxdoc}
\usepackage{url}
%    \end{macrocode}
%
%    We do want an index, using linenumbers, but not update information.
%    \begin{macrocode}
\makeatletter
  \@mparswitchfalse
\makeatother
\EnableCrossrefs
\CodelineIndex
%% \RecordChanges
%    \end{macrocode}
% Don't use the default Short Verb.
%    \begin{macrocode}
\AtBeginDocument{\DeleteShortVerb{\|}}
%    \end{macrocode}
% We had better have page headings to aid navigation, but I don't
% like Uppercased titles.
%    \begin{macrocode}
\renewcommand{\MakeUppercase}[1]{#1}
\pagestyle{headings}
%    \end{macrocode}
% Need more space for ToC subsection numbers
%    \begin{macrocode}
\makeatletter
\renewcommand*{\l@subsection}{\@dottedtocline{2}{1.5em}{3.2em}}

%    \end{macrocode}
%    We may use many \file{docstrip} modules so we set the
%    \texttt{StandardModuleDepth} counter to 1.
%    \begin{macrocode}
\setcounter{StandardModuleDepth}{1}
%    \end{macrocode}
%    Some commonly used abbreviations
%    \begin{macrocode}
\newcommand*{\Lopt}[1]{\textsf {#1}}            % typeset an option
\newcommand*{\file}[1]{\texttt {#1}}            % typeset a file
\newcommand*{\Lcount}[1]{\textsl {\small#1}}    % typeset a counter
\newcommand*{\pstyle}[1]{\textsl {#1}}          % typeset a pagestyle
\newcommand*{\Lenv}[1]{\texttt {#1}}            % typeset an environment
\newcommand*{\Lpack}[1]{\textsf {#1}}           % typeset a package
\newcommand*{\ctt}{\textsc{ctt}}
\newcommand{\Lclass}[1]{\textsf{#1}}
\newcommand{\ledmac}{ledmac}
\newcommand{\Ledmac}{\Lpack{\ledmac}}
\newcommand{\edmac}{\texttt{EDMAC}}
\newcommand{\tabmac}{\texttt{TABMAC}}
\newcommand{\PWcomment}[1]{}
\newenvironment{PW}{\itshape}{}
\renewenvironment{PW}{\sffamily}{}
\newcommand{\texbook}{\textit{TeXbook}}
\newcommand{\thetexbook}{\textit{The TeXbook}}
\newcommand{\egstart}{}
\newcommand{\egmid}{}
\newcommand{\egend}{}
\renewcommand{\egstart}{%
   \par
   \begingroup
   \centering
   \begin{minipage}{0.45\textwidth}}
\renewcommand{\egmid}{%
   \end{minipage}\hfill\begin{minipage}{0.45\textwidth}}
\renewcommand{\egend}{%
   \end{minipage}\par\endgroup}
%    \end{macrocode}
%    We want the full details printed.
%    \begin{macrocode}
\begin{document}
\DocInput{mempatch.dtx}
\PrintIndex
%% \PrintChanges
\end{document}
%</driver>
%    \end{macrocode}
%
% 
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}\
% \DoNotIndex{\@dotsep,\@empty,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
% \DoNotIndex{\@namedef,\@nameuse,\csname,\endcsname}
%
%
%
% \section{Patches for hyperref and friends} \label{sec:hyper}
%
% The \Lpack{hyperref} package~\cite{HYPERREF} is a marvel of macro coding but it does
% seem to have a habit of not working too well with classes or packages
% that contain anything out of the
% ordinary.
%
%    \begin{macrocode}
%<*hyper>
%    \end{macrocode}
%
%
% The \Lpack{memhfixc} package provides \Lpack{hyperref} related temporary 
% fixes and extensions for version v1.618 of the \Lpack{memoir} class.
% \begin{itemize}
% \item  hyperref fix for part and chapter entries in the ToC (v1.0)
%  \item Other fixes as and when
% \end{itemize}
% Only use this package in conjunction with the hyperref package. 
% Call the package without options after the hyperref package as:
% \begin{verbatim}
% \documentclass[...]{memoir}
% ...
% \usepackage[...]{hyperref}
% \usepackage{memhfixc}
% \end{verbatim}
%
%    \begin{macrocode}
%%
%% The memhfixc package provides hyperref related temporary 
%% fixes and extensions for versions v1.618 and later of the memoir class.
%%     o hyperref fix for part and chapter entries in the ToC (v1.0)
%%     o Other fixes as and when
%% 
%% Only use this package in conjunction with the hyperref package. 
%% Call the package without options after the hyperref package as:
%% \documentclass[...]{memoir}
%% ...
%% \usepackage[...]{hyperref}
%% \usepackage{memhfixc}
%%
%% With thanks to Heiko Oberdiek, if you use hyperref dated 2006/11/15
%% or later, memhfixc will be automatically loaded after hyperref.
%%
%% Version 1.15  2010/08/17
%% Version 1.14  2010/06/10
%% Version 1.13  2010/04/19
%% Version 1.12  2009/02/06
%% Version 1.11  2009/01/18
%% Version 1.10  2008/08/23
%% Version 1.9  2006/11/22
%% Version 1.8  2006/01/21
%% Version 1.7  2005/11/15
%% Version 1.6  2004/05/13
%% Version 1.5  2003/10/14
%% Version 1.4  2003/09/26
%% Version 1.3  2003/02/20
%% Version 1.2  2003/02/02
%% Version 1.1  2003/01/22
%% Version 1.0  2002/10/22
%%
%    \end{macrocode}
% 
%
%    \begin{macrocode}
\ProvidesPackage{memhfixc}[2010/08/17 v1.15 nameref/hyperref package fixes for memoir class]
%    \end{macrocode}
%
% \begin{macro}{\M@hfixcfinish}
% The \Lpack{memhfixc} package is only useful with the memoir class
%    \begin{macrocode}
\let\M@hfixcfinish\relax
\@ifclassloaded{memoir}{}%
                       {\let\M@hfixcfinish\endinput
                        \typeout{No memoir class: memhfixc does nothing}}
\M@hfixcfinish

%    \end{macrocode}
% \end{macro}
%
% \subsection{Patches for nameref}
%
% \changes{v1.13}{2010/04/19}{Rewritten to help fix a race condition}
% 
% The nameref package changes \cs{@sect} and \cs{label} so we bring
% back the memoir stuff. We have earlier been using
% \verb?\AtBeginDocument? plus \verb?\@ifpackageloaded{nameref}? to
% add our changes to \Lpack{nameref}. But this is not a good solution,
% as \Lpack{hyperref} can delay \Lpack{nameref} loading using
% \verb?\AtBeginDocument{\usepackage{nameref}}? \emph{and} add thiis
% \emph{after} \Lpack{memhfixc} is loaded. A better solution is to use
% \verb?\AtEndPackage?, then it does not matter how far after
% \Lpack{memhfixc} \Lpack{nameref} is loaded.
%
% \changes{v1.13}{2010/04/19}{Code in the next part have been changed
% to match \cs{AtEndPackage}}
%    \begin{macrocode}
\AtEndPackage{nameref}{%
%    \end{macrocode}

% \begin{macro}{\M@sect}
% \begin{macro}{\NR@sectm@m}
% The \Lpack{nameref} package~\cite{NAMEREF} fiddles with \cs{@sect} (which memoir replaces
%  by \cs{M@sect}). 
%    \begin{macrocode}
  \@ifundefined{NR@sectm@m}{% haven't fiddled with \M@sect
    \typeout{Redoing nameref's sectioning}
    \let\NR@sectm@m\M@sect
    \def\M@sect##1##2##3##4##5##6[##7][##8]##9{%
      \setcounter{section@level}{##2}%
      \def\@currentlabelname{##7}%
      \NR@sectm@m{##1}{##2}{##3}{##4}{##5}{##6}[{##7}][{##8}]{\Sectionformat{##9}{##2}}}%
  }%
  {% \NR@sectm@m has already been defined
  }%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \begin{macro}{\label}
% \begin{macro}{\MNR@label}
% The \Lpack{nameref} package replaces \cs{label}, which (which memoir has added to).
%  Make the memoir addition again.
%
%    \begin{macrocode}
  \@ifundefined{MNR@label}{% haven't fiddled with \label
    \typeout{Redoing nameref's label}
    \let\MNR@label\label
    \def\label##1{\@bsphack\begingroup
      \protected@edef\@currentlabel{\protect\M@TitleReference
        {\@currentlabel}{\M@currentTitle}}%
      \MNR@label{##1}%
      \endgroup \@esphack}%
    \let\MNR@old@caption\@caption
    \long\def\@caption##1[##2]##3{%
      \MNR@old@caption{##1}[{##2}]{##3}%
      \def\@currentlabelname{##2}%
      \M@gettitle{##2}%
    }%
  }%
  {% \MNR@label has already been defined
  }%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\nameref}
%   We use \cs{titleref} to provide the same functionality as
%   \cs{nameref}, so as not to confuse users, we let \cs{nameref} be
%   an alias for \cs{titleref}.
%    \begin{macrocode}
\DeclareRobustCommand\nameref{\@ifstar{\@mem@titlerefnolink}{\@mem@titleref}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
}% end of AtEndPackage
%    \end{macrocode}


%
% We are done unless the \Lpack{hyperref} package has been loaded
%    \begin{macrocode}
%% We are done unless the hyperref package has been loaded
\@ifpackageloaded{hyperref}{}{\let\M@hfixcfinish\endinput}
\M@hfixcfinish

%    \end{macrocode}
%
% \subsection{Patches for hyperref}
%
% \begin{macro}{\H@old@sbook}
% \begin{macro}{\@sbook}
%  Possibly this will provide some hyperref bookmarks support for
% the \cs{book*} document division (see page
% 206 in the \textit{Hypertext marks in LaTeX} manual that I processed
% on 2002/10/23 (cunningly it was internally dateless). It is based on
% hyperref's code for \cs{@spart}, which uses \cs{H@old@spart} to hold
% its original definition.
%    \begin{macrocode}
\let\H@old@sbook\@sbook
\def\@sbook#1{%
  \H@old@sbook{#1}%
  \Hy@GlobalStepCount\Hy@linkcounter
  \xdef\@currentHref{book*.\the\Hy@linkcounter}%
  \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\Hy@captionsenglish}
% \begin{macro}{\HyLang@english}
% Not sure what these do. I do know I have one version of \Lpack{hyperref}
% that defines \cs{Hy@captionsenglish} and a later one that
% defines \cs{HyLang@english} instead.
%    \begin{macrocode}
\@ifundefined{Hy@captionsenglish}{}{%
  \g@addto@macro{\Hy@captionsenglish}{\def\bookautorefname{Book}}}
\@ifundefined{HyLang@english}{}{%
  \g@addto@macro{\HyLang@english}{\def\bookautorefname{Book}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\Hy@captionsgerman}
% \begin{macro}{\HyLang@german}
%    \begin{macrocode}
\@ifundefined{Hy@captionsgerman}{}{%
  \g@addto@macro{\Hy@captionsgerman}{\def\bookautorefname{Buch}}}
\@ifundefined{HyLang@german}{}{%
  \g@addto@macro{\HyLang@german}{\def\bookautorefname{Buch}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\Hy@captionsportuges}
% \begin{macro}{\HyLang@portuges}
%    \begin{macrocode}
\@ifundefined{Hy@captionsportuges}{}{%
  \g@addto@macro{\Hy@captionsportuges}{\def\bookautorefname{Livro}}}
\@ifundefined{HyLang@portuges}{}{%
  \g@addto@macro{\HyLang@portuges}{\def\bookautorefname{Livro}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\Hy@captionsspanish}
% \begin{macro}{\HyLang@spanish}
%    \begin{macrocode}
\@ifundefined{Hy@captionsspanish}{}{%
  \g@addto@macro{\Hy@captionsspanish}{\def\bookautorefname{Libro}}}
\@ifundefined{HyLang@spanish}{}{%
  \g@addto@macro{\HyLang@spanish}{\def\bookautorefname{Libro}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\Hy@captionsafrikaans}
% \begin{macro}{\HyLang@afrikaans}
%    \begin{macrocode}
\@ifundefined{Hy@captionsafrikaans}{}{%
  \g@addto@macro{\Hy@captionsafrikaans}{\def\bookautorefname{Boek}}}
\@ifundefined{HyLang@afrikaans}{}{%
  \g@addto@macro{\HyLang@afrikaans}{\def\bookautorefname{Boek}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\bookautorefname}
%    \begin{macrocode}
\providecommand{\bookautorefname}{Book}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@writetorep}
% Change \Lpack{hyperref}'s \cs{@@writetorep} as memoir uses \cs{partnumberline} and 
% \cs{chapternumberline} as well as the normal \cs{numberline}
% \changes{v1.9}{2006/11/22}{\cs{@@writetorep} now in hyperref 2006/11/15}
%    \begin{macrocode}
\@ifpackagelater{hyperref}{2006/11/15}{%
}{%
\def\@@writetorep#1#2#3#4#5{%
  \begingroup
    \def\Hy@tempa{#5}%
    \ifx\Hy@tempa\Hy@bookmarkstype
      \edef\Hy@level{#4}%
      \ifx\Hy@levelcheck Y%
        \@tempcnta\Hy@level\relax
        \advance\@tempcnta by -1
        \ifnum\Hy@currentbookmarklevel<\@tempcnta
          \advance\@tempcnta by -\Hy@currentbookmarklevel\relax
          \advance\@tempcnta by 1
          \Hy@Warning{%
            Difference (\the\@tempcnta) between bookmark levels is %
            greater \MessageBreak than one, level fixed%
          }%
          \@tempcnta\Hy@currentbookmarklevel
          \advance\@tempcnta by 1
          \edef\Hy@level{\the\@tempcnta}%
        \fi
      \else
        \global\let\Hy@levelcheck Y%
      \fi
      \global\let\Hy@currentbookmarklevel\Hy@level
      \@tempcnta\Hy@level\relax
      \expandafter\xdef\csname Parent\Hy@level\endcsname{#3}%
      \advance\@tempcnta by -1
      \edef\Hy@tempa{#3}
      \edef\Hy@tempb{\csname Parent\the\@tempcnta\endcsname}%
      \ifx\Hy@tempa\Hy@tempb
        \Hy@Warning{%
          The anchor of a bookmark and its parent's must not%
          \MessageBreak be the same. Added a new anchor%
        }%
        \phantomsection
      \fi
      \ifHy@bookmarksnumbered
        \let\numberline\Hy@numberline
        \let\booknumberline\Hy@numberline     % <- added
        \let\partnumberline\Hy@numberline     % <- added
        \let\chapternumberline\Hy@numberline  % <- added
      \else
        \let\numberline\@gobble
        \let\booknumberline\@gobble           % <- added
        \let\partnumberline\@gobble           % <- added
        \let\chapternumberline\@gobble        % <- added
      \fi
      \pdfstringdef\Hy@tempa{#2}%
      \protected@write\@outlinefile{}{%
        \protect\BOOKMARK
          [\Hy@level][\@bookmarkopenstatus{\Hy@level}]{#3}%
          {\Hy@tempa}{\Hy@tempb}%
      }%
    \fi
  \endgroup}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\M@sect}
% \Lpack{hyperref} fix for memoir's redefinition of \cs{@sect}
% \changes{v1.14}{2010/06/10}{At some point hyperref changed the way
% it changed \cs{@sect} such that the link target goes above the
% section title. Here we bring memoir back up to speed}
% The change being made is quite simple. We use \cs{M@sect} and it
% takes 9 args not the standard 8.
% \changes{v1.15}{2010/08/17}{Fixed typo, 8 -> \#8}
%    \begin{macrocode}
\@ifundefined{H@old@sectm@m}{% haven't fiddled with \M@sect
  \let\H@old@sectm@m\M@sect
  \def\M@sect#1#2#3#4#5#6[#7][#8]#9{%
    \ifnum #2>\c@secnumdepth%
      \expandafter\@firstoftwo%
    \else%
      \expandafter\@secondoftwo%
    \fi%
    {%
      \Hy@MakeCurrentHrefAuto{section*}%
      \setlength{\Hy@SectionHShift}{#3}%
      \begingroup
      \toks@{\H@old@sectm@m{#1}{#2}{#3}{#4}{#5}{#6}[{#7}][{#8}]}%
      \toks\tw@\expandafter{%
        \expandafter\Hy@SectionAnchorHref\expandafter{\@currentHref}%
        #9%
      }%
      \edef\x{\endgroup%
        \the\toks@{\the\toks\tw@}%
      }\x%
    }{%
      \H@old@sectm@m{#1}{#2}{#3}{#4}{#5}{#6}[{#7}][{#8}]{#9}%
    }%
  }%
}%
{% already fiddled \M@sect 
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@resets@pp}
% \Lpack{hyperref} fix for memoir's \texttt{appendices} environment
%      (discovered by Lars Hoemke, \url{hoemke@nikocity.de},
%       private email 20 Feb 2003)
%    \begin{macrocode}
\let\MH@old@resets@pp\@resets@pp
\renewcommand*{\@resets@pp}{%
  \MH@old@resets@pp
  \def\theHchapter{\Alph{chapter}}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@resets@ppsub}
% \Lpack{hyperref} fix for memoir's \texttt{subappendices} environment
%      (Problem reported by Ignasi Furio, \url{ignasi.furio@uib.es},
%       private email 13 May 2004)
% \changes{v1.6}{2004/05/13}{Added \cs{@resets@ppsub} to memhfixc}
%    \begin{macrocode}
\let\MH@old@resets@ppsub\@resets@ppsub
\renewcommand*{\@resets@ppsub}{%
  \MH@old@resets@ppsub
  \def\theHsection{\theHchapter.\Alph{section}}}
\def\endsubappendices{\def\theHsection{\theHchapter.\arabic{section}}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftaddtitleline}
% \begin{macro}{\cftaddnumtitleline}
% \Lpack{hyperref} fix for memoir's add to contents macros
%      (discovered by Martin Siegumfeldt, \ctt{} 2003/09/25
%       \textit{`Combinig [sic] Tocloft and hyperref'}
%    \begin{macrocode}
\renewcommand{\cftaddtitleline}[4]{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{#4}{\@currentHref}}}
\renewcommand{\cftaddnumtitleline}[5]{\addtocontents{#1}{%
  \protect\contentsline{#2}{\protect\numberline{#3}#4}{#5}{\@currentHref}}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\caption}
% Yet another little jolly (fixed in version 1.5). \Lpack{hyperref}'s
% \verb?\def? of \verb?\caption? cunningly messes up \Lpack{memoir}'s,
% thereby screwing up the labels for subcaptions.
%    \begin{macrocode}
\let\m@moldhypcaption\caption
\renewcommand{\caption}{\donemaincaptiontrue\m@moldhypcaption}

%    \end{macrocode}
% \end{macro}
%
%    More tweaks are needed for continued captions and sidecaptions.
% The need for these discovered by 
% \v{Z}arko F \v{C}u\v{c}ej\footnote{\texttt{zarko.cucej@uni-mb.si}}
% (for \cs{contcaption}) and by 
% J{\o}rgen Larsen\footnote{\texttt{jl@ruc.dk}} (for \cs{sidecaption}),
% and by Eitan Gurari (for \texttt{tex4ht}).
% \changes{v1.7}{2005/11/15}{Added tweaks for \cs{contcaption},
%                \cs{sidecaption} and \cs{sidecontcaption}}
%
% \begin{macro}{\c@memhycontfloat}
% \begin{macro}{\thememhycontfloat}
% \begin{macro}{\theHmemhycontfloat}
% We need an extra marker for continued captions.
% \changes{v1.7}{2005/11/15}{Added extra counter for continued captions}
% \changes{v1.10}{2008/08/23}{Fixed \cs{theHmemhycontfloat} undefined
%          problem (courtsesy Eitan Gurari)}
%    \begin{macrocode}
\newcounter{memhycontfloat}
\renewcommand*{\thememhycontfloat}{\arabic{memhycontfloat}}
\providecommand*{\theHmemhycontfloat}{}
\renewcommand*{\theHmemhycontfloat}{\arabic{memhycontfloat}}
\setcounter{memhycontfloat}{0}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\contcaption}
% Tweak the \cs{contcaption} macro.
%    \begin{macrocode}
\renewcommand{\contcaption}{%
  \refstepcounter{memhycontfloat}%
  \addtocounter{\@captype}{\m@ne}\H@refstepcounter{\@captype}%
  \@contcaption\@captype}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endsidecaption}
% Tweak the \texttt{sidecaption} environment. I don't know why it 
% works but it took a lot of time trying all sorts of combinations
% of commands to get it to do so (if it really does).
%    \begin{macrocode}
\def\endsidecaption{%
  \m@mscapend@fbox
  \H@refstepcounter{\@captype}%
  \hyper@makecurrent{\@captype}%
  \m@mscaplabel
  \begin{lrbox}{\m@mscap@capbox}%
    \begin{minipage}[c]{\sidecapwidth}%
      \sidecapstyle
      \@caption\@captype[\m@mscap@fortoc]{\m@mscap@forcap}%
    \end{minipage}%
  \end{lrbox}%
  \m@mscapopboxes}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sidecontcaption}
% \begin{macro}{\endsidecontcaption}
% Tweaks for the \texttt{sidecontcaption} environment. Again it was 
% a miss, miss, \ldots hit method to get something that appears 
% to work.
%    \begin{macrocode}
\renewcommand*{\sidecontcaption}{%
  \refstepcounter{memhycontfloat}%
  \@sidecontcaption}
\def\endsidecontcaption{%
  \m@mscapend@fbox
  \addtocounter{\@captype}{\m@ne}\H@refstepcounter{\@captype}%
  \hyper@makecurrent{memhycontfloat}%
  \m@mscaplabel
  \begin{lrbox}{\m@mscap@capbox}%
    \begin{minipage}[c]{\sidecapwidth}%
      \sidecapstyle
      \@contcaption\@captype{\m@mscap@forcap}%
    \end{minipage}%
  \end{lrbox}%
  \m@mscapopboxes}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@mem@titlerefnolink}
%   \Lpack{hyperref} provide a \cs{ref*} command that does not give a
%   hyperlink under \Lpack{hyperref}, we extend \cs{titleref} to
%   support it.
%    \begin{macrocode}
\def\@mem@titlerefnolink#1{\begingroup \let\numberline\@gobble
  \let\M@TitleReference\@mem@theTR % interrupt recursion of \ref
  \ref*{#1}\endgroup}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\printpageinnoteshyperref}
% When \Lpack{hyperref} is active, page references in the page notes
% list looks better with a specialised macro. The macro is provided
% within the class, and here we activate it.
%    \begin{macrocode}
\AtBeginDocument{%
    \let\printpageinnotes\printpageinnoteshyperref%
}
%    \end{macrocode}
% \end{macro}
%
% The end of the \Lpack{hyperref} related patches.
%
%    \begin{macrocode}
%</hyper>
%    \end{macrocode}
%
%
% \section{Patches for the class code}     \label{sec:class}
%
% At this date, 2008/07/23, with the simultaneous release of memoir v1.6180339 
% and the patch file, by definition there are no patches.
%
% \subsection{Identification} \label{sec:id}
%
% \changes{v2.0}{2004/01/31}{No code in mempatch.sty}
% \changes{v2.1}{2004/02/12}{Code now required in mempatch.sty}
% \changes{v2.1a}{2004/02/19}{Extra pagestyle code for handling \cs{linespread}}
% \changes{v2.4}{2004/04/26}{Removed extraneous spaces}
% \changes{v2.4+}{2004/04/26}{Stopped noting general changes}
% 
%    \begin{macrocode}
%<*patch>
%    \end{macrocode}
%
% ^^A \typeout{mempatch.sty 2002/12/12 v1.1 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/01/06 v1.2 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/01/22 v1.3 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/02/13 v1.4 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/04/26 v1.5 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/06/28 v1.6 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/07/23 v1.7 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/09/16 v1.8 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/10/06 v1.8a Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2003/11/16 v1.9 Patches for memoir class v1.3a}
% ^^A \typeout{mempatch.sty 2004/01/31 v2.0 Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/02/12 v2.1 Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/02/19 v2.1a Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/03/01 v2.2 Patches for memoir class v1.6}
% ^^A \typeout{mempatch.sty 2004/03/28 v2.3 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/04/26 v2.3 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/04/27 v2.3a Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/04/30 v2.3b Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/05/10 v2.3c Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/05/14 v2.3d Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/12/14 v3.0 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2004/12/19 v3.1 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/01/01 v3.2 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/01/17 v3.3 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/01/18 v3.4 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/02/01 v3.5 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/02/07 v3.6 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/02/26 v3.7 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/03/06 v3.8 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/03/23 v3.9 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/05/16 v3.10 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/05/23 v3.11 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/06/06 v3.12 Patches for memoir class v1.61}
% ^^A \typeout{mempatch.sty 2005/09/25 v4.0 Patches for memoir class v1.618}
% ^^A \ProvidesFile{mempatch.sty}[2005/10/06 v4.1 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2005/11/21 v4.2 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2005/12/13 v4.3 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/01/21 v4.4 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/01/23 v4.4a Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/07/10 v4.5 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/08/08 v4.5 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/12/11 v4.6 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2006/12/23 v4.7 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2007/01/22 v4.8 Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2007/12/14 v4.9 Patches for memoir class v1.618]
%
% ^^A \ProvidesFile{mempatch.sty}[2007/12/24 v4.9a Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2007/12/31 v4.9a+ Patches for memoir class v1.618]
% ^^A \ProvidesFile{mempatch.sty}[2008/05/26 v5.0 Patches for memoir class v1.61803]
% ^^A \ProvidesFile{mempatch.sty}[2008/07/11 v5.1 Patches for memoir class v1.618033]
%    \begin{macrocode}
\ProvidesPackage{mempatch}[2009/07/24 v6.0f Patches for memoir class v1.6180339]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Version 6.0 was released simultaneously with version 1.6180339 
%%% of memoir.
%%% By definition there were no patches.
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%    \end{macrocode}
%
%
% The end of the patch file.
%
%    \begin{macrocode}
%</patch>
%    \end{macrocode}
%
%
% \bibliographystyle{alpha}
% \begingroup
% \raggedright
% \begin{thebibliography}{GMSN94A}
%
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock \emph{The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
%
% \bibitem[Rah01]{NAMEREF}
% Sebastian Rahtz.
% \newblock \emph{Section name references in LaTeX}.
% \newblock January 2001.
% \newblock (Available from CTAN in
%            \texttt{/macros/latex/contrib/hyperref})
%
% \bibitem[Rah02]{HYPERREF}
% Sebastian Rahtz.
% \newblock \emph{Hypertext marks in LaTeX}.
% \newblock March 2002.
% \newblock (Available from CTAN in
%            \texttt{/macros/latex/contrib/hyperref})
%
% \bibitem[Wil08]{MEMOIR}
% Peter Wilson.
% \newblock \emph{The LaTeX \Lpack{memoir} class for configurable 
%                 typesetting: Source code}.
% \newblock July 2008.
% \newblock (Available from CTAN in
%            \texttt{macros/latex/contrib/memoir})
%
%
% \end{thebibliography}
% \endgroup
%
% \Finale
%
\endinput

%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%