summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/psfragx/laprint.m
blob: badef843362f814703e396dbfb455bddccb0f37a (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
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
function laprint(figno,filename,varargin)
%LAPRINT prints a figure for inclusion in LaTeX documents.
%  LaPrint creates an eps-file and a tex-file. The tex-file contains
%  the annotation of the figure such as titles, labels and texts. The
%  eps-file contains the non-text part of the figure as well as the 
%  position of the text-objects. The packages 'graphicx' (or 'epsfig')
%  and 'psfrag' (and possibly ''color'') are required for the LaTeX 
%  run. A postscript driver like 'dvips' is required for printing. 
%
%  Usage:   >> laprint
%
%  This opens a graphical user interface window, to control the
%  various settings. It includes a help facility. Just try it.
%
%  As an alternative to the GUI you can call laprint from the command
%  line with various extra input arguments. These arguments are 
%  explained in the help window of the GUI, which can be also be 
%  opened using the command
%      >> laprint helpwindow
%
%  There is an Users Guide available at
%      http://www.uni-kassel.de/fb16/rat/matlab/laprint/laprintdoc.ps  

%  (c) Arno Linnemann.   All rights reserved. 
%  The author of this program assumes no responsibility for any  errors 
%  or omissions. In no event shall he be liable for damages  arising out of 
%  any use of the software. Redistribution of the unchanged file is allowed.
%  Distribution of changed versions is allowed provided the file is renamed
%  and the source and authorship of the original version is acknowledged in 
%  the modified file.

%  Please report bugs, suggestions and comments to:
%  Arno Linnemann
%  Control and Automation
%  Department of Electrical and Computer Engineering 
%  University of Kassel
%  34109 Kassel
%  Germany
%  mailto:linnemann@uni-kassel.de

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% Initialize
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

laprintident = '3.16 (13.9.2004)';   
vers = version;
vers = eval(vers(1:3));
if vers < 6.1
  error('Sorry. Matlab 6.1 or above is required.')
end

hf=131;
hhf=132;

% no output
if nargout
   error('No output argument, please.')
end  

inter=get(0,'defaulttextinterpreter');
if ~strcmp(inter,'none')
  warning('LaPrint:general',['It is recommended to switch off the '...
          'text interpreter\nbefore creating a figure to be saved '...
          'with LaPrint. Use the command\n',...
          '   >> set(0,''defaulttextinterpreter'',''none'').'])
end

if nargin==0

   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %%%%
   %%%% GUI
   %%%%
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   try
     delete(hf) 
   end 
   try
     delete(hhf) 
   end 

   %---------------------------------
   % open window
   %---------------------------------

   hf = figure(hf);
   clf reset;
   set(hf,'NumberTitle','off',...
          'Name','LaPrint (LaTeX Print)',...
          'Units','points',...
          'CloseRequestFcn','laprint(''quit'');',...
          'menubar','none')
   h = uicontrol('Parent',hf,'Units','points');
   fsize = get(h,'Fontsize');
   delete(h)
   posf = get(hf,'Position');
   figheight = 10*fsize;
   figwidth  = 32*fsize; 
   posf = [ posf(1) posf(2)+posf(4)-figheight figwidth figheight];
   set(hf,'Position',posf)
   uicontrol('Parent',hf,'style','frame','Units','points',...
	  'Position',[0 0 figwidth figheight])
   curh = figheight-0*fsize;

   LAPRINTHAN=struct('figno',{0},'filename',{0},...
      'keepfontprops',{0},'asonscreen',{0},'keepticklabels',{0},...
      'mathticklabels',{0},'head',{0},'extrapicture',{0},...
      'verbose',{0},'figcopy',{0},'package_epsfig',{0},...
      'package_graphicx',{0},'color',{0},'createview',{0},...
      'processview',{0});
  
   %---------------------------------
   % figure no.
   %---------------------------------

   loch = 1.7*fsize;
   curh = curh-loch-1.5*fsize;
   h = uicontrol('Parent',hf,...
                 'style','text',...
                 'Units','points',...
                 'Position',[1*fsize curh 18*fsize loch],...
                 'HorizontalAlignment','left',...
                 'string','Number of Figure to be saved:');
   h = uicontrol('Parent',hf,...
                 'style','edit',...
                 'Units','points',...
                 'Position',[19*fsize curh 12*fsize loch],...
                 'HorizontalAlignment','left',...
                 'BackgroundColor',[1 1 1],...
                 'Callback','laprint(''figno'');');
   LAPRINTHAN.figno = h;

   %---------------------------------
   % filename
   %---------------------------------

   loch = 1.7*fsize;
   curh = curh-loch-1*fsize;
   h = uicontrol('Parent',hf,...
                 'style','text',...
                 'Units','points',...
                 'Position',[1*fsize curh 18*fsize loch],...
                 'HorizontalAlignment','left',...
                 'string','Basename of Files to be Created:');
   h = uicontrol('Parent',hf,...
                 'style','edit',...
                 'Units','points',...
                 'Position',[19*fsize curh 12*fsize loch],...
                 'HorizontalAlignment','left',...
                 'BackgroundColor',[1 1 1],...
                 'Callback','laprint(''filename'');');
   LAPRINTHAN.filename = h;

   %---------------------------------
   % save, quit
   %---------------------------------

   loch = 2*fsize;
   curh = curh-loch-1*fsize;
   h = uicontrol('Parent',hf,...
                 'Style','pushbutton',...
                 'Units','Points',...
                 'Position',[19*fsize curh 5*fsize loch],...
                 'HorizontalAlignment','center',...
                 'String','Go !',...
                 'Callback','laprint(''save'');');
   h = uicontrol('Parent',hf,...
                 'Style','pushbutton',...
                 'Units','Points',...
                 'Position',[26*fsize curh 5*fsize loch],...
                 'HorizontalAlignment','center',...
                 'String','Quit',...
                 'Callback','laprint(''quit'');');

   %---------------------------------
   % options uimenue
   %---------------------------------

   hm1 = uimenu('label','Options');

   uimenu(hm1,...
       'label','Sizes and Scalings ...',...
       'callback','laprint(''size'')');

   LAPRINTHAN.keepfontprops = uimenu(hm1,...
       'label','Translate Matlab Font Properties to LaTeX',...
       'callback','laprint(''keepfontprops'')');

   LAPRINTHAN.asonscreen = uimenu(hm1,...
       'label','Print Limits and Ticks as on Screen',...
       'separator','on',...
       'callback','laprint(''asonscreen'')');

   LAPRINTHAN.keepticklabels = uimenu(hm1,...
       'label','Keep Tick Labels within eps File',...
       'callback','laprint(''keepticklabels'')');

   LAPRINTHAN.mathticklabels = uimenu(hm1,...
       'label','Set Tick Labels in LaTeX Math Mode',...
       'callback','laprint(''mathticklabels'')');

   LAPRINTHAN.head = uimenu(hm1,...
       'label','Equip the tex File with a Head',...
       'separator','on',...
       'callback','laprint(''head'')');

   uimenu(hm1,...
       'label','Comment in the Head of the tex File ...',...
       'callback','laprint(''comment'')');

   uimenu(hm1,...
       'label','Place a LaTeX Caption in the tex File ...',...
       'callback','laprint(''caption'')');

   LAPRINTHAN.extrapicture = uimenu(hm1,...
       'label','Place an Extra Picture in each Axes',...
       'callback','laprint(''extrapicture'')');

   uimenu(hm1,...
       'label','Length of psfrag Replacement Strings ...',...
       'callback','laprint(''nzeros'')');

   LAPRINTHAN.verbose = uimenu(hm1,...
       'label','Call LaPrint in Verbose Mode',...
       'separator','on',...
       'callback','laprint(''verbose'')');

   LAPRINTHAN.figcopy = uimenu(hm1,...
       'label','Copy Figure and Modify that Copy',...
       'callback','laprint(''figcopy'')');

   uimenu(hm1,...
       'label','Matlab Print Command ...',...
       'separator','on',...
       'callback','laprint(''printcmd'')');

   h=uimenu(hm1,...
       'separator','on',...
       'label','LaTeX Graphics Package');
   
   LAPRINTHAN.package_graphicx = uimenu(h,...
       'label','graphicx',...
       'callback','laprint(''package_graphicx'')');
   
   LAPRINTHAN.package_epsfig = uimenu(h,...
       'label','epsfig',...
       'callback','laprint(''package_epsfig'')');
     
   LAPRINTHAN.color = uimenu(hm1,...
       'label','Use LaTeX ''color'' Package',...
       'callback','laprint(''color'')');
  
   h = uimenu(hm1,...
       'label','View File ...',...
       'separator','on');
 
   LAPRINTHAN.createview = uimenu(h,...
       'label','Create a View File',...
       'callback','laprint(''createview'')');
  
   uimenu(h,...
       'label','Name of the View File ...',...
       'callback','laprint(''viewfilename'')');

   LAPRINTHAN.processview = uimenu(h,...
       'label','Process the View File',...
       'separator','on',...
       'callback','laprint(''processview'')');

   uimenu(h,...
       'label','Executables for Processing View File...',...
       'callback','laprint(''cmdsview'')');

   %---------------------------------
   % Preferences uimenue
   %---------------------------------
     
   hm3=uimenu('label','Preferences');
     
   uimenu(hm3,...
       'label','Get Preferences',...
       'callback','laprint(''getpref'')')
   
   uimenu(hm3,...
       'label','Set Preferences to Current Settings',...
       'callback','laprint(''setpref'')')
   
   uimenu(hm3,...
       'label','Remove Preferences',...
       'callback','laprint(''rmpref'')')
   
   uimenu(hm3,...
       'label','Save Current Settings to a File ...',...
       'separator','on',...
       'callback','laprint(''savepref'')')
   
   uimenu(hm3,...
       'label','Load Settings from a File ...',...
       'callback','laprint(''loadpref'')')
   
   uimenu(hm3,...
       'label','Get Factory Defaults',...
       'separator','on',...
       'callback','laprint(''factory'')')

  
   %---------------------------------
   % Help uimenue
   %---------------------------------
   
   hm2=uimenu('label','Help');
   
   uimenu(hm2,...
       'label',['LaPrint Online Help ...'],...
       'callback','laprint(''helpwindow'')');
  
   uimenu(hm2,...
       'label','Get the LaPrint Users Guide',...
       'callback',['web www.uni-kassel.de/fb16/rat/matlab',...
                   '/laprint/laprintdoc.ps -browser'])
    
   uimenu(hm2,...
       'label',['Look for a newer version of LaPrint ' ...
           '(Matlab Central File Exchange)...'],...
       'callback',['web http://www.mathworks.de/matlabcentral/',...
                      'fileexchange/loadFile.do?objectId=4638',...
                      '&objectType=file -browser'])
    
   uimenu(hm2,...
       'label','Version and Author ...',...
       'callback','laprint(''whois'')')

   %---------------------------------
   % make hf invisible
   %---------------------------------

   set(hf,'HandleVisibility','callback') 

   %---------------------------------
   % get settings
   %---------------------------------
 
   LAPRINTOPT = prefsettings;
   if isempty(LAPRINTOPT)
      LAPRINTOPT = factorysettings;
   end  

   %---------------------------------
   % get figure
   %---------------------------------
    
   gcfig=gcf;
   if gcfig == hf
       allfigs = findobj('type','figure');
       allfigs = allfigs(find(allfigs~=hf));
       if length(allfigs)
          figno = allfigs(1);
       else
          figure(1)
          figno=1;
       end    
   else
       figno=gcfig;
   end
   LAPRINTOPT.figno = figno;

   %---------------------------------
   % update
   %---------------------------------
  
   updategui(LAPRINTHAN,LAPRINTOPT)
   sethf(hf,LAPRINTHAN,LAPRINTOPT)
   figure(hf)

   %---------------------------------
   % done
   %---------------------------------

   return
   
end  % if nargin==0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% callback calls ('factory' and 'getprefs' also 
%%%%                  used from command line)
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isa(figno,'char') 

  switch figno
  case 'figno'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    LAPRINTOPT.figno=eval(get(LAPRINTHAN.figno,'string'));
    figure(LAPRINTOPT.figno)
    figure(hf)
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'filename'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    LAPRINTOPT.filename=get(LAPRINTHAN.filename,'string');
    [texfullnameext,texbasenameext,texbasename,texdirname] = ...
	getfilenames(LAPRINTOPT.filename,'tex',0);
    [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
	getfilenames(LAPRINTOPT.filename,'eps',0);
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'save'
%     lapcmd = [ 'laprint(' int2str(LAPRINTOPT.figno) ...
% 	   ', ''' LAPRINTOPT.filename ''''...
% 	   ', ''options'', LAPRINTOPT)'];
    lapcmd = 'laprint({})';
    eval(lapcmd)
  case 'quit'
    delete(hf)
    try
      delete(hhf)
    end
  case 'size'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    answer = inputdlg({['Please enter the width (in centimeters) ',...
         'of the graphics in the LaTeX document (The height ',...
         'will be computed such that the aspect ratio of the ',...
         'figure on screen is retained.) :'],...
         ['Please enter the factor by which the size of the '...
         'graphics in the LaTeX document differs from the size of the '...
         'Postscipt graphics ( Explaination: A factor <1 scales ',...
         'the picture down. This means that lines become thinner ',...
         'and fonts become smaller. ) :'],...
         ['Please specify if you want to scale the fonts along with ',...
         'the graphics (enter ''on'' or ''off'') : '] },...
         'LaPrint Settings',1,{num2str(LAPRINTOPT.width),...
         num2str(LAPRINTOPT.factor),...
         valueyn(LAPRINTOPT.scalefonts)},'on');
    if length(answer)
         LAPRINTOPT.width=eval(answer{1});
         LAPRINTOPT.factor = eval(answer{2});
         LAPRINTOPT.scalefonts = value01(answer{3});
    end
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'keepfontprops'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.keepfontprops==1
      LAPRINTOPT.keepfontprops=0;
      set(LAPRINTHAN.keepfontprops,'check','off')
    else
      LAPRINTOPT.keepfontprops=1;
      set(LAPRINTHAN.keepfontprops,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'asonscreen'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.asonscreen==1
      LAPRINTOPT.asonscreen=0;
      set(LAPRINTHAN.asonscreen,'check','off')
    else
      LAPRINTOPT.asonscreen=1;
      set(LAPRINTHAN.asonscreen,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'keepticklabels'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.keepticklabels==1
      LAPRINTOPT.keepticklabels=0;
      set(LAPRINTHAN.keepticklabels,'check','off')
    else
      LAPRINTOPT.keepticklabels=1;
      set(LAPRINTHAN.keepticklabels,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'mathticklabels'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.mathticklabels==1
      LAPRINTOPT.mathticklabels=0;
      set(LAPRINTHAN.mathticklabels,'check','off')
    else
      LAPRINTOPT.mathticklabels=1;
      set(LAPRINTHAN.mathticklabels,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'head'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.head==1
      LAPRINTOPT.head=0;
      set(LAPRINTHAN.head,'check','off')
    else
      LAPRINTOPT.head=1;
      set(LAPRINTHAN.head,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'comment'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    answer = inputdlg({['Please enter a describing comment to '...
         'be placed into the head of the tex file:']},...
         'LaPrint Settings',1,{LAPRINTOPT.comment},'on');
    if length(answer)
         LAPRINTOPT.comment = answer{1};
    end
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'caption'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    answer = inputdlg(['If the following text is nonempty, ' ...
         'then it will be placed as a \caption{} into the tex '...
         'file along with \label{fig:' LAPRINTOPT.filename '}. '...
         'Please enter the caption text:'],...
         'LaPrint Settings',1,{LAPRINTOPT.caption},'on');
    if length(answer)
         LAPRINTOPT.caption = answer{1};
    end
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'extrapicture'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.extrapicture==1
      LAPRINTOPT.extrapicture=0;
      set(LAPRINTHAN.extrapicture,'check','off')
    else
      LAPRINTOPT.extrapicture=1;
      set(LAPRINTHAN.extrapicture,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'nzeros'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    answer = inputdlg({['Please enter length of the psfrag replacement '...
         'strings (must be >= 3) :']},...
         'LaPrint Settings',1,{num2str(LAPRINTOPT.nzeros)},'on');
    if length(answer)
        LAPRINTOPT.nzeros = max(eval(answer{1}),3);
    end
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'verbose'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.verbose==1
      LAPRINTOPT.verbose=0;
      set(LAPRINTHAN.verbose,'check','off')
    else
      LAPRINTOPT.verbose=1;
      set(LAPRINTHAN.verbose,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'figcopy'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.figcopy==1
      LAPRINTOPT.figcopy=0;
      set(LAPRINTHAN.figcopy,'check','off')
    else
      LAPRINTOPT.figcopy=1;
      set(LAPRINTHAN.figcopy,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'printcmd'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    answer = inputdlg({['Please enter the Matlab command '...
         'to be used for printing the eps file '...
         '(LaPrint will internally replace <figurenumber> by the '...
         'number of the figure <filename.eps> by the ' ... 
         'eps-filename and <filename> '...
         'by the basename of the file, respectively). You can add options '...
         'here (like ''-loose'') or use a different program '...
         'for printing (like ''exportfig'') :']},...
         'LaPrint Settings',1,{LAPRINTOPT.printcmd},'on');
    if length(answer)
         LAPRINTOPT.printcmd = answer{1};
    end
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'package_epsfig'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    LAPRINTOPT.package='epsfig';
    set(LAPRINTHAN.package_epsfig,'check','on')
    set(LAPRINTHAN.package_graphicx,'check','off')
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'package_graphicx'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    LAPRINTOPT.package='graphicx';
    set(LAPRINTHAN.package_epsfig,'check','off')
    set(LAPRINTHAN.package_graphicx,'check','on')
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'color'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.color==1
      LAPRINTOPT.color=0;
      set(LAPRINTHAN.color,'check','off')
    else
      LAPRINTOPT.color=1;
      set(LAPRINTHAN.color,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'createview'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.createview==1
      LAPRINTOPT.createview=0;
      LAPRINTOPT.processview=0;
      set(LAPRINTHAN.createview,'check','off')
      set(LAPRINTHAN.processview,'check','off')
    else
      LAPRINTOPT.createview=1;
      set(LAPRINTHAN.createview,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'viewfilename'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
      trydlg=1;
      txt=['Please enter the name of the '...
          'viewfile (without extension .tex) : '];
      txt2='';
      while trydlg
        answer = inputdlg({[txt txt2]},...
          'LaPrint Settings',1,{LAPRINTOPT.viewfilename},'on');
        if length(answer)
          if strcmp(answer{1},LAPRINTOPT.filename)
            txt2=['The name must be different from the name of the '...
                  'graphics file):'];
          else
             trydlg=0;  
             LAPRINTOPT.viewfilename = answer{1};
             [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
  	                getfilenames(LAPRINTOPT.viewfilename,'tex',0);
         end      
        else
          trydlg=0;
        end  
      end
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'processview'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    if LAPRINTOPT.processview==1
      LAPRINTOPT.processview=0;
      set(LAPRINTHAN.processview,'check','off')
    else
      LAPRINTOPT.processview=1;
      set(LAPRINTHAN.processview,'check','on')
      LAPRINTOPT.createview=1;
      set(LAPRINTHAN.createview,'check','on')
    end      
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'cmdsview'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    answer = inputdlg({...
       ['Please enter up to 8 commands to process the view-file. ',...
       'Leave any of the fields empty, if you have ',...
       'less than 8 commands. ',...  
       'In any of the following commands, LaPrint internally '...
       'replaces the tag <viewfile> by the name of the viewfile ',...
       'and the tag <filename> by the basename specified in the ',...
       'main LaPrint Window. ',...
       'At minimum you should enter the commands for the LaTeX ',...
       'compilation and for the dvi-to-postscript conversion ',...
       'here. See the LaPrint Online-Help for futher ',...
       'suggestions.   ',...
       'Please enter the 1st command:'],...
       'Please enter the 2nd command:',...
       'Please enter the 3rd command:',...
       'Please enter the 4th command:',...
       'Please enter the 5th command:',...
       'Please enter the 6th command:',...
       'Please enter the 7th command:',...
       'Please enter the 8th command:'},...
       'LaPrint Settings',1,{LAPRINTOPT.cmd1,...
       LAPRINTOPT.cmd2,LAPRINTOPT.cmd3,...
       LAPRINTOPT.cmd4,LAPRINTOPT.cmd5,LAPRINTOPT.cmd6,...
       LAPRINTOPT.cmd7,LAPRINTOPT.cmd8},'on');
    if length(answer)==8
       LAPRINTOPT.cmd1=answer{1};
       LAPRINTOPT.cmd2=answer{2};
       LAPRINTOPT.cmd3=answer{3};
       LAPRINTOPT.cmd4=answer{4};
       LAPRINTOPT.cmd5=answer{5};
       LAPRINTOPT.cmd6=answer{6};
       LAPRINTOPT.cmd7=answer{7};
       LAPRINTOPT.cmd8=answer{8};
    end   
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'getpref'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    out = prefsettings;
    if ~isempty(out)
       oldfigno = LAPRINTOPT.figno;   % keep this!         
       LAPRINTOPT = out;
       LAPRINTOPT.figno = oldfigno;        
    else
       errordlg('No LaPrint preferences available.')   
    end
    updategui(LAPRINTHAN,LAPRINTOPT);
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'setpref'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    setpref('LaPrint','LAPRINTOPT',LAPRINTOPT);
  case 'rmpref'
    if ispref('LaPrint')
      rmpref('LaPrint');
    else
      errordlg('Preference does not exist.')   
    end
  case 'savepref'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    txt = 'Save preferences file ';
    [preffile,prefpath]=uiputfile('laprint.mat',txt);
    save([prefpath preffile],'LAPRINTOPT');
  case 'loadpref'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    txt = ['Load preferences file '...
           '(must be previously created by LaPrint)'];
    [preffile,prefpath]=uigetfile('laprint.mat',txt);
    if ~isequal(preffile,0) & ~isequal(prefpath,0)
      oldfigno = LAPRINTOPT.figno;   % keep this!         
      load([prefpath preffile]); % hope file contains correct
      LAPRINTOPT.figno = oldfigno;                   % LAPRINTOPT
      updategui(LAPRINTHAN,LAPRINTOPT);
      sethf(hf,LAPRINTHAN,LAPRINTOPT);
    end
  case 'factory'
    [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
    out = factorysettings;
    if ~isempty(out)
       oldfigno = LAPRINTOPT.figno;   % keep this!         
       LAPRINTOPT = out;
       LAPRINTOPT.figno = oldfigno;        
    else
       errordlg('No LaPrint preferences available.')   
    end
    updategui(LAPRINTHAN,LAPRINTOPT);
    sethf(hf,LAPRINTHAN,LAPRINTOPT);
  case 'helpwindow'
    hhf=figure(hhf);
    set(hhf,'Name','LaPrint Online Help',...
            'Numbertitle','off',...
            'menubar','none',...
            'HandleVisibility','callback',... 
            'resize','on',...
            'ResizeFcn','laprint(''helpwindow'');');
    hht=uicontrol('Parent',hhf,...
              'style','listbox',...
              'units','normalized',...
              'position',[0.005 0.005 0.9 0.99],...
              'BackgroundColor','w',...
              'Fontsize',12,...
              'foregroundcolor','k',...
              'FontName','FixedWidth',...
              'HorizontalAlignment','left');
    [txt,hhtpos]=textwrap(hht,helptext);
    set(hht,'string',txt)
    set(hht,'position',[0.005 0.005 0.99 0.99])
    set(hht,'HandleVisibility','callback') 
  case 'whois'
    msgbox({['This is LaPrint, Version ' laprintident],...
          '',...
          'To blame for LaPrint:',...
	      'Arno Linnemann','Control and Automation',...
	      'Department of Electrical and Computer Engineering',...
	      'University of Kassel',...
	      '34109 Kassel',...      
	      'Germany',...
          'mailto:linnemann@uni-kassel.de'},...
          'LaPrint Info')
  otherwise 
    error('unknown callback option')
  end
  return 
end    % if isa(figno,'char') 

% nargin >=1 and ~isa(figno,'char')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% PART 1 of advanced usage:
%%%% Check inputs and initialize
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isa(figno,'cell') % called from GUI (all set)

  [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  figno=LAPRINTOPT.figno;
  filename=LAPRINTOPT.filename;

else % advanced usage
  
  % get settings 
  LAPRINTOPT = prefsettings;
  if isempty(LAPRINTOPT)
     LAPRINTOPT = factorysettings;
  end

  % modify prefs
  if ~isa(figno,'double') 
    figno
    error('This is not a figure handle.') 
  end
  if ~any(get(0,'children')==figno)
    figno
    error('This is not a figure handle.') 
  end
  LAPRINTOPT.figno = figno;

  if nargin>1
    if ~isa(filename,'char')  
      filename
      error('This is not a file name.') 
    end
    LAPRINTOPT.filename=filename; 
  end    
end

% read and check command line options  

try  % try old usage (Version 2.03)
   if nargin <=2
      error('lets take new usage')
   end
   % 2.03 defaults
   width           = 12;
   factor          = 0.8;
   scalefonts      = 1;
   keepfontprops   = 0;
   asonscreen      = 0;
   keepticklabels  = 0;
   mathticklabels  = 0;
   head            = 1;
   comment         = '';
   caption         = '';
   extrapicture    = 1;
   nzeros          = 5;
   verbose         = 0;
   figcopy         = 1;
   printcmd        = ['print(''-f<figurenumber>'',' ...
                      '''-deps'',''<filename.eps>'')'];
   package         = 'epsfig';
   color           = 0;
   createview      = 0;
   viewfilename    = [filename '_'];
   processview     = 0;
   cmd1            = '';
   cmd2            = '';
   cmd3            = '';
   cmd4            = '';
   cmd5            = '';
   cmd6            = '';
   cmd7            = '';
   cmd8            = '';
   for i=1:nargin-2
    if ~isa(varargin{i},'char')
      error('Options must be character arrays.')
    end  
    oriopt=varargin{i}(:)';
    opt=[ lower(strrep(oriopt,' ','')) '                   ' ];
    if strcmp(opt(1:7),'verbose')
      verbose=1;
    elseif strcmp(opt(1:10),'asonscreen')
      asonscreen=1;
    elseif strcmp(opt(1:14),'keepticklabels')
      keepticklabels=1;
    elseif strcmp(opt(1:14),'mathticklabels')
      mathticklabels=1;
    elseif strcmp(opt(1:13),'keepfontprops')
      keepfontprops=1;
    elseif strcmp(opt(1:14),'noextrapicture')
      extrapicture=0;
    elseif strcmp(opt(1:14),'noextrapicture')
      extrapicture=0;
    elseif strcmp(opt(1:5),'loose')
      printcmd = ['print(''-f<figurenumber>'',' ...
                      '''-deps'',''-loose'',''<filename.eps>'')'];
    elseif strcmp(opt(1:9),'nofigcopy')
      figcopy=0;
    elseif strcmp(opt(1:12),'noscalefonts')
      scalefonts=0;
    elseif strcmp(opt(1:6),'nohead')
      head=0;
    elseif strcmp(opt(1:7),'caption')
      eqpos=findstr(oriopt,'=');
      if isempty(eqpos)
	    caption='Matlab Figure';
      else	
	    caption=oriopt(eqpos+1:length(oriopt));
      end	
    elseif strcmp(opt(1:8),'comment=')
      eqpos=findstr(oriopt,'=');
      comment=oriopt(eqpos(1)+1:length(oriopt));
    elseif strcmp(opt(1:9),'viewfile=')
      createview=1;
      eqpos=findstr(oriopt,'=');
      viewfilename=oriopt(eqpos(1)+1:length(oriopt));
    elseif strcmp(opt(1:6),'width=')
      eval([ opt ';' ]);
    elseif strcmp(opt(1:7),'factor=')
      eval([ opt ';' ]);
    else
      error([ 'Option ' varargin{i} ' not recognized.'])
    end   
  end
 
  warning('LaPrint:general',['You are using the old LaPrint '...
          'syntax. This syntax might not be supported in '...
          'future releases of LaPrint.'])

catch % old usage doesn't work, take new one
  
  % restore preferences / factory defaults
  width           = LAPRINTOPT.width;
  factor          = LAPRINTOPT.factor;
  scalefonts      = LAPRINTOPT.scalefonts;
  keepfontprops   = LAPRINTOPT.keepfontprops;
  asonscreen      = LAPRINTOPT.asonscreen;
  keepticklabels  = LAPRINTOPT.keepticklabels;
  mathticklabels  = LAPRINTOPT.mathticklabels;
  head            = LAPRINTOPT.head;
  comment         = LAPRINTOPT.comment;
  caption         = LAPRINTOPT.caption;
  extrapicture    = LAPRINTOPT.extrapicture;
  nzeros          = LAPRINTOPT.nzeros;
  verbose         = LAPRINTOPT.verbose;
  figcopy         = LAPRINTOPT.figcopy;
  printcmd        = LAPRINTOPT.printcmd;
  package         = LAPRINTOPT.package;
  color           = LAPRINTOPT.color;
  createview      = LAPRINTOPT.createview;
  viewfilename    = LAPRINTOPT.viewfilename;
  processview     = LAPRINTOPT.processview;
  cmd1            = LAPRINTOPT.cmd1;
  cmd2            = LAPRINTOPT.cmd2;
  cmd3            = LAPRINTOPT.cmd3;
  cmd4            = LAPRINTOPT.cmd4;
  cmd5            = LAPRINTOPT.cmd5;
  cmd6            = LAPRINTOPT.cmd6;
  cmd7            = LAPRINTOPT.cmd7;
  cmd8            = LAPRINTOPT.cmd8;

  if nargin > 2
    if rem(nargin,2)
      error('Option names/values must appear in pairs.')
    end    
    for i=1:2:nargin-2
      if ~isa(varargin{i},'char')
         error('Option name must be a character array.')
      end  
      opt = lower(strrep(varargin{i}(:)',' ',''));
      val = varargin{i+1}(:)';
      switch opt
        case 'options'      
          if isa(val,'char')
            if strcmp(val,'factory')
              val = factorysettings;
            else
              load(val)
              val = LAPRINTOPT;
            end
          end
          if ~isa(val,'struct')
            error('Value of options must be a structure array.')
          end  
          % no error checking here!
          width           = val.width;
          factor          = val.factor;
          scalefonts      = val.scalefonts;
          keepfontprops   = val.keepfontprops;
          asonscreen      = val.asonscreen;
          keepticklabels  = val.keepticklabels;
          mathticklabels  = val.mathticklabels;
          head            = val.head;
          comment         = val.comment;
          caption         = val.caption;
          extrapicture    = val.extrapicture;
          nzeros          = val.nzeros;
          verbose         = val.verbose;
          figcopy         = val.figcopy;
          printcmd        = val.printcmd;
          package         = val.package;
          color           = val.color;
          createview      = val.createview;
          viewfilename    = val.viewfilename;
          processview     = val.processview;
          cmd1            = val.cmd1;
          cmd2            = val.cmd2;
          cmd3            = val.cmd3;
          cmd4            = val.cmd4;
          cmd5            = val.cmd5;
          cmd6            = val.cmd6;
          cmd7            = val.cmd7;
          cmd8            = val.cmd8;
        case 'width'     
          if ~isa(val,'double')  
            error('Value of width must be a double.')
          end  
          width = val;  
        case 'factor'     
          if ~isa(val,'double')  
            error('Value of factor must be a double.')
          end  
          factor=val;  
        case 'scalefonts'
          scalefonts = value01(val,opt); 
        case 'keepfontprops'
          keepfontprops = value01(val,opt); 
        case 'asonscreen'     
          asonscreen = value01(val,opt);
        case 'keepticklabels'
          keepticklabels = value01(val,opt); 
        case 'mathticklabels'
          mathticklabels = value01(val,opt) ;
        case 'head'
          head = value01(val,opt); 
        case 'comment'
          if ~isa(val,'char')
            error('Value of comment must be a character array.')
          end
          comment = val;
        case 'caption'
          if ~isa(val,'char')
            error('Value of caption must be a character array.')
          end
          caption = val;
        case 'extrapicture'
          extrapicture = value01(val,opt); 
        case 'nzeros'     
          if ~isa(val,'double')  
            error('Value of nzeros must be a double.')
          end  
          nzeros = val;
        case 'verbose'
          verbose = value01(val,opt);
        case 'figcopy'
          figcopy = value01(val,opt); 
        case 'printcmd'
          if ~isa(val,'char')
            error('Value of printcmd must be a character array.')
          end
          printcmd = val;
        case 'package'
          if ~isa(val,'char')
            error('Value of package must be a character array.')
          end
          val = lower(strrep(val,' ',''));
          switch val
            case {'graphicx','epsfig'}
              % fine
            otherwise
              error('Value of package is unknown.')
          end  
          package = val;
        case 'color'
          color = value01(val,opt); 
        case 'createview'
          createview = value01(val,opt);
        case 'viewfilename'
          if ~isa(val,'char')
            error('Value of viewfilename must be a character array.')
          end
          viewfilename = val;
        case 'processview'
          processview = value01(val,opt); 
        case 'cmd1'
          if ~isa(val,'char')
            error('Value of cmd1 must be a character array.')
          end
          cmd1 = val;
        case 'cmd2'
          if ~isa(val,'char')
            error('Value of cmd2 must be a character array.')
          end
          cmd2 = val;
        case 'cmd3'
          if ~isa(val,'char')
            error('Value of cmd3 must be a character array.')
          end
          cmd3 = val;
        case 'cmd4'
          if ~isa(val,'char')
            error('Value of cmd4 must be a character array.')
          end
          cmd4 = val;
        case 'cmd5'
          if ~isa(val,'char')
            error('Value of cmd5 must be a character array.')
          end
          cmd5 = val;
        case 'cmd6'
          if ~isa(val,'char')
            error('Value of cmd6 must be a character array.')
          end
          cmd6 = val;
        case 'cmd7'
          if ~isa(val,'char')
            error('Value of cmd7 must be a character array.')
          end
          cmd7 = val;
        case 'cmd8'
          if ~isa(val,'char')
            error('Value of cmd8 must be a character array.')
          end
          cmd8 = val;
        otherwise
          error(['Option ''' opt ''' unknown'])
      end % switch opt
    end % for i=3:2:nargin 
  end % if nargin > 2
end % try / catch    

if verbose, 
  disp([ 'This is LaPrint, version ' laprintident '.' ]); 
end  

comment   = strrep(strrep(comment,'\','\\'),'%','%%');
caption   = strrep(strrep(caption,'\','\\'),'%','%%');
iscaption = logical(length(caption));

if nzeros < 3
  warning('LaPrint:general',...
          'The value of nzero should be >=3. I will use nzeros=3.')
  nzeros=3;  
end

if processview 
  createview=1;
end

if mathticklabels
  Do='$';
else  
  Do='';
end  

% eps- and tex- filenames
[epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
                       getfilenames(filename,'eps',verbose);
[texfullnameext,texbasenameext,texbasename,texdirname] = ...
                       getfilenames(filename,'tex',verbose);
if ~strcmp(texdirname,epsdirname)
   warning('LaPrint:files',['The eps-file and tex-file are '...
          'placed in different directories.']);
end

if createview | processview
  [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
                       getfilenames(viewfilename,'tex',verbose);
  if strcmp(texfullnameext,viewfullnameext)
    viewfilename=[ viewfilename '_'];
    warning('LaPrint:files',['The tex- and view-file coincide. '... 
           'I''ll use '' ' viewfilename ' ''. Hope that''s ok.' ])
  end  
  [viewfullnameext,viewbasenameext,viewbasename,viewdirname]= ...
                       getfilenames(viewfilename,'tex',verbose);
  if ~strcmp(texdirname,viewdirname)
    warning('LaPrint:files',['The eps-file and view-file are '...
	   'placed in different directories.' ])
  end  
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% PART 2 of advanced usage:
%%%% Create new figure, insert tags, and bookkeep original text
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% show all
shh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on');

% preparing check for copyobj bug
figno_ori = figno;
number_children_ori = length(get(figno_ori,'children'));

% open new figure (if required) and set properties
if figcopy
  figno = copyobj(figno,0);
  set(figno,'visible','off')
  set(figno,'Numbertitle','off')
  set(figno,'MenuBar','none')
  pause(0.5)
end  

if asonscreen  
  xlimmodeauto       = findobj(figno,'xlimmode','auto');
  xtickmodeauto      = findobj(figno,'xtickmode','auto');
  xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
  ylimmodeauto       = findobj(figno,'ylimmode','auto');
  ytickmodeauto      = findobj(figno,'ytickmode','auto');
  yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
  zlimmodeauto       = findobj(figno,'zlimmode','auto');
  ztickmodeauto      = findobj(figno,'ztickmode','auto');
  zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
  set(xlimmodeauto,'xlimmode','manual')
  set(xtickmodeauto,'xtickmode','manual')
  set(xticklabelmodeauto,'xticklabelmode','manual')
  set(ylimmodeauto,'ylimmode','manual')
  set(ytickmodeauto,'ytickmode','manual')
  set(yticklabelmodeauto,'yticklabelmode','manual')
  set(zlimmodeauto,'ylimmode','manual')
  set(ztickmodeauto,'ytickmode','manual')
  set(zticklabelmodeauto,'yticklabelmode','manual')
end  
set(figno,'paperunits','centimeters');
set(figno,'units','centimeters');
orip = get(figno,'Position');

% determine width and height
if factor <= 0
  factor = width/orip(3);
end 
latexwidth = width;
epswidth   = latexwidth/factor;
epsheight  = epswidth*orip(4)/orip(3);

set(figno,'PaperPosition',[0 0 epswidth epsheight ])
set(figno,'papersize',[epswidth epsheight])
set(figno,'Position',[orip(1)+0.5 orip(2)-0.5 epswidth epsheight ])
set(figno,'Name',[ 'To be printed; size: ' num2str(factor,3) ...
  ' x (' num2str(epswidth,3) 'cm x ' num2str(epsheight,3) 'cm)' ])

% some warnings
if verbose
  if (epswidth<13) | (epsheight<13*0.75)
    warning('LaPrint:size',['The size of the eps-figure is quite '...
       'small. The text objects might not be properly set. '...
       'Reducing ''factor'' might help.'])
  end
  if latexwidth/epswidth<0.5
    warning('LaPrint:size',['The size of the eps-figure is large ' ...
           'compared to the latex figure. '...
           'The text size might be too small. '...
           'Increasing ''factor'' might help.'])
  end  
  if (orip(3)-epswidth)/orip(3) > 0.1
    warning('LaPrint:size',['The size of the eps-figure is much '...
            'smaller than the original '...
            'figure on screen. Matlab might save different ticks '...
            'and ticklabels than in the original figure. '...
            'See option ''asonscreen''.'])
  end
  disp('Strike any key to continue.');
  pause
end  

%
% TEXT OBJECTS: modify new figure 
%

% find all text objects
hxl = get(findobj(figno,'type','axes'),'xlabel');
hyl = get(findobj(figno,'type','axes'),'ylabel');
hzl = get(findobj(figno,'type','axes'),'zlabel');
hti = get(findobj(figno,'type','axes'),'title');
hte = findobj(figno,'type','text');

% array of all text handles
htext = unique([ celltoarray(hxl) celltoarray(hyl) celltoarray(hzl) ...
      celltoarray(hti) celltoarray(hte)]);
nt = length(htext);

% set(celltoarray(hxl),'VerticalAlignment','top');
% get alignments
hora  = get(htext,'HorizontalAlignment');
vera  = get(htext,'VerticalAlignment');
align = cell(nt,1);
for i=1:nt
  align{i} = hora{i}(1);
  switch vera{i}
  case 'top'
    align{i} = [align{i} 't'];
  case 'cap'
%     if ~isempty(get(htext(i),'string'))
%       warning('LaPrint:text',['Using vertical ' ...
%             'alignment ''top'' instead of ''cap''.'])
%     end  
    align{i} = [align{i} 't'];
  case 'middle'
    align{i} = [align{i} 'c'];
  case 'baseline'
    align{i} = [align{i} 'B'];
  case 'bottom'
    align{i} = [align{i} 'b'];
  otherwise
    warning('LaPrint:text',['Vertical alignment ' vera{i} ...
            ' unknown. Using ''c''.'])
    align{i} = [align{i} 'c'];
  end
end  

% generate new strings and store old ones
oldstr   = get(htext,'string');
newstr   = cell(nt,1);
basestr  = ['s' char(48*ones(1,nzeros-1))];
extrastr = 0;
for i=1:nt
  osi = oldstr{i};
  oldstr{i} = ['\setlength{\tabcolsep}{0pt}\begin{tabular}{' ...
          align{i}(1) '}'];
  isnonempty_osi = 0;
  if strcmp(get(get(htext(i),'parent'),'tag'),'legend')
    newstr1 = [];  
    if isa(osi,'cell')
      % Legend/cell : Don't use tabular, employ extra strings 
      nlines = length(osi);
      if nlines > 1
        newstr{nt+extrastr+nlines-1} = [];
        oldstr{nt+extrastr+nlines-1} = [];
        htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
        for line=1:nlines-1  
          oldstr{nt+extrastr+line} = ...
              strrep(strrep(osi{line},'\','\\'),'%','%%'); 
          newstr{nt+extrastr+line} = ...
              overwritetail(basestr,nt+extrastr+line);
          newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)]; 
        end    
        extrastr = extrastr+nlines-1;  
      end    
      if nlines > 0
        oldstr{i} = strrep(strrep(osi{nlines},'\','\\'),'%','%%'); 
        newstr{i} = overwritetail(basestr,i);
        newstr1   = [newstr1; overwritetail(basestr,i)]; 
      end  
      % replace strings in figure
      set(htext(i),'string',cellstr(newstr1));
    else
      % Legend/matrix : Don't use tabular, employ extra strings 
      nlines=size(osi,1);
      if nlines > 1
        newstr{nt+extrastr+nlines-1} = [];
        oldstr{nt+extrastr+nlines-1} = [];
        htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
        for line=1:nlines-1  
          oldstr{nt+extrastr+line} = ...
              strrep(strrep(osi(line,:),'\','\\'),'%','%%'); 
          newstr{nt+extrastr+line} = ...
              overwritetail(basestr,nt+extrastr+line);
          newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)]; 
        end    
        extrastr = extrastr+nlines-1;  
      end    
      if nlines > 0
        oldstr{i} = strrep(strrep(osi(nlines,:),'\','\\'),'%','%%'); 
        newstr{i} = overwritetail(basestr,i);
        newstr1   = [newstr1; overwritetail(basestr,i)]; 
      end  
      % replace strings in figure
      set(htext(i),'string',newstr1);
    end
  else
    % text, not a legend  
    if isa(osi,'cell')
      nlines = length(osi);
      if nlines > 1
        for line=1:nlines-1  
          oldstr{i}=[oldstr{i} osi{line} '\\'];
          isnonempty_osi = isnonempty_osi+length(osi{line});  
        end    
        if align{i}(2) == 'B'
          warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
                  'in text with multiple rows might not match.'])
          align{i}(2) = 't';
        end  
      end    
      if nlines > 0
        oldstr{i} = [oldstr{i} osi{nlines} '\end{tabular}'];
        isnonempty_osi = isnonempty_osi+length(osi{nlines});
      end  
      oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');  
      if isnonempty_osi
        newstr{i} = overwritetail(basestr,i);
      else  
        newstr{i} = '';    
      end
      % replace strings in figure
      set(htext(i),'string',newstr{i}); 
    else
      nlines=size(osi,1);
      if nlines > 1
        for line=1:nlines-1  
          oldstr{i} = [oldstr{i} osi(line,:) '\\'];
          isnonempty_osi = isnonempty_osi+length(osi(line,:));  
        end    
        if align{i}(2) == 'B'
          warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
                  'in text with multiple rows might not match.'])
          align{i}(2) = 't';
        end  
      end
      if nlines > 0
        oldstr{i} = [oldstr{i} osi(nlines,:) '\end{tabular}'];
        isnonempty_osi = isnonempty_osi+length(osi(nlines,:));
      end  
      oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');  
   
      if isnonempty_osi
        newstr{i} = overwritetail(basestr,i);
      else  
        newstr{i} = '';    
      end
      % replace string in figure
      set(htext(i),'string',newstr{i});
    end % isa cell  
  end % isa legend  
end % for

ntp = nt+extrastr;

% Alignment of Legends
if extrastr > 0
  align{ntp} = [];
  [align{nt+1:ntp}] = deal('lc');
end

% get font properties and create commands
if ntp > 0
  [fontsizecmd{1:ntp}]   = deal('');
  [fontanglecmd{1:ntp}]  = deal('');
  [fontweightcmd{1:ntp}] = deal('');
  [colorcmd{1:ntp}]      = deal('');
  [colorclose{1:ntp}]    = deal('');
end
selectfontcmd = '';

if keepfontprops

  % fontsize
  set(htext,'fontunits','points');
  fontsize = get(htext,'fontsize');
  for i=1:ntp
    fontsizecmd{i} = [ '\\fontsize{' num2str(fontsize{i}) '}{' ...
	  num2str(fontsize{i}*1.5) '}'  ];
  end
    
  % fontweight
  fontweight = get(htext,'fontweight');
  for i=1:ntp
    switch fontweight{i}
    case 'light'
      fontweightcmd{i} = [ '\\fontseries{l}\\mathversion{normal}' ];
    case 'normal'
      fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
    case 'demi'
      fontweightcmd{i} = [ '\\fontseries{sb}\\mathversion{bold}' ];
    case 'bold'
      fontweightcmd{i} = [ '\\fontseries{bx}\\mathversion{bold}' ];
    otherwise
      warning('LaPrint:text',['Unknown fontweight: ' fontweight{i} ])
      fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
    end
  end  

  % fontangle
  fontangle = get(htext,'fontangle');
  for i=1:ntp
    switch fontangle{i}
    case 'normal'
      fontanglecmd{i} = [ '\\fontshape{n}' ];
    case 'italic'
      fontanglecmd{i} = [ '\\fontshape{it}' ];
    case 'oblique'
      fontanglecmd{i} = [ '\\fontshape{it}' ];
    otherwise
      warning('LaPrint:text',['unknown fontangle: ' fontangle{i} ])
      fontanglecmd{i} = [ '\\fontshape{n}' ];
    end
  end  
  selectfontcmd = '\\selectfont ';
   
end

if color & ntp>0
  col   = get(htext,'color');
  bgcol = get(htext,'BackgroundColor');
  ecol  = get(htext,'EdgeColor');
  for i=1:ntp
    col0           = get(get(htext(i),'parent'),'color'); 
    [coli,isc]     = char2rgb(col{i},[0 0 0]);
    [bgcoli,isbgc] = char2rgb(bgcol{i},col0);
    [ecoli,isec]   = char2rgb(ecol{i},col0);
    if isbgc | isec
      set(htext(i),'BackgroundColor','none')
      set(htext(i),'EdgeColor','none')
      colorcmd{i} = ['\\setlength{\\fboxsep}{2pt}\\fcolorbox[rgb]{' ...
        num2str(ecoli(1)) ',' num2str(ecoli(2)) ',' ...
        num2str(ecoli(3)) '}{' ...
        num2str(bgcoli(1)) ',' num2str(bgcoli(2)) ',' ...
        num2str(bgcoli(3)) '}{\\color[rgb]{' ...
        num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];  
      colorclose{i} = '}';   
    else  
      colorcmd{i} = ['\\color[rgb]{' ...
        num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
    end  
  end  
end

%
% LABELS: modify new figure
%

if ~keepticklabels

  % all axes
  hax = celltoarray(findobj(figno,'type','axes'));
  na  = length(hax);

%   % try to figure out if we have 3D axes an warn
%   issuewarning = 0;
%   for i=1:na
%     issuewarning = max(issuewarning,is3d(hax(i)));
%   end
%   if issuewarning
%     warning('LaPrint:label',['This seems to be a 3D plot. '...
%             'The LaTeX labels are possibly incorrect. '...
%             'The option  ''keepticklabels'' might help. '...
%             'Setting ''figcopy'' to ''off'' might be wise, too.'])
%   end

  % try to figure out if we linear scale with extra factor 
  % and determine powers of 10
  powers = NaN*zeros(na,3);  % matrix with powers of 10 
  for i=1:na                    % all axes
    allxyz = { 'x', 'y', 'z' };
    for ixyz=1:3                % x,y,z
      xyz = allxyz{ixyz};
      ticklabelmode = get(hax(i),[ xyz 'ticklabelmode']);
      if strcmp(ticklabelmode,'auto')
        tick      = get(hax(i),[ xyz 'tick']);
        ticklabel = get(hax(i),[ xyz 'ticklabel']);	      
	    nticklabels    = size(ticklabel,1);
	    nticks    = length(tick);
	    if nticks==0,
          powers(i,ixyz)=0;
          nticklabels=0;
	    end  
	    if nticklabels==0,
          powers(i,ixyz)=0;
  	    end  
        for k=1:nticklabels    % all ticks
	      label = str2num(ticklabel(k,:));
	      if length(label)==0, 
	        powers(i,ixyz) = 0;
	        break; 
	      end  
	      if ( label==0 ) & ( abs(tick(k))>1e-10 )
	        powers(i,ixyz) = 0;
	        break; 
          end	      
	      if label~=0    
            expon  = log10(tick(k)/label);
	        rexpon = round(expon);
	        if abs(rexpon-expon)>1e-10
              powers(i,ixyz) = 0;
	          break; 
            end	
            if isnan(powers(i,ixyz))
	          powers(i,ixyz) = rexpon;
	        else 	
	          if powers(i,ixyz)~=rexpon
        	    powers(i,ixyz) = 0;
	            break; 
              end		
	        end 
          end  	    
	    end % k	    
      else % if 'auto'
        powers(i,ixyz) = 0;
      end % if 'auto'
    end % ixyz
  end % i
  
  % place text to be replaced by powers on y-axis
  for i=1:na             
    allxyz = { 'x', 'y', 'z' };
    ixyz=2;                % x,y,z
    xyz = allxyz{ixyz};
    leftright=get(hax(i),'yaxislocation');
    if powers(i,ixyz) & ~is3d(hax(i)) & isequal(leftright,'left')
        powertext = ['ypower' int2str(i)];
        xlimit    = get(hax(i),'xlim');
        ylimit    = get(hax(i),'ylim');
        htext     = text(xlimit(1),ylimit(2)+...
                  0.01*(ylimit(2)-ylimit(1)),...
                  powertext);
        set(htext,'VerticalAlignment','Baseline');
    end
  end % i

  % replace all ticklabels and bookkeep
  nxlabel = zeros(1,na);
  nylabel = zeros(1,na);
  nzlabel = zeros(1,na);
  allxyz={ 'x', 'y', 'z' }; 
  for ixyz=1:3
    xyz = allxyz{ixyz};
    k=1;
    if strcmp(xyz,'y') 
      basestr = [ 'v' char(48*ones(1,nzeros-1))];
    else
      basestr = [ xyz char(48*ones(1,nzeros-1))];
    end  
    oldtl  = cell(na,1);
    newtl  = cell(na,1);
    nlabel = zeros(1,na);
    for i=1:na
      % set(hax(i),[ xyz 'tickmode' ],'manual')
      % set(hax(i),[ xyz 'ticklabelmode' ],'manual')
      oldtl{i}  = chartocell(get(hax(i),[ xyz 'ticklabel' ]));
      nlabel(i) = length(oldtl{i});
      newtl{i}  = cell(1,nlabel(i));
      for j=1:nlabel(i)
        newtl{i}{j} = overwritetail(basestr,k);
        k = k+1;
        oldtl{i}{j} = deblank(strrep(strrep(oldtl{i}{j},'\','\\'),...
                             '%','%%'));
      end
      set(hax(i),[ xyz 'ticklabel' ],newtl{i});
    end  
    eval([ 'old' xyz 'tl=oldtl;' ]);
    eval([ 'new' xyz 'tl=newtl;' ]);
    eval([ 'n' xyz 'label=nlabel;' ]);
  end

  % determine latex commands for font properties
  
  if keepfontprops

    % ticklabel font size
    afsize = zeros(na,1);
    for i=1:na
      afsize(i) = get(hax(i),'fontsize');
    end          
    if (any(afsize ~= afsize(1) ))
      warning('LaPrint:text',['Different font sizes for axes not '...
              'supported. All axes will have font size ' ...
	           num2str(afsize(1)) '.' ] )
    end      
    afsizecmd = [ '\\fontsize{' num2str(afsize(1)) '}{' ...
	  num2str(afsize(1)*1.5) '}'  ];

    % ticklabel font weight
    afweight = cell(na,1);
    for i=1:na
      afweight{i} = get(hax(i),'fontweight');
    end
    switch afweight{1}
    case 'light'
      afweightcmd = [ '\\fontseries{l}\\mathversion{normal}' ];
    case 'normal'
      afweightcmd = [ '\\fontseries{m}\\mathversion{normal}' ];
    case 'demi'
      afweightcmd = [ '\\fontseries{sb}\\mathversion{bold}' ];
    case 'bold'
      afweightcmd = [ '\\fontseries{bx}\\mathversion{bold}' ];
    otherwise
      warning('LaPrint:text',['unknown fontweight: ' afweight{1} ])
      afweightcmd = [ '\\fontseries{m}\\mathversion{normal}' ];
    end
    for i=1:na
      if ~strcmp(afweight{i},afweight{1})
        warning('LaPrint:text',['Different font weights for axes '...
                'are not supported. All axes will have font weight ' ...
                afweightcmd '.'])
      end      
    end      

    % ticklabel font angle
    afangle = cell(na,1);
    for i=1:na
      afangle{i} = get(hax(i),'fontangle');
    end
    switch afangle{1}
    case 'normal'
      afanglecmd = [ '\\fontshape{n}' ];
    case 'italic'
      afanglecmd = [ '\\fontshape{it}' ];
    case 'oblique'
      afanglecmd = [ '\\fontshape{it}' ];
    otherwise
      warning('LaPrint:text',['unknown fontangle: ' afangle{1} ])
      afanglecmd=[ '\\fontshape{n}' ];
    end
    for i=1:na
      if ~strcmp(afangle{i},afangle{1})
        warning('LaPrint:text',['Different font angles for axes not '...
                'supported. All axes will have font angle ' ...
                afanglecmd '.'] )
      end      
    end      
  
  end

  % ticklabel color
  acolcmd='';
  if color
    acol=[];
    allxyz={ 'x', 'y', 'z' }; 
    acolwarn = 0;
    for i=1:na
      for ixyz=1:3
        xyzcolor = [allxyz{ixyz} 'color'];
        if  ~isempty(get(hax(i),[allxyz{ixyz} 'ticklabel']))
          if isempty(acol)
            acol = char2rgb(get(hax(i),xyzcolor));  
          else
            if any(char2rgb(get(hax(i),xyzcolor))~=acol)
              acolwarn = 1;
            end 
          end
        end   
      end 
    end
    if acolwarn
      warning('LaPrint:label',['Different colors for axes not ' ...
            'supported. All ticklabels will have color [ ' ...
             num2str(acol) ' ].' ] )
    end
    if ~isempty(acol)
      if any(acol~=[0 0 0])
        acolcmd = [ '\\color[rgb]{' num2str(acol(1)) ',' ...
              num2str(acol(2)) ',' num2str(acol(3)) '}' ];
      end	
    end 
  end

  % ticklabel alignment
    xyzalign = char([116*ones(na,1) 114*ones(na,1) 114*ones(na,1)]); 
    for i=1:na
      switch get(hax(i),'XAxisLocation')
      case 'top'
        xyzalign(i,1)='B';
      end
      switch get(hax(i),'YAxisLocation')
      case 'right'
        xyzalign(i,2)='l';
      end
    end

end

%
% extra picture environment
%

if extrapicture
  unitlength = zeros(na,1);
  ybound     = zeros(na,1);
  for i=na:-1:1   % reverse order, to keep axes in original order
    if ~is3d(hax(i))
      xlim = get(hax(i),'xlim');
      ylim = get(hax(i),'ylim');
      axes(hax(i));
      hori = text(ylim(1),ylim(1),[ 'origin' int2str(i) ]);
      set(hori,'VerticalAlignment','bottom');
      set(hori,'Fontsize',2);
      set(hax(i),'Units','normalized')
      pos = get(hax(i),'Position');
      unitlength(i) = pos(3)*epswidth;
      ybound(i) = (pos(4)*epsheight)/(pos(3)*epswidth);
    else
      warning('LaPrint:extrapic',['Option ''extrapicture'' for 3D ' ...
                  'axes not supported.'])
    end
  end 
end  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% PART 3 of advanced usage:
%%%% save eps and tex files
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% prevent matlab print command to modify lims and ticks 
% (empty, if asonscreen=1)
if ~keepticklabels
  xlimmodeauto       = findobj(figno,'xlimmode','auto');
  xtickmodeauto      = findobj(figno,'xtickmode','auto');
  xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
  ylimmodeauto       = findobj(figno,'ylimmode','auto');
  ytickmodeauto      = findobj(figno,'ytickmode','auto');
  yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
  zlimmodeauto       = findobj(figno,'zlimmode','auto');
  ztickmodeauto      = findobj(figno,'ztickmode','auto');
  zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
  set(xlimmodeauto,'xlimmode','manual')
  set(xtickmodeauto,'xtickmode','manual')
  set(xticklabelmodeauto,'xticklabelmode','manual')
  set(ylimmodeauto,'ylimmode','manual')
  set(ytickmodeauto,'ytickmode','manual')
  set(yticklabelmodeauto,'yticklabelmode','manual')
  set(zlimmodeauto,'ylimmode','manual')
  set(ztickmodeauto,'ytickmode','manual')
  set(zticklabelmodeauto,'yticklabelmode','manual')
end

% create eps file
cmd = strrep(printcmd,'<filename.eps>',epsfullnameext);
cmd = strrep(cmd,'<filename>',filename);
cmd = strrep(cmd,'<figurenumber>',int2str(figno));
  
if verbose
  disp([ 'executing: '' ' cmd ' ''' ]);
end
eval(cmd);

%
% create latex file
%
if verbose
  disp([ 'writing to: '' ' texfullnameext ' ''' ])
end
fid = fopen(texfullnameext,'w');

% head
if head
  fprintf(fid,[ '%% This file is generated by the MATLAB m-file' ...
       ' laprint.m. It can be included\n']);
  fprintf(fid,[ '%% into LaTeX documents using the packages ']);
  fprintf(fid,package);
  if color
      fprintf(fid,', color');
  end    
  fprintf(fid,[ ' and psfrag.\n' ]);
  fprintf(fid,  ['%% It is accompanied by a postscript file. ',... 
     'A sample LaTeX file is:\n']);
  fprintf(fid, '%%    \\documentclass{article}\\usepackage{');
  fprintf(fid,package);
  if color
     fprintf(fid,',color');
  end    
  fprintf(fid, ',psfrag}\n');
  fprintf(fid,[ '%%    \\begin{document}\\input{' ...
	texbasename '}\\end{document}\n' ]);
    fprintf(fid, [ '%% See http://www.mathworks.de/matlabcentral'...
      '/fileexchange/loadFile.do?objectId=4638\n']);
    fprintf(fid, [ '%% for recent versions of laprint.m.\n' ]);
  fprintf(fid,  '%%\n');
  fprintf(fid,[ '%% created by:           ' 'LaPrint version ' ...
	laprintident '\n' ]);
  fprintf(fid,[ '%% created on:           ' datestr(now) '\n' ]);
  fprintf(fid,[ '%% eps bounding box:     ' num2str(epswidth) ...
      ' cm x ' num2str(epsheight) ' cm\n' ]);
  fprintf(fid,[ '%% comment:              ' comment '\n' ]);
  fprintf(fid,'%%\n');
else 
  fprintf(fid,[ '%% generated by laprint.m\n' ]);
  fprintf(fid,'%%\n');
end

% go on
fprintf(fid,'\\begin{psfrags}%%\n');
%fprintf(fid,'\\fontsize{10}{12}\\selectfont%%\n');
fprintf(fid,'\\psfragscanon%%\n');

% text strings

numbertext=0;
for i=1:nt
  numbertext = numbertext+length(newstr{i});
end
if numbertext>0,
  fprintf(fid,'%%\n');
  fprintf(fid,'%% text strings:\n');
  for i=1:ntp
    if length(newstr{i})
      alig = strrep(align{i},'c','');
      fprintf(fid,[ '\\psfrag{' newstr{i} '}[' alig '][' alig ']{' ...
        fontsizecmd{i} fontweightcmd{i} fontanglecmd{i}  ...
        selectfontcmd colorcmd{i} oldstr{i} colorclose{i} '}%%\n' ]);
    end
  end
end

% labels

if ~keepticklabels
  if ~isempty(acolcmd)
     fprintf(fid,'%%\n');
     fprintf(fid,'%% axes ticklabel color:\n');
     fprintf(fid,[ acolcmd '%%\n' ]);
  end    
  if keepfontprops
    fprintf(fid,'%%\n');
    fprintf(fid,'%% axes font properties:\n');
    fprintf(fid,[ afsizecmd afweightcmd '%%\n' ]);
    fprintf(fid,[ afanglecmd '\\selectfont%%\n' ]);
  end  
  nxlabel = zeros(1,na);
  nylabel = zeros(1,na);
  nzlabel = zeros(1,na);
  for i=1:na
    nxlabel(i) = length(newxtl{i});
    nylabel(i) = length(newytl{i});
    nzlabel(i) = length(newztl{i});
  end    
      
  allxyz = { 'x', 'y', 'z' };
  for ixyz=1:3
    xyz = allxyz{ixyz};
    eval([ 'oldtl=old' xyz 'tl;' ]);
    eval([ 'newtl=new' xyz 'tl;' ]);
    eval([ 'nlabel=n' xyz 'label;' ]);
    if sum(nlabel) > 0
      fprintf(fid,'%%\n');
      fprintf(fid,[ '%% ' xyz 'ticklabels:\n']);
      for i=1:na
        poss = ['[' xyzalign(i,ixyz) '][' xyzalign(i,ixyz) ']']; 
        if nlabel(i)
          if strcmp(get(hax(i),[ xyz 'scale']),'linear')
	        % lin scale
            rexpon = powers(i,ixyz);
            if ~rexpon 
              % no powers
              for j=1:nlabel(i)
                fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
		                    Do oldtl{i}{j} Do '}%%\n' ]);
              end 
            else
              % powers
              if ixyz==2 
                leftright=get(hax(i),'yaxislocation');
                if ~is3d(hax(i)) & isequal(leftright,'left')
                  for j=1:nlabel(i)
                    fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
	 	                    Do oldtl{i}{j} Do '}%%\n' ]);
                  end 
                  fprintf(fid,[ '\\psfrag{ypower' int2str(i) ...
                     '}[Bl][Bl]{$\\times 10^{' ...
 		             int2str(rexpon) '}$}%%\n' ]);
                else
                  for j=1:nlabel(i)-1
                    fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
		                      Do oldtl{i}{j} Do '}%%\n' ]);
                  end 
                  if ~is3d(hax(i))
	                fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
                     '}' poss '{' ... 
                     Do oldtl{i}{nlabel(i)} Do '$\\times 10^{'...
		             int2str(rexpon) '}$}%%\n' ]);
                  else
 	                fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
                     '}' poss '{\\shortstack{' ... 
                     Do oldtl{i}{nlabel(i)} Do '\\\\$\\times 10^{'...
		             int2str(rexpon) '}\\ $}}%%\n' ]);

                  end 
                end  
              elseif ixyz==1
                for j=1:nlabel(i)-1
                  fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
		                    Do oldtl{i}{j} Do '}%%\n' ]);
                end 
                leftright=get(hax(i),'xaxislocation');
                if isequal(leftright,'bottom')
	              fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
                     '}' poss '{\\shortstack{' ... 
                     Do oldtl{i}{nlabel(i)} Do '\\\\$\\times 10^{'...
		             int2str(rexpon) '}\\ $}}%%\n' ]);
	            else
                  fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
                     '}' poss '{\\shortstack{$\\times 10^{' ...
                     int2str(rexpon) '}\\ $\\\\' ...
                     Do oldtl{i}{nlabel(i)} Do '}}%%\n' ]);
                end
              else
                for j=1:nlabel(i)-1
                  fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
		                    Do oldtl{i}{j} Do '}%%\n' ]);
                end 
	            fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
		           '}' poss '{' Do oldtl{i}{nlabel(i)} Do ...
                   '\\setlength{\\unitlength}{1ex}' ...
		           '\\begin{picture}(0,0)\\put(0.5,1.5){$\\times 10^{' ...
		           int2str(rexpon) '}$}\\end{picture}}%%\n' ]);
              end 
            end % rexpon 
          else
            % log scale
            for j=1:nlabel(i)
              fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{$10^{' ...
                oldtl{i}{j} '}$}%%\n' ]);
            end % for (log)
          end % if linear
        end  % if nlabel(i) 
      end
    end
  end
