summaryrefslogtreecommitdiffstats
path: root/src/latexgen.cpp
blob: 50ec496dbb38ea688540cff914a2f64c14e9d48e (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
/******************************************************************************
 *
 * $Id$
 *
 * Copyright (C) 1997-1999 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * All output generated with Doxygen is not covered by this license.
 *
 */

#include <stdlib.h>
#include <qdir.h>
#include "latexgen.h"
#include "config.h"
#include "message.h"
#include "doxygen.h"
#include "util.h"
#include "diagram.h"
#include "language.h"

//static QString escapeLabelName(const QString &s)
//{
//  QString result;
//  uint i;
//  for (i=0;i<s.length();i++)
//  {
//    char c=s.at(i);
//    switch (c)
//    {
//      case '~': result+=".1"; break;
//      case '%': result+=".2"; break;
//      default: result+=c;
//    }
//  }
//  return result;
//}


LatexGenerator::LatexGenerator()
  : OutputGenerator()
{
  dir=latexOutputDir;
  col=0;
}

LatexGenerator::~LatexGenerator()
{
}

//LatexGenerator::LatexGenerator(const LatexGenerator &g)
//  : OutputGenerator(g)
//{
//  col=g.col;
//}

void LatexGenerator::append(const OutputGenerator *g)
{
  t << g->getContents();
  col+=((LatexGenerator *)g)->col;
}


void LatexGenerator::init()
{
  QString dir=latexOutputDir;
  QDir d(dir);
  if (!d.exists() && !d.mkdir(dir))
  {
    err("Could not create output directory %s\n",dir.data());
    exit(1);
  }
  
  QString fileName=dir+"/Makefile";
  QFile file(fileName);
  if (!file.open(IO_WriteOnly))
  {
    err("Could not open file %s for writing\n",fileName.data());
    exit(1);
  }
  QTextStream t(&file);
  t << "all: refman.dvi" << endl
    << endl
    << "ps: refman.ps" << endl
    << endl
    << "refman.ps: refman.dvi" << endl
    << "\tdvips -o refman.ps refman.dvi" << endl
    << endl
    << "refman.dvi: refman.tex doxygen.sty" << endl
    << "\techo \"Running latex...\"" << endl
    << "\tlatex refman.tex" << endl
    << "\techo \"Running makeindex...\"" << endl
    << "\tmakeindex refman.idx" << endl
    << "\techo \"Rerunning latex....\"" << endl
    << "\tlatex refman.tex" << endl
    << "clean:" << endl
    << "\trm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log" << endl;
}

void LatexGenerator::startFile(const char *name,const char *,bool)
{
  QString fileName=name;
  if (fileName.right(4)!=".tex" && fileName.right(4)!=".sty") fileName+=".tex";
  startPlainFile(fileName);
}

void LatexGenerator::endFile()
{
  endPlainFile();
}

//void LatexGenerator::writeIndex()
//{
//  startFile("refman.tex");
//} 
  
void LatexGenerator::startProjectNumber()
{
  t << "\\\\[1ex]\\large "; 
}

void LatexGenerator::startIndexSection(IndexSections is)
{
  QString paperName;
  switch (is)
  {
    case isTitlePageStart:
      {
        if (paperType=="a4wide") paperName="a4"; else paperName=paperType;
        t << "\\documentclass[" << paperName << "paper]{";
        if (compactLatexFlag) t << "article"; else t << "book";
        t << "}\n";
        if (paperType=="a4wide") t << "\\usepackage{a4wide}\n";
        t << "\\usepackage{makeidx}\n"
          "\\usepackage{fancyheadings}\n"
          "\\usepackage{epsf}\n"
          "\\usepackage{float}\n"
          "\\usepackage{doxygen}\n";
        if (!theTranslator->latexBabelPackage().isEmpty())
        {
          t << "\\usepackage{" << theTranslator->latexBabelPackage() << "}\n";
        }
        const char *s=extraPackageList.first();
        while (s)
        {
          t << "\\usepackage{" << s << "}\n";
          s=extraPackageList.next();
        }
        t << "\\makeindex\n"
          "\\setcounter{tocdepth}{1}\n"
          "\\setlength{\\footrulewidth}{0.4pt}\n"
          "\\begin{document}\n"
          "\\title{";
        //docify(projectName);
        //t << " Reference Manual";
        //if (!projectNumber.isEmpty()) 
        //{
        //  t << "\\\\[1ex]\\large "; 
        //  docify(projectNumber);
        //}
      }
      break;
    case isTitlePageAuthor:
      t << "}\n\\author{";
      break;
    case isModuleIndex:
      if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
      t << "{"; //Module Index}\n"
      break;
    case isClassHierarchyIndex:
      if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
      t << "{"; //Hierarchical Index}\n"
      break;
    case isCompoundIndex:
      if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
      t << "{"; //Annotated Compound Index}\n"
      break;
    case isFileIndex:
      if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
      t << "{"; //Annotated File Index}\n"
      break;
    case isModuleDocumentation:
      {
        GroupDef *gd=groupList.first();
        bool found=FALSE;
        while (gd && !found)
        {
          if (gd->hasDocumentation() || gd->countMembers()>0)
          {
            if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
            t << "{"; //Module Documentation}\n";
            found=TRUE;
          }
          gd=groupList.next();
        }
      }
      break;
    case isClassDocumentation:
      {
        ClassDef *cd=classList.first();
        bool found=FALSE;
        while (cd && !found)
        {
          //if (cd->classFile()[0]!='@' && !cd->getReference() &&
          //    (cd->hasDocumentation() || !hideClassFlag) &&
          //    (cd->protection()!=Private || extractPrivateFlag)
          //   ) 
          
          if (!cd->isReference() && cd->isVisible())
          {
            if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
            t << "{"; //Compound Documentation}\n";
            found=TRUE;
          }
          cd=classList.next();
        }
      }
      break;
    case isFileDocumentation:
      {
        bool isFirst=TRUE;
        FileName *fn=inputNameList.first();
        while (fn)
        {
          FileDef *fd=fn->first();
          while (fd)
          {
            if (fd->hasDocumentation() && !fd->isReference())
            {
              if (isFirst)
              {
                if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
                t << "{"; //File Documentation}\n";
                isFirst=FALSE;
                break;
              }
            }
            fd=fn->next();
          }
          fn=inputNameList.next();
        }
      }
      break;
    case isExampleDocumentation:
      {
        if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
        t << "{"; //Example Documentation}\n";
      }
      break;
    case isPageDocumentation:
      {
        if (compactLatexFlag) t << "\\section"; else t << "\\chapter";
        t << "{"; //Page Documentation}\n";
      }
      break;
    case isEndIndex:
      break;
  }
}

void LatexGenerator::endIndexSection(IndexSections is)
{
  switch (is)
  {
    case isTitlePageStart:
      break;
    case isTitlePageAuthor:
      t << " Doxygen}\n"
        "\\date{" << dateToString(TRUE) << "}\n"
        "\\maketitle\n"
        "\\pagenumbering{roman}\n";
      if (!compactLatexFlag) t << "\\clearemptydoublepage\n";
      t << "\\tableofcontents\n";
      if (!compactLatexFlag) t << "\\clearemptydoublepage\n";
      t << "\\pagenumbering{arabic}\n";
      break;
    case isModuleIndex:
      t << "}\n\\input{modules}\n";
      break;
    case isClassHierarchyIndex:
      t << "}\n\\input{hierarchy}\n";
      break;
    case isCompoundIndex:
      t << "}\n\\input{annotated}\n";
      break;
    case isFileIndex:
      t << "}\n\\input{files}\n";
      break;
    case isModuleDocumentation:
      {
        GroupDef *gd=groupList.first();
        bool found=FALSE;
        while (gd && !found)
        {
          if (gd->hasDocumentation() || gd->countMembers()>0)
          {
            t << "}\n\\input{" << gd->groupFile() << "}\n";
            found=TRUE;
          }
          gd=groupList.next();
        }
        while (gd)
        {
          if (gd->hasDocumentation() || gd->countMembers()>0)
          {
            if (compactLatexFlag) t << "\\input"; else t << "\\include";
            t << "{" << gd->groupFile() << "}\n";
          }
          gd=groupList.next();
        }
      }
      break;
    case isClassDocumentation:
      {
        ClassDef *cd=classList.first();
        bool found=FALSE;
        while (cd && !found)
        {
          //if (cd->classFile()[0]!='@' && !cd->getReference() &&
          //    (cd->hasDocumentation() || !hideClassFlag) &&
          //    (cd->protection()!=Private || extractPrivateFlag)
          //   ) 
          if (!cd->isReference() && cd->isVisible())
          {
            t << "}\n\\input{" << cd->classFile() << "}\n";
            found=TRUE;
          }
          cd=classList.next();
        }
        while (cd)
        {
          //if (cd->classFile()[0]!='@' && !cd->getReference() &&
          //    (cd->hasDocumentation() || !hideClassFlag) &&
          //    (cd->protection()!=Private || extractPrivateFlag)
          //   )
          if (!cd->isReference() && cd->isVisible())
          {
            if (compactLatexFlag) t << "\\input"; else t << "\\include";
            t << "{" << cd->classFile() << "}\n";
          } 
          cd=classList.next();
        }
      }
      break;
    case isFileDocumentation:
      {
        bool isFirst=TRUE;
        FileName *fn=inputNameList.first();
        while (fn)
        {
          FileDef *fd=fn->first();
          while (fd)
          {
            if (fd->hasDocumentation() && !fd->isReference())
            {
              if (isFirst)
              {
                t << "}\n\\input{" << fd->diskName() << "}\n";
                isFirst=FALSE;
              }
              else
              {
                if (compactLatexFlag) t << "\\input" ; else t << "\\include";
                t << "{" << fd->diskName() << "}\n";
              }
            }
            fd=fn->next();
          }
          fn=inputNameList.next();
        }
      }
      break;
    case isExampleDocumentation:
      {
        t << "}\n";
        PageInfo *pi=exampleList.first();
        if (pi)
        {
          t << "\\input{" << convertSlashes(pi->name,TRUE) << "-example}\n";
          pi=exampleList.next();
        }
        while (pi)
        {
          if (compactLatexFlag) t << "\\input" ; else t << "\\include";
          t << "{" << convertSlashes(pi->name,TRUE) << "-example}\n";
          pi=exampleList.next();
        }
      }
      break;
    case isPageDocumentation:
      {
        t << "}\n";
        PageInfo *pi=pageList.first();
        if (pi)
        {
          QString pageName;
          if (caseSensitiveNames)
            pageName=pi->name.copy();
          else
            pageName=pi->name.lower();
          t << "\\input{" << pageName << "}\n";
          pi=pageList.next();
        }
        while (pi)
        {
          if (compactLatexFlag) t << "\\input" ; else t << "\\include";
          QString pageName;
          if (caseSensitiveNames)
            pageName=pi->name.copy();
          else
            pageName=pi->name.lower();
          t << "{" << pageName << "}\n";
          pi=pageList.next();
        }
      }
      break;
    case isEndIndex:
      t << "\\printindex\n";
      t << "\\end{document}\n";
      break;
  }
}
void LatexGenerator::writeStyleInfo(int part)
{
  switch(part)
  {
    case 0:
      {
        QString pname=projectName.stripWhiteSpace();
        startPlainFile("doxygen.sty");
        t << "\\NeedsTeXFormat{LaTeX2e}\n";
        t << "\\ProvidesPackage{doxygen}\n";
        t << "\\RequirePackage{calc}\n";
        t << "\\RequirePackage{array}\n";
        t << "\\pagestyle{fancyplain}\n";
        t << "\\addtolength{\\headwidth}{\\marginparsep}\n";
        t << "\\addtolength{\\headwidth}{\\marginparwidth}\n";
        t << "\\newcommand{\\clearemptydoublepage}{\\newpage{\\pagestyle{empty}";
        t << "\\cleardoublepage}}\n";
        if (!compactLatexFlag) 
          t << "\\renewcommand{\\chaptermark}[1]{\\markboth{#1}{}}\n";
        t << "\\renewcommand{\\sectionmark}[1]{\\markright{\\thesection\\ #1}}\n";
        t << "\\lhead[\\fancyplain{}{\\bfseries\\thepage}]\n";
        t << "        {\\fancyplain{}{\\bfseries\\rightmark}}\n";
        t << "\\rhead[\\fancyplain{}{\\bfseries\\leftmark}]\n";
        t << "        {\\fancyplain{}{\\bfseries\\thepage}}\n";
        t << "\\rfoot[\\fancyplain{}{\\bfseries\\scriptsize ";
      }
      break;
    case 1:
    case 3:
      t << " Doxygen ";
      break;
    case 2:
      {
        t << " Dimitri van Heesch \\copyright 1997-1999}]{}\n";
        //QString dtString=dateToString(FALSE);
        t << "\\lfoot[]{\\fancyplain{}{\\bfseries\\scriptsize ";
      }
      break;
    case 4:
      {
        t << " Dimitri van Heesch \\copyright 1997-1999}}\n";
        t << "\\cfoot{}\n";
        t << "\\newenvironment{CompactList}\n";
        t << "{\\begin{list}{}{\n";
        t << "  \\setlength{\\leftmargin}{0.5cm}\n";
        t << "  \\setlength{\\itemsep}{0pt}\n";
        t << "  \\setlength{\\parsep}{0pt}\n";
        t << "  \\setlength{\\topsep}{0pt}\n";
        t << "  \\renewcommand{\\makelabel}{}}}\n";
        t << "{\\end{list}}\n";
        t << "\\newenvironment{CompactItemize}\n";
        t << "{\n";
        t << "  \\begin{itemize}\n";
        t << "  \\setlength{\\itemsep}{-4pt}\n";
        t << "  \\setlength{\\parsep}{0pt}\n";
        t << "  \\setlength{\\topsep}{0pt}\n";
        t << "  \\setlength{\\partopsep}{0pt}\n";
        t << "}\n";
        t << "{\\end{itemize}}\n";
        t << "\\newcommand{\\PBS}[1]{\\let\\temp=\\\\#1\\let\\\\=\\temp}\n";
        t << "\\newlength{\\tmplength}\n";
        t << "\\newenvironment{TabularC}[1]\n";
        t << "{\n";
        t << "\\setlength{\\tmplength}\n";
        t << "     {\\linewidth/(#1)-\\tabcolsep*2-\\arrayrulewidth*(#1+1)/(#1)}\n";
        t << "      \\par\\begin{tabular*}{\\linewidth}\n";
        t << "             {*{#1}{|>{\\PBS\\raggedright\\hspace{0pt}}p{\\the\\tmplength}}|}\n";
        t << "}\n";
        t << "{\\end{tabular*}\\par}\n";
        t << "\\newcommand{\\entrylabel}[1]{\n";
        t << "   {\\parbox[b]{\\labelwidth-4pt}{\\makebox[0pt][l]{\\textbf{#1}}\\\\}}}\n";
        t << "\\newenvironment{Desc}\n";
        t << "{\\begin{list}{}\n";
        t << "  {\n";
        t << "    \\settowidth{\\labelwidth}{40pt}\n";
        t << "    \\setlength{\\leftmargin}{\\labelwidth}\n";
        t << "    \\setlength{\\parsep}{0pt}\n";
        t << "    \\setlength{\\itemsep}{-4pt}\n";
        t << "    \\renewcommand{\\makelabel}{\\entrylabel}\n";
        t << "  }\n";
        t << "}\n";
        t << "{\\end{list}}\n";
        t << "\\setlength{\\parindent}{0cm}\n";
        t << "\\setlength{\\parskip}{0.2cm}\n";
        t << "\\sloppy\n";
        endPlainFile();
      }
      break;
  }
}

void LatexGenerator::endTitleHead(const char *name)
{
  t << "}" << endl;
  if (name)
  {
    t << "\\label{" << name << "}\\index{" 
      << name << "@{";
    docify(name);
    t << "}}";
  }
  t << endl;
}

void LatexGenerator::newParagraph()
{
  t << endl << endl;
}

void LatexGenerator::writeString(const char *text)
{
  t << text;
}

void LatexGenerator::writeIndexItem(const char *ref,const char *fn,
                                    const char *name)
{
  t << "\\item ";
  if (!ref && fn)
  {
    t << "\\contentsline{section}{";
    docify(name);
    t << "}{\\pageref{" << name << "}}" << endl;
  }
  else
    docify(name);
}

//void LatexGenerator::writeIndexFileItem(const char *,const char *text)
//{
//  t << "\\item\\contentsline{section}{";
//  docify(text);
//  t << "}{\\pageref{" << text << "}}" << endl;
//}


void LatexGenerator::writeHtmlLink(const char *url,const char *text)
{
  docify(text);
  if (url)
  {
  //  t << " {\\tt (";
  //  docify(url);
  //  t << ")}";
  }
}

void LatexGenerator::writeStartAnnoItem(const char *,const char *,
                                        const char *path,const char *name)
{
  t << "\\item\\contentsline{section}{{\\bf ";
  if (path) docify(path);
  docify(name); 
  t << "} ";
}

void LatexGenerator::writeEndAnnoItem(const char *name)
{
  t << "}{\\pageref{" << name << "}}" << endl;
}

//void LatexGenerator::writeClassLink(const char *,const char *,
//                                    const char *,const char *name)
//{
//  t << "{\\bf ";
//  docify(name);
//  t << "}"; 
//}

void LatexGenerator::writeObjectLink(const char *, const char *,
                                     const char *, const char *text)
{
  t << "{\\bf ";
  docify(text);
  t << "}"; 
}

void LatexGenerator::writePageRef(const char *clname, const char *anchor)
{
  t << " {\\rm (p. \\pageref{";
  if (clname) t << clname; 
  if (anchor) t << "_" << anchor;
  t << "})}";
}

void LatexGenerator::writeCodeLink(const char *,const char *,
                                   const char *,const char *name)
{
  t << name;
  col+=strlen(name);
}


void LatexGenerator::startTitle()
{
  if (compactLatexFlag) t << "\\subsection{"; else t << "\\section{"; 
}

void LatexGenerator::startGroupHeader()
{
  if (compactLatexFlag) t << "\\subsubsection*{"; else t << "\\subsection*{";
}

void LatexGenerator::endGroupHeader()
{
  t << "}" << endl;
}

void LatexGenerator::startMemberDoc(const char *clname,
                                    const char *memname,const char *)
{ 
  t << "\\index{";
  if (clname)
  {
    t << clname << "@{";
    docify(clname);
    t << "}!";
  }
  t << memname << "@{";
  docify(memname);
  t << "}}" << endl;
  
  t << "\\index{" << memname << "@{";
  docify(memname);
  t << "}";
  if (clname)
  {
    t << "!" << clname << "@{";
    docify(clname);
    t << "}"; 
  }
  t << "}" << endl;
  //
  if (compactLatexFlag) t << "\\subsubsection{"; else t << "\\subsection{";
  t << "\\setlength{\\rightskip}{0pt plus 5cm}";
}

void LatexGenerator::writeDoxyAnchor(const char *clname,const char *anchor,const char *)
{
  t << "\\label{";
  if (clname) t << clname;
  if (anchor) t << "_" << anchor;
  t << "}" << endl;
}

void LatexGenerator::addToIndex(const char *s1,const char *s2)
{
  if (s1)
  {
    t << "\\index{" << s1 << "@{";
    docify(s1);
    t << "}";
    if (s2)
    {
      t << "!" << s2 << "@{";
      docify(s2);
      t << "}";
    }
    t << "}";
  }
}

void LatexGenerator::writeSection(const char *lab,const char *title,bool sub)
{
  t << "\\";
  if (sub) t << "subsection{"; else t << "section{";
  docify(title);
  t << "}\\label{" << lab << "}" << endl;
}

void LatexGenerator::writeSectionRef(const char *,const char *lab,
                                     const char *)
{
  t << "\\ref{" << lab << "}";
}

void LatexGenerator::writeSectionRefItem(const char *,const char *lab,
                                     const char *title)
{
  t << "\\contentsline{section}{";
  docify(title);
  t << "}{\\ref{" << lab << "}}" << endl;
}

//void LatexGenerator::docify(const char *str)
//{
//  docifyStatic(t,str);
//}

//void LatexGenerator::docifyStatic(QTextStream &t,const char *str)
void LatexGenerator::docify(const char *str)
{
  if (str)
  {
    const unsigned char *p=(const unsigned char *)str;
    unsigned char c;
    unsigned char pc='\0';
    while (*p)
    {
      c=*p++;
      switch(c)
      {
        case '#':  t << "\\#";           break;
        case '$':  t << "\\$";           break;
        case '%':  t << "\\%";           break;
        case '^':  t << "$^\\wedge$";    break;
        case '&':  t << "\\&";           break;
        case '*':  t << "$\\ast$";       break;
        case '_':  t << "\\_\\-";        break;
        case '{':  t << "\\{";           break;
        case '}':  t << "\\}";           break;
        case '<':  t << "$<$";           break;
        case '>':  t << "$>$";           break;
        case '|':  t << "$|$";           break;
        case '~':  t << "$\\sim$";       break;
        case '-':  if (*p=='>') 
                     { t << " $\\rightarrow$ "; p++; }
                   else
                     { t << (char)c; }
                   break;
        case '\\': if (*p=='<') 
                     { t << "$<$"; p++; }
                   else if (*p=='>')
                     { t << "$>$"; p++; } 
                   else  
                     { t << "$\\backslash$"; }
                   break;           
        // the Latin-1 characters
        case 161: t << "!`";            break;
        case 181: t << "$\\mu$";        break;
        case 191: t << "?`";            break;
        case 192: t << "\\`{A}";        break;
        case 193: t << "\\'{A}";        break;
        case 194: t << "\\^{A}";        break;
        case 195: t << "\\~{A}";        break;
        case 196: t << "\\\"{A}";       break;
        case 197: t << "\\AA ";         break;
        case 198: t << "\\AE ";         break;
        case 199: t << "\\c{C}";        break;
        case 200: t << "\\`{E}";        break;
        case 201: t << "\\'{E}";        break;
        case 202: t << "\\^{E}";        break;
        case 203: t << "\\\"{E}";       break;
        case 204: t << "\\`{I}";        break;
        case 205: t << "\\'{I}";        break;
        case 206: t << "\\^{I}";        break;
        case 207: t << "\\\"{I}";       break;
        case 208: t << "D ";            break; // anyone know the real code?
        case 209: t << "\\~{N}";        break;
        case 210: t << "\\`{O}";        break;
        case 211: t << "\\'{O}";        break;
        case 212: t << "\\^{O}";        break;
        case 213: t << "\\~{O}";        break;
        case 214: t << "\\\"{O}";       break;
        case 215: t << "$\\times$";     break;
        case 216: t << "\\O";           break;
        case 217: t << "\\`{U}";        break;
        case 218: t << "\\'{U}";        break;
        case 219: t << "\\^{U}";        break;
        case 220: t << "\\\"{U}";       break;
        case 221: t << "\\'{Y}";        break;
        case 223: t << "\"s ";          break; // assumes german package     
        case 224: t << "\\`{a}";        break;
        case 225: t << "\\'{a}";        break;
        case 226: t << "\\^{a}";        break;
        case 227: t << "\\~{a}";        break;
        case 228: t << "\\\"{a}";       break;
        case 229: t << "\\aa ";         break;
        case 230: t << "\\ae ";         break;
        case 231: t << "\\c{c}";        break;
        case 232: t << "\\`{e}";        break;
        case 233: t << "\\'{e}";        break;
        case 234: t << "\\^{e}";        break;
        case 235: t << "\\\"{e}";       break;
        case 236: t << "\\`{\\i}";      break;
        case 237: t << "\\'{\\i}";      break;
        case 238: t << "\\^{\\i}";      break;
        case 239: t << "\\\"{\\i}";     break;
        case 241: t << "\\~{n}";        break;
        case 242: t << "\\`{o}";        break;
        case 243: t << "\\'{o}";        break;
        case 244: t << "\\^{o}";        break;
        case 245: t << "\\~{o}";        break;
        case 246: t << "\\\"{o}";       break;
        case 248: t << "\\o ";          break;
        case 249: t << "\\`{u}";        break;
        case 250: t << "\\'{u}";        break;
        case 251: t << "\\^{u}";        break;
        case 252: t << "\\\"{u}";       break;
        case 253: t << "\\'{y}";        break;
        case 255: t << "\\\"{y}";       break;           
        
        default:   
                   if ((isupper(c) && islower(pc)) 
                   // ||
                   //    (pc!=':' && c==':') ||
                   //    (pc==':' && c!=':')
                      ) t << "\\-";
                   t << (char)c; 
      }
      pc = c;
    }
  }
}

void LatexGenerator::codify(const char *str)
{
  static char spaces[]="        ";
  if (str)
  { 
    const char *p=str;
    char c;
    while (*p)
    {
      c=*p++;
      switch(c)
      {
        case '\t': t << &spaces[col&7]; col+=8-(col&7); break; 
        case '\n': t << '\n'; col=0;                    break;
        default:   t << c;    col++;                    break;
      }
    }
  }
}

void LatexGenerator::writeChar(char c)
{
  char cs[2];
  cs[0]=c;
  cs[1]=0;
  docify(cs);
}

void LatexGenerator::startClassDiagram()
{
  if (compactLatexFlag) t << "\\subsubsection*"; else t << "\\subsection*";
  t << "{";
}

void LatexGenerator::endClassDiagram(ClassDiagram &d,
                                       const char *fileName,const char *)
{
  d.writeFigure(t,dir,fileName);
}

void LatexGenerator::writeFormula(const char *,const char *text)
{
  t << text;
}