summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/mbenotes/mbenotes.sty
blob: faceddc9896e597c014e70257e9e5f11ce1fb8ff (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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       ****************************************
%       *              mbeNOTES  
%       ****************************************
%
%  Date of this version: 2013-06-1
%  Matthias Borck-Elsner
%
%% Based on endnotes.sty Copyright 2002 John Lavagnino
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The lambe version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%  Uses an extra external file, with .mbe extension, to hold the 
%%  text of the mbenotes.  This may be deleted after the run; a new
%%  version is generated each time--it doesn't require information
%%  collected from the previous run.
%%
%%  This code does not obey \nofiles.  Perhaps it should.
%%
%%
%%  To turn all the footnotes in your documents into mbenotes, say
%%
%%     \let\footnote=\mbenote
%%
%%  in your preamble, and then add something like
%%
%%     \newpage
%%     \begingroup
%%     \parindent 0pt
%%     \parskip 2ex
%%     \def\mbenotesize{\normalsize}
%%     \thembenotes  
%%     \endgroup
%%
%% as the last thing in your document.  (But \thembenotes all
%% by itself will work.)
%%
%%       ****************************************
%%       *        mbeNOTE COMMANDS              *
%%       ****************************************
%%
%%
%%   \mbenote{NOTE}       : User command to insert a mbenote.
%%
%%   \mbenote[NUM]{NOTE}  : User command to insert a mbenote numbered
%%                           NUM, where NUM is a number -- 1, 2,
%%                           etc.  For example, if mbenotes are numbered
%%                           *, **, etc. within pages, then  \mbenote[2]{...}
%%                           produces mbenote '**'.  This command does  not
%%                           step the mbenote counter.
%%
%%   \mbenotemark[NUM]    : Command to produce just the mbenote mark in
%%                           the text, but no mbenote.  With no argument,
%%                           it steps the mbenote counter before  generating
%%                           the mark.
%%
%%   \mbenotetext[NUM]{TEXT} : Command to produce the mbenote but no 
%%                              mark.  \mbenote is equivalent to
%%                              \mbenotemark \mbenotetext .
%%
%%   \addtombenotes{TEXT} : Command to add text or commands to current
%%                              mbenotes file: for inserting headings,
%%                              pagebreaks, and the like into mbenotes
%%                              sections.  TEXT a moving argument:
%%                              \protect required for fragile commands.
%%
%%       ****************************************
%%       *        mbeNOTE USER COMMANDS         *
%%       ****************************************
%%
%%   mbenotes use the following parameters, similar to those relating
%%   to footnotes:
%%
%%   \mbenotesize   : Size-changing command for mbenotes.
%%
%%   \thembenote : In usual LaTeX style, produces the mbenote number.
%%
%%   \thembemark : Holds the current mbenote's mark--e.g., \dag or '1' or 'a'.
%%                 (You don't want to set this yourself, as it comes
%%                 either from the autonumbering of notes or from
%%                 the optional argument to \mbenote. But you'll need
%%                 to use it if you define your own \makembemark.)
%%
%%   \makembemark : A macro to generate the mbenote marker from  \thembemark
%%                  The default definition is \hbox{$^\thembemark$}.
%%
%%   \@makembetext{NOTE} :
%%        Must produce the actual mbenote, using \thembemark as the mark
%%        of the mbenote and NOTE as the text.  It is called when effectively
%%        inside a \parbox, with \hsize = \columnwidth.  For example, it might
%%        be as simple as
%%               $^{\thembemark}$ NOTE
%%
%%
%%       ****************************************
%%       *       mbeNOTE MACROS             *
%%       ****************************************
%%
%%
\ProvidesPackage{mbenotes}[2013/06/01 (Version 3) Notes for Text,tables,images and equations ]\RequirePackage{graphicx,xcolor,amsmath}\@definecounter{mbenote}
\def\thembenote{\@arabic\c@mbenote}

\def\@makembemark{\hbox{\@textsuperscript{{\tiny\@thembemark}}}}
\def\makembemark{\@makembemark}

\def\thembemark{\@thembemark}

\newdimen\mbenotesep

\def\mbenote{\@ifnextchar[\@xmbenote{\stepcounter{mbenote}%
     \protected@xdef\@thembemark{\thembenote}%
     \@mbenotemark\@mbenotetext}}

\def\@xmbenote[#1]{
   \begingroup
     \c@mbenote=#1\relax
     \unrestored@protected@xdef\@thembemark{\thembenote}%
   \endgroup
   \@mbenotemark\@mbenotetext }

%%  Here begins a section of mbenote code that's really different from
%% the footnote code of LaTeX.

\let\@doanmbenote=0
\let\@endanmbenote=0

\newwrite\@mbenotes
\newif\if@mbenotesopen \global\@mbenotesopenfalse

\def\@openmbenotes{\immediate\openout\@mbenotes=\jobname.mbe\relax
      \global\@mbenotesopentrue}

%%  The stuff with \next and \meaning is a trick from the TeXbook, 382,
%% there intended for setting verbatim text, but here used to avoid
%% macro expansion when the footnote text is written.  \next will have
%% the entire text of the footnote as one long line, which might well
%% overflow limits on output line length; the business with \newlinechar
%% makes every space become a newline in the \@mbenotes file, so that all
%% of the lines wind up being quite short.
%%
\long\def\@mbenotetext#1{%
     \if@mbenotesopen \else \@openmbenotes \fi
     \immediate\write\@mbenotes{\@doanmbenote{\@thembemark}}%
     \begingroup
        \def\next{#1}%
        \newlinechar='40
        \immediate\write\@mbenotes{\meaning\next}%
     \endgroup
     \immediate\write\@mbenotes{\@endanmbenote}}

%% \addtombenotes works the way the other mbenote macros probably should
%% have, requiring the use of \protect for fragile commands.

\long\def\addtombenotes#1{%
     \if@mbenotesopen \else \@openmbenotes \fi
     \begingroup
        \newlinechar='40
        \let\protect\string
        \immediate\write\@mbenotes{#1}%
     \endgroup}

%%  End of unique mbenote code
%%
\def\mbenotemark{%
   \@ifnextchar[\@xmbenotemark
     {\stepcounter{mbenote}%
      \protected@xdef\@thembemark{\thembenote}%
      \@mbenotemark}}

\def\@xmbenotemark[#1]{%
   \begingroup
      \c@mbenote #1\relax
      \unrestored@protected@xdef\@thembemark{\thembenote}%
   \endgroup
   \@mbenotemark}

\def\@mbenotemark{%
  \leavevmode
  \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
  \makembemark
  \ifhmode\spacefactor\@x@sf\fi
  \relax}

\def\mbenotetext{
     \@ifnextchar [\@xmbenotenext
       {\protected@xdef\@thembemark{\thembenote}%
    \@mbenotetext}}

\def\@xmbenotenext[#1]{\begingroup \c@mbenote=#1\relax
   \xdef\@thembemark{\thembenote}\endgroup \@mbenotetext}

\def\@xmbenotenext[#1]{%
  \begingroup
     \c@mbenote=#1\relax
     \unrestored@protected@xdef\@thembemark{\thembenote}%
  \endgroup
  \@mbenotetext}


%%  \thembenotes actually prints out the mbenotes.

%%  The user may want separate mbenotes for each chapter, or a big
%% block of them at the end of the whole document.  As it stands,
%% either will work; you just say \thembenotes wherever you want the
%% mbenotes so far to be inserted.  The counter is always set to 0 %%
%%  \mbenoteformat is provided so user can specify some special formatting
%% for the mbenotes.  It needs to set up the paragraph parameters, start
%% the paragraph, and print the label.  The \mbox stuff in \mbenoteheading
%% is to make and undo a dummbe paragraph, to get around the games \section*
%% plays with paragraph indenting and instead give us uniform
%% indenting for all notes.

\def\mbenotesname{mbenotes} 
\def\mbenoteheading{\subsubsection*{\footnotesize{\mbenotesname} \@mkboth{\MakeUppercase{\mbenotesname}}{\MakeUppercase{\mbenotesname}}}
  \mbox{ }\par\vskip-\baselineskip}

\def\mbenoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
  \leavevmode\llap{\makembemark}}

\def\mbenotesize{\footnotesize}

\def\thembenotes[#1]{\def\mbenotesname{#1}\immediate\closeout\@mbenotes \global\@mbenotesopenfalse
  \begingroup
    \makeatletter
    %%
    %% The machinery with \@ResetGT and > here ensures that
    %% \@doanmbenote works properly even if > is an active character
    %% at the point where \thembenotes is invoked. > needs to have
    %% catcode 12 when the arguments of \@doanmbenote are scanned, so
    %% that the > in the string "macro:->" is matched.  The actual
    %% footnote text is not an argument to \@doanmbenote, but just
    %% follows it in the .mbe file; so \@ResetGT can reset the
    %% category code for > that should be used when processing
    %% that text.  That resetting takes place within a
    %% \begingroup-\endgroup block set up by \@doanmbenote and
    %% \@endanmbenote, so the catcode for > is back to 12 for the
    %% next note.
    %
    \edef\@tempa{`\string >}%
    \ifnum\catcode\@tempa=12%
      \let\@ResetGT\relax
    \else
      \edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
      \@makeother\>%
    \fi
    \def\@doanmbenote##1##2>{\def\@thembemark{##1}\par\begingroup
        \@ResetGT
        \edef\@currentlabel{\csname p@mbenote\endcsname\@thembemark}%
        \mbenoteformat}
    \def\@endanmbenote{\par\endgroup}%
     \mbenoteheading 
    \mbenotesize
    \input{\jobname.mbe}%
    \setcounter{mbenote}{0} \vspace{1.8em} 
  \endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       ****************************************
%       *              tabNOTES  
%       ****************************************
%
%  Date of this version: 2013-06-1
%  Matthias Borck-Elsner
%
%% Based on endnotes.sty Copyright 2002 John Lavagnino
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The lambe version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%  Uses an extra external file, with .tab extension, to hold the 
%%  text of the tabnotes.  This may be deleted after the run; a new
%%  version is generated each time--it doesn't require information
%%  collected from the previous run.
%%
%%  This code does not obey \nofiles.  Perhaps it should.
%%
%%
%%  To turn all the footnotes in your documents into tabnotes, say
%%
%%     \let\footnote=\tabnote
%%
%%  in your preamble, and then add something like
%%
%%     \newpage
%%     \begingroup
%%     \parindent 0pt
%%     \parskip 2ex
%%     \def\tabnotesize{\normalsize}
%%     \thetabnotes  
%%     \endgroup
%%
%% as the last thing in your document.  (But \thetabnotes all
%% by itself will work.)
%%
%%       ****************************************
%%       *        tabNOTE COMMANDS              *
%%       ****************************************
%%
%%
%%   \tabnote{NOTE}       : User command to insert a tabnote.
%%
%%   \tabnote[NUM]{NOTE}  : User command to insert a tabnote numbered
%%                           NUM, where NUM is a number -- 1, 2,
%%                           etc.  For example, if tabnotes are numbered
%%                           *, **, etc. within pages, then  \tabnote[2]{...}
%%                           produces tabnote '**'.  This command does  not
%%                           step the tabnote counter.
%%
%%   \tabnotemark[NUM]    : Command to produce just the tabnote mark in
%%                           the text, but no tabnote.  With no argument,
%%                           it steps the tabnote counter before  generating
%%                           the mark.
%%
%%   \tabnotetext[NUM]{TEXT} : Command to produce the tabnote but no 
%%                              mark.  \tabnote is equivalent to
%%                              \tabnotemark \tabnotetext .
%%
%%   \addtotabnotes{TEXT} : Command to add text or commands to current
%%                              tabnotes file: for inserting headings,
%%                              pagebreaks, and the like into tabnotes
%%                              sections.  TEXT a moving argument:
%%                              \protect required for fragile commands.
%%
%%       ****************************************
%%       *        tabNOTE USER COMMANDS         *
%%       ****************************************
%%
%%   tabnotes use the following parameters, similar to those relating
%%   to footnotes:
%%
%%   \tabnotesize   : Size-changing command for tabnotes.
%%
%%   \thetabnote : In usual LaTeX style, produces the tabnote number.
%%
%%   \thetabmark : Holds the current tabnote's mark--e.g., \dag or '1' or 'a'.
%%                 (You don't want to set this yourself, as it comes
%%                 either from the autonumbering of notes or from
%%                 the optional argument to \tabnote. But you'll need
%%                 to use it if you define your own \maketabmark.)
%%
%%   \maketabmark : A macro to generate the tabnote marker from  \thetabmark
%%                  The default definition is \hbox{$^\thetabmark$}.
%%
%%   \@maketabtext{NOTE} :
%%        Must produce the actual tabnote, using \thetabmark as the mark
%%        of the tabnote and NOTE as the text.  It is called when effectively
%%        inside a \parbox, with \hsize = \columnwidth.  For example, it might
%%        be as simple as
%%               $^{\thetabmark}$ NOTE
%%
%%
%%       ****************************************
%%       *       tabNOTE MACROS             *
%%       ****************************************
%%
%%
\ProvidesPackage{mbenotes}[2013/06/01 (Version 3) Notes for Text,tables,images and equations ]\RequirePackage{graphicx,xcolor,amsmath}\@definecounter{tabnote}
\def\thetabnote{\@arabic\c@tabnote}

\def\@maketabmark{\hbox{\@textsuperscript{{\tiny\@thetabmark}}}}
\def\maketabmark{\@maketabmark}

\def\thetabmark{\@thetabmark}

\newdimen\tabnotesep

\def\tabnote{\@ifnextchar[\@xtabnote{\stepcounter{tabnote}%
     \protected@xdef\@thetabmark{\thetabnote}%
     \@tabnotemark\@tabnotetext}}

\def\@xtabnote[#1]{
   \begingroup
     \c@tabnote=#1\relax
     \unrestored@protected@xdef\@thetabmark{\thetabnote}%
   \endgroup
   \@tabnotemark\@tabnotetext }

%%  Here begins a section of tabnote code that's really different from
%% the footnote code of LaTeX.

\let\@doantabnote=0
\let\@endantabnote=0

\newwrite\@tabnotes
\newif\if@tabnotesopen \global\@tabnotesopenfalse

\def\@opentabnotes{\immediate\openout\@tabnotes=\jobname.tab\relax
      \global\@tabnotesopentrue}

%%  The stuff with \next and \meaning is a trick from the TeXbook, 382,
%% there intended for setting verbatim text, but here used to avoid
%% macro expansion when the footnote text is written.  \next will have
%% the entire text of the footnote as one long line, which might well
%% overflow limits on output line length; the business with \newlinechar
%% makes every space become a newline in the \@tabnotes file, so that all
%% of the lines wind up being quite short.
%%
\long\def\@tabnotetext#1{%
     \if@tabnotesopen \else \@opentabnotes \fi
     \immediate\write\@tabnotes{\@doantabnote{\@thetabmark}}%
     \begingroup
        \def\next{#1}%
        \newlinechar='40
        \immediate\write\@tabnotes{\meaning\next}%
     \endgroup
     \immediate\write\@tabnotes{\@endantabnote}}

%% \addtotabnotes works the way the other tabnote macros probably should
%% have, requiring the use of \protect for fragile commands.

\long\def\addtotabnotes#1{%
     \if@tabnotesopen \else \@opentabnotes \fi
     \begingroup
        \newlinechar='40
        \let\protect\string
        \immediate\write\@tabnotes{#1}%
     \endgroup}

%%  End of unique tabnote code
%%
\def\tabnotemark{%
   \@ifnextchar[\@xtabnotemark
     {\stepcounter{tabnote}%
      \protected@xdef\@thetabmark{\thetabnote}%
      \@tabnotemark}}

\def\@xtabnotemark[#1]{%
   \begingroup
      \c@tabnote #1\relax
      \unrestored@protected@xdef\@thetabmark{\thetabnote}%
   \endgroup
   \@tabnotemark}

\def\@tabnotemark{%
  \leavevmode
  \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
  \maketabmark
  \ifhmode\spacefactor\@x@sf\fi
  \relax}

\def\tabnotetext{
     \@ifnextchar [\@xtabnotenext
       {\protected@xdef\@thetabmark{\thetabnote}%
    \@tabnotetext}}

\def\@xtabnotenext[#1]{\begingroup \c@tabnote=#1\relax
   \xdef\@thetabmark{\thetabnote}\endgroup \@tabnotetext}

\def\@xtabnotenext[#1]{%
  \begingroup
     \c@tabnote=#1\relax
     \unrestored@protected@xdef\@thetabmark{\thetabnote}%
  \endgroup
  \@tabnotetext}


%%  \thetabnotes actually prints out the tabnotes.

%%  The user may want separate tabnotes for each chapter, or a big
%% block of them at the end of the whole document.  As it stands,
%% either will work; you just say \thetabnotes wherever you want the
%% tabnotes so far to be inserted.  The counter is always set to 0 %%
%%  \tabnoteformat is provided so user can specify some special formatting
%% for the tabnotes.  It needs to set up the paragraph parameters, start
%% the paragraph, and print the label.  The \mbox stuff in \tabnoteheading
%% is to make and undo a dummbe paragraph, to get around the games \section*
%% plays with paragraph indenting and instead give us uniform
%% indenting for all notes.

\def\tabnotesname{tabnotes} 
\def\tabnoteheading{\subsubsection*{\footnotesize{\tabnotesname} \@mkboth{\MakeUppercase{\tabnotesname}}{\MakeUppercase{\tabnotesname}}}
  \mbox{ }\par\vskip-\baselineskip}

\def\tabnoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
  \leavevmode\llap{\maketabmark}}

\def\tabnotesize{\footnotesize}

\def\thetabnotes[#1]{\def\tabnotesname{#1}\immediate\closeout\@tabnotes \global\@tabnotesopenfalse
  \begingroup
    \makeatletter
    %%
    %% The machinery with \@ResetGT and > here ensures that
    %% \@doantabnote works properly even if > is an active character
    %% at the point where \thetabnotes is invoked. > needs to have
    %% catcode 12 when the arguments of \@doantabnote are scanned, so
    %% that the > in the string "macro:->" is matched.  The actual
    %% footnote text is not an argument to \@doantabnote, but just
    %% follows it in the .tab file; so \@ResetGT can reset the
    %% category code for > that should be used when processing
    %% that text.  That resetting takes place within a
    %% \begingroup-\endgroup block set up by \@doantabnote and
    %% \@endantabnote, so the catcode for > is back to 12 for the
    %% next note.
    %
    \edef\@tempa{`\string >}%
    \ifnum\catcode\@tempa=12%
      \let\@ResetGT\relax
    \else
      \edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
      \@makeother\>%
    \fi
    \def\@doantabnote##1##2>{\def\@thetabmark{##1}\par\begingroup
        \@ResetGT
        \edef\@currentlabel{\csname p@tabnote\endcsname\@thetabmark}%
        \tabnoteformat}
    \def\@endantabnote{\par\endgroup}%
     \tabnoteheading 
    \tabnotesize
    \input{\jobname.tab}%
    \setcounter{tabnote}{0} \vspace{1.8em} 
  \endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       ****************************************
%       *              imgNOTES  
%       ****************************************
%
%  Date of this version: 2013-06-1
%  Matthias Borck-Elsner
%
%% Based on endnotes.sty Copyright 2002 John Lavagnino
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The lambe version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%  Uses an extra external file, with .img extension, to hold the 
%%  text of the imgnotes.  This may be deleted after the run; a new
%%  version is generated each time--it doesn't require information
%%  collected from the previous run.
%%
%%  This code does not obey \nofiles.  Perhaps it should.
%%
%%
%%  To turn all the footnotes in your documents into imgnotes, say
%%
%%     \let\footnote=\imgnote
%%
%%  in your preamble, and then add something like
%%
%%     \newpage
%%     \begingroup
%%     \parindent 0pt
%%     \parskip 2ex
%%     \def\imgnotesize{\normalsize}
%%     \theimgnotes  
%%     \endgroup
%%
%% as the last thing in your document.  (But \theimgnotes all
%% by itself will work.)
%%
%%       ****************************************
%%       *        imgNOTE COMMANDS              *
%%       ****************************************
%%
%%
%%   \imgnote{NOTE}       : User command to insert a imgnote.
%%
%%   \imgnote[NUM]{NOTE}  : User command to insert a imgnote numbered
%%                           NUM, where NUM is a number -- 1, 2,
%%                           etc.  For example, if imgnotes are numbered
%%                           *, **, etc. within pages, then  \imgnote[2]{...}
%%                           produces imgnote '**'.  This command does  not
%%                           step the imgnote counter.
%%
%%   \imgnotemark[NUM]    : Command to produce just the imgnote mark in
%%                           the text, but no imgnote.  With no argument,
%%                           it steps the imgnote counter before  generating
%%                           the mark.
%%
%%   \imgnotetext[NUM]{TEXT} : Command to produce the imgnote but no 
%%                              mark.  \imgnote is equivalent to
%%                              \imgnotemark \imgnotetext .
%%
%%   \addtoimgnotes{TEXT} : Command to add text or commands to current
%%                              imgnotes file: for inserting headings,
%%                              pagebreaks, and the like into imgnotes
%%                              sections.  TEXT a moving argument:
%%                              \protect required for fragile commands.
%%
%%       ****************************************
%%       *        imgNOTE USER COMMANDS         *
%%       ****************************************
%%
%%   imgnotes use the following parameters, similar to those relating
%%   to footnotes:
%%
%%   \imgnotesize   : Size-changing command for imgnotes.
%%
%%   \theimgnote : In usual LaTeX style, produces the imgnote number.
%%
%%   \theimgmark : Holds the current imgnote's mark--e.g., \dag or '1' or 'a'.
%%                 (You don't want to set this yourself, as it comes
%%                 either from the autonumbering of notes or from
%%                 the optional argument to \imgnote. But you'll need
%%                 to use it if you define your own \makeimgmark.)
%%
%%   \makeimgmark : A macro to generate the imgnote marker from  \theimgmark
%%                  The default definition is \hbox{$^\theimgmark$}.
%%
%%   \@makeimgtext{NOTE} :
%%        Must produce the actual imgnote, using \theimgmark as the mark
%%        of the imgnote and NOTE as the text.  It is called when effectively
%%        inside a \parbox, with \hsize = \columnwidth.  For example, it might
%%        be as simple as
%%               $^{\theimgmark}$ NOTE
%%
%%
%%       ****************************************
%%       *       imgNOTE MACROS             *
%%       ****************************************
%%
%%
\ProvidesPackage{mbenotes}[2013/06/01 (Version 3) Notes for Text,tables,images and equations ]\RequirePackage{graphicx,xcolor,amsmath}\@definecounter{imgnote}
\def\theimgnote{\@arabic\c@imgnote}

\def\@makeimgmark{\hbox{\@textsuperscript{{\tiny\@theimgmark}}}}
\def\makeimgmark{\@makeimgmark}

\def\theimgmark{\@theimgmark}

\newdimen\imgnotesep

\def\imgnote{\@ifnextchar[\@ximgnote{\stepcounter{imgnote}%
     \protected@xdef\@theimgmark{\theimgnote}%
     \@imgnotemark\@imgnotetext}}

\def\@ximgnote[#1]{
   \begingroup
     \c@imgnote=#1\relax
     \unrestored@protected@xdef\@theimgmark{\theimgnote}%
   \endgroup
   \@imgnotemark\@imgnotetext }

%%  Here begins a section of imgnote code that's really different from
%% the footnote code of LaTeX.

\let\@doanimgnote=0
\let\@endanimgnote=0

\newwrite\@imgnotes
\newif\if@imgnotesopen \global\@imgnotesopenfalse

\def\@openimgnotes{\immediate\openout\@imgnotes=\jobname.img\relax
      \global\@imgnotesopentrue}

%%  The stuff with \next and \meaning is a trick from the TeXbook, 382,
%% there intended for setting verbatim text, but here used to avoid
%% macro expansion when the footnote text is written.  \next will have
%% the entire text of the footnote as one long line, which might well
%% overflow limits on output line length; the business with \newlinechar
%% makes every space become a newline in the \@imgnotes file, so that all
%% of the lines wind up being quite short.
%%
\long\def\@imgnotetext#1{%
     \if@imgnotesopen \else \@openimgnotes \fi
     \immediate\write\@imgnotes{\@doanimgnote{\@theimgmark}}%
     \begingroup
        \def\next{#1}%
        \newlinechar='40
        \immediate\write\@imgnotes{\meaning\next}%
     \endgroup
     \immediate\write\@imgnotes{\@endanimgnote}}

%% \addtoimgnotes works the way the other imgnote macros probably should
%% have, requiring the use of \protect for fragile commands.

\long\def\addtoimgnotes#1{%
     \if@imgnotesopen \else \@openimgnotes \fi
     \begingroup
        \newlinechar='40
        \let\protect\string
        \immediate\write\@imgnotes{#1}%
     \endgroup}

%%  End of unique imgnote code
%%
\def\imgnotemark{%
   \@ifnextchar[\@ximgnotemark
     {\stepcounter{imgnote}%
      \protected@xdef\@theimgmark{\theimgnote}%
      \@imgnotemark}}

\def\@ximgnotemark[#1]{%
   \begingroup
      \c@imgnote #1\relax
      \unrestored@protected@xdef\@theimgmark{\theimgnote}%
   \endgroup
   \@imgnotemark}

\def\@imgnotemark{%
  \leavevmode
  \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
  \makeimgmark
  \ifhmode\spacefactor\@x@sf\fi
  \relax}

\def\imgnotetext{
     \@ifnextchar [\@ximgnotenext
       {\protected@xdef\@theimgmark{\theimgnote}%
    \@imgnotetext}}

\def\@ximgnotenext[#1]{\begingroup \c@imgnote=#1\relax
   \xdef\@theimgmark{\theimgnote}\endgroup \@imgnotetext}

\def\@ximgnotenext[#1]{%
  \begingroup
     \c@imgnote=#1\relax
     \unrestored@protected@xdef\@theimgmark{\theimgnote}%
  \endgroup
  \@imgnotetext}


%%  \theimgnotes actually prints out the imgnotes.

%%  The user may want separate imgnotes for each chapter, or a big
%% block of them at the end of the whole document.  As it stands,
%% either will work; you just say \theimgnotes wherever you want the
%% imgnotes so far to be inserted.  The counter is always set to 0 %%
%%  \imgnoteformat is provided so user can specify some special formatting
%% for the imgnotes.  It needs to set up the paragraph parameters, start
%% the paragraph, and print the label.  The \mbox stuff in \imgnoteheading
%% is to make and undo a dummbe paragraph, to get around the games \section*
%% plays with paragraph indenting and instead give us uniform
%% indenting for all notes.

\def\imgnotesname{imgnotes} 
\def\imgnoteheading{\subsubsection*{\footnotesize{\imgnotesname} \@mkboth{\MakeUppercase{\imgnotesname}}{\MakeUppercase{\imgnotesname}}}
  \mbox{ }\par\vskip-\baselineskip}

\def\imgnoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
  \leavevmode\llap{\makeimgmark}}

\def\imgnotesize{\footnotesize}

\def\theimgnotes[#1]{\def\imgnotesname{#1}\immediate\closeout\@imgnotes \global\@imgnotesopenfalse
  \begingroup
    \makeatletter
    %%
    %% The machinery with \@ResetGT and > here ensures that
    %% \@doanimgnote works properly even if > is an active character
    %% at the point where \theimgnotes is invoked. > needs to have
    %% catcode 12 when the arguments of \@doanimgnote are scanned, so
    %% that the > in the string "macro:->" is matched.  The actual
    %% footnote text is not an argument to \@doanimgnote, but just
    %% follows it in the .img file; so \@ResetGT can reset the
    %% category code for > that should be used when processing
    %% that text.  That resetting takes place within a
    %% \begingroup-\endgroup block set up by \@doanimgnote and
    %% \@endanimgnote, so the catcode for > is back to 12 for the
    %% next note.
    %
    \edef\@tempa{`\string >}%
    \ifnum\catcode\@tempa=12%
      \let\@ResetGT\relax
    \else
      \edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
      \@makeother\>%
    \fi
    \def\@doanimgnote##1##2>{\def\@theimgmark{##1}\par\begingroup
        \@ResetGT
        \edef\@currentlabel{\csname p@imgnote\endcsname\@theimgmark}%
        \imgnoteformat}
    \def\@endanimgnote{\par\endgroup}%
     \imgnoteheading 
    \imgnotesize
    \input{\jobname.img}%
    \setcounter{imgnote}{0} \vspace{1.8em} 
  \endgroup}
 \newlength\imgheight{} \newlength\imgwidth{} \def\imgsize#1#2{\imgwidth=#1 \imgheight#2 }
\def\putimgnote#1#2#3{\put(#1\imgwidth,#2\imgheight){\imgnote{#3 }}}\def\ruler#1#2{\begin{picture}(0,0)(#1,#2)\begin{tiny} 
%%horizontal
\put(0\imgwidth,0){\rotatebox{270}{ -0.00}}
\put(-0.10\imgwidth,0){\rotatebox{270}{ -0.10}}
\put(-0.20\imgwidth,0){\rotatebox{270}{ -0.20}}
\put(-0.30\imgwidth,0){\rotatebox{270}{ -0.30}}
\put(-0.40\imgwidth,0){\rotatebox{270}{ -0.40}}
\put(-0.50\imgwidth,0){\rotatebox{270}{ -0.50}}
\put(-0.60\imgwidth,0){\rotatebox{270}{ -0.60}}
\put(-0.70\imgwidth,0){\rotatebox{270}{ -0.70}}
\put(-0.80\imgwidth,0){\rotatebox{270}{ -0.80}}
\put(-0.90\imgwidth,0){\rotatebox{270}{ -0.90}}
\put(-1.00\imgwidth,0){\rotatebox{270}{ -1.00}}
%%vertical
\put(0,0\imgheight){{\rotatebox{0}{+0.0}}}
\put(0,0.10\imgheight){{\rotatebox{0}{+0.10}}}
\put(0,0.20\imgheight){{\rotatebox{0}{+0.20}}}
\put(0,0.30\imgheight){{\rotatebox{0}{+0.30}}}
\put(0,0.40\imgheight){{\rotatebox{0}{+0.40}}}
\put(0,0.50\imgheight){{\rotatebox{0}{+0.50}}}
\put(0,0.60\imgheight){{\rotatebox{0}{+0.60}}}
\put(0,0.70\imgheight){{\rotatebox{0}{+0.70}}}
\put(0,0.80\imgheight){{\rotatebox{0}{+0.80}}}
\put(0,0.90\imgheight){{\rotatebox{0}{+0.90}}}
\put(0,1.00\imgheight){{\rotatebox{0}{+1.00}}}
\end{tiny} \end{picture}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       ****************************************
%       *              mathNOTES  
%       ****************************************
%
%  Date of this version: 2013-06-1
%  Matthias Borck-Elsner
%
%% Based on endnotes.sty Copyright 2002 John Lavagnino
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The lambe version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%  Uses an extra external file, with .math extension, to hold the 
%%  text of the mathnotes.  This may be deleted after the run; a new
%%  version is generated each time--it doesn't require information
%%  collected from the previous run.
%%
%%  This code does not obey \nofiles.  Perhaps it should.
%%
%%
%%  To turn all the footnotes in your documents into mathnotes, say
%%
%%     \let\footnote=\mathnote
%%
%%  in your preamble, and then add something like
%%
%%     \newpage
%%     \begingroup
%%     \parindent 0pt
%%     \parskip 2ex
%%     \def\mathnotesize{\normalsize}
%%     \themathnotes  
%%     \endgroup
%%
%% as the last thing in your document.  (But \themathnotes all
%% by itself will work.)
%%
%%       ****************************************
%%       *        mathNOTE COMMANDS              *
%%       ****************************************
%%
%%
%%   \mathnote{NOTE}       : User command to insert a mathnote.
%%
%%   \mathnote[NUM]{NOTE}  : User command to insert a mathnote numbered
%%                           NUM, where NUM is a number -- 1, 2,
%%                           etc.  For example, if mathnotes are numbered
%%                           *, **, etc. within pages, then  \mathnote[2]{...}
%%                           produces mathnote '**'.  This command does  not
%%                           step the mathnote counter.
%%
%%   \mathnotemark[NUM]    : Command to produce just the mathnote mark in
%%                           the text, but no mathnote.  With no argument,
%%                           it steps the mathnote counter before  generating
%%                           the mark.
%%
%%   \mathnotetext[NUM]{TEXT} : Command to produce the mathnote but no 
%%                              mark.  \mathnote is equivalent to
%%                              \mathnotemark \mathnotetext .
%%
%%   \addtomathnotes{TEXT} : Command to add text or commands to current
%%                              mathnotes file: for inserting headings,
%%                              pagebreaks, and the like into mathnotes
%%                              sections.  TEXT a moving argument:
%%                              \protect required for fragile commands.
%%
%%       ****************************************
%%       *        mathNOTE USER COMMANDS         *
%%       ****************************************
%%
%%   mathnotes use the following parameters, similar to those relating
%%   to footnotes:
%%
%%   \mathnotesize   : Size-changing command for mathnotes.
%%
%%   \themathnote : In usual LaTeX style, produces the mathnote number.
%%
%%   \themathmark : Holds the current mathnote's mark--e.g., \dag or '1' or 'a'.
%%                 (You don't want to set this yourself, as it comes
%%                 either from the autonumbering of notes or from
%%                 the optional argument to \mathnote. But you'll need
%%                 to use it if you define your own \makemathmark.)
%%
%%   \makemathmark : A macro to generate the mathnote marker from  \themathmark
%%                  The default definition is \hbox{$^\themathmark$}.
%%
%%   \@makemathtext{NOTE} :
%%        Must produce the actual mathnote, using \themathmark as the mark
%%        of the mathnote and NOTE as the text.  It is called when effectively
%%        inside a \parbox, with \hsize = \columnwidth.  For example, it might
%%        be as simple as
%%               $^{\themathmark}$ NOTE
%%
%%
%%       ****************************************
%%       *       mathNOTE MACROS             *
%%       ****************************************
%%
%%
\ProvidesPackage{mbenotes}[2013/06/01 (Version 3) Notes for Text,tables,images and equations ]\RequirePackage{graphicx,xcolor,amsmath}\@definecounter{mathnote}
\def\themathnote{\@arabic\c@mathnote}

\def\@makemathmark{\hbox{\@textsuperscript{ \textcolor{red}{\tiny(\@themathmark)}}}}
\def\makemathmark{\@makemathmark}

\def\themathmark{\@themathmark}

\newdimen\mathnotesep

\def\mathnote{\@ifnextchar[\@xmathnote{\stepcounter{mathnote}%
     \protected@xdef\@themathmark{\themathnote}%
     \@mathnotemark\@mathnotetext}}

\def\@xmathnote[#1]{
   \begingroup
     \c@mathnote=#1\relax
     \unrestored@protected@xdef\@themathmark{\themathnote}%
   \endgroup
   \@mathnotemark\@mathnotetext }

%%  Here begins a section of mathnote code that's really different from
%% the footnote code of LaTeX.

\let\@doanmathnote=0
\let\@endanmathnote=0

\newwrite\@mathnotes
\newif\if@mathnotesopen \global\@mathnotesopenfalse

\def\@openmathnotes{\immediate\openout\@mathnotes=\jobname.math\relax
      \global\@mathnotesopentrue}

%%  The stuff with \next and \meaning is a trick from the TeXbook, 382,
%% there intended for setting verbatim text, but here used to avoid
%% macro expansion when the footnote text is written.  \next will have
%% the entire text of the footnote as one long line, which might well
%% overflow limits on output line length; the business with \newlinechar
%% makes every space become a newline in the \@mathnotes file, so that all
%% of the lines wind up being quite short.
%%
\long\def\@mathnotetext#1{%
  \ifmeasuring@%
  \else%
\if@mathnotesopen \else \@openmathnotes \fi%
    \immediate\write\@mathnotes{\@doanmathnote{\@themathmark}}%
 \begingroup \def\next{#1}%
\newlinechar='40 \immediate\write\@mathnotes{\meaning\next}%
    \endgroup \immediate\write\@mathnotes{\@endanmathnote}%
  \fi}%% \addtomathnotes works the way the other mathnote macros probably should
%% have, requiring the use of \protect for fragile commands.

\long\def\addtomathnotes#1{%
     \if@mathnotesopen \else \@openmathnotes \fi
     \begingroup
        \newlinechar='40
        \let\protect\string
        \immediate\write\@mathnotes{#1}%
     \endgroup}

%%  End of unique mathnote code
%%
\def\mathnotemark{%
   \@ifnextchar[\@xmathnotemark
     {\stepcounter{mathnote}%
      \protected@xdef\@themathmark{\themathnote}%
      \@mathnotemark}}

\def\@xmathnotemark[#1]{%
   \begingroup
      \c@mathnote #1\relax
      \unrestored@protected@xdef\@themathmark{\themathnote}%
   \endgroup
   \@mathnotemark}

\def\@mathnotemark{%
  \leavevmode
  \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
  \makemathmark
  \ifhmode\spacefactor\@x@sf\fi
  \relax}

\def\mathnotetext{
     \@ifnextchar [\@xmathnotenext
       {\protected@xdef\@themathmark{\themathnote}%
    \@mathnotetext}}

\def\@xmathnotenext[#1]{\begingroup \c@mathnote=#1\relax
   \xdef\@themathmark{\themathnote}\endgroup \@mathnotetext}

\def\@xmathnotenext[#1]{%
  \begingroup
     \c@mathnote=#1\relax
     \unrestored@protected@xdef\@themathmark{\themathnote}%
  \endgroup
  \@mathnotetext}


%%  \themathnotes actually prints out the mathnotes.

%%  The user may want separate mathnotes for each chapter, or a big
%% block of them at the end of the whole document.  As it stands,
%% either will work; you just say \themathnotes wherever you want the
%% mathnotes so far to be inserted.  The counter is always set to 0 %%
%%  \mathnoteformat is provided so user can specify some special formatting
%% for the mathnotes.  It needs to set up the paragraph parameters, start
%% the paragraph, and print the label.  The \mbox stuff in \mathnoteheading
%% is to make and undo a dummbe paragraph, to get around the games \section*
%% plays with paragraph indenting and instead give us uniform
%% indenting for all notes.

\def\mathnotesname{mathnotes} 
\def\mathnoteheading{\subsubsection*{\footnotesize{\mathnotesname} \@mkboth{\MakeUppercase{\mathnotesname}}{\MakeUppercase{\mathnotesname}}}
  \mbox{ }\par\vskip-\baselineskip}

\def\mathnoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
  \leavevmode\llap{\makemathmark}}

\def\mathnotesize{\footnotesize}

\def\themathnotes[#1]{\def\mathnotesname{#1}\immediate\closeout\@mathnotes \global\@mathnotesopenfalse
  \begingroup
    \makeatletter
    %%
    %% The machinery with \@ResetGT and > here ensures that
    %% \@doanmathnote works properly even if > is an active character
    %% at the point where \themathnotes is invoked. > needs to have
    %% catcode 12 when the arguments of \@doanmathnote are scanned, so
    %% that the > in the string "macro:->" is matched.  The actual
    %% footnote text is not an argument to \@doanmathnote, but just
    %% follows it in the .math file; so \@ResetGT can reset the
    %% category code for > that should be used when processing
    %% that text.  That resetting takes place within a
    %% \begingroup-\endgroup block set up by \@doanmathnote and
    %% \@endanmathnote, so the catcode for > is back to 12 for the
    %% next note.
    %
    \edef\@tempa{`\string >}%
    \ifnum\catcode\@tempa=12%
      \let\@ResetGT\relax
    \else
      \edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
      \@makeother\>%
    \fi
    \def\@doanmathnote##1##2>{\def\@themathmark{##1}\par\begingroup
        \@ResetGT
        \edef\@currentlabel{\csname p@mathnote\endcsname\@themathmark}%
        \mathnoteformat}
    \def\@endanmathnote{\par\endgroup}%
     \mathnoteheading 
    \mathnotesize
    \input{\jobname.math}%
    \setcounter{mathnote}{0} \vspace{1.8em} 
  \endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       ****************************************
%       *              bibNOTES  
%       ****************************************
%
%  Date of this version: 2013-06-1
%  Matthias Borck-Elsner
%
%% Based on endnotes.sty Copyright 2002 John Lavagnino
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The lambe version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%  Uses an extra external file, with .bib extension, to hold the 
%%  text of the bibnotes.  This may be deleted after the run; a new
%%  version is generated each time--it doesn't require information
%%  collected from the previous run.
%%
%%  This code does not obey \nofiles.  Perhaps it should.
%%
%%
%%  To turn all the footnotes in your documents into bibnotes, say
%%
%%     \let\footnote=\bibnote
%%
%%  in your preamble, and then add something like
%%
%%     \newpage
%%     \begingroup
%%     \parindent 0pt
%%     \parskip 2ex
%%     \def\bibnotesize{\normalsize}
%%     \thebibnotes  
%%     \endgroup
%%
%% as the last thing in your document.  (But \thebibnotes all
%% by itself will work.)
%%
%%       ****************************************
%%       *        bibNOTE COMMANDS              *
%%       ****************************************
%%
%%
%%   \bibnote{NOTE}       : User command to insert a bibnote.
%%
%%   \bibnote[NUM]{NOTE}  : User command to insert a bibnote numbered
%%                           NUM, where NUM is a number -- 1, 2,
%%                           etc.  For example, if bibnotes are numbered
%%                           *, **, etc. within pages, then  \bibnote[2]{...}
%%                           produces bibnote '**'.  This command does  not
%%                           step the bibnote counter.
%%
%%   \bibnotemark[NUM]    : Command to produce just the bibnote mark in
%%                           the text, but no bibnote.  With no argument,
%%                           it steps the bibnote counter before  generating
%%                           the mark.
%%
%%   \bibnotetext[NUM]{TEXT} : Command to produce the bibnote but no 
%%                              mark.  \bibnote is equivalent to
%%                              \bibnotemark \bibnotetext .
%%
%%   \addtobibnotes{TEXT} : Command to add text or commands to current
%%                              bibnotes file: for inserting headings,
%%                              pagebreaks, and the like into bibnotes
%%                              sections.  TEXT a moving argument:
%%                              \protect required for fragile commands.
%%
%%       ****************************************
%%       *        bibNOTE USER COMMANDS         *
%%       ****************************************
%%
%%   bibnotes use the following parameters, similar to those relating
%%   to footnotes:
%%
%%   \bibnotesize   : Size-changing command for bibnotes.
%%
%%   \thebibnote : In usual LaTeX style, produces the bibnote number.
%%
%%   \thebibmark : Holds the current bibnote's mark--e.g., \dag or '1' or 'a'.
%%                 (You don't want to set this yourself, as it comes
%%                 either from the autonumbering of notes or from
%%                 the optional argument to \bibnote. But you'll need
%%                 to use it if you define your own \makebibmark.)
%%
%%   \makebibmark : A macro to generate the bibnote marker from  \thebibmark
%%                  The default definition is \hbox{$^\thebibmark$}.
%%
%%   \@makebibtext{NOTE} :
%%        Must produce the actual bibnote, using \thebibmark as the mark
%%        of the bibnote and NOTE as the text.  It is called when effectively
%%        inside a \parbox, with \hsize = \columnwidth.  For example, it might
%%        be as simple as
%%               $^{\thebibmark}$ NOTE
%%
%%
%%       ****************************************
%%       *       bibNOTE MACROS             *
%%       ****************************************
%%
%%
\ProvidesPackage{mbenotes}[2013/06/01 (Version 3) Notes for Text,tables,images and equations ]\RequirePackage{graphicx,xcolor,amsmath}\@definecounter{bibnote}
\def\thebibnote{\@arabic\c@bibnote}

\def\@makebibmark{\hbox{\@textsuperscript{{\tiny\@thebibmark}}}}
\def\makebibmark{\@makebibmark}

\def\thebibmark{\@thebibmark}

\newdimen\bibnotesep

\def\bibnote{\@ifnextchar[\@xbibnote{\stepcounter{bibnote}%
     \protected@xdef\@thebibmark{\thebibnote}%
     \@bibnotemark\@bibnotetext}}

\def\@xbibnote[#1]{
   \begingroup
     \c@bibnote=#1\relax
     \unrestored@protected@xdef\@thebibmark{\thebibnote}%
   \endgroup
   \@bibnotemark\@bibnotetext }

%%  Here begins a section of bibnote code that's really different from
%% the footnote code of LaTeX.

\let\@doanbibnote=0
\let\@endanbibnote=0

\newwrite\@bibnotes
\newif\if@bibnotesopen \global\@bibnotesopenfalse

\def\@openbibnotes{\immediate\openout\@bibnotes=\jobname.bib\relax
      \global\@bibnotesopentrue}

%%  The stuff with \next and \meaning is a trick from the TeXbook, 382,
%% there intended for setting verbatim text, but here used to avoid
%% macro expansion when the footnote text is written.  \next will have
%% the entire text of the footnote as one long line, which might well
%% overflow limits on output line length; the business with \newlinechar
%% makes every space become a newline in the \@bibnotes file, so that all
%% of the lines wind up being quite short.
%%
\long\def\@bibnotetext#1{%
     \if@bibnotesopen \else \@openbibnotes \fi
     \immediate\write\@bibnotes{\@doanbibnote{\@thebibmark}}%
     \begingroup
        \def\next{#1}%
        \newlinechar='40
        \immediate\write\@bibnotes{\meaning\next}%
     \endgroup
     \immediate\write\@bibnotes{\@endanbibnote}}

%% \addtobibnotes works the way the other bibnote macros probably should
%% have, requiring the use of \protect for fragile commands.

\long\def\addtobibnotes#1{%
     \if@bibnotesopen \else \@openbibnotes \fi
     \begingroup
        \newlinechar='40
        \let\protect\string
        \immediate\write\@bibnotes{#1}%
     \endgroup}

%%  End of unique bibnote code
%%
\def\bibnotemark{%
   \@ifnextchar[\@xbibnotemark
     {\stepcounter{bibnote}%
      \protected@xdef\@thebibmark{\thebibnote}%
      \@bibnotemark}}

\def\@xbibnotemark[#1]{%
   \begingroup
      \c@bibnote #1\relax
      \unrestored@protected@xdef\@thebibmark{\thebibnote}%
   \endgroup
   \@bibnotemark}

\def\@bibnotemark{%
  \leavevmode
  \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
  \makebibmark
  \ifhmode\spacefactor\@x@sf\fi
  \relax}

\def\bibnotetext{
     \@ifnextchar [\@xbibnotenext
       {\protected@xdef\@thebibmark{\thebibnote}%
    \@bibnotetext}}

\def\@xbibnotenext[#1]{\begingroup \c@bibnote=#1\relax
   \xdef\@thebibmark{\thebibnote}\endgroup \@bibnotetext}

\def\@xbibnotenext[#1]{%
  \begingroup
     \c@bibnote=#1\relax
     \unrestored@protected@xdef\@thebibmark{\thebibnote}%
  \endgroup
  \@bibnotetext}


%%  \thebibnotes actually prints out the bibnotes.

%%  The user may want separate bibnotes for each chapter, or a big
%% block of them at the end of the whole document.  As it stands,
%% either will work; you just say \thebibnotes wherever you want the
%% bibnotes so far to be inserted.  The counter is always set to 0 %%
%%  \bibnoteformat is provided so user can specify some special formatting
%% for the bibnotes.  It needs to set up the paragraph parameters, start
%% the paragraph, and print the label.  The \mbox stuff in \bibnoteheading
%% is to make and undo a dummbe paragraph, to get around the games \section*
%% plays with paragraph indenting and instead give us uniform
%% indenting for all notes.

\def\bibnotesname{bibnotes} 
\def\bibnoteheading{\subsubsection*{\footnotesize{\bibnotesname} \@mkboth{\MakeUppercase{\bibnotesname}}{\MakeUppercase{\bibnotesname}}}
  \mbox{ }\par\vskip-\baselineskip}

\def\bibnoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
  \leavevmode\llap{\makebibmark}}

\def\bibnotesize{\footnotesize}

\def\thebibnotes[#1]{\def\bibnotesname{#1}\immediate\closeout\@bibnotes \global\@bibnotesopenfalse
  \begingroup
    \makeatletter
    %%
    %% The machinery with \@ResetGT and > here ensures that
    %% \@doanbibnote works properly even if > is an active character
    %% at the point where \thebibnotes is invoked. > needs to have
    %% catcode 12 when the arguments of \@doanbibnote are scanned, so
    %% that the > in the string "macro:->" is matched.  The actual
    %% footnote text is not an argument to \@doanbibnote, but just
    %% follows it in the .bib file; so \@ResetGT can reset the
    %% category code for > that should be used when processing
    %% that text.  That resetting takes place within a
    %% \begingroup-\endgroup block set up by \@doanbibnote and
    %% \@endanbibnote, so the catcode for > is back to 12 for the
    %% next note.
    %
    \edef\@tempa{`\string >}%
    \ifnum\catcode\@tempa=12%
      \let\@ResetGT\relax
    \else
      \edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
      \@makeother\>%
    \fi
    \def\@doanbibnote##1##2>{\def\@thebibmark{##1}\par\begingroup
        \@ResetGT
        \edef\@currentlabel{\csname p@bibnote\endcsname\@thebibmark}%
        \bibnoteformat}
    \def\@endanbibnote{\par\endgroup}%
     \bibnoteheading 
    \bibnotesize
    \input{\jobname.bib}%
    \setcounter{bibnote}{0} \vspace{1.8em} 
  \endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%