end  

% extra picture
if extrapicture
  fprintf(fid,'%%\n');
  fprintf(fid,'%% extra picture(s):\n');
  for i=1:na
    fprintf(fid,[ '\\psfrag{origin' int2str(i) '}[lb][lb]{' ...
                  '\\setlength{\\unitlength}{' ...
		  num2str(unitlength(i),'%5.5f') 'cm}%%\n' ]);
    fprintf(fid,[ '\\begin{picture}(1,' ...
		  num2str(ybound(i),'%5.5f') ')%%\n' ]);
    %fprintf(fid,'\\put(0,0){}%% lower left corner\n');
    %fprintf(fid,[ '\\put(1,' num2str(ybound(i),'%5.5f') ...
    %	          '){}%% upper right corner\n' ]);
    fprintf(fid,'\\end{picture}%%\n');
    fprintf(fid,'}%%\n');
  end
end  

% figure
fprintf(fid,'%%\n');
fprintf(fid,'%% Figure:\n');
if iscaption
  fprintf(fid,[ '\\parbox{' num2str(latexwidth) 'cm}{\\centering%%\n' ]);
end  
if ~scalefonts
  switch package
  case 'epsfig'   
     fprintf(fid,[ '\\epsfig{file=' epsbasenameext ',width=' ...
	 num2str(latexwidth) 'cm}%%\n' ]);
  case 'graphicx'   
     fprintf(fid,[ '\\includegraphics[width=' num2str(latexwidth) ...
             'cm]{' epsbasenameext '}%%\n' ]);
  otherwise  
    warning('LaPrint:general',['Package ''' package ''' not known. '...
            'I hope you know what you are doing...'])    
  end
else
  switch package
  case 'epsfig'  
     fprintf(fid,[ '\\resizebox{' num2str(latexwidth) 'cm}{!}' ...
      '{\\epsfig{file=' epsbasenameext '}}%%\n' ]);
  case 'graphicx' 
     fprintf(fid,[ '\\resizebox{' num2str(latexwidth) 'cm}{!}' ...
      '{\\includegraphics{' epsbasenameext '}}%%\n' ]);
  otherwise
    warning('LaPrint:general',['Package ''' package ''' not known. '...
            'I hope you know what you are doing...'])    
  end
end
if iscaption
  fprintf(fid,[ '\\caption{' caption '}%%\n' ]);
  fprintf(fid,[ '\\label{fig:' texbasename '}%%\n' ]);
  fprintf(fid,[ '}%%\n' ]);
end  
fprintf(fid,'\\end{psfrags}%%\n');
fprintf(fid,'%%\n');
fprintf(fid,[ '%% End ' texbasenameext '\n' ]);
fclose(fid);

set(figno,'Name','Printed by LaPrint')
if figcopy
  if verbose
    disp('Strike any key to continue.');
    pause
  end
  hlegend = findobj(figno,'Tag','legend');
  set(hlegend,'DeleteFcn','')
  close(figno)
end

% check for copyobj-bug --> should be ok now!
number_children_new = length(get(figno_ori,'children'));
if number_children_new < number_children_ori
   if figcopy 
      warning(['LaPrint:general','Objects in the figure have been '...
              'deleted! This is due to a bug in matlabs '...
              '''copyopj''. You might want to try to set '...
              '''figcopy'' to ''off''.']) 
   else    
      warning('LaPrint:general',['Objects in the figure have been '...
              'deleted!'])
   end
 end
    
%
% create view file
%

if createview | processview
  if verbose
    disp([ 'writing to: '' ' viewfullnameext ' ''' ])
  end
  fid = fopen(viewfullnameext,'w');

  if head
    fprintf(fid,[ '%% This file is generated by laprint.m.\n' ]);
    fprintf(fid,[ '%% It calls ' texbasenameext ...
		  ', which in turn  calls ' epsbasenameext '.\n' ]);
    fprintf(fid,[ '%% Process this file using, e.g.,\n' ]);
    fprintf(fid,[ '%%   latex ' viewbasenameext '\n' ]);
    fprintf(fid,[ '%%   dvips -o' viewbasename '.ps ' viewbasename ...
            '.dvi\n']);
    fprintf(fid,[ '%%   ghostview ' viewbasename '.ps&\n' ]);
  else 
    fprintf(fid,[ '%% generated by laprint.m\n' ]);
  end

  fprintf(fid,[ '\\documentclass{article}\n' ]);
  fprintf(fid,[ '\\usepackage{' ]);
  fprintf(fid,package);
  if color
      fprintf(fid,',color');
  end    
  fprintf(fid,[ ',psfrag,a4}\n' ]);
  fprintf(fid,[ '\\usepackage[latin1]{inputenc}\n' ]);
  if ~strcmp(epsdirname,viewdirname)
    fprintf(fid,[ '\\graphicspath{{' epsdirname '}}\n' ]);
  end  
  fprintf(fid,[ '\\begin{document}\n' ]);
  fprintf(fid,[ '\\pagestyle{empty}\n' ]);
  if strcmp(texdirname,viewdirname) 
    fprintf(fid,[ '    \\input{' texbasenameext '}\n' ]);
  else
    fprintf(fid,[ '    \\input{' texdirname texbasenameext '}\n' ]);
  end
  fprintf(fid,[ '\\end{document}\n' ]);
  fclose(fid);
