-
Notifications
You must be signed in to change notification settings - Fork 2
/
tex.cc
1766 lines (1709 loc) · 71.6 KB
/
tex.cc
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
// -*- mode:C++ ; compile-command: "g++-3.4 -I.. -g -c tex.cc" -*-
#include "giacPCH.h"
/*
* Copyright (C) 2002,2014 B. Parisse, Institut Fourier, 38402 St Martin d'Heres
* Figure printing adapted from eukleides (c) 2002, Christian Obrecht
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __ANDROID__
using std::vector;
#endif
using namespace std;
#include "gen.h"
#include "gausspol.h"
#include "identificateur.h"
#include "symbolic.h"
#include "poly.h"
#include "usual.h"
#include "tex.h"
#include "prog.h"
#include "rpn.h"
#include "plot.h"
#include "giacintl.h"
#if !defined NSPIRE && !defined FXCG && !defined GIAC_HAS_STO_38 && !defined KHICAS && !defined NSPIRE_NEWLIB
#include <fstream>
#endif
#ifndef NO_NAMESPACE_GIAC
namespace giac {
#endif // ndef NO_NAMESPACE_GIAC
// find if a*x+b*y=c intersects the rectangle xmin..xmax,ymin..ymax
// if true set x0,y0 and x1,y1 to the intersections
bool is_clipped(double a,double xmin,double xmax,double b,double ymin,double ymax,double c,double & x0,double &y0,double & x1,double &y1){
int found=0;
// find the intersects with x=xmin/x=xmax
double x,y;
// test whether a or b is too small
double theta=std::atan2(b,a);
if (absdouble(M_PI/2-absdouble(theta))<1e-3){
// line y=cst
x0=xmin;
x1=xmax;
y0=y1=c/b;
return y0>=ymin && y0<=ymax;
}
if (absdouble(theta)<1e-3 || (M_PI-absdouble(theta))<1e-3){
// line x=cst
y0=ymin;
y1=ymax;
x0=x1=c/a;
return x0>=xmin && x0<=xmax;
}
y=(c-a*xmin)/b;
if (y>=ymin && y<=ymax){
++found;
x0=xmin;
y0=y;
}
y=(c-a*xmax)/b;
if (y>=ymin && y<=ymax){
if (found){
x1=xmax;
y1=y;
return true;
}
++found;
x0=xmax;
y0=y;
}
x=(c-b*ymin)/a;
if (x>=xmin && x<=xmax){
if (found){
x1=x;
y1=ymin;
return true;
}
++found;
x0=x;
y0=ymin;
}
x=(c-b*ymax)/a;
if (x>=xmin && x<=xmax){
if (found){
x1=x;
y1=ymax;
return true;
}
++found;
x0=x;
y0=ymax;
}
return false;
}
bool in_rectangle(double ax,double ay,double xmin,double ymin,double xmax,double ymax){
return (ax>=xmin && ax<=xmax && ay>=ymin && ay<=ymax);
}
// clip line or segment or halfline, result in xa,ya xb,yb
// mode can be _LINE__VECT (line), _HALFLINE__VECT (halfline)
// anything else is considered to be a segment
// return true if there is something to draw
bool clip_line(double x1,double y1,double x2,double y2,double xmin,double ymin,double xmax,double ymax,int mode,double & xa,double & ya,double & xb,double & yb){
bool in1=in_rectangle(x1,y1,xmin,ymin,xmax,ymax);
bool in2=in_rectangle(x2,y2,xmin,ymin,xmax,ymax);
if (mode!=_LINE__VECT && mode !=_HALFLINE__VECT && in1 && in2){
xa=x1; ya=y1; xb=x2; yb=y2;
return true;
}
// Line equation is (y2-y1)*x-(x2-x1)*y=(y2*x1-x2*y1)
double dy=y2-y1;
double dx=x2-x1;
double c=(y2*x1-x2*y1);
bool a=false,b=false;
// Find 2 intersections y of x=xmin and x=xmax with line
// Check if they are inside clip region >=ymin and <=ymax
if (dx){
double y=(dy*xmin-c)/dx;
if (y>=ymin && y<=ymax){
xa=xmin;
ya=y;
a=true;
}
y=(dy*xmax-c)/dx;
if (y>=ymin && y<=ymax){
if (a){ xb=xmax; yb=y; b=true; }
else { xa=xmax; ya=y; a=true; }
}
}
// Find 2 intersections of y=ymin and y=ymax with line
if (!b && dy){
double x=(dx*ymin+c)/dy;
if (x>=xmin && x<=xmax){
if (a){ xb=x; yb=ymin; b=true; }
else { xa=x; ya=ymin; a=true;}
}
x=(dx*ymax+c)/dy;
if (x>=xmin && x<=xmax){
if (a){ xb=x; yb=ymax; b=true; }
else { xa=x; ya=ymax; a=true;}
}
}
if (a && b){ // if not true there is nothing to draw
// First case is line, we are done
if (mode==_LINE__VECT)
return true;
if (mode!=_HALFLINE__VECT){ // segment
// we know that both points are not inside
if (!in1 && !in2) // both are outside, it's like a line
return (xa-xmin)*(xb-xmin)<0;
if (in1){ // 1 is in, 2 not, find if a is between 1 and 2
if ((xa-x1)*(x2-x1)>0 || (ya-y1)*(y2-y1)>0){
xb=x1; yb=y1;
}
else {
xa=x1; ya=y1;
}
return true;
}
if (in2){ // 2 is in, 1 not, find if a is between 2 and 1
if ((xa-x2)*(x1-x2)>0 || (ya-y2)*(y1-y2)>0){
xb=x2; yb=y2;
}
else {
xa=x2; ya=y2;
}
return true;
}
}
}
return false;
}
// dimension of the LaTeX output figures default 12 cm x 12 cm
double horiz_latex=12.;
double vert_latex=12.;
const char tex_preamble[]="\\documentclass{article} \n\\usepackage{pst-plot,color} \n\\usepackage{graphicx} \n\\begin{document}\n";
#if defined RTOS_THREADX || defined POCKETCAS
const char tex_color[]="";
#else
const char tex_color[]="\\newrgbcolor{fltkcolor0}{0 0 0}\n\\newrgbcolor{fltkcolor1}{0.9961 0 0}\n\\newrgbcolor{fltkcolor2}{0 0.9961 0}\n\\newrgbcolor{fltkcolor3}{0.9961 0.9961 0}\n\\newrgbcolor{fltkcolor4}{0 0 0.9961}\n\\newrgbcolor{fltkcolor5}{0.9961 0 0.9961}\n\\newrgbcolor{fltkcolor6}{0 0.9961 0.9961}\n\\newrgbcolor{fltkcolor7}{0.9961 0.9961 0.9961}\n\\newrgbcolor{fltkcolor8}{0.332 0.332 0.332}\n\\newrgbcolor{fltkcolor9}{0.7734 0.4414 0.4414}\n\\newrgbcolor{fltkcolor10}{0.4414 0.7734 0.4414}\n\\newrgbcolor{fltkcolor11}{0.5547 0.5547 0.2188}\n\\newrgbcolor{fltkcolor12}{0.4414 0.4414 0.7734}\n\\newrgbcolor{fltkcolor13}{0.5547 0.2188 0.5547}\n\\newrgbcolor{fltkcolor14}{0.2188 0.5547 0.5547}\n\\newrgbcolor{fltkcolor15}{0 0 0.5}\n\\newrgbcolor{fltkcolor16}{0.6562 0.6562 0.5938}\n\\newrgbcolor{fltkcolor17}{0.9062 0.9062 0.8438}\n\\newrgbcolor{fltkcolor18}{0.4062 0.4062 0.3438}\n\\newrgbcolor{fltkcolor19}{0.5938 0.6562 0.6562}\n\\newrgbcolor{fltkcolor20}{0.8438 0.9062 0.9062}\n\\newrgbcolor{fltkcolor21}{0.3438 0.4062 0.4062}\n\\newrgbcolor{fltkcolor22}{0.6094 0.6094 0.6562}\n\\newrgbcolor{fltkcolor23}{0.8594 0.8594 0.9062}\n\\newrgbcolor{fltkcolor24}{0.3594 0.3594 0.4062}\n\\newrgbcolor{fltkcolor25}{0.6094 0.6562 0.6094}\n\\newrgbcolor{fltkcolor26}{0.8594 0.9062 0.8594}\n\\newrgbcolor{fltkcolor27}{0.3594 0.4062 0.3594}\n\\newrgbcolor{fltkcolor28}{0.5625 0.5625 0.5625}\n\\newrgbcolor{fltkcolor29}{0.75 0.75 0.75}\n\\newrgbcolor{fltkcolor30}{0.3125 0.3125 0.3125}\n\\newrgbcolor{fltkcolor31}{0.625 0.625 0.625}\n\\newrgbcolor{fltkcolor32}{0 0 0}\n\\newrgbcolor{fltkcolor33}{0.05078 0.05078 0.05078}\n\\newrgbcolor{fltkcolor34}{0.1016 0.1016 0.1016}\n\\newrgbcolor{fltkcolor35}{0.1484 0.1484 0.1484}\n\\newrgbcolor{fltkcolor36}{0.1914 0.1914 0.1914}\n\\newrgbcolor{fltkcolor37}{0.2383 0.2383 0.2383}\n\\newrgbcolor{fltkcolor38}{0.2812 0.2812 0.2812}\n\\newrgbcolor{fltkcolor39}{0.332 0.332 0.332}\n\\newrgbcolor{fltkcolor40}{0.3711 0.3711 0.3711}\n\\newrgbcolor{fltkcolor41}{0.4141 0.4141 0.4141}\n\\newrgbcolor{fltkcolor42}{0.457 0.457 0.457}\n\\newrgbcolor{fltkcolor43}{0.5 0.5 0.5}\n\\newrgbcolor{fltkcolor44}{0.5391 0.5391 0.5391}\n\\newrgbcolor{fltkcolor45}{0.582 0.582 0.582}\n\\newrgbcolor{fltkcolor46}{0.625 0.625 0.625}\n\\newrgbcolor{fltkcolor47}{0.6641 0.6641 0.6641}\n\\newrgbcolor{fltkcolor48}{0.707 0.707 0.707}\n\\newrgbcolor{fltkcolor49}{0.75 0.75 0.75}\n\\newrgbcolor{fltkcolor50}{0.793 0.793 0.793}\n\\newrgbcolor{fltkcolor51}{0.832 0.832 0.832}\n\\newrgbcolor{fltkcolor52}{0.875 0.875 0.875}\n\\newrgbcolor{fltkcolor53}{0.9141 0.9141 0.9141}\n\\newrgbcolor{fltkcolor54}{0.957 0.957 0.957}\n\\newrgbcolor{fltkcolor55}{0.9961 0.9961 0.9961}\n\\newrgbcolor{fltkcolor56}{0 0 0}\n\\newrgbcolor{fltkcolor57}{0 0.1406 0}\n\\newrgbcolor{fltkcolor58}{0 0.2812 0}\n\\newrgbcolor{fltkcolor59}{0 0.4258 0}\n\\newrgbcolor{fltkcolor60}{0 0.5664 0}\n\\newrgbcolor{fltkcolor61}{0 0.7109 0}\n\\newrgbcolor{fltkcolor62}{0 0.8516 0}\n\\newrgbcolor{fltkcolor63}{0 0.9961 0}\n\\newrgbcolor{fltkcolor64}{0.2461 0 0}\n\\newrgbcolor{fltkcolor65}{0.2461 0.1406 0}\n\\newrgbcolor{fltkcolor66}{0.2461 0.2812 0}\n\\newrgbcolor{fltkcolor67}{0.2461 0.4258 0}\n\\newrgbcolor{fltkcolor68}{0.2461 0.5664 0}\n\\newrgbcolor{fltkcolor69}{0.2461 0.7109 0}\n\\newrgbcolor{fltkcolor70}{0.2461 0.8516 0}\n\\newrgbcolor{fltkcolor71}{0.2461 0.9961 0}\n\\newrgbcolor{fltkcolor72}{0.4961 0 0}\n\\newrgbcolor{fltkcolor73}{0.4961 0.1406 0}\n\\newrgbcolor{fltkcolor74}{0.4961 0.2812 0}\n\\newrgbcolor{fltkcolor75}{0.4961 0.4258 0}\n\\newrgbcolor{fltkcolor76}{0.4961 0.5664 0}\n\\newrgbcolor{fltkcolor77}{0.4961 0.7109 0}\n\\newrgbcolor{fltkcolor78}{0.4961 0.8516 0}\n\\newrgbcolor{fltkcolor79}{0.4961 0.9961 0}\n\\newrgbcolor{fltkcolor80}{0.7461 0 0}\n\\newrgbcolor{fltkcolor81}{0.7461 0.1406 0}\n\\newrgbcolor{fltkcolor82}{0.7461 0.2812 0}\n\\newrgbcolor{fltkcolor83}{0.7461 0.4258 0}\n\\newrgbcolor{fltkcolor84}{0.7461 0.5664 0}\n\\newrgbcolor{fltkcolor85}{0.7461 0.7109 0}\n\\newrgbcolor{fltkcolor86}{0.7461 0.8516 0}\n\\newrgbcolor{fltkcolor87}{0.7461 0.9961 0}\n\\newrgbcolor{fltkcolor88}{0.9961 0 0}\n\\newrgbcolor{fltkcolor89}{0.9961 0.1406 0}\n\\newrgbcolor{fltkcolor90}{0.9961 0.2812 0}\n\\newrgbcolor{fltkcolor91}{0.9961 0.4258 0}\n\\newrgbcolor{fltkcolor92}{0.9961 0.5664 0}\n\\newrgbcolor{fltkcolor93}{0.9961 0.7109 0}\n\\newrgbcolor{fltkcolor94}{0.9961 0.8516 0}\n\\newrgbcolor{fltkcolor95}{0.9961 0.9961 0}\n\\newrgbcolor{fltkcolor96}{0 0 0.2461}\n\\newrgbcolor{fltkcolor97}{0 0.1406 0.2461}\n\\newrgbcolor{fltkcolor98}{0 0.2812 0.2461}\n\\newrgbcolor{fltkcolor99}{0 0.4258 0.2461}\n\\newrgbcolor{fltkcolor100}{0 0.5664 0.2461}\n\\newrgbcolor{fltkcolor101}{0 0.7109 0.2461}\n\\newrgbcolor{fltkcolor102}{0 0.8516 0.2461}\n\\newrgbcolor{fltkcolor103}{0 0.9961 0.2461}\n\\newrgbcolor{fltkcolor104}{0.2461 0 0.2461}\n\\newrgbcolor{fltkcolor105}{0.2461 0.1406 0.2461}\n\\newrgbcolor{fltkcolor106}{0.2461 0.2812 0.2461}\n\\newrgbcolor{fltkcolor107}{0.2461 0.4258 0.2461}\n\\newrgbcolor{fltkcolor108}{0.2461 0.5664 0.2461}\n\\newrgbcolor{fltkcolor109}{0.2461 0.7109 0.2461}\n\\newrgbcolor{fltkcolor110}{0.2461 0.8516 0.2461}\n\\newrgbcolor{fltkcolor111}{0.2461 0.9961 0.2461}\n\\newrgbcolor{fltkcolor112}{0.4961 0 0.2461}\n\\newrgbcolor{fltkcolor113}{0.4961 0.1406 0.2461}\n\\newrgbcolor{fltkcolor114}{0.4961 0.2812 0.2461}\n\\newrgbcolor{fltkcolor115}{0.4961 0.4258 0.2461}\n\\newrgbcolor{fltkcolor116}{0.4961 0.5664 0.2461}\n\\newrgbcolor{fltkcolor117}{0.4961 0.7109 0.2461}\n\\newrgbcolor{fltkcolor118}{0.4961 0.8516 0.2461}\n\\newrgbcolor{fltkcolor119}{0.4961 0.9961 0.2461}\n\\newrgbcolor{fltkcolor120}{0.7461 0 0.2461}\n\\newrgbcolor{fltkcolor121}{0.7461 0.1406 0.2461}\n\\newrgbcolor{fltkcolor122}{0.7461 0.2812 0.2461}\n\\newrgbcolor{fltkcolor123}{0.7461 0.4258 0.2461}\n\\newrgbcolor{fltkcolor124}{0.7461 0.5664 0.2461}\n\\newrgbcolor{fltkcolor125}{0.7461 0.7109 0.2461}\n\\newrgbcolor{fltkcolor126}{0.7461 0.8516 0.2461}\n\\newrgbcolor{fltkcolor127}{0.7461 0.9961 0.2461}\n\\newrgbcolor{fltkcolor128}{0.9961 0 0.2461}\n\\newrgbcolor{fltkcolor129}{0.9961 0.1406 0.2461}\n\\newrgbcolor{fltkcolor130}{0.9961 0.2812 0.2461}\n\\newrgbcolor{fltkcolor131}{0.9961 0.4258 0.2461}\n\\newrgbcolor{fltkcolor132}{0.9961 0.5664 0.2461}\n\\newrgbcolor{fltkcolor133}{0.9961 0.7109 0.2461}\n\\newrgbcolor{fltkcolor134}{0.9961 0.8516 0.2461}\n\\newrgbcolor{fltkcolor135}{0.9961 0.9961 0.2461}\n\\newrgbcolor{fltkcolor136}{0 0 0.4961}\n\\newrgbcolor{fltkcolor137}{0 0.1406 0.4961}\n\\newrgbcolor{fltkcolor138}{0 0.2812 0.4961}\n\\newrgbcolor{fltkcolor139}{0 0.4258 0.4961}\n\\newrgbcolor{fltkcolor140}{0 0.5664 0.4961}\n\\newrgbcolor{fltkcolor141}{0 0.7109 0.4961}\n\\newrgbcolor{fltkcolor142}{0 0.8516 0.4961}\n\\newrgbcolor{fltkcolor143}{0 0.9961 0.4961}\n\\newrgbcolor{fltkcolor144}{0.2461 0 0.4961}\n\\newrgbcolor{fltkcolor145}{0.2461 0.1406 0.4961}\n\\newrgbcolor{fltkcolor146}{0.2461 0.2812 0.4961}\n\\newrgbcolor{fltkcolor147}{0.2461 0.4258 0.4961}\n\\newrgbcolor{fltkcolor148}{0.2461 0.5664 0.4961}\n\\newrgbcolor{fltkcolor149}{0.2461 0.7109 0.4961}\n\\newrgbcolor{fltkcolor150}{0.2461 0.8516 0.4961}\n\\newrgbcolor{fltkcolor151}{0.2461 0.9961 0.4961}\n\\newrgbcolor{fltkcolor152}{0.4961 0 0.4961}\n\\newrgbcolor{fltkcolor153}{0.4961 0.1406 0.4961}\n\\newrgbcolor{fltkcolor154}{0.4961 0.2812 0.4961}\n\\newrgbcolor{fltkcolor155}{0.4961 0.4258 0.4961}\n\\newrgbcolor{fltkcolor156}{0.4961 0.5664 0.4961}\n\\newrgbcolor{fltkcolor157}{0.4961 0.7109 0.4961}\n\\newrgbcolor{fltkcolor158}{0.4961 0.8516 0.4961}\n\\newrgbcolor{fltkcolor159}{0.4961 0.9961 0.4961}\n\\newrgbcolor{fltkcolor160}{0.7461 0 0.4961}\n\\newrgbcolor{fltkcolor161}{0.7461 0.1406 0.4961}\n\\newrgbcolor{fltkcolor162}{0.7461 0.2812 0.4961}\n\\newrgbcolor{fltkcolor163}{0.7461 0.4258 0.4961}\n\\newrgbcolor{fltkcolor164}{0.7461 0.5664 0.4961}\n\\newrgbcolor{fltkcolor165}{0.7461 0.7109 0.4961}\n\\newrgbcolor{fltkcolor166}{0.7461 0.8516 0.4961}\n\\newrgbcolor{fltkcolor167}{0.7461 0.9961 0.4961}\n\\newrgbcolor{fltkcolor168}{0.9961 0 0.4961}\n\\newrgbcolor{fltkcolor169}{0.9961 0.1406 0.4961}\n\\newrgbcolor{fltkcolor170}{0.9961 0.2812 0.4961}\n\\newrgbcolor{fltkcolor171}{0.9961 0.4258 0.4961}\n\\newrgbcolor{fltkcolor172}{0.9961 0.5664 0.4961}\n\\newrgbcolor{fltkcolor173}{0.9961 0.7109 0.4961}\n\\newrgbcolor{fltkcolor174}{0.9961 0.8516 0.4961}\n\\newrgbcolor{fltkcolor175}{0.9961 0.9961 0.4961}\n\\newrgbcolor{fltkcolor176}{0 0 0.7461}\n\\newrgbcolor{fltkcolor177}{0 0.1406 0.7461}\n\\newrgbcolor{fltkcolor178}{0 0.2812 0.7461}\n\\newrgbcolor{fltkcolor179}{0 0.4258 0.7461}\n\\newrgbcolor{fltkcolor180}{0 0.5664 0.7461}\n\\newrgbcolor{fltkcolor181}{0 0.7109 0.7461}\n\\newrgbcolor{fltkcolor182}{0 0.8516 0.7461}\n\\newrgbcolor{fltkcolor183}{0 0.9961 0.7461}\n\\newrgbcolor{fltkcolor184}{0.2461 0 0.7461}\n\\newrgbcolor{fltkcolor185}{0.2461 0.1406 0.7461}\n\\newrgbcolor{fltkcolor186}{0.2461 0.2812 0.7461}\n\\newrgbcolor{fltkcolor187}{0.2461 0.4258 0.7461}\n\\newrgbcolor{fltkcolor188}{0.2461 0.5664 0.7461}\n\\newrgbcolor{fltkcolor189}{0.2461 0.7109 0.7461}\n\\newrgbcolor{fltkcolor190}{0.2461 0.8516 0.7461}\n\\newrgbcolor{fltkcolor191}{0.2461 0.9961 0.7461}\n\\newrgbcolor{fltkcolor192}{0.4961 0 0.7461}\n\\newrgbcolor{fltkcolor193}{0.4961 0.1406 0.7461}\n\\newrgbcolor{fltkcolor194}{0.4961 0.2812 0.7461}\n\\newrgbcolor{fltkcolor195}{0.4961 0.4258 0.7461}\n\\newrgbcolor{fltkcolor196}{0.4961 0.5664 0.7461}\n\\newrgbcolor{fltkcolor197}{0.4961 0.7109 0.7461}\n\\newrgbcolor{fltkcolor198}{0.4961 0.8516 0.7461}\n\\newrgbcolor{fltkcolor199}{0.4961 0.9961 0.7461}\n\\newrgbcolor{fltkcolor200}{0.7461 0 0.7461}\n\\newrgbcolor{fltkcolor201}{0.7461 0.1406 0.7461}\n\\newrgbcolor{fltkcolor202}{0.7461 0.2812 0.7461}\n\\newrgbcolor{fltkcolor203}{0.7461 0.4258 0.7461}\n\\newrgbcolor{fltkcolor204}{0.7461 0.5664 0.7461}\n\\newrgbcolor{fltkcolor205}{0.7461 0.7109 0.7461}\n\\newrgbcolor{fltkcolor206}{0.7461 0.8516 0.7461}\n\\newrgbcolor{fltkcolor207}{0.7461 0.9961 0.7461}\n\\newrgbcolor{fltkcolor208}{0.9961 0 0.7461}\n\\newrgbcolor{fltkcolor209}{0.9961 0.1406 0.7461}\n\\newrgbcolor{fltkcolor210}{0.9961 0.2812 0.7461}\n\\newrgbcolor{fltkcolor211}{0.9961 0.4258 0.7461}\n\\newrgbcolor{fltkcolor212}{0.9961 0.5664 0.7461}\n\\newrgbcolor{fltkcolor213}{0.9961 0.7109 0.7461}\n\\newrgbcolor{fltkcolor214}{0.9961 0.8516 0.7461}\n\\newrgbcolor{fltkcolor215}{0.9961 0.9961 0.7461}\n\\newrgbcolor{fltkcolor216}{0 0 0.9961}\n\\newrgbcolor{fltkcolor217}{0 0.1406 0.9961}\n\\newrgbcolor{fltkcolor218}{0 0.2812 0.9961}\n\\newrgbcolor{fltkcolor219}{0 0.4258 0.9961}\n\\newrgbcolor{fltkcolor220}{0 0.5664 0.9961}\n\\newrgbcolor{fltkcolor221}{0 0.7109 0.9961}\n\\newrgbcolor{fltkcolor222}{0 0.8516 0.9961}\n\\newrgbcolor{fltkcolor223}{0 0.9961 0.9961}\n\\newrgbcolor{fltkcolor224}{0.2461 0 0.9961}\n\\newrgbcolor{fltkcolor225}{0.2461 0.1406 0.9961}\n\\newrgbcolor{fltkcolor226}{0.2461 0.2812 0.9961}\n\\newrgbcolor{fltkcolor227}{0.2461 0.4258 0.9961}\n\\newrgbcolor{fltkcolor228}{0.2461 0.5664 0.9961}\n\\newrgbcolor{fltkcolor229}{0.2461 0.7109 0.9961}\n\\newrgbcolor{fltkcolor230}{0.2461 0.8516 0.9961}\n\\newrgbcolor{fltkcolor231}{0.2461 0.9961 0.9961}\n\\newrgbcolor{fltkcolor232}{0.4961 0 0.9961}\n\\newrgbcolor{fltkcolor233}{0.4961 0.1406 0.9961}\n\\newrgbcolor{fltkcolor234}{0.4961 0.2812 0.9961}\n\\newrgbcolor{fltkcolor235}{0.4961 0.4258 0.9961}\n\\newrgbcolor{fltkcolor236}{0.4961 0.5664 0.9961}\n\\newrgbcolor{fltkcolor237}{0.4961 0.7109 0.9961}\n\\newrgbcolor{fltkcolor238}{0.4961 0.8516 0.9961}\n\\newrgbcolor{fltkcolor239}{0.4961 0.9961 0.9961}\n\\newrgbcolor{fltkcolor240}{0.7461 0 0.9961}\n\\newrgbcolor{fltkcolor241}{0.7461 0.1406 0.9961}\n\\newrgbcolor{fltkcolor242}{0.7461 0.2812 0.9961}\n\\newrgbcolor{fltkcolor243}{0.7461 0.4258 0.9961}\n\\newrgbcolor{fltkcolor244}{0.7461 0.5664 0.9961}\n\\newrgbcolor{fltkcolor245}{0.7461 0.7109 0.9961}\n\\newrgbcolor{fltkcolor246}{0.7461 0.8516 0.9961}\n\\newrgbcolor{fltkcolor247}{0.7461 0.9961 0.9961}\n\\newrgbcolor{fltkcolor248}{0.9961 0 0.9961}\n\\newrgbcolor{fltkcolor249}{0.9961 0.1406 0.9961}\n\\newrgbcolor{fltkcolor250}{0.9961 0.2812 0.9961}\n\\newrgbcolor{fltkcolor251}{0.9961 0.4258 0.9961}\n\\newrgbcolor{fltkcolor252}{0.9961 0.5664 0.9961}\n\\newrgbcolor{fltkcolor253}{0.9961 0.7109 0.9961}\n\\newrgbcolor{fltkcolor254}{0.9961 0.8516 0.9961}\n\\newrgbcolor{fltkcolor255}{0.9961 0.9961 0.9961}\n";
#endif
const char tex_end[]="\n\\end{document}";
const char mbox_begin[]="\\mathrm{"; // ("\\mbox{");
const char mbox_end[]="}";
string spread2tex(const matrice & m,int formule,GIAC_CONTEXT){
int l=int(m.size());
if (!l)
return "\\mbox{empty_spread}";
int c=int(m.front()._VECTptr->size());
string s("\\ \\mbox{\\begin{tabular}{|");
for (int j=0;j<=c;++j)
s += "r|";
s += "}\\hline\n & ";
for (int k=0;;){ // write first line
string tmp;
int i=k;
for(int j=0;;++j){
tmp=char('A'+i%26-(j!=0))+tmp;
i=i/26;
if (!i)
break;
}
s += tmp;
++k;
if (k==c){
s += " \\\\\\hline\n";
break;
}
else
s += " & ";
}
for (int i=0;i<l;++i){
s += print_INT_(i)+" & ";
for (int j=0;j<c;++j){
if (formule)
s += "$"+gen2tex(m[i][j][formule],contextptr)+"$" ;
else {
int save_r=printcell_current_row(contextptr),save_c=printcell_current_col(contextptr);
printcell_current_row(contextptr)=i,printcell_current_col(contextptr)=j;
string t(m[i][j][0].print(contextptr)),tt;
int ll=int(t.size());
for (int l=0;l<ll;++l){
if (t[l]!='$')
tt += t[l];
else
tt += "\\$";
}
s += "{\\tt $"+tt+"$}";
printcell_current_row(contextptr)=save_r;printcell_current_col(contextptr)=save_c;
}
if (j!=c-1)
s += " & ";
}
if (i!=l-1){
if (i%5==4)
s += " \\\\\\hline";
else
s += " \\\\";
}
else
s += " \\\\\\hline";
s+='\n';
}
s += "\\end{tabular} } ";
return s;
}
static string matrix2tex(const matrice & m,GIAC_CONTEXT){
int l=int(m.size());
if (!l)
return string("()");
int c=int(m.front()._VECTptr->size());
string s("\\left(\\begin{array}{");
for (int j=0;j<c;++j)
s += 'c';
s += "}\n";
for (int i=0;i<l;++i){
for (int j=0;j<c;++j){
s += gen2tex(m[i][j],contextptr) ;
if (j!=c-1)
s += " & ";
}
if (i!=l-1)
s += " \\\\";
s+='\n';
}
s += "\\end{array}\\right) ";
return s;
}
static string _VECT2tex(const vecteur & v,int subtype,GIAC_CONTEXT){
string s(begin_VECT_string(subtype,true,contextptr));
vecteur::const_iterator it=v.begin(),itend=v.end();
for (;it!=itend;){
s += gen2tex(*it,contextptr);
++it;
if (it!=itend)
s += ',';
}
s += end_VECT_string(subtype,true,contextptr);
return s;
}
static string prod_vect2tex(const vecteur & v,GIAC_CONTEXT){
if (v.empty())
return "1";
vecteur::const_iterator it=v.begin(),itend=v.end();
string s;
for (;;){
if ( (it->type==_CPLX && !is_zero(*it->_CPLXptr) && !is_zero(*(it->_CPLXptr+1))) || (it->type==_SYMB && ( it->_SYMBptr->sommet==at_plus || (it->_SYMBptr->sommet==at_neg && need_parenthesis(it->_SYMBptr->feuille)) ) ) )
s += string("(")+gen2tex(*it,contextptr)+string(")");
else
s += gen2tex(*it,contextptr);
++it;
if (it==itend)
return s;
if (it->type<=_IDNT || (it->type==_SYMB &&
(it->_SYMBptr->sommet==at_neg || (it->_SYMBptr->sommet.ptr()->printsommet && it->_SYMBptr->feuille.type==_VECT && !it->_SYMBptr->feuille._VECTptr->empty() && it->_SYMBptr->feuille._VECTptr->front().type<=_IDNT))
)) // second part of the test added for e.g. latex('2*3*5^2')
s += "\\cdot ";
else
s += " ";
}
}
string translate_underscore(const string & s){
string res;
string::const_iterator it=s.begin(),itend=s.end();
for (;it!=itend;++it){
switch (*it){
case '_':
res += "\\_";
break;
case '^':
res += "{\\tt\\symbol{94}}";
break;
case '~':
res += "{\\tt\\symbol{126}}";
break;
case '<':
res += "{\\tt\\symbol{60}}";
break;
case '>':
res += "{\\tt\\symbol{62}}";
break;
case '\n':
res += "\\\\\n";
break;
case '&':
res += "\\&";
break;
case '{':
res += "\\{";
break;
case '}':
res += "\\}";
break;
case '\\':
res += "$\\backslash $";
break;
case '%':
res += "\\%";
break;
case '#':
res += "\\#";
break;
case '$':
res += "\\$";
break;
default:
res += *it;
}
}
string s0;
greek2tex(res,s0,false);
return s0;
}
static string fill_flag(bool flag){
if (flag)
return "linestyle=none,fillstyle=solid,";
else
return "";
}
/*
static string line_flag(int flag){
switch(flag) {
case _STYLE_FULL : return "";
case _STYLE_DOTTED : return "[linestyle=dotted]";
case _STYLE_DASHED : return "[linestyle=dashed]";
}
return "error";
}
*/
static string vector_flag(int flag){
switch(flag) {
case _VECTOR__VECT : return "{->}";
// case BACKARROW : return "{<-}";
// case DOUBLEARROW : return "{<->}";
default : return "";
}
}
static string point_flag(int flag){
switch(flag) {
case _STYLE_BOX : return "[dotstyle=square*]";
case _STYLE_CROSS : return "[dotstyle=x]";
case _STYLE_PLUS : return "[dotstyle=+]";
default : return "[dotstyle=*]";
}
}
#ifdef GIAC_HAS_STO_38
static string flcolor2pstrickscolor(int color){
switch(color) {
case FL_BLACK: return "black";
case FL_WHITE: return "white";
case FL_DARK1: return "darkgray";
case FL_GRAY: return "gray";
}
return "unknown";
}
#else
static string flcolor2pstrickscolor(int color){
switch(color) {
case FL_BLACK: return "black";
case FL_DARK1: return "darkgray";
case FL_GRAY: return "gray";
case FL_LIGHT1 : return "lightgray";
#ifdef HAVE_LIBFLTK
case _WHITE: return "white";
#endif
case FL_WHITE : return "white";
#ifdef HAVE_LIBFLTK
case _RED: return "red";
#endif
case FL_RED : return "red";
#ifdef HAVE_LIBFLTK
case _GREEN: return "green";
#endif
case FL_GREEN : return "green";
#ifdef HAVE_LIBFLTK
case _BLUE: return "blue";
#endif
case FL_BLUE : return "blue";
#ifdef HAVE_LIBFLTK
case _CYAN: return "cyan";
#endif
case FL_CYAN : return "cyan";
#ifdef HAVE_LIBFLTK
case _MAGENTA: return "magenta";
#endif
case FL_MAGENTA : return "magenta";
#ifdef HAVE_LIBFLTK
case _YELLOW: return "yellow";
#endif
case FL_YELLOW : return "yellow";
default: return "black";
}
return "fltkcolor"+print_INT_(color);
}
#endif // GIAC_HAS_STO_38
static string double2tex(double d){
char s[32];
#if 0 // def BESTA_OS
assert(0);
// returning an auto-var, when the string is constructed before the copy?
// not the niceest of things to do....
// BP: I don't understand where you see a problem, a string is constructed from s
// then the std::string is returned
#else
if (d<=-1e30 || d>=1e30)
sprintfdouble(s,"%13g",d);
else
sprintfdouble(s,"%13.6f",d);
#endif
return s;
}
// convert UTF-8 string to wchar_t *, return adjusted length
// FIXME: use utf82unicode instead?
static unsigned int utf8(wchar_t * wline,const char * line,unsigned int n){
unsigned int i=0,j=0,c;
for (;i<n;i++){
c=line[i];
if ( (c & 0xc0) == 0x80)
continue;
if (c < 128){
wline[j]=c;
j++;
continue;
}
if ( (c & 0xe0) == 0xc0) {
i++;
c = (c & 0x1f) << 6 | (line[i] & 0x3f);
wline[j]=c;
j++;
continue;
}
if ( (c & 0xf0) == 0xe0) {
i++;
c = (c & 0x0f) << 6 | (line[i] & 0x3f);
i++;
c = c << 6 | (line[i] & 0x3f);
wline[j]=c;
j++;
continue;
}
if ( (c & 0xf1) == 0xf0) {
i++;
c = (c & 0x0f) << 6 | (line[i] & 0x3f);
i++;
c = c << 6 | (line[i] & 0x3f);
i++;
c = c << 6 | (line[i] & 0x3f);
} else
c = 0xfffd;
wline[j]=c;
j++;
}
wline[j]=0;
return j;
}
int greek2tex(const string & s,string & texs,bool mathmode){
int n=int(s.size()),res=0;
wchar_t * w = new wchar_t[n+1];
n=utf8(w,s.c_str(),n);
for (int j=0;j<n;j++){
switch(w[j]){
case 8745: if (!mathmode) texs+="$"; texs+="\\cap"; texs+=mathmode?' ':'$'; res++; break; // '∩'
case 8746: if (!mathmode) texs+="$"; texs+="\\cup"; texs+=mathmode?' ':'$'; res++; break; // '∪'
case 8599: if (!mathmode) texs+="$"; texs+="\\nearrow"; texs+=mathmode?' ':'$'; res++; break;
case 8600: if (!mathmode) texs+="$"; texs+="\\searrow"; texs+=mathmode?' ':'$'; res++; break;
case 8595: if (!mathmode) texs+="$"; texs+="\\downarrow"; texs+=mathmode?' ':'$'; res++; break;
case 8593: if (!mathmode) texs+="$"; texs+="\\uparrow"; texs+=mathmode?' ':'$'; res++; break;
case 0x0386: texs+="\\'A"; break;
case 0x0388: texs+="\\'E"; break;
case 0x0389: texs+="\\'H"; break;
case 0x038A: texs+="\\'I"; break;
case 0x038C: texs+="\\'O"; break;
case 0x038E: texs+="\\'Y"; break;
case 0x038F: if (!mathmode) texs+="$"; texs+="\\Omega"; texs+=mathmode?' ':'$'; res++; break;
case 0x0390: texs+="\'i"; break;
case 0x0391: texs+="A"; break;
case 0x0392: texs+="B"; break;
case 0x0393: if (!mathmode) texs+="$"; texs+="\\Gamma"; texs+=mathmode?' ':'$'; res++; break;
case 0x0394: if (!mathmode) texs+="$"; texs+="\\Delta"; texs+=mathmode?' ':'$'; res++; break;
case 0x0395: texs+="E"; break;
case 0x0396: texs+="Z"; break;
case 0x0397: texs+="H"; break;
case 0x0398: if (!mathmode) texs+="$"; texs+="\\Eta"; texs+=mathmode?' ':'$'; res++; break;
case 0x0399: texs+="I"; break;
case 0x039A: texs+="K"; break;
case 0x039B: if (!mathmode) texs+="$"; texs+="\\Lambda"; texs+=mathmode?' ':'$'; res++; break;
case 0x039C: texs+="M"; break;
case 0x039D: texs+="N"; break;
case 0x039E: if (!mathmode) texs+="$"; texs+="\\Xi"; texs+=mathmode?' ':'$'; res++; break;
case 0x039F: texs+="O"; break;
case 0x03A0: if (!mathmode) texs+="$"; texs+="\\Pi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03A1: texs+="P"; break;
case 0x03A3: if (!mathmode) texs+="$"; texs+="\\Sigma"; texs+=mathmode?' ':'$'; res++; break;
case 0x03A4: texs+="T"; break;
case 0x03A5: texs+="Y"; break;
case 0x03A6: if (!mathmode) texs+="$"; texs+="\\Phi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03A7: texs+="X"; break;
case 0x03A8: if (!mathmode) texs+="$"; texs+="\\Psi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03A9: if (!mathmode) texs+="$"; texs+="\\Omega"; texs+=mathmode?' ':'$'; res++; break;
case 0x03AA: texs+="I"; break;
case 0x03AB: texs+="Y"; break;
case 0x03AC: if (!mathmode) texs+="$"; texs+="\\alpha"; texs+=mathmode?' ':'$'; res++; break;
case 0x03AD: if (!mathmode) texs+="$"; texs+="\\epsilon"; texs+=mathmode?' ':'$'; res++; break;
case 0x03AE: if (!mathmode) texs+="$"; texs+="\\eta"; texs+=mathmode?' ':'$'; res++; break;
case 0x03AF: texs+="i"; res++; break;
case 0x03B0: if (!mathmode) texs+="$"; texs+="\\upsilon"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B1: if (!mathmode) texs+="$"; texs+="\\alpha"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B2: if (!mathmode) texs+="$"; texs+="\\beta"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B3: if (!mathmode) texs+="$"; texs+="\\gamma"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B4: if (!mathmode) texs+="$"; texs+="\\delta"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B5: if (!mathmode) texs+="$"; texs+="\\epsilon"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B6: if (!mathmode) texs+="$"; texs+="\\zeta"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B7: if (!mathmode) texs+="$"; texs+="\\eta"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B8: if (!mathmode) texs+="$"; texs+="\\theta"; texs+=mathmode?' ':'$'; res++; break;
case 0x03B9: texs+="i"; res++; break;
case 0x03BA: if (!mathmode) texs+="$"; texs+="\\kappa"; texs+=mathmode?' ':'$'; res++; break;
case 0x03BB: if (!mathmode) texs+="$"; texs+="\\lambda"; texs+=mathmode?' ':'$'; res++; break;
case 0x03BC: if (!mathmode) texs+="$"; texs+="\\mu"; texs+=mathmode?' ':'$'; res++; break;
case 0x03BD: if (!mathmode) texs+="$"; texs+="\\nu"; texs+=mathmode?' ':'$'; res++; break;
case 0x03BE: if (!mathmode) texs+="$"; texs+="\\xi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03BF: if (!mathmode) texs+="$"; texs+="\\omicron"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C0: if (!mathmode) texs+="$"; texs+="\\pi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C1: if (!mathmode) texs+="$"; texs+="\\rho"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C2: texs+="V"; res++; break;
case 0x03C3: if (!mathmode) texs+="$"; texs+="\\sigma"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C4: if (!mathmode) texs+="$"; texs+="\\tau"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C5: if (!mathmode) texs+="$"; texs+="\\upsilon"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C6: if (!mathmode) texs+="$"; texs+="\\varphi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C7: if (!mathmode) texs+="$"; texs+="\\chi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C8: if (!mathmode) texs+="$"; texs+="\\psi"; texs+=mathmode?' ':'$'; res++; break;
case 0x03C9: if (!mathmode) texs+="$"; texs+="\\omega"; texs+=mathmode?' ':'$'; res++; break;
case 0x03CA: texs+="i"; res++; break;
case 0x03CB: if (!mathmode) texs+="$"; texs+="\\upsilon"; texs+=mathmode?' ':'$'; res++; break;
case 0x03CC: if (!mathmode) texs+="$"; texs+="\\omicron"; texs+=mathmode?' ':'$'; res++; break;
case 0x03CD: if (!mathmode) texs+="$"; texs+="\\upsilon"; texs+=mathmode?' ':'$'; res++; break;
case 0x03CE: if (!mathmode) texs+="$"; texs+="\\omega"; texs+=mathmode?' ':'$'; res++; break;
case 0x03D1: texs+="J"; res++; break;
case 0x03D2: texs+="j"; res++; break;
case 0x03D6: texs+="v"; res++; break;
default: texs+=char(w[j] & 0xff);
}
}
delete [] w;
return res;
}
static string idnt2tex(const string & sorig,bool & mathmode){
string s0;
mathmode=greek2tex(sorig,s0,true)!=0;
if (mathmode)
return s0;
mathmode=true;
int n=int(s0.size()),j;
for (j=n-1;j>=2;--j){
if (s0[j]>32 && isalpha(s0[j]))
break;
}
string s=s0.substr(0,j+1),sadd;
if (j<n-1)
sadd=s0.substr(j+1,n-1-j);
switch (s.size()){
case 2:
if (s=="mu" || s=="nu" || s=="pi" || s=="xi" || s=="Xi")
return "\\"+s+sadd;
if (s=="im")
return "\\Im"+s+sadd;
if (s=="re")
return "\\Re"+sadd;
break;
case 3:
if (s=="chi" || s=="phi" || s=="Phi" || s=="eta" || s=="rho" || s=="tau" || s=="psi" || s=="Psi")
return "\\"+s+sadd;
break;
case 4:
if (s=="beta" || s=="zeta")
return "\\"+s+sadd;
break;
case 5:
if (s=="alpha" || s=="delta" || s=="Delta" || s=="gamma" || s=="Gamma" || s=="kappa" || s=="theta" || s=="Theta" || s=="sigma" || s=="Sigma" || s=="Omega" || s=="omega" || s=="aleph")
return "\\"+s+sadd;
break;
case 6:
if (s=="lambda" || s=="Lambda" || s=="approx")
return "\\"+s+sadd;
break;
case 7:
if (s=="epsilon" || s=="product")
return "\\"+s+sadd;
break;
}
mathmode=false;
return s0;
}
static string idnt2tex(const string & e){
bool mathmode;
if (e.size()==3 && (e=="sin" || e=="cos" || e=="tan" || e=="exp" || e=="log"))
return "\\"+e;
if (e.size()==2 && (e=="ln"))
return "\\"+e;
string s=idnt2tex(e,mathmode);
if (mathmode || s.size()==1)
return s;
else
return mbox_begin+translate_underscore(s)+mbox_end;
}
static string idnt2tex(const gen & e,GIAC_CONTEXT){
if (e==unsigned_inf)
return "\\infty ";
if (e==cst_pi)
return "\\pi ";
if (e==undef)
return "\\,"+(mbox_begin+string("undef")+mbox_end)+"\\,";
return idnt2tex(e.print(contextptr));
}
static void pnt2texlegende(FILE * file,const vecteur & arg,double xd,double yd,double xunit,int couleur,int labelpos,string * sres){
// draw legende at xd,yd +
string ss;
if (arg[2].type==_STRNG)
ss=*arg[2]._STRNGptr;
else
ss=arg[2].print(context0);
bool mathmode;
ss=idnt2tex(ss,mathmode);
if (mathmode)
ss="$"+ss+"$";
ss="\\color{"+flcolor2pstrickscolor(couleur) +"} "+ss;
double labelsep(0.1/xunit),angle(45+labelpos*90);
if (file)
fprintf(file,"\\uput{%.4f}[%.4f](%.4f,%.4f){%s}\n",labelsep,angle,xd,yd, ss.c_str());
if (sres)
*sres += "\\uput{"+double2tex(labelsep)+"}["+double2tex(angle)+"]("+double2tex(xd)+","+double2tex(yd)+"){"+ss+"}\n";
}
// This function is an adaptation of drawing.c from eukleides by C. Obrecht
// v is the output history
// output is written to file or to sres if file==NULL
static bool pnt2tex_(FILE * file,const vecteur & v,double xmin,double ymin,double xmax,double ymax,double & xd,double & yd,bool & drawlegende, int & labelpos,int & couleur,string * sres,GIAC_CONTEXT){
drawlegende=true;
int s=int(v.size());
if (!s)
return false;
// set color
int ensemble_attributs=0;
if (s>=2){
if (v[1].type==_INT_)
ensemble_attributs=v[1].val;
if (v[1].type==_VECT){
vecteur & w=*v[1]._VECTptr;
if (!w.empty() && (w.front().type==_INT_) )
ensemble_attributs=w.front().val;
}
}
int width =(ensemble_attributs & 0x00070000) >> 16; // 3 bits
// FIXME should be used!
// int epaisseur_point =(ensemble_attributs & 0x00380000) >> 19; // 3 bits
// int type_line =(ensemble_attributs & 0x01c00000) >> 22; // 3 bits
int type_point =(ensemble_attributs & 0x0e000000) >> 25; // 3 bits
labelpos =(ensemble_attributs & 0x30000000) >> 28; // 2 bits
bool fill_polygon =((ensemble_attributs & 0x40000000) >> 30)!=0;
couleur =(ensemble_attributs & 0x0000ffff);
string col(flcolor2pstrickscolor(couleur));
++width;
if (file)
fprintf(file,"\\psset{linecolor=%s}\n\\psset{linewidth=%.4fpt}\n", col.c_str(),width*0.5);
if (sres)
*sres += "\\psset{linecolor="+col+"}\n\\psset{linewidth="+double2tex(width*0.5)+"pt}\n";
// draw point/line/parametric
gen point=v[0],x,y;
// point is either a symb that evals to a complex or a param curve
// or a vector of complex points
// next line should be replaced by postscript (rpn) translation of curve
// equation if possible
if ( (point.type==_SYMB) && (point._SYMBptr->sommet==at_curve) && (point._SYMBptr->feuille.type==_VECT) && (point._SYMBptr->feuille._VECTptr->size()) )
point=point._SYMBptr->feuille._VECTptr->back();
if ( (point.type==_SYMB) && (point._SYMBptr->sommet==at_cercle)){
vecteur v=*point._SYMBptr->feuille._VECTptr;
gen diametre=remove_at_pnt(v[0]);
gen e1=diametre._VECTptr->front().evalf(1,contextptr),e2=diametre._VECTptr->back().evalf(1,contextptr);
gen centre=rdiv(e1+e2,gen(2.0),contextptr),rayon=abs(rdiv(e2-e1,gen(2.0),contextptr),contextptr);
x=evalf_double(re(centre,contextptr),1,contextptr);
y=evalf_double(im(centre,contextptr),1,contextptr);
if ( (x.type==_DOUBLE_) && (y.type==_DOUBLE_) && (rayon.type==_DOUBLE_) ){
xd=x._DOUBLE_val;
yd=y._DOUBLE_val;
if (v.size()>2){
gen theta1=evalf_double(v[1],1,contextptr),theta2=evalf_double(v[2],1,contextptr);
//grad
int mode=get_mode_set_radian(contextptr);
gen angle=arg(e2-e1,contextptr).evalf_double(1,contextptr);
angle_mode(mode, contextptr);
if (theta1.type==_DOUBLE_ && theta2.type==_DOUBLE_ && angle.type==_DOUBLE_){
double t1=theta1._DOUBLE_val,t2=theta2._DOUBLE_val;
if (t1>t2){
double tmp=t1;
t1=t2;
t2=tmp;
}
t1=(t1+angle._DOUBLE_val)*rad2deg_d;
t2=(t2+angle._DOUBLE_val)*rad2deg_d;
if (file)
fprintf (file,"\\pswedge[%sfillcolor=%s](%.4f,%.4f){%.4f}{%.4f}{%.4f}\n",fill_flag(fill_polygon).c_str(),col.c_str(),xd,yd,rayon._DOUBLE_val,t1,t2); // was psarc
if (sres)
*sres += "\\pswedge[" + fill_flag(fill_polygon) +
"fillcolor=" + col + "](" +
double2tex(xd)+","+double2tex(yd)+"){" +
double2tex(rayon._DOUBLE_val) + "}{" +
double2tex(t1)+ "}{" + double2tex(t2) + "}\n";
xd=x._DOUBLE_val+rayon._DOUBLE_val*std::cos(t1);
yd=y._DOUBLE_val+rayon._DOUBLE_val*std::sin(t1);
return true;
}
}
if (file)
fprintf(file,"\\pscircle[%sfillcolor=%s](%.4f,%.4f){%.4f}\n",fill_flag(fill_polygon).c_str(),col.c_str(),xd,yd,rayon._DOUBLE_val);
if (sres)
*sres += "\\pscircle["+fill_flag(fill_polygon)+"fillcolor="+col+
"]("+ double2tex(xd)+","+double2tex(yd)+"){"+
double2tex(rayon._DOUBLE_val)+"}\n";
xd=x._DOUBLE_val+rayon._DOUBLE_val;
return true;
}
return false;
} // end cercle
if (point.type!=_VECT){ // single point
point=evalf_double(point,1,contextptr);
x=re(point,contextptr);
y=im(point,contextptr).evalf(1,contextptr);
if ( (x.type==_DOUBLE_) && (y.type==_DOUBLE_) ){
xd=x._DOUBLE_val;
yd=y._DOUBLE_val;
if (file)
fprintf(file,"\\psdots%s(%.4f,%.4f)\n", point_flag(type_point).c_str(), xd, yd);
if (sres)
*sres += "\\psdots"+point_flag(type_point)+"("+double2tex(xd)+","+double2tex(yd)+")\n";
return true;
}
return false;
}
vecteur & w=*point._VECTptr;
int ws=int(w.size());
if (ws==2){
gen A=w[0].evalf(1,contextptr),B=w[1].evalf(1,contextptr);
gen Ax=re(A,contextptr),Ay=im(A,contextptr).evalf(1,contextptr),
Bx=re(B,contextptr),By=im(B,contextptr).evalf(1,contextptr);
if ( (Ax.type==_DOUBLE_) && (Ay.type==_DOUBLE_)
&& (Bx.type==_DOUBLE_) && (By.type==_DOUBLE_) ){
double ax=Ax._DOUBLE_val,ay=Ay._DOUBLE_val,bx=Bx._DOUBLE_val,by=By._DOUBLE_val;
xd=(ax+bx)/2.;
yd=(ay+by)/2.;
if (point.subtype==_GROUP__VECT)
drawlegende=false;
double x1,y1,x2,y2;
if (point.subtype!=_HALFLINE__VECT){
clip_line(ax,ay,bx,by,xmin,ymin,xmax,ymax,point.subtype,x1,y1,x2,y2);
if (file)
fprintf(file,"\\psline%s(%.4f,%.4f)(%.4f,%.4f)\n",vector_flag(point.subtype).c_str(), x1,y1,x2,y2);
if (sres)
*sres += "\\psline"+vector_flag(point.subtype)+
"("+double2tex(x1)+","+double2tex(y1)+")("+
double2tex(x2)+","+double2tex(y2)+")\n";
return true;
}
double vx=bx-ax,vy=by-ay;
// check for line/halfline
bx=bx+5*vx;
by=by+5*vy;
// FIXME: improve clipping!! Removed here
if (file)
fprintf(file,"\\psline%s(%.4f,%.4f)(%.4f,%.4f)\n",vector_flag(point.subtype).c_str(),ax,ay,bx,by);
if (sres)
*sres += "\\psline"+vector_flag(point.subtype)+"("+double2tex(ax)+","+double2tex(ay)+")("+double2tex(bx)+","+double2tex(by)+")\n";
return true;
} // end DOUBLE types
return false;
} // end w.size()==2
// multi-line
string prefixstr,printstring;
if (fill_polygon)
printstring="\\pspolygon["+fill_flag(fill_polygon)+"fillcolor="+col+"]";
else
prefixstr = "\\psline[fillcolor="+col+"]";
double xprec=0,yprec=0,xa,ya,xb,yb;
for (int i=0;i<ws;++i){
x=w[i].evalf(1,contextptr);
y=im(x,contextptr).evalf(1,contextptr);
x=re(x,contextptr);
if ( (x.type!=_DOUBLE_) || (y.type!=_DOUBLE_) )
continue;
xd=x._DOUBLE_val;
yd=y._DOUBLE_val;
if (fill_polygon){
if (in_rectangle(xd,yd,xmin,ymin,xmax,ymax))
printstring += "("+double2tex(xd)+","+double2tex(yd)+")";
else {
if (i && clip_line(xprec,yprec,xd,yd,xmin,ymin,xmax,ymax,0,xa,ya,xb,yb) ){
printstring += "("+double2tex(xa)+","+double2tex(ya)+")";
printstring += "("+double2tex(xb)+","+double2tex(yb)+")";
}
}
}
else {
if (i && clip_line(xprec,yprec,xd,yd,xmin,ymin,xmax,ymax,0,xa,ya,xb,yb)){
printstring += prefixstr+"("+double2tex(xa)+","+double2tex(ya)+")";
printstring += "("+double2tex(xb)+","+double2tex(yb)+")\n";
}
}
xprec=xd;
yprec=yd;
}
printstring += '\n';
if (file)
fprintf(file,"%s",printstring.c_str());
if (sres)
*sres += printstring;
return true;
}
static bool pnt2tex(FILE * file,const vecteur & v,double xmin,double ymin,double xmax,double ymax,double & xd,double & yd,bool & drawlegende, int & labelpos,int & couleur,string * sres,GIAC_CONTEXT){
specialtexprint_double(true,contextptr);
bool b=pnt2tex_(file,v,xmin,ymin,xmax,ymax,xd,yd,drawlegende,labelpos,couleur,sres,contextptr);
specialtexprint_double(false,contextptr);
return b;
}
static void invectpnt2tex(FILE * file,const gen & g,double X1,double X2,double Y1,double Y2,double xunit,double yunit,string * resptr,GIAC_CONTEXT){
if (g.type==_VECT){
const_iterateur it=g._VECTptr->begin(),itend=g._VECTptr->end();
for (;it!=itend;++it)
invectpnt2tex(file,*it,X1,X2,Y1,Y2,xunit,yunit,resptr,contextptr);
}
else {
if (g.is_symb_of_sommet(at_pnt) && !is3d(g)){
gen & feu = g._SYMBptr->feuille;
if (feu.type==_VECT){
vecteur & arg=*feu._VECTptr;
double xd,yd;
bool drawlegende;
int labelpos,couleur;
if (pnt2tex(file,arg,X1,Y1,X2,Y2,xd,yd,drawlegende,labelpos,couleur,resptr,contextptr)){
if (drawlegende && (arg.size()>2)){
xunit=(gnuplot_xmax-gnuplot_xmin);
pnt2texlegende(file,arg,xd,yd,xunit,couleur,labelpos,resptr);
}
}
}
}
}
}
// evalf_double of a and splt re/im
void evalfdouble2reim(const gen & a,gen & e,gen & f0,gen & f1,GIAC_CONTEXT){
if (a.type==_CPLX){
f0=a._CPLXptr->evalf2double(1,contextptr);
f1=(a._CPLXptr+1)->evalf2double(1,contextptr);
if (a._CPLXptr->type==_DOUBLE_ && (a._CPLXptr+1)->type==_DOUBLE_)
e=a;
else
e=gen(f0._DOUBLE_val,f1._DOUBLE_val);
return ;
}
#ifndef NO_STDEXCEPT
try {
#endif
e=a.evalf_double(1,contextptr); // FIXME? level 1 does not work for non 0 context
#ifndef NO_STDEXCEPT
} catch (std::runtime_error & error ){
last_evaled_argptr(contextptr)=NULL;
CERR << error.what() << '\n';
}
#endif
if (e.type==_CPLX){
f0=*e._CPLXptr;
f1=*(e._CPLXptr+1);
}
else {
f0=e;
f1=0.0;
}
}
static bool in_autoscale(const gen & g,vector<double> & vx,vector<double> & vy,vector<double> & vz,GIAC_CONTEXT,bool curve=false){
if (g.type==_VECT && g.subtype==_POINT__VECT && g._VECTptr->size()==3){
vecteur v=*evalf_double(g,1,contextptr)._VECTptr;
if (v[2].type==_CPLX)
v[2]=abs(v[2],contextptr);
if (v[0].type==_DOUBLE_ && v[1].type==_DOUBLE_ && v[2].type==_DOUBLE_ ){
vx.push_back(v[0]._DOUBLE_val);
vy.push_back(v[1]._DOUBLE_val);
vz.push_back(v[2]._DOUBLE_val);
return false;
}
}
if (g.type==_VECT ){
if (!curve && g.subtype==_GROUP__VECT && !g._VECTptr->empty() && g._VECTptr->front().type!=_VECT){ // "compressed" hypersurface?
vecteur v=*evalf_double(g,1,contextptr)._VECTptr;
int s=v.size();
if (s%3==0){
int i;
for (i=0;i<s;i+=3){
if (v[i].type!=_DOUBLE_ || v[i+1].type!=_DOUBLE_)
break;
}
if (i==s){
for (int i=0;i<s;i+=3){
vx.push_back(v[i]._DOUBLE_val);
vy.push_back(v[i+1]._DOUBLE_val);
if (v[i+2].type==_CPLX)
vz.push_back(abs(v[i+2],contextptr)._DOUBLE_val);
else
vz.push_back(v[i+2]._DOUBLE_val);
}
return false;
}
}
}
bool ortho=false;
if (g.subtype==_POLYEDRE__VECT)
ortho=true;
const_iterateur it=g._VECTptr->begin(),itend=g._VECTptr->end();
for (;it!=itend;++it){
ortho = ortho | in_autoscale(*it,vx,vy,vz,contextptr);