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
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; LATEX.CMD
;
; microEMACS for Windows macros to give LaTeX functionality
;
; MODIFICATION HISTORY:
; Feb 10 94 Took out readhook line.
; Feb 04 94 Modified for MEW 3.12
; Note that there are still some funny bugs, particularly with
; reference to file locking. If you get funny errors about
; files being in use, try deleting the "._xlk" sub-directories.
; Jan 25 93 Use dviwin as viewer
;
; MEWLaTeX Version 1.0
;
; Original release Jan 11 1993.
;
; Michael F. Reid <M.Reid@phys.canterbury.ac.nz>
; Department of Physics and Astronomy, University of Canterbury
; Christchurch, New Zealand.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; There are three sections:
; GENERAL
; SPELL-CHECKING
; LATEX
;
; Key bindings and menu bindings are at the end of each section
;
; We begin with variables that must be setup locally by the user.
; As a debug tool we have variable %l-menus-loaded to prevent menus
; from being loaded twice if we edit the file and re-run it.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; VARIABLES
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GENERAL
set %x-rename "xrename.bat" ; delete and rename, used for backup-save
; if xrename.bat is not in your path, you won't get a backup!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SPELL CHECKING
set %spell-exec "spell.pif"
; using spell.pif allows better control over the spell-checker
; amSpell likes to run full-screen, for example
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; LaTeX
set %l-file-path "e:\bin\mewin\latex\"
; finish with "\"
; place to look for help and templates
set %l-latex "latex.pif"
set %l-tex "tex.pif"
set %l-view "e:\tex\dviwin\dviwin"
set %l-print "texprint.pif"
set %l-dvi2ps "dvi2ps.pif"
set %l-psview "gs.pif"
set %l-makeindex "makeindx.pif"
set %l-bibtex "bibtex.pif"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; GENERAL COMMANDS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
set $discmd FALSE
print "[Loading general macros...]"
store-procedure toggle-overwrite ; make Insert key behave "normally"
set $cmode &bxor $cmode 32
!endm
store-procedure del-blanks ; use ^Delete to delete to next non-blank
!while TRUE
!if ¬ &seq &chr $curchar " "
!return
!endif
delete-next-character
!endwhile
!endm
store-procedure insert-date
insert-string $time
!endm
store-procedure save-all-buffers
; This macro saves all the modified buffers to their respective
; files
; Modified by MFR - you could replace the version in emacs.rc
set %tmp $cbufname
!while TRUE
!if &equ $cbflags 2 ;MFR don't try to save unchanged files
!force save-file
!endif
!force next-buffer
!if &seq %tmp $cbufname
!return
!endif
!endwhile
!endm
store-procedure readhook-proc ; TeX and bib get C and Wrap modes
; modified by MFR - you could replace the version in emacs.rc
run extension
!if &sin "|c|h|cpp|hpp|dlg|def|rc|cmd|" &cat &cat "|" %ext "|"
add-mode cmode
!else
!if &sin "||me|1st|doc|txt|" &cat &cat "|" %ext "|"
add-mode wrap
!else
!if &sin "||tex|bib|" &cat &cat "|" %ext "|"
add-mode cmode
add-mode wrap
!endif
!endif
!endif
!endm
; set $readhook readhook-proc ; commented out 10 Feb 94
store-procedure file-split
; split $cfname into %f-dir %f-name %f-ext
; uses %f-tmp1, %f-tmp2, %f-tmp3
set %f-dir &low $cfname
set %f-name ""
set %f-ext ""
set %f-tmp1 &length %f-dir
set %f-tmp2 &sindex %f-dir "."
!if ¬ &equ %f-tmp2 0
set %f-ext &mid %f-dir &add %f-tmp2 1 &sub %f-tmp1 %f-tmp2
set %f-dir &mid %f-dir 1 &sub %f-tmp2 1
!endif
set %f-tmp1 &length %f-dir
set %f-tmp2 &sindex %f-dir "\"
!if ¬ &equ %f-tmp2 0
set %f-tmp2 &length %f-dir
!while ¬ &sequal "\" &mid %f-dir %f-tmp2 1
set %f-tmp3 &mid %f-dir %f-tmp2 1
set %f-tmp2 &sub %f-tmp2 1
!endwhile
set %f-name &mid %f-dir &add %f-tmp2 1 &sub %f-tmp1 %f-tmp2
set %f-dir &mid %f-dir 1 %f-tmp2
!endif
; print &cat &cat &cat &cat %f-dir "+" %f-name "+" %f-ext
!endm
store-procedure query-save-all
; This macro saves all the modified buffers to their respective
; files, but asks as it goes along
; uses %f-tmp1, %f-tmp2
set %f-tmp1 $cbufname
!while TRUE
!if &equ $cbflags 2
set %f-tmp2 @&cat &cat "Save " $cbufname " (y/n)? [y]: "
!if ¬ &sequal %f-tmp2 "n"
!force save-file
!endif
!endif
!force next-buffer
!if &seq %f-tmp1 $cbufname
!return
!endif
!endwhile
!endm
store-procedure backup-save
; renames then saves, like gnuemcs x.y -> x.~y
; uses %f-tmp1, %f-tmp2, %f-tmp3
; x-rename is a batch file name. Batch file contains:
; del %2
; rename %1 %2
!if ¬ &equ $cbflags 2 ; needs saving?
print "[File not modified]"
!else
file-split
set %f-tmp1 $cbufname ; old buffer
set %f-tmp2 $cfname ; old filename
set %f-tmp3 &cat &cat &cat %f-name ".~~" %f-ext ; backup filename
print "[Backing up...]"
; 1 forces it to wait for completion
1 shell-command &cat &cat &cat &cat %x-rename " " %f-tmp2 " " %f-tmp3
save-file
!endif
!endm
store-procedure s-insert-file
; insert file, keeping point at same place, like gnu emacs
; uses %s-tmp
set %s-tmp $yankflag
set $yankflag TRUE
!force execute-named-command insert-file
set $yankflag %s-tmp
!endm
store-procedure force-current-directory
; make sure we are using directory of current buffer
!if ¬ &seq $cfname "" ; e.g. main has no file name
!force find-file $cfname ; force current directory
!endif
!endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GENERAL MENU ADDITIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bind-to-key set-mark ^@ ; gnu binding ; Doesn't work for 3.12
; This is because ^@ means ^-space --- see documentation :-(
macro-to-key toggle-overwrite FNC ; Insert key
macro-to-key del-blanks FN^D ; ^Delete
macro-to-key save-all-buffers M-^Z ; bind to ESC Ctrl+Z
macro-to-key backup-save M-S ;
macro-to-key s-insert-file ^XI ; gnu binding
macro-to-key s-insert-file ^X^I ; old insert-file binding
!if ¬ %l-menus-loaded
; change from insert-file to s-insert-file
unbind-menu ">&File>&Insert..."
macro-to-menu s-insert-file ">&File>&Insert...@2"
; add backup-save to File menu
macro-to-menu backup-save ">&File>Back&up and Save@6"
; add insert-date to Edit menu
macro-to-menu insert-date ">&Edit>Insert &Date@3"
; add clip-region to menu under Edit/Region
bind-to-menu clip-region ">&Edit>&Region>To Clip&board@0"
bind-to-menu nop "-"
!endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; SPELL-CHECKING COMMANDS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Run spell checker on current buffer and re-read the file.
; The spell-checker is a DOS program stored in %spell-exec
write-message "[Loading Spell macros...]"
store-procedure spell-buffer
; uses s-tmp1
save-file
run force-current-directory
; the 1 forces it to wait for completion
1 execute-program &cat &cat %spell-exec " " $cfname
set %s-tmp1 @"[Spell] (Wait until completion) Re-Read file (y/n)? [y]: "
!if ¬ &sequal &lower %s-tmp1 "n"
read-file $cfname
!endif
!endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SPELL-CHECKING MENU ADDITIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!if ¬ %l-menus-loaded
macro-to-menu spell-buffer ">S&pell@4>&Buffer"
!endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; LaTeX COMMANDS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print "[Loading LaTeX macros...]"
set $fmtlead "\ %" ; to prevent formatting of TeX stuff. Note blank!
set $paralead "\% ~t"
set %l-log-screen "LaTeX LOG"
set %l-log-buffer "_texlog"
set %l-fn "?" ; file name being processed (no extension)
set %l-prog "?" ; program being used
set %l-ext "?" ; extension for program (tex, dvi, etc.)
set %l-log "?" ; logfile extension
store-procedure set-latex-fn
; uses %l-fn, %l-tmp1
; set LaTeX file name
; default is current buffer - remembers from run to run.
!if &sequ %l-fn "?"
run file-split
set %l-fn %f-name
!endif
set %l-tmp1 ""
set %l-tmp1 @&cat &cat &cat %l-prog " Filename (^G aborts )[" %l-fn "]: "
!if ¬ &equ 0 &sindex %l-tmp1 "[" ; Hack for ^G
print [Abort]
set %l-fn "?"
set %l-tmp1 ""
!return
!endif
!if ¬ &equal 0 &length %l-tmp1
set %l-fn %l-tmp1
!endif
print &cat &cat %l-prog "file name: " %l-fn
!endm
store-procedure l-run
; uses %l-fn
; %l-prog and %l-ext must be set before running this
run query-save-all
run set-latex-fn
run force-current-directory
!if &seq %l-fn "?" ; no file
!return
!endif
!if ¬ &exist &cat &cat %l-fn "." %l-ext
print &cat &cat &cat &cat "[No file " %l-fn "." %l-ext "]"
set %l-fn "?"
!else
; kill old log
!if &seq $scrname %l-log-screen ; current screen is log
!force delete-buffer %l-log-buffer ; kill buffer
!force select-buffer %l-log-buffer
add-mode view
!else ; current screen is not log
!force delete-screen %l-log-screen ; kill screen and buffer
!force delete-buffer %l-log-buffer
!endif
print &cat &cat &cat &cat "[" %l-prog " " %l-fn "]"
!if &seq %l-ext "ps" ; gs requires the ".ps"
execute-program &cat &cat &cat %l-prog " " %l-fn ".ps"
!else
execute-program &cat &cat %l-prog " " %l-fn
!endif
!endif
!endm
store-procedure run-latex
set %l-prog %l-latex
set %l-ext "tex"
set %l-log "log"
run l-run
!endm
store-procedure run-tex
set %l-prog %l-tex
set %l-ext "tex"
set %l-log "log"
run l-run
!endm
store-procedure run-bibtex
set %l-prog %l-bibtex
set %l-ext "aux"
set %l-log "blg"
run l-run
!endm
store-procedure run-makeindex
set %l-prog %l-makeindex
set %l-ext "aux"
set %l-log "ilg"
run l-run
!endm
store-procedure print-latex
set %l-prog %l-print
set %l-ext "dvi"
set %l-log "?"
run l-run
!endm
store-procedure dvi2ps-latex
set %l-prog %l-dvi2ps
set %l-ext "dvi"
set %l-log "?"
run l-run
!endm
store-procedure psview-latex
set %l-prog %l-psview
set %l-ext "ps"
set %l-log "?"
run l-run
!endm
store-procedure view-latex
set %l-prog %l-view
set %l-ext "dvi"
run set-latex-fn
run force-current-directory
!if ¬ &exist &cat %l-fn ".dvi"
run file-split
print &cat &cat "[No file " %l-fn ".dvi]"
set %l-fn "?"
!else
print &cat &cat "[view " %l-fn "]"
execute-program &cat &cat &cat %l-view " " %l-fn ".dvi"
!endif
!endm
store-procedure view-charset ; View LaTeX character set
!if ¬ &exist &cat %l-file-path "charset.dvi"
print &cat &cat "[No file " %l-file-path "charset.dvi]"
!else
print &cat &cat "[view " %l-file-path "charset.dvi]"
execute-program &cat &cat &cat %l-view " " %l-file-path "charset.dvi"
!endif
!endm
store-procedure l-display-log
run force-current-directory
set %l-tmp1 &cat &cat %l-fn "." %l-log
set %l-tmp2 @&cat &cat " Read Log (^G aborts )[" %l-tmp1 "]: "
!if ¬ &equ 0 &sindex %l-tmp2 "[" ; Hack for ^G
print "[Abort]"
!return
!endif
!if ¬ &equ &len %l-tmp2 0
set %l-tmp1 %l-tmp2
!endif
!if ¬ &exist %l-tmp1
print &cat &cat "[No file " %l-tmp1 "]"
!return
!endif
!force find-screen %l-log-screen
!force select-buffer %l-log-buffer
!force read-file %l-tmp1
add-mode view
print "[F4 to find error]"
!endm
store-procedure l-find-error
; Modified for 3.12 by turning $discmd on and off... 4 Feb 94
; parse LaTeX log-file for errors
; %e-upto is line in log-file we are up to
; %e-line and %e-file are where the errors are
; uses %l-tmp1
print "[Searching for LaTeX error]"
set $discmd FALSE
find-screen %l-log-screen
select-buffer %l-log-buffer
set $discmd TRUE ; turning it on seems essential
!if &seq $cfname "" ; read log if there is none
l-display-log
update-screen
print "[Searching for LaTeX error]"
!endif
set $discmd FALSE
!force search-forward "~nl." ; find next error
!if ¬ $status
print "[No more errors]"
!return
!endif
update-screen
set %e-upto $curline
set-mark
end-of-word
set %e-line $region
set %e-paren 1 ; number of parentheses - count down to 0
!force search-reverse "~!" ; search back for file name
!while TRUE
!force previous-line
!if ¬ $status
print "[Cannot locate file name]"
!return
!endif
beginning-of-line
!if &seq &chr $curchar "?" ; skip error listing
!force search-reverse "~n!"
!force next-line
!else
!if &seq &chr $curchar "." ; TeX warnings
!force search-reverse "~n[]"
!else
!if ¬ &seq &mid $line 1 15 "LaTeX Warning: "
!if ¬ &seq &chr $curchar "\"
!if ¬ &and &equ &sindex $line "(" 0 &equ &sindex $line ")" 0
; examine the line for brackets
; update-screen
; set %dummy @&cat &cat &cat "examining line" $line " " %e-paren
end-of-line
!while ¬ &equ $curcol 0
backward-character
!if &seq &chr $curchar "("
set %e-paren &sub %e-paren 1
!endif
!if &seq &chr $curchar ")"
set %e-paren &add %e-paren 1
!endif
!if &equ %e-paren 0
!break
!endif
!endwhile
!if &equ %e-paren 0
!break
!endif
!endif ; end of examine the line for brackets
!endif
!endif
!endif
!endif
!endwhile ; should now be at filename
!if ¬ &seq &chr $curchar "("
print "[Cannot locate file name]"
!return
!endif
forward-character
set-mark
end-of-line
set %e-file $region
set %l-tmp1 &sindex %e-file " " ; always a blank before [n] etc.
!if ¬ &equ 0 %l-tmp1
set %e-file &mid %e-file 1 &sub %l-tmp1 1
!endif
goto-line %e-upto
!force next-line
beginning-of-line
set $discmd TRUE
update-screen
print &cat &cat %e-file " " %e-line
set %l-tmp1 @&cat &cat &cat "Enter for error: " %e-file " " %e-line
set $discmd FALSE
!force find-file %e-file
set %l-tmp $cbufname ; juggle the buffers - must be easier way!
!force find-screen %l-tmp
!force select-buffer %l-tmp
!force find-screen %l-log-screen
!force select-buffer %l-log-buffer
!force find-screen %l-tmp
!if ¬ $status
set $discmd TRUE
print &cat &cat "[Cannot find file " %e-file "]"
set $discmd FALSE
!endif
!force goto-line %e-line
set $discmd TRUE
print "[F4 for next error]"
!endm
store-procedure clear-latex-file
set %l-fn "?"
!endm
; superscripts/subscripts
store-procedure superscript-b
insert-string "^{}"
backward-character
!endm
store-procedure subscript-b
insert-string "_{}"
backward-character
!endm
; useful pairs of delimiters
store-procedure curly-b
insert-string "{}"
backward-character
!endm
store-procedure round-b
insert-string "()"
backward-character
!endm
store-procedure square-b
insert-string "[]"
backward-character
!endm
store-procedure angle-b
insert-string "\langle\rangle"
7 backward-character
!endm
store-procedure vert-b
insert-string "||"
backward-character
!endm
store-procedure d-vert-b
insert-string "\|\|"
2 backward-character
!endm
store-procedure quote-b
insert-string "``''"
backward-character
backward-character
!endm
store-procedure slash-curly-b
insert-string "\{\}"
2 backward-character
!endm
store-procedure slash-round-b
insert-string "\(\)"
2 backward-character
!endm
store-procedure slash-square-b
insert-string "\[\]"
2 backward-character
!endm
store-procedure dollar-b
insert-string "$$"
backward-character
!endm
store-procedure double-dollar-b
insert-string "$$$$"
2 backward-character
!endm
store-procedure sizable-curly-b
insert-string "\left\{\right\}"
8 backward-character
!endm
store-procedure sizable-square-b
insert-string "\left[\right]"
7 backward-character
!endm
store-procedure sizable-round-b
insert-string "\left(\right)"
7 backward-character
!endm
store-procedure sizable-angle-b
insert-string "\left\langle\right\rangle"
13 backward-character
!endm
store-procedure sizable-vert-b
insert-string "\left|\right|"
7 backward-character
!endm
store-procedure sizable-d-vert-b
insert-string "\left\|\right\|"
8 backward-character
!endm
set %p-doline FALSE ; default is to do a "word"
set %p-gotop TRUE ; default is to go to top of file
; other choices may be useful
; store the general motion commands for position-cursor
; in %motion-c1 and %motion-c2
; NOTE: Too long a string crashes the program !!
set %motion-c1 "!forward-character!backward-character!"
set %motion-c1 &cat %motion-c1 "next-line!previous-line!"
set %motion-c1 &cat %motion-c1 "beginning-of-line!end-of-line!"
set %motion-c2 "!beginning-of-file!end-of-file!"
set %motion-c2 &cat %motion-c2 "end-of-word!previous-word!"
set %motion-c2 &cat %motion-c2 "next-page!previous-page!"
store-procedure position-cursor
; Uses %p-tmp %p-tmp-t %p-tmp-l.
; if %p-gotop make sure we are at top of file.
; Use arrow, paging keys, mouse, or search to position cursor
; OR type into %p-tmp-t
; Enter terminates it, C-G aborts.
; %p-tmp-t is not blank, return it in %p-tmp,
; else if $curcol!=0 and $curline!=1 return blank-delimited string
; (not "word") at current point. If %p-doline get whole line.
!if %p-gotop
set $curcol 0
set $curline 1
!endif
set %p-tmp ""
set %p-tmp-t ""
!while TRUE ; break out with newline
print &cat "[Type, or Select, then Enter (^G aborts)]: " %p-tmp-t
update-screen
set %p-tmp >cmd
!if &equ &len %p-tmp 1 ; Then it's a printable character
set %p-tmp-t &cat %p-tmp-t %p-tmp
!else
set %p-tmp &bind %p-tmp ; translate command
!if &seq %p-tmp "delete-previous-character" ; delete last character
set %p-tmp-l &len %p-tmp-t
!if &greater %p-tmp-l 0
set %p-tmp-t &mid %p-tmp-t 1 &sub %p-tmp-l 1
!endif
!else
; print %p-tmp
!if &seq %p-tmp newline ; break out with newline
!break
!endif
!if &seq %p-tmp abort-command ; break out with ^G
!break
!endif
!if ¬ &seq %p-tmp ERROR ; if valid command
!while TRUE ; break out if recognized motion key
; first look for general motion
!if ¬ &equ 0 &sindex %motion-c1 &cat &cat "!" %p-tmp "!"
!force %p-tmp
!break
!endif
!if ¬ &equ 0 &sindex %motion-c2 &cat &cat "!" %p-tmp "!"
!force %p-tmp
!break
!endif
!if &seq %p-tmp [MSleft-down] ; mouse strokes
!force run MSleft-down
!break
!endif
!if &seq %p-tmp [MSleft-up]
!force run MSleft-up
!break
!endif
!if &seq %p-tmp search-forward ; searching
execute-named-command search-forward
!endif
!if &seq %p-tmp search-reverse
execute-named-command search-reverse
!endif
!break ; break if we didnt get anything
!endwhile ; test for motion commands
!endif ; not ERROR
!endif
!endif
update-screen
!endwhile ; test for return
!if &seq %p-tmp abort-command ; return nothing if aborted
set %p-tmp ""
!else
!if &greater &len %p-tmp-t 0
set %p-tmp %p-tmp-t
!else
!if &and &equ $curline 1 &equ $curcol 0
set %p-tmp ""
!else
!if %p-doline ; copy line
beginning-of-line
!while &and &equ &chr $curchar " " ¬ &equ $curcol $lwidth
forward-character
!endwhile
set-mark
end-of-line
!else ; copy word
!while &and ¬ &seq &chr $curchar " " ¬ &equ $curcol 0
backward-character
!endwhile
!if &seq &chr $curchar " "
forward-character
!endif
set-mark
!while &and ¬ &seq &chr $curchar " " ¬ &equ $curcol $lwidth
forward-character
!endwhile
!endif
set %p-tmp $region
!endif
!endif
!endif
; print %p-tmp
!endm
store-procedure get-help-word
; uses %h-oldfile, %h-file, %h-buffer
; display file %h-file and return a word using position-cursor
; word is returned in %p-tmp
set %h-oldfile $cfname
!if ¬ &exist &cat %l-file-path %h-file
print &cat &cat &cat "[No file " %l-file-path %h-file "]"
set %p-tmp "ERROR"
!return
!endif
find-file &cat %l-file-path %h-file
add-mode VIEW
update-screen
run position-cursor
set %h-buffer $cbufname
!force find-file %h-oldfile
!force delete-buffer %h-buffer
!endm
store-procedure l-insert-word
; Insert command from file %h-file
; If it has a {, position after the first one.
; Used by many of below command, but some have to add things, so
; do similar things themselves.
run get-help-word
!if &seq %p-tmp "ERROR"
!return
!endif
set %l-tmp1 %p-tmp
; print %l-tmp1
!if ¬ &equ &len %l-tmp1 0
insert-string &cat %l-tmp1
set %l-tmp2 &sindex %l-tmp1 "{"
!if ¬ &equ %l-tmp2 0
set %l-tmp3 &sub &len %l-tmp1 %l-tmp2
!force %l-tmp3 backward-character
!endif
!endif
!endm
store-procedure l-env-pair
; uses %l-tmp1, %p-tmp
; create a LaTeX environment from user input
set %h-file "environ.lh"
run get-help-word
!if &seq %p-tmp "ERROR"
!return
!endif
set %l-tmp1 %p-tmp
!if ¬ &equ &len %l-tmp1 0
2 open-line
insert-string &cat &cat "\begin{" %l-tmp1 "}"
!if &seq %l-tmp1 "array"
insert-string "{lrc}"
!endif
!if &seq %l-tmp1 "list"
insert-string "{labeling}{spacing}"
!endif
!if &seq %l-tmp1 "minipage"
insert-string "[pos]{vsize}"
!endif
!if &seq %l-tmp1 "picture"
insert-string "(x,y)(xl,yl)"
!endif
!if &seq %l-tmp1 "tabular"
insert-string "{lrc}"
!endif
!if &seq %l-tmp1 "thebibliography"
insert-string "{99}"
!endif
2 next-line
insert-string &cat &cat "\end{" %l-tmp1 "}"
previous-line
!endif
!endm
store-procedure l-heading
; uses %h-file, %l-tmp1, %p-tmp
; create a LaTeX heading from user input
set %h-file "headings.lh"
run get-help-word
!if &seq %p-tmp "ERROR"
!return
!endif
set %l-tmp1 %p-tmp
; print %l-tmp1
!if ¬ &equ &len %l-tmp1 0
insert-string &cat &cat "\" %l-tmp1 "{}"
backward-character
!endif
!endm
store-procedure l-template
; LaTeX templates
; uses %l-tmp1, %l-tmp2, %h-file, %p-tmp
set %h-file "ltemp.lh"
run get-help-word
!if &seq %p-tmp "ERROR"
!return
!endif
set %l-tmp1 %p-tmp
!if ¬ &equ &len %l-tmp1 0
set %l-tmp1 &cat &cat %l-file-path %l-tmp1 ".lt"
!if ¬ &exist %l-tmp1
print &cat &cat &cat "[No file " %l-tmp1 "]"
!else
set %l-tmp2 $yankflag
set $yankflag TRUE ; keep point at start of included file
insert-file %l-tmp1
set $yankflag %l-tmp2
!endif
!endif
!endm
store-procedure b-template
; BibTeX templates
; uses %l-tmp1, %l-tmp2, %h-file, %p-tmp
set %h-file "btemp.lh"
run get-help-word
!if &seq %p-tmp "ERROR"
!return
!endif
set %l-tmp1 %p-tmp
!if ¬ &equ &len %l-tmp1 0
set %l-tmp1 &cat &cat %l-file-path %l-tmp1 ".bt"
!if ¬ &exist %l-tmp1
print &cat &cat &cat "[No file " %l-file-path %l-tmp1 "]"
!else
set %l-tmp2 $yankflag
set $yankflag TRUE ; keep point at start of included file
insert-file %l-tmp1
set $yankflag %l-tmp2
end-of-line
backward-character
!endif
!endif
!endm
store-procedure l-misc
; Miscellaneous LaTeX commands
set %h-file "misc.lh"
run l-insert-word
!endm
store-procedure l-taccents
; Text accents
set %h-file "taccents.lh"
run l-insert-word
!endm
store-procedure l-tspecial
; special sybols
set %h-file "tspecial.lh"
run l-insert-word
!endm
store-procedure l-tforeign
; foreign symbols
set %h-file "tforeign.lh"
run l-insert-word
!endm
store-procedure l-maccents
; math accents
set %h-file "maccents.lh"
run l-insert-word
!endm
store-procedure l-greek
; greek letters
set %h-file "greek.lh"
run l-insert-word
!endm
store-procedure l-mbinops
; math binary operators
set %h-file "mbinops.lh"
run l-insert-word
!endm
store-procedure l-mrel
; math relations
set %h-file "mrel.lh"
run l-insert-word
!endm
store-procedure l-marrow
; math arrows
set %h-file "marrow.lh"
run l-insert-word
!endm
store-procedure l-mmisc
; math miscellaneous
set %h-file "mmisc.lh"
run l-insert-word
!endm
store-procedure l-mloglike
; math loglike
set %h-file "mloglike.lh"
run l-insert-word
!endm
store-procedure l-mdelim
; math delimiters
set %h-file "mdelim.lh"
run l-insert-word
!endm
store-procedure l-mvarsym
; math variable-sized symbols
set %h-file "mvarsym.lh"
run l-insert-word
!endm
store-procedure l-mline
; math overline/underline
set %h-file "mline.lh"
run l-insert-word
!endm
store-procedure latex-help
help-engine &cat %l-file-path latex.hlp
!endm
store-procedure search-latex-help
; uses %s-tmp
; pull keyword off the current file and search help.
; only works for exact match.
!force end-of-word
set-mark
!force previous-word
set %s-tmp @&cat &cat "Search Help for [" $region "]: "
!if &equ &len %s-tmp 0
set %s-tmp $region
!endif
help-engine &cat %l-file-path latex.hlp
help-engine &cat %l-file-path latex.hlp %s-tmp
; note that there are two parameters to help engine in this case
print &cat &cat "[Searching help file for " %s-tmp "]"
!endm
store-procedure interface-help
help-engine &cat %l-file-path "interfac.hlp"
!endm
store-procedure installation-help
!force find-screen "Installation Help"
!force find-file &cat %l-file-path mewlatex.txt
add-mode view
!endm
store-procedure tex-info
; TeX information files, e.g. FAQ
; You will want to change texinfo.lh for you local setup
set %h-file "texinfo.lh"
run get-help-word
!if &seq %p-tmp "ERROR"
!return
!endif
!if ¬ &equ &len %p-tmp 0
!if ¬ &exist %p-tmp
print &cat &cat "[No file " %p-tmp "]"
!else
!force find-screen &cat "Information: "%p-tmp
!force find-file %p-tmp
add-mode view
!endif
!endif
!endm
store-procedure clean-bibitem
; get rid of pairs of quotes from bibTeX item.
; only makes sense for a .bib file.
; NOTE!: assumes the format in the template files, i.e.
; one item per line, and the closing } on an separate line.
set $discmd FALSE
!force search-reverse "@"
beginning-of-line
!if ¬ &sequal "@" &mid $line 1 1
!return
!endif
!while TRUE
!force next-line
!if ¬ $status
!break
!endif
!if &sequal "@" &mid $line 1 1
!break
!endif
!if ¬ &equ 0 &sindex $line "~"~""
1 kill-to-end-of-line
!force previous-line
!endif
!endwhile
!force backward-character
!if ¬ $status
!return
!endif
!while &or &seq &chr $curchar " " &seq &chr $curchar "~n"
!force backward-character
!if ¬ $status
!return
!endif
!endwhile
!if ¬ &seq &chr $curchar "}"
!return
!endif
!force backward-character
!while &or &seq &chr $curchar " " &seq &chr $curchar "~n"
!force backward-character
!if ¬ $status
!return
!endif
!endwhile
!if &seq &chr $curchar ","
delete-next-character
!endif
; clear-message-line
set $discmd TRUE
!endm
store-procedure clean-bibfile
; run clean-bib-item on whole file
run query-save-all
set %l-tmp1 @"Do you really want to clean your entire bibTeX file? [n]: "
!if ¬ &sequal &lower %l-tmp1 "y"
!return
!endif
print "[Cleaning BibTeX file. This may take a while...]"
set $discmd FALSE
beginning-of-file
!while TRUE
!force search-forward "@"
!if ¬ $status
!break
!endif
run clean-bibitem
; update-screen
!force next-line
end-of-line
!endwhile
beginning-of-file
open-line
insert-string "BibFile Cleaned: "
run insert-date
print "[Please check this has not messed up your file!]"
set $discmd TRUE
!endm
store-procedure get-bib-key
; get bibkey from current line, assuming "@name{key," synatax
set %b-key ""
!force search-forward "{"
!if ¬ $status
!return
!endif
set-mark
!force end-of-word
set %b-key $region
; print %b-key
!endm
store-procedure find-min-key
; return %m-key and %m-pos
set %m-key ""
set %m-pos 0
!force search-forward "@"
!if ¬ $status
!return
!endif
run get-bib-key
set %m-key %b-key
set %m-pos $curline
!while TRUE
!force search-forward "@"
!if ¬ $status
!break
!endif
run get-bib-key
!if &sless %b-key %m-key
set %m-key %b-key
set %m-pos $curline
!endif
!endwhile
; print &cat &cat %m-key " " %m-pos
!endm
store-procedure sort-bibfile
; sort a .bib file on the cite key
; uses %s-pos to remember the current position
; works through the file, doing an insertion sort on the %b-key
;
run query-save-all
set %l-tmp1 @"Do you really want to sort your entire bibTeX file? [n]: "
!if ¬ &sequal &lower %l-tmp1 "y"
!return
!endif
print "[Sorting BibTeX file. This may take a while...]"
set $discmd FALSE
beginning-of-file
!while TRUE
!force search-forward "@"
!if ¬ $status
!break
!endif
set %s-pos $curline
beginning-of-line
run find-min-key
; update-screen
; set %dummy @&cat &cat &cat %s-pos " " %m-pos
!if &greater %m-pos %s-pos
goto-line %m-pos
beginning-of-line
set-mark
end-of-line
!force search-forward "@"
!if ¬ $status
end-of-file
!else
beginning-of-line
!endif
kill-region
goto-line %s-pos
yank
!endif
goto-line %s-pos
end-of-line
!endwhile
beginning-of-file
open-line
insert-string "BibFile Sorted: "
run insert-date
print "[Please check this has not messed up your file!]"
set $discmd TRUE
!endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; LaTeX MENU ADDITIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; help
macro-to-key latex-help FN1
macro-to-key search-latex-help FN2
; debug
macro-to-key l-display-log FN3
macro-to-key l-find-error FN4
; environment pair
macro-to-key l-env-pair A-V
; super/subscripts
macro-to-key superscript-b A-^ ; ^{}
macro-to-key subscript-b A-_ ; _{}
; delimiter pairs -- you may want to personalize these key-bindings
macro-to-key curly-b A-{ ; {}
macro-to-key round-b A-( ; ()
macro-to-key square-b A-[ ; []
macro-to-key angle-b A-< ; \langle\rangle
macro-to-key vert-b A-| ; ||
macro-to-key d-vert-b A-\ ; \|\|
macro-to-key quote-b A-" ; ``''
macro-to-key slash-curly-b A-} ; \{\}
macro-to-key slash-round-b A-) ; \(\)
macro-to-key slash-square-b A-] ; \{\}
macro-to-key dollar-b A-$ ; $$
macro-to-key double-dollar-b ^XA-$ ; $$$$
macro-to-key sizable-curly-b ^XA-{ ; \left\{\right\}
macro-to-key sizable-square-b ^XA-[ ; \left[\right]
macro-to-key sizable-round-b ^XA-( ; \left(\right)
macro-to-key sizable-angle-b ^XA-< ; \left\langle\right\rangle
macro-to-key sizable-vert-b ^XA-| ; \left|\right|
macro-to-key sizable-d-vert-b ^XA-\ ; \left\|\right\|
!if ¬ %l-menus-loaded
print "[Setting up LaTeX Menus]"
macro-to-menu l-template ">&TeX@5>LaTeX &Input>&Templates"
macro-to-menu l-heading "&Headings"
macro-to-menu l-env-pair "En&vironments"
macro-to-menu dollar-b ">&TeX>LaTeX &Input>Math E&nvironments@3>$ $"
macro-to-menu double-dollar-b "$$ $$"
macro-to-menu slash-round-b "\( \)"
macro-to-menu slash-square-b "\[ \]"
macro-to-menu curly-b ">&TeX>LaTeX &Input>&Brackets@4>{ }"
macro-to-menu slash-curly-b "\{ \}"
macro-to-menu round-b "( )"
macro-to-menu square-b "[ ]"
macro-to-menu angle-b "\langle \rangle"
macro-to-menu vert-b "| |"
macro-to-menu d-vert-b "\| \|"
macro-to-menu quote-b "`` ''"
macro-to-menu l-taccents ">&TeX>LaTeX &Input>Te&xt@5>&Accents"
macro-to-menu l-tspecial "&Special Symbols"
macro-to-menu l-tforeign "&Foreign Symbols"
macro-to-menu superscript-b ">&TeX>LaTeX &Input>&Math@6>&Super/Subscripts>^{}"
macro-to-menu subscript-b "_{}"
macro-to-menu sizable-curly-b ">&TeX>LaTeX &Input>&Math>Variable &Brackets@1>left\{ \right\}"
macro-to-menu sizable-round-b "left( \right)"
macro-to-menu sizable-square-b "left[ \right]"
macro-to-menu sizable-angle-b "\left\langle \right\rangle"
macro-to-menu sizable-vert-b "left| \right|"
macro-to-menu sizable-d-vert-b "left\| \right\|"
macro-to-menu l-maccents ">&TeX>LaTeX &Input>&Math>&Accents@2"
macro-to-menu l-greek "&Greek"
macro-to-menu l-mbinops "Binary &Operators"
macro-to-menu l-mrel "&Relation Symbols"
macro-to-menu l-marrow "Arro&ws"
macro-to-menu l-mmisc "&Miscellanous"
macro-to-menu l-mloglike "&Log Like"
macro-to-menu l-mdelim "&Delimiters"
macro-to-menu l-mvarsym "&Variable Symbols"
macro-to-menu l-mline "Over/&Under Line"
macro-to-menu l-misc ">&TeX>LaTeX &Input>Mis&cellaneous@7"
macro-to-menu b-template ">&TeX>&BibTeX Input@1>&Templates"
macro-to-menu clean-bibitem "Clean Bib&Item"
macro-to-menu clean-bibfile "Clean Bib&File"
macro-to-menu sort-bibfile "&Sort BibFile"
macro-to-menu run-latex ">&TeX>E&xecute@2>&LaTeX"
macro-to-menu run-tex "&TeX"
macro-to-menu view-latex "&View"
macro-to-menu dvi2ps-latex "&DVI to PostScript"
macro-to-menu psview-latex "Post&Script Preview"
macro-to-menu print-latex "&Print"
macro-to-menu run-bibtex "&BibTeX"
macro-to-menu run-makeindex "&MakeIndex"
macro-to-menu clear-latex-file "&Clear Filename"
macro-to-menu l-display-log ">&TeX>&Debug@3>&Read Logfile"
macro-to-menu l-find-error "&Find Next Error"
macro-to-menu latex-help ">&TeX>&Help@4>&LaTeX Commands"
macro-to-menu search-latex-help "&Search LaTeX Commands"
macro-to-menu view-charset "&Character Set"
macro-to-menu tex-info "&TeX Information"
macro-to-menu interface-help "&MicroEMACS Interface"
macro-to-menu installation-help "MicroEMACS I&nstallation"
!endif
set %l-menus-loaded "TRUE" ; so menu commands are only done once.
print "[LaTeX Interface Loaded]"
set $discmd TRUE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|