end

% process view file
    
if processview
    conti=1;
    
    for i=1:8
      eval(['cmdi=cmd' int2str(i) ';'])
      if ~isempty(cmdi) & conti
        cmd = strrep(cmdi,'<viewfile>',viewbasename);
        cmd = strrep(cmd,'<filename>',filename);
        disp([ 'executing: '' ' cmd ' ''' ]);
        [stat,resu]=system(cmd);
        if stat %| isempty(strfind(resu,'Output written on'))
          disp(resu)
          conti=0;
        end
      end 
    end

    if ~conti
       disp('An error occured in the latex/friends sequence.')
    end

end

set(0,'ShowHiddenHandles',shh);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% functions used
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [fullnameext,basenameext,basename,dirname] = getfilenames(...
    filename,extension,verbose);
% appends an extension to a filename (as '/home/tom/tt') and determines  
% fullnameext: filename with extension and dirname, as '/home/tom/tt.tex'
% basenameext: filename with extension without dirname, as 'tt.tex'
% basename   : filename without extension without dirname, as 'tt'
% dirname    : dirname without filename, as '/home/tom/'
% In verbose mode, it asks if to overwrite or to modify.
%
[dirname, basename] = splitfilename(filename);
fullnameext = [ dirname basename '.' extension ];
basenameext = [ basename '.' extension ];
if verbose
  quest = (exist(fullnameext)==2);
  while quest
    yn = input([ strrep(strrep(fullnameext,'\','\\'),'%','%%') ...
            ' exists. Overwrite? (y/n) '],'s');
    if strcmp(yn,'y') 
      quest = 0;
    else
      filename = input( ...
	             [ 'Please enter new filename (without extension .' ...
	             extension '): ' ],'s');
      [dirname, basename] = splitfilename(filename);
      fullnameext = [ dirname basename '.' extension ];
      basenameext = [ basename '.' extension ];
      quest = (exist(fullnameext)==2);
    end
  end
end
if ( exist(dirname)~=7 & ~strcmp(dirname,[ '.' filesep ]) ...
      & ~strcmp(dirname,filesep) )
  error([ 'Directory ' dirname ' does not exist.' ] )
end  

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

function [dirname,basename] = splitfilename(filename);
% splits filename into dir and base
slashpos  = findstr(filename,filesep);
nslash    = length(slashpos);
nfilename = length(filename);
if nslash
  dirname  = filename(1:slashpos(nslash));
  basename = filename(slashpos(nslash)+1:nfilename);
else
  dirname = pwd;
  nn=length(dirname);
  if ~strcmp(dirname(nn),filesep)
    dirname = [ dirname filesep ];
  end   
  basename = filename;
end  

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

function yesno = is3d(haxes);
% tries to figure out if axes is 3D
yesno = 0;
CameraPosition = get(haxes,'CameraPosition');
CameraTarget = get(haxes,'CameraTarget');
CameraUpVector = get(haxes,'CameraUpVector');
if CameraPosition(1)~=CameraTarget(1)
  yesno = 1;
end  
if CameraPosition(2)~=CameraTarget(2)
  yesno = 1;
end  
if any(CameraUpVector~=[0 1 0])
  yesno = 1;
end  

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

function b = celltoarray(a);
% converts a cell of doubles to an array
if iscell(a),
  b = [];
  for i=1:length(a),
    b = [b a{i}]; 
  end  
else, 
  b = a(:)';
end  

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

function b = chartocell(a)
% converts a character array into a cell array of characters

% convert to cell 
if isa(a,'char')
  n = size(a,1);
  b = cell(1,n);
  for j=1:n
    b{j}=a(j,:); 
  end  
else
  b = a;
end  
% convert to char
n=length(b);
for j=1:n
  if isa(b{j},'double')
    b{j} = num2str(b{j});
  end  
end	

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

function b = overwritetail(a,k)
% overwrites tail of a by k
% a,b: strings
% k: integer
ks = int2str(k);
b = [ a(1:(length(a)-length(ks))) ks ];

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

function [rgb,isc] = char2rgb(c,c0)
% convert color definitions from character to rgb-vector

isc = 1;
if ~ischar(c)
  rgb = c; 
else  
  switch c
  case {'y','yellow'}
    rgb = [1 1 0];
  case {'m','magenta'}
    rgb = [1 0 1];
  case {'c','cyan'}
    rgb = [0 1 1];
  case {'r','red'}
    rgb = [1 0 0];
  case {'g','green'}
    rgb = [0 1 0];
  case {'b','blue'}
    rgb = [0 0 1];
  case {'w','white'}
    rgb = [1 1 1];
  case {'k','black'}
    rgb = [0 0 0];
  case 'none' 
    if nargin==2
      rgb = char2rgb(c0);
    else
      rgb = [1 1 1];    
    end    
    isc = 0;
  otherwise
    warning('LaPrint:general',['Unknown Color: ''' c ...
            '''. Taking black.'])
    rgb = [0 0 0];
  end    
end    

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

function v = value01(val,opt)
% convert off/on to 0/1

if nargin==2
   txt = ['Value of ' opt ' must be ''on'' or ''off'''];
else
   txt = ['Value must be ''on'' or ''off'''];
end

if  ~isa(val,'char')  
  error(txt)
end
val = lower(strrep(val,' ',''));
switch val
  case 'on'
    v = 1;
  case 'off'
    v = 0;
  otherwise
    error(txt)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function v = valueyn(val)
% convert 0/1 to off/on 

if  ~isa(val,'double')  
  error([ 'Value must be ''0'' or ''1'''])
end
switch val
  case 0
    v = 'off';
  case 1
    v = 'on';
  otherwise
    error([ 'Value must be ''0'' or ''1'''])
end

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

function sethf(hf,LAPRINTHAN,LAPRINTOPT)
% store in UserData of gui 

set(hf,'UserData',{LAPRINTHAN,LAPRINTOPT})

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

function [LAPRINTHAN,LAPRINTOPT]=gethf(hf)
% load from UserData of gui 

d=get(hf,'UserData');
LAPRINTHAN=d{1};
LAPRINTOPT=d{2};

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

function opt = prefsettings
    if ispref('LaPrint','LAPRINTOPT')  
      opt = getpref('LaPrint','LAPRINTOPT');
    else
      opt = [];  
    end    

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

function opt=factorysettings

% try to find LaTeX and friends 
if ispc
  try 
    latexpath = winqueryreg('HKEY_LOCAL_MACHINE',...
	  'SOFTWARE\MiK\MiKTeX\CurrentVersion\MiKTeX','Install Root');
    latexcmd = [latexpath '\miktex\bin\latex.exe -halt-on-error '...
               '-interaction nonstopmode <viewfile>.tex'];
    dvipscmd = [latexpath '\miktex\bin\dvips.exe -D600 -E* '...
               '-o<viewfile>.eps <viewfile>.dvi'];
  catch    % hoping the path variable is properly set
    latexcmd = ['latex.exe -halt-on-error '...
               '-interaction nonstopmode <viewfile>.tex'];
    dvipscmd = ['dvips.exe -D600 -E* '...
               '-o<viewfile>.eps <viewfile>.dvi'];
  end
  epstoolcmd = ['C:\Ghostgum\epstool\bin\epstool.exe '...
               '--bbox --copy --output '...
               '<filename>_final.eps <viewfile>.eps'];
  delcmd =     ['del <viewfile>.eps <viewfile>.dvi ',...
               '<viewfile>.aux <viewfile>.log ',...
               '<viewfile>.pfg'];
  gsviewcmd = 'C:\Ghostgum\gsview\gsview32.exe <filename>_final.eps&';
else % hoping the path variable is properly set
  latexcmd =   ['latex -halt-on-error '...
               '-interaction nonstopmode <viewfile>.tex'];
  dvipscmd =   ['dvips -D600 -E* '...
               '-o<viewfile>.eps <viewfile>.dvi'];
  epstoolcmd = ['epstool --bbox --copy --output '...
               '<filename>_final.eps <viewfile>.eps'];
  delcmd =     ['rm <viewfile>.eps <viewfile>.dvi ',...
               '<viewfile>.aux <viewfile>.log ',...
               '<viewfile>.pfg'];
  gsviewcmd =  'ghostview <filename>_final.eps&';
end

vers = version;
vers = eval(vers(1:3));
if vers < 6.5
  colorvalue=0;
else
  colorvalue=1;
end

   opt = struct(...
      'figno',{1},...
      'filename','unnamed',...
      'width',12,...
      'factor',0.8,...
      'scalefonts',1,...
      'keepfontprops',0,...
      'asonscreen',0,...
      'keepticklabels',0,...
      'mathticklabels',0,...
      'head',1,...
      'comment','',...
      'caption','',...
      'extrapicture',0,...
      'nzeros',3,...
      'verbose',0,...
      'figcopy',1,...
      'printcmd',['print(''-f<figurenumber>'',' ...
                      '''-depsc'',''-painters'','...
                      '''<filename.eps>'')'],...
      'package','graphicx',...
      'color',colorvalue,...
      'createview',0,...
      'viewfilename','unnamed_',...
      'processview',0,...
      'cmd1',latexcmd,...
      'cmd2',dvipscmd,...
      'cmd3',epstoolcmd,...
      'cmd4',delcmd,...
      'cmd5',gsviewcmd,...
      'cmd6','',...
      'cmd7','',...
      'cmd8','');

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

function updategui(LAPRINTHAN,LAPRINTOPT)
% update gui

set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno))
set(LAPRINTHAN.filename,'string',LAPRINTOPT.filename)
% width, factor, scalefonts
if LAPRINTOPT.keepfontprops
   set(LAPRINTHAN.keepfontprops,'check','on')
else 
   set(LAPRINTHAN.keepfontprops,'check','off')
end
if LAPRINTOPT.asonscreen
   set(LAPRINTHAN.asonscreen,'check','on')
else 
   set(LAPRINTHAN.asonscreen,'check','off')
end
if LAPRINTOPT.keepticklabels
   set(LAPRINTHAN.keepticklabels,'check','on')
else 
   set(LAPRINTHAN.keepticklabels,'check','off')
end
if LAPRINTOPT.mathticklabels
   set(LAPRINTHAN.mathticklabels,'check','on')
else 
   set(LAPRINTHAN.mathticklabels,'check','off')
end
if LAPRINTOPT.head
   set(LAPRINTHAN.head,'check','on')
else 
   set(LAPRINTHAN.head,'check','off')
end
% comment, caption
if LAPRINTOPT.extrapicture
   set(LAPRINTHAN.extrapicture,'check','on')
else 
   set(LAPRINTHAN.extrapicture,'check','off')
end
% nzeros
if LAPRINTOPT.verbose
   set(LAPRINTHAN.verbose,'check','on')
else 
   set(LAPRINTHAN.verbose,'check','off')
end
if LAPRINTOPT.figcopy
   set(LAPRINTHAN.figcopy,'check','on')
else 
   set(LAPRINTHAN.figcopy,'check','off')
end
% printcmd
switch LAPRINTOPT.package
  case 'epsfig'
   set(LAPRINTHAN.package_epsfig,'check','on')
   set(LAPRINTHAN.package_graphicx,'check','off')
  case 'graphicx'
   set(LAPRINTHAN.package_epsfig,'check','off')
   set(LAPRINTHAN.package_graphicx,'check','on')
end
if LAPRINTOPT.color
   set(LAPRINTHAN.color,'check','on')
else 
   set(LAPRINTHAN.color,'check','off')
end
if LAPRINTOPT.createview
   set(LAPRINTHAN.createview,'check','on')
else 
   set(LAPRINTHAN.createview,'check','off')
end
% viewfilename
if LAPRINTOPT.processview
   set(LAPRINTHAN.processview,'check','on')
else 
   set(LAPRINTHAN.processview,'check','off')
end
% cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8

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

function txt = helptext()
% help text
txt={...
'',...
['LAPRINT prints a figure for inclusion in LaTeX documents. ',...
'It creates an eps-file and a tex-file. The tex-file contains the ',...
'annotation of the figure such as titles, labels and texts. The ',...
'eps-file contains the non-text part of the figure and is called ',...
'by the tex-file. The main advantage of using LaPrint ',...
'is that the annotation can be neatly (e.g., including math ',...
'mode and fancy font constructs) set within LaTeX.'],...
'',...
'Prerequisites:',...
'~~~~~~~~~~~~~~',...
['Matlab 6.1 or above is required. To process the LaTeX file, a ',...
'LaTeX compiler (including the packages ''graphicx'' and ',...
'''psfrag'') and a dvi-to-postscript converter (like dvips) '...
'is required. Optional tools are a postscript-viewer ',...
'(like ghostview), a postscript bounding box converter ',...
'(like epstool) and the LaTeX packages color ',...
'and epsfig.'],...
'',...
'Installation:',...
'~~~~~~~~~~~~~',...
['LaPrint comes as a single m-file, which has to be placed  ',...
'somewhere in the Matlab search path. If you want LaPrint to ',...
'call LaTeX and friends, the (system dependent) executables have ',...
'to be defined using the GUI (see below).'],...
'',...
'An example to get started:',...
'~~~~~~~~~~~~~~~~~~~~~~~~~~',...
['It is recommended to switch off the Matlab TeX ',...
'interpreter before creating a graphics to be processed by ',...
'LaPrint:'],...
'  >> set(0,''DefaultTextInterpreter'',''none'')',...
'Create an example graphics using',...
'  >> figure(1), clf',...
'  >> plot([1 2])',...
'  >> xlabel(''$x$'')',...
'  >> ylabel(''A straight line $f(x)=\alpha x + \beta$'')',...
'  >> text(1.1,1.9,{''\textbf{This figure is not exiting.}'',...',...
'     ''(but it shows some features of \texttt{laprint})''})',...
['Note that the text uses LaTeX constructs like ''$.$'', ',...
'''\alpha'' and ''\textbf{}''. You can employ the full LaTeX ',...
'repertoire here.'],...
['Open the LaPrint graphical user interface (GUI) ',...
'(if you haven''t already done so), by typing'],...
'  >> laprint',...
['Check if the GUI points to Figure Number 1, ',...
'and save the graphics by pressing ''Go!''. ',...
'This creates the files ''unnamed.tex'' and ''unnamed.eps''. ',...
'These can be included in a LaTeX document as follows:'],...
'  % This is the LaTeX document testdoc.tex',...
'  \documentclass{article}',...
'  \usepackage{graphicx,color,psfrag}',...
'  \begin{document}',...
'  Here comes a Matlab figure created with \texttt{laprint}:\\',...
'  \input{unnamed}',...
'  \end{document}',...
['This document can be compiled with LaTeX (to create ',...
'''testdoc.dvi'') and converted to postscript (to create ',...
'''testdoc.ps''). The document ''testdoc.ps'' will contain the ',...
'Matlab graphics with LaTeX annotation. Observe that the ',...
'figure is 12cm wide and that the fonts are scaled to 80% ',...
'of their original size. This is the default behaviour of ',...
'LaPrint, which can be adjusted using ''Options'' in the ',...
'GUI menu bar (as will explained below).'],...
'',...
['Instead of using the GUI you can also call LaPrint ',...
'from the command line (or from an m-file) as follows:'],...
'  >> laprint(1,''unnamed'')',...
'',...
'This is what LaPrint does:',...
'~~~~~~~~~~~~~~~~~~~~~~~~~~',...
'Basically, LaPrint performs the following tasks:',...
' - Take a preliminary copy of the figure. ',...
' - In the preliminary figure, replace all text objects by tags.',...
[' - Save the preliminary figure (with tags) as an eps-file using ',...
'the Matlab ''print'' command.'],...
[' - Create a tex-file which calls the eps-file (using the ',...
'''graphicx'' package) and replaces ',...
'the tags by the original text (using the ''psfrag'' package).'],...
'',...
['It is instructive to have a look into the tex-file ',...
'(''unnamed.tex'' in the above example). ',...
'If your graphics contains huge amounts of LaTeX-code, then ',... 
'you might also consider editing the tex-file with your ',...
'favourate LaTeX editor. You have however to be carefull, ',...
'because LaPrint (using default settings) doesn''t care ',...
'overwriting files.'],...
'',...
'Using the LaPrint GUI: ',...
'~~~~~~~~~~~~~~~~~~~~~~',...
['The behaviour of LaPrint can be controlled by various settings ',...
'and options. Using the GUI, these can be set using the ''Options'' ',...
'entry in the menu bar. Using LaPrint from the command line, ' ,...
'these can be set by extra input arguments in the form of ',...
'option/value pairs. In the following, the options are explained ',...
'in some detail based on the GUI. Later, a table with the ',...
'command line option/value pairs is given.'],...
'',...
'In the main LaPrint window you can specify',...
['-- the number of the Matlab figure to be saved (this must be ',...
'the handle of an open Matlab window) and '],...
['-- the basename of the files to be saved (for instance, if ',...
'the basename is ''unnamed'', then ''unnamed.tex'' and ',...
'''unnamed.eps'' are created;).'],...
'',...
'Via the menu bar you can control the following settings:',...
'',...
'Options --> Sizes and Scalings ...',...
'',...
'This opens a window where you can specify ',...
'-- the width (in cm) of the graphics in the LaTeX document;',...
'-- a scaling factor and',...
'-- whether you want fonts to be scaled.',...
['The width controls the size of the graphics. Its height ',...
'is computed such that the ratio of width to height of the ',...
'figure on screen is retained. The factor controls the ',...
'''denseness'' of the graphics. For instance, if the width is ',...
'w=12 and the factor is f=0.8, then the graphics in the ',...
'eps-file will have width w/f=15 cm and the tex-file ',...
'scales it down to 12 cm. This means that lines become thinner ',...
'and fonts become smaller (as compared to w=12; f=1.0). ',...
'Good values for papers are f=0.8 to f=1.0, ',...
'and f=1.5 is a good value for presentations. ',...
'Switching font scaling off only scales the graphics. ',...
'You may want to experiment with some w/f/scalefont combinations ',...
'to find out your personal preference. '],...
'',...
'Options --> Translate Matlab Font Properties to LaTeX ',...
'',...
['This option can be switched on/off. When off, all text ',...
'will be set using the LaTeX font which is active while ',...
'entering the tex-file (Matlab font settings are ignored). When ',...
'on, Matlab font settings are translated to LaTeX font ',...
'settings.'],...
'',...
'Options --> Print Limits and Ticks as on Screen',...
'',...
['This option can be switched on/off. When on, the axes ',...
'limits and ticks are frozen. They appear in the LaTeX ',...
'document as on screen. When off, they are adapted by ',...
'Matlab.'],...
'',...
'Options --> Keep Tick Labels within eps File',...
'',...
['This option can be switched on/off. When on, the tick ',...
'labels aren''t replaced by their LaTeX equivalents. This is ',...
'useful for some 3D-plots.'],...
'',...
'Options --> Set Tick Labels in LaTeX Math Mode',...
'',...
['This option can be switched on/off. When on, the tick ',...
'labels are surrounded by a ''$''.'],...
'',...
'Options --> Equip the tex File with a Head',...
'',...
['This option can be switched on/off. When on, the tex-file ',...
'is equipped with a header with a bunch of comments (date, files, ',...
'example, comment text,...).'],...
'',...
'Options --> Comment in the Head of the tex File ...',...
'',...
['This opens a window where you can specify a comment to be ',...
'placed in the header of the tex file.'],...
'',...
'Options --> Place a LaTeX caption in the tex File ...',...
'',...
['This opens a window where you can enter a caption text. If this ',...
'caption text is nonempty, it is placed as a \caption{} ',...
'into the tex-file. Thus the text will appear in the LaTeX ',...
'document. In addition a \label{} is placed in the tex-file ',...
'which can be used to refer to the graphics. The label will ',...
'be fig: followed by the basename of the files, e.g., ',...
'\label{fig:unnamed}.'],...
'',...
'Options --> Place an Extra Picture in each Axes',...
'',...
['This option can be switched on/off. When on, each axes in the ',...
'figure is equipped with an empty LaTeX ''picture'' environment. ',...
'It can be used to place some additional material into the ',...
'figure by editing the tex-file.'],...
'',...
'Options --> Length of the psfrag Replacement Strings ...',...
'',...
['This opens a window where you can enter the length of the ',...
'psfrag tags. If you have huge amounts of text, the default ',...
'length of 3 might not suffice.'],...
'',...
'Options --> Call LaPrint in verbose mode',...
'',...
['This option can be switched on/off. When on, LaPrint issues ',...
'some messages and warns before overwriting files.'],...
'',...
'Options --> Copy Figure and Modify that Copy',...
'',...
['This option can be switched on/off. When on, LaPrint takes ',...
'a copy of the figure to be printed and places its tags into ',...
'that copy. When done, the copy is deleted. When off, the ',...
'figure is messed up by tags. It gets unusable, but you can see ',...
'what LaPrint is doing. Besides, there are bugs in the Matlab ',...
'''copyobj'' command. If these show up, this option is useful.'],...
'',...
'Options --> Matlab Print Command ...',...
'',...
['This opens a window where you can enter the Matlab command to ',...
'save the graphics in an eps-file. You can modify the standard ',...
'print command to include or remove options (like ''-loose'') ',...
'or employ a different command (like exportfig). '],...
'',...
'Options --> Matlab Graphics Package',...
'',...
'You can chose between ''graphicx'' and ''epsfig''.',...
'',...
'Options --> Use LaTeX ''color'' package',...
'',...
['This option can be switched on/off. When on, LaPrint places ',...
'color commands into the tex file to optain colored text.'],...
'',...
'Options --> View File ... --> Create a View File',...
'',...
['This option can be switched on/off. When on, LaPrint creates ',...
'a third file (the view-file), which is a complete LaTeX ',...
'document showing the graphics. You can process this file ',...
'with your favourate LaTeX- and dvi-to-postscript compiler. ',...
'This is useful to have a quick look at the result and to ',...
'create a futher eps-file containing everything (see below). ',...
'The process of compiling the view-file can be automated using ',...
'the options described below.'],...
'',...
'Options --> View File ... --> Name of the View File',...
'',...
['This opens a window where you can enter the name of the ',...
'view-file to be created.'],...
'',...
'Options --> View File ... --> Process the View File',...
'',...
['This option can be switched on/off. When on, LaPrint ',...
'calls the LaTeX compiler and its friends to process the ',...
'view file. The names of the executables to be used and ',...
'their syntax can be set using the following option. '],...
'',...
['Options --> View File ... --> Executables for processing ',...
'View File'],...
'',...
['This opens a window where you can enter the names of up to 8 ',...
'system commands to process the view-file. If you have less than 8 ',...
'programs, you can leave the some of the fields empty. In all ',...
'commands, LaPrint internally replaces the tag ''<viewfile>'' ',...
'by the basename of the viewfile and the tag <filename> by ',...
'the basename specified in the main LaPrint window. ',...
'In following example you have to add the paths, if the ',...
'commands are not in the system search path.'],...
'',...
'To create and view a ps document:',...
' cmd1:  latex <viewfile>.tex',...
' cmd2:  dvips -o<viewfile>.ps <viewfile>.dvi',...
' cmd3:  gsview32 <viewfile>.ps   (ghostview for Unix)',...
'',...
'',...
'Preferences:',...
'~~~~~~~~~~~~',...
['All options and settings of LaPrint can be ',...
'(internally and externally) stored ',...
'in ''Preferences''. Suppose that you have changed, via ',...
'the ''Options'' menu bar entry, the settings of LaPrint. ',...
'You can make these settings to your preferred (default) ',...
'settings by chosing'],...
'',...
'Preferences --> Set Preferences to Current Settings',...
'',...
['This means that future sessions of LaPrint load these ',...
'settings on startup. You can also manually reload these ',...
'settings by chosing'],...
'',...
'Preferences --> Get Preferences',...
'',...
['LaPrint has built-in (factory default) preferences, ',...
'which you see when using ',...
'LaPrint the first time. You can restore these defaults ',...
'by chosing'],...
'',...
'Preferences --> Get Factory Defaults',...
'',...
['If you want your personal preferences be completely removed ',...
'(switching back to factory defaults on startup), you should ',...
'chose'],...
'',...
'Preferences --> Remove Preferences',...
'',...
['If you have multiple projects running and want to use different ',...
'settings simultaneously, you can save/load preferences ',...
'to/from mat-files by chosing'],...
'',...
'Preferences --> Save Current Settings to a File ',...
'Preferences --> Load Settings from a File ',...
'',...
'These open a new window asking for the name of a .mat file.',...
'',...
'Using LaPrint from the command line:',...
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',...
['When using LaPrint from the command line (or from an m-file), ',...
'the following syntax is required:'],...
'',...
'  laprint(figno,filename)',...
'  laprint(figno,filename,opta,vala,optb,valb,..)',...
'',...
'where',...
'  figno        : integer, figure to be printed',...
'  filename     : string (character array), basename of files',...
'                 to be created',...
'  opta,vala,.. : option and value pairs, where opta is one',...
'                 of the following options and vala is',...
'                 the corresponding value.',...
'',...
['When calling LaPrint from the command line without ',...
'option/value pairs, it uses the same '],...
['settings/options as the GUI on startup. This means that ',...
'it uses'],...
['-- the factory default settings (if you havn''t ',...
'stored your personal preferences using the GUI) or '],...
'-- your personal preferences. ',...
'The factory default settings can be enforced by typing ',...
'  laprint(figno,filename,''options'',''factory'')',...
['These settings can be overwritten by option/value pairs ',...
'as explained in the following table.'],...
'',...
'option          |class/val.| remark',...
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',...
'''width''         | <double> | width of the figure in the LaTeX',...
'                |          | document (in cm).',...
'''factor''        | <double> | factor by which the figure in ',...
'                |          | the LaTeX document is smaller than ',...
'                |          | the figure in the postscript file.',...
'''scalefonts''    |''on''/''off''| scales the fonts with the ',...
'                |          | figure (see option ''factor'').',...
'''keepfontprops'' |''on''/''off''| translates MATLAB font',... 
'                |          | properties (size, width, angle) into',...
'                |          | corresponding LaTeX font properties.',... 
'''asonscreen''    |''on''/''off''| prints ticks and lims ',...
'                |          | ''as on screen''.',...
'''keepticklabels''|''on''/''off''| keeps the tick labels within',...
'                |          | the eps-file (not using LaTeX).',...
'''mathticklabels''|''on''/''off''| tick labels are set in LaTeX',...
'                |          | math mode',...
'''head''          |''on''/''off''| places a commenting header in ',...
'                |          | the tex-file.',...
'''comment''       | <string> | places the comment <string> into',...
'                |          | the header of the tex-file.',...
'''caption''       | <string> | adds \caption{<string>} and',...
'                |          | \label{fig:<filename>} to the',...
'                |          | tex-file.',...
'''extrapicture''  |''on''/''off''| adds empty picture environments',...
'                |          | to the axes.',...
'''nzeros''        | <int>    | uses replacement strings of',...
'                |          | length <int> in the eps-file.',...
'''verbose''       |''on''/''off''| verbose mode; asks before',...
'                |          | overwriting files and issues some ',...
'                |          | more messages.',... 
'''figcopy''       |''on''/''off''| directly modifies the original',...
'                |          | figure.',...
'''printcmd''      | <string> | uses ''<string>'' as Matlab print',...
'                |          | command.',...
'''package''       | <string> | uses the LaTeX graphics package',...
'                |          | ''<string>''. Possible values are',...
'                |          | ''graphicx'' and ''epsfig''.',...
'''color''         |''on''/''off''| uses colored fonts (using the',... 
'                |          | LaTeX ''color'' package).',... 
'''createview''    |''on''/''off''| creates a view-file, which ',... 
'                |          | calls the tex-file.',...
'''viewfilename''  | <string> | Basename of the  view-file.',...
'''processview''   |''on''/''off''| processes the view-file ',... 
'                |          | by LaTeX and friends.',...
'''cmd1''          | <string> | 1st Command in the sequence of',...
'                |          | LaTeX and friends (enter an empty',...
'                |          | string to skip this command).',... 
'''cmd2''          | <string> | 2nd LaTeX/friend Command ',...
'''cmd3''          | <string> | 3rd LaTeX/friend Command ',...
'''cmd4''          | <string> | 4th LaTeX/friend Command ',...
'''cmd5''          | <string> | 5th LaTeX/friend Command ',...
'''cmd6''          | <string> | 6th LaTeX/friend Command ',...
'''cmd7''          | <string> | 7th LaTeX/friend Command ',...
'''cmd8''          | <string> | 8th LaTeX/friend Command ',...
'''options''       | <string> | This option can be used to ',...
'                |          | employ project-dependent ',... 
'                |          | preferences as follows:',... 
'                |          | 1) Save your preferences to a file ',... 
'                |          |    using the GUI:',... 
'                |          |    Preferences --> ',... 
'                |          |     Save Current Settings to a file',... 
'                |          | 2) Reload these preferences',... 
'                |          |    with laprint:',... 
'                |          |    >> laprint(1,''unnamed'',..',... 
'                |          |        ''options'',<string>)',... 
'                |          |    where <string> is the name of ',...
'                |          |    the mat-file with preferences.',...
'',...
'',...
' ...................... ENJOY ! .......................',...
'',...
};