-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
latexgen.cpp
2648 lines (2436 loc) · 74.7 KB
/
latexgen.cpp
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
/******************************************************************************
*
* Copyright (C) 1997-2023 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.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#include <cstdlib>
#include "latexgen.h"
#include "config.h"
#include "message.h"
#include "doxygen.h"
#include "util.h"
#include "diagram.h"
#include "language.h"
#include "version.h"
#include "dot.h"
#include "dotcallgraph.h"
#include "dotclassgraph.h"
#include "dotdirdeps.h"
#include "dotgroupcollaboration.h"
#include "dotincldepgraph.h"
#include "pagedef.h"
#include "docparser.h"
#include "docnode.h"
#include "latexdocvisitor.h"
#include "dirdef.h"
#include "cite.h"
#include "groupdef.h"
#include "classlist.h"
#include "namespacedef.h"
#include "filename.h"
#include "resourcemgr.h"
#include "portable.h"
#include "fileinfo.h"
#include "utf8.h"
#include "datetime.h"
#include "portable.h"
#include "outputlist.h"
#include "moduledef.h"
static QCString g_header;
static QCString g_footer;
static const SelectionMarkerInfo latexMarkerInfo = { '%', "%%BEGIN ",8 ,"%%END ",6, "",0 };
static QCString substituteLatexKeywords(const QCString &str, const QCString &title);
LatexCodeGenerator::LatexCodeGenerator(TextStream *t,const QCString &relPath,const QCString &sourceFileName)
: m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
{
}
LatexCodeGenerator::LatexCodeGenerator(TextStream *t) : m_t(t)
{
}
void LatexCodeGenerator::setRelativePath(const QCString &path)
{
m_relPath = path;
}
void LatexCodeGenerator::setSourceFileName(const QCString &name)
{
m_sourceFileName = name;
}
void LatexCodeGenerator::codify(const QCString &str)
{
if (!str.isEmpty())
{
const char *p=str.data();
char c = 0;
//char cs[5];
int tabSize = Config_getInt(TAB_SIZE);
static THREAD_LOCAL char *result = nullptr;
static THREAD_LOCAL int lresult = 0;
while ((c=*p))
{
switch(c)
{
case 0x0c: p++; // remove ^L
break;
case ' ': *m_t << (m_doxyCodeLineOpen ? "\\ " : " ");
m_col++;
p++;
break;
case '^': *m_t <<"\\string^";
m_col++;
p++;
break;
case '`': *m_t <<"\\`{}";
m_col++;
p++;
break;
case '\t': {
int spacesToNextTabStop = tabSize - (m_col%tabSize);
for (int i = 0; i < spacesToNextTabStop; i++) *m_t << (m_doxyCodeLineOpen ? "\\ " : " ");
m_col+=spacesToNextTabStop;
p++;
}
break;
case '\n': *m_t << '\n';
m_col=0;
p++;
break;
default:
{
int i=0;
#undef COPYCHAR
// helper macro to copy a single utf8 character, dealing with multibyte chars.
#define COPYCHAR() do { \
int bytes = getUTF8CharNumBytes(c); \
if (lresult < (i + bytes + 1)) \
{ \
lresult += 512; \
result = static_cast<char *>(realloc(result, lresult)); \
} \
for (int j=0; j<bytes && *p; j++) \
{ \
result[i++]=*p++; \
} \
m_col++; \
} while(0)
// gather characters until we find whitespace or another special character
COPYCHAR();
while ((c=*p) &&
c!=0x0c && c!='\t' && c!='\n' && c!=' ' && c!='^'
)
{
COPYCHAR();
}
result[i]=0; // add terminator
filterLatexString(*m_t,result,
m_insideTabbing, // insideTabbing
true, // insidePre
false, // insideItem
m_usedTableLevel>0, // insideTable
false // keepSpaces
);
}
break;
}
}
}
}
void LatexCodeGenerator::writeCodeLink(CodeSymbolType,
const QCString &ref,const QCString &f,
const QCString &anchor,const QCString &name,
const QCString &)
{
bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
bool usePDFLatex = Config_getBool(USE_PDFLATEX);
size_t l = name.length();
if (ref.isEmpty() && usePDFLatex && pdfHyperlinks)
{
*m_t << "\\mbox{\\hyperlink{";
if (!f.isEmpty()) *m_t << stripPath(f);
if (!f.isEmpty() && !anchor.isEmpty()) *m_t << "_";
if (!anchor.isEmpty()) *m_t << anchor;
*m_t << "}{";
codify(name);
*m_t << "}}";
}
else
{
codify(name);
}
m_col+=l;
}
void LatexCodeGenerator::writeLineNumber(const QCString &ref,const QCString &fileName,const QCString &anchor,int l,bool writeLineAnchor)
{
bool usePDFLatex = Config_getBool(USE_PDFLATEX);
bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
if (!m_doxyCodeLineOpen)
{
*m_t << "\\DoxyCodeLine{";
m_doxyCodeLineOpen = TRUE;
}
if (Config_getBool(SOURCE_BROWSER))
{
QCString lineNumber;
lineNumber.sprintf("%05d",l);
QCString lineAnchor;
if (!m_sourceFileName.isEmpty())
{
lineAnchor.sprintf("_l%05d",l);
lineAnchor.prepend(stripExtensionGeneral(m_sourceFileName, ".tex"));
}
bool showTarget = usePDFLatex && pdfHyperlinks && !lineAnchor.isEmpty() && writeLineAnchor;
if (showTarget)
{
*m_t << "\\Hypertarget{" << stripPath(lineAnchor) << "}";
}
if (!fileName.isEmpty())
{
writeCodeLink(CodeSymbolType::Default,ref,fileName,anchor,lineNumber,QCString());
}
else
{
codify(lineNumber);
}
*m_t << "\\ ";
}
else
{
QCString lineNumber;
lineNumber.sprintf("%05d",l);
codify(lineNumber);
*m_t << "\\ ";
}
m_col=0;
}
void LatexCodeGenerator::startCodeLine(int)
{
m_col=0;
if (!m_doxyCodeLineOpen)
{
*m_t << "\\DoxyCodeLine{";
m_doxyCodeLineOpen = TRUE;
}
}
void LatexCodeGenerator::endCodeLine()
{
if (m_doxyCodeLineOpen)
{
*m_t << "}";
m_doxyCodeLineOpen = FALSE;
}
codify("\n");
}
void LatexCodeGenerator::startFontClass(const QCString &name)
{
*m_t << "\\textcolor{" << name << "}{";
}
void LatexCodeGenerator::endFontClass()
{
*m_t << "}";
}
void LatexCodeGenerator::startCodeFragment(const QCString &style)
{
*m_t << "\n\\begin{" << style << "}{" << m_usedTableLevel << "}\n";
}
void LatexCodeGenerator::endCodeFragment(const QCString &style)
{
//endCodeLine checks is there is still an open code line, if so closes it.
endCodeLine();
*m_t << "\\end{" << style << "}\n";
}
//-------------------------------
LatexGenerator::LatexGenerator()
: OutputGenerator(Config_getString(LATEX_OUTPUT))
, m_codeList(std::make_unique<OutputCodeList>())
{
m_codeGen = m_codeList->add<LatexCodeGenerator>(&m_t);
}
LatexGenerator::LatexGenerator(const LatexGenerator &og) : OutputGenerator(og.m_dir), OutputGenIntf()
{
m_codeList = std::make_unique<OutputCodeList>(*og.m_codeList);
m_codeGen = m_codeList->get<LatexCodeGenerator>(OutputType::Latex);
m_codeGen->setTextStream(&m_t);
m_firstDescItem = og.m_firstDescItem;
m_disableLinks = og.m_disableLinks;
m_relPath = og.m_relPath;
m_indent = og.m_indent;
m_templateMemberItem = og.m_templateMemberItem;
m_hierarchyLevel = og.m_hierarchyLevel;
}
LatexGenerator &LatexGenerator::operator=(const LatexGenerator &og)
{
if (this!=&og)
{
m_dir = og.m_dir;
m_codeList = std::make_unique<OutputCodeList>(*og.m_codeList);
m_codeGen = m_codeList->get<LatexCodeGenerator>(OutputType::Latex);
m_codeGen->setTextStream(&m_t);
m_firstDescItem = og.m_firstDescItem;
m_disableLinks = og.m_disableLinks;
m_relPath = og.m_relPath;
m_indent = og.m_indent;
m_templateMemberItem = og.m_templateMemberItem;
m_hierarchyLevel = og.m_hierarchyLevel;
}
return *this;
}
LatexGenerator::~LatexGenerator() = default;
void LatexGenerator::addCodeGen(OutputCodeList &list)
{
list.add<LatexCodeGeneratorDefer>(m_codeGen);
}
static void writeLatexMakefile()
{
bool generateBib = !CitationManager::instance().isEmpty();
QCString fileName=Config_getString(LATEX_OUTPUT)+"/Makefile";
std::ofstream f = Portable::openOutputStream(fileName);
if (!f.is_open())
{
term("Could not open file %s for writing\n",qPrint(fileName));
}
TextStream t(&f);
// inserted by KONNO Akihisa <konno@researchers.jp> 2002-03-05
QCString latex_command = theTranslator->latexCommandName().quoted();
QCString mkidx_command = Config_getString(MAKEINDEX_CMD_NAME).quoted();
QCString bibtex_command = "bibtex";
QCString manual_file = "refman";
const int latex_count = 8;
// end insertion by KONNO Akihisa <konno@researchers.jp> 2002-03-05
t << "LATEX_CMD?=" << latex_command << "\n"
<< "MKIDX_CMD?=" << mkidx_command << "\n"
<< "BIBTEX_CMD?=" << bibtex_command << "\n"
<< "LATEX_COUNT?=" << latex_count << "\n"
<< "MANUAL_FILE?=" << manual_file << "\n"
<< "\n";
if (!Config_getBool(USE_PDFLATEX)) // use plain old latex
{
t << "all: $(MANUAL_FILE).dvi\n"
<< "\n"
<< "ps: $(MANUAL_FILE).ps\n"
<< "\n"
<< "pdf: $(MANUAL_FILE).pdf\n"
<< "\n"
<< "ps_2on1: $(MANUAL_FILE).ps\n"
<< "\n"
<< "pdf_2on1: $(MANUAL_FILE).pdf\n"
<< "\n"
<< "$(MANUAL_FILE).ps: $(MANUAL_FILE).dvi\n"
<< "\tdvips -o $(MANUAL_FILE).ps $(MANUAL_FILE).dvi\n"
<< "\n";
t << "$(MANUAL_FILE).pdf: $(MANUAL_FILE).ps\n";
t << "\tps2pdf $(MANUAL_FILE).ps $(MANUAL_FILE).pdf\n\n";
t << "$(MANUAL_FILE).dvi: clean $(MANUAL_FILE).tex doxygen.sty\n"
<< "\techo \"Running latex...\"\n"
<< "\t$(LATEX_CMD) $(MANUAL_FILE).tex || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n"
<< "\techo \"Running makeindex...\"\n"
<< "\t$(MKIDX_CMD) $(MANUAL_FILE).idx\n";
if (generateBib)
{
t << "\techo \"Running bibtex...\"\n";
t << "\t$(BIBTEX_CMD) $(MANUAL_FILE)\n";
t << "\techo \"Rerunning latex....\"\n";
t << "\t$(LATEX_CMD) $(MANUAL_FILE).tex || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n";
}
t << "\techo \"Rerunning latex....\"\n"
<< "\t$(LATEX_CMD) $(MANUAL_FILE).tex\n"
<< "\tlatex_count=$(LATEX_COUNT) ; \\\n"
<< "\twhile grep -E -s 'Rerun (LaTeX|to get cross-references right|to get bibliographical references right)' $(MANUAL_FILE).log && [ $$latex_count -gt 0 ] ;\\\n"
<< "\t do \\\n"
<< "\t echo \"Rerunning latex....\" ;\\\n"
<< "\t $(LATEX_CMD) $(MANUAL_FILE).tex ; \\\n"
<< "\t $(LATEX_CMD) $(MANUAL_FILE).tex || \\\n"
<< "\t if [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\t fi; \\\n"
<< "\t latex_count=`expr $$latex_count - 1` ;\\\n"
<< "\t done\n"
<< "\t$(MKIDX_CMD) $(MANUAL_FILE).idx\n"
<< "\t$(LATEX_CMD) $(MANUAL_FILE).tex || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n"
<< "$(MANUAL_FILE).ps: $(MANUAL_FILE).ps\n"
<< "\tpsnup -2 $(MANUAL_FILE).ps >$(MANUAL_FILE).ps\n"
<< "\n"
<< "$(MANUAL_FILE).pdf: $(MANUAL_FILE).ps\n"
<< "\tps2pdf $(MANUAL_FILE).ps $(MANUAL_FILE).pdf\n";
}
else // use pdflatex for higher quality output
{
t << "all: $(MANUAL_FILE).pdf\n\n"
<< "pdf: $(MANUAL_FILE).pdf\n\n";
t << "$(MANUAL_FILE).pdf: clean $(MANUAL_FILE).tex\n";
t << "\t$(LATEX_CMD) $(MANUAL_FILE) || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n";
t << "\t$(MKIDX_CMD) $(MANUAL_FILE).idx\n";
if (generateBib)
{
t << "\t$(BIBTEX_CMD) $(MANUAL_FILE)\n";
t << "\t$(LATEX_CMD) $(MANUAL_FILE) || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n";
}
t << "\t$(LATEX_CMD) $(MANUAL_FILE) || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n"
<< "\tlatex_count=$(LATEX_COUNT) ; \\\n"
<< "\twhile grep -E -s 'Rerun (LaTeX|to get cross-references right|to get bibliographical references right)' $(MANUAL_FILE).log && [ $$latex_count -gt 0 ] ;\\\n"
<< "\t do \\\n"
<< "\t echo \"Rerunning latex....\" ;\\\n"
<< "\t $(LATEX_CMD) $(MANUAL_FILE) || \\\n"
<< "\t if [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\t fi; \\\n"
<< "\t latex_count=`expr $$latex_count - 1` ;\\\n"
<< "\t done\n"
<< "\t$(MKIDX_CMD) $(MANUAL_FILE).idx\n"
<< "\t$(LATEX_CMD) $(MANUAL_FILE) || \\\n"
<< "\tif [ $$? != 0 ] ; then \\\n"
<< "\t \\echo \"Please consult $(MANUAL_FILE).log to see the error messages\" ; \\\n"
<< "\t false; \\\n"
<< "\tfi\n";
}
t << "\n"
<< "clean:\n"
<< "\trm -f "
<< "*.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl $(MANUAL_FILE).pdf\n";
}
static void writeMakeBat()
{
#if defined(_MSC_VER)
QCString dir=Config_getString(LATEX_OUTPUT);
QCString fileName=dir+"/make.bat";
QCString latex_command = theTranslator->latexCommandName().quoted();
QCString mkidx_command = Config_getString(MAKEINDEX_CMD_NAME).quoted();
QCString bibtex_command = "bibtex";
QCString manual_file = "refman";
const int latex_count = 8;
bool generateBib = !CitationManager::instance().isEmpty();
std::ofstream t = Portable::openOutputStream(fileName);
if (!t.is_open())
{
term("Could not open file %s for writing\n",qPrint(fileName));
}
t << "pushd %~dp0\r\n";
t << "if not %errorlevel% == 0 goto :end1\r\n";
t << "\r\n";
t << "set ORG_LATEX_CMD=%LATEX_CMD%\r\n";
t << "set ORG_MKIDX_CMD=%MKIDX_CMD%\r\n";
t << "set ORG_BIBTEX_CMD=%BIBTEX_CMD%\r\n";
t << "set ORG_LATEX_COUNT=%LATEX_COUNT%\r\n";
t << "set ORG_MANUAL_FILE=%MANUAL_FILE%\r\n";
t << "if \"X\"%LATEX_CMD% == \"X\" set LATEX_CMD=" << latex_command << "\r\n";
t << "if \"X\"%MKIDX_CMD% == \"X\" set MKIDX_CMD=" << mkidx_command << "\r\n";
t << "if \"X\"%BIBTEX_CMD% == \"X\" set BIBTEX_CMD=" << bibtex_command << "\r\n";
t << "if \"X\"%LATEX_COUNT% == \"X\" set LATEX_COUNT=" << latex_count << "\r\n";
t << "if \"X\"%MANUAL_FILE% == \"X\" set MANUAL_FILE=" << manual_file << "\r\n";
t << "\r\n";
t << "del /s /f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl %MANUAL_FILE%.pdf\r\n\r\n";
t << "\r\n";
if (!Config_getBool(USE_PDFLATEX)) // use plain old latex
{
t << "%LATEX_CMD% %MANUAL_FILE%.tex\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
t << "echo ----\r\n";
t << "%MKIDX_CMD% %MANUAL_FILE%.idx\r\n";
if (generateBib)
{
t << "%BIBTEX_CMD% %MANUAL_FILE%\r\n";
t << "echo ----\r\n";
t << "\t%LATEX_CMD% %MANUAL_FILE%.tex\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
}
t << "setlocal enabledelayedexpansion\r\n";
t << "set count=%LAT#EX_COUNT%\r\n";
t << ":repeat\r\n";
t << "set content=X\r\n";
t << "for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun LaTeX\" %MANUAL_FILE%.log' ) do set content=\"%%~T\"\r\n";
t << "if !content! == X for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun to get cross-references right\" %MANUAL_FILE%.log' ) do set content=\"%%~T\"\r\n";
t << "if !content! == X for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun to get bibliographical references right\" %MANUAL_FILE%.log' ) do set content=\"%%~T\"\r\n";
t << "if !content! == X goto :skip\r\n";
t << "set /a count-=1\r\n";
t << "if !count! EQU 0 goto :skip\r\n\r\n";
t << "echo ----\r\n";
t << "%LATEX_CMD% %MANUAL_FILE%.tex\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
t << "goto :repeat\r\n";
t << ":skip\r\n";
t << "endlocal\r\n";
t << "%MKIDX_CMD% %MANUAL_FILE%.idx\r\n";
t << "%LATEX_CMD% %MANUAL_FILE%.tex\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
t << "dvips -o %MANUAL_FILE%.ps %MANUAL_FILE%.dvi\r\n";
t << Portable::ghostScriptCommand();
t << " -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite "
"-sOutputFile=%MANUAL_FILE%.pdf -c save pop -f %MANUAL_FILE%.ps\r\n";
}
else // use pdflatex
{
t << "%LATEX_CMD% %MANUAL_FILE%\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
t << "echo ----\r\n";
t << "%MKIDX_CMD% %MANUAL_FILE%.idx\r\n";
if (generateBib)
{
t << "%BIBTEX_CMD% %MANUAL_FILE%\r\n";
t << "%LATEX_CMD% %MANUAL_FILE%\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
}
t << "echo ----\r\n";
t << "%LATEX_CMD% %MANUAL_FILE%\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
t << "\r\n";
t << "setlocal enabledelayedexpansion\r\n";
t << "set count=%LATEX_COUNT%\r\n";
t << ":repeat\r\n";
t << "set content=X\r\n";
t << "for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun LaTeX\" %MANUAL_FILE%.log' ) do set content=\"%%~T\"\r\n";
t << "if !content! == X for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun to get cross-references right\" %MANUAL_FILE%.log' ) do set content=\"%%~T\"\r\n";
t << "if !content! == X for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun to get bibliographical references right\" %MANUAL_FILE%.log' ) do set content=\"%%~T\"\r\n";
t << "if !content! == X goto :skip\r\n";
t << "set /a count-=1\r\n";
t << "if !count! EQU 0 goto :skip\r\n\r\n";
t << "echo ----\r\n";
t << "%LATEX_CMD% %MANUAL_FILE%\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
t << "goto :repeat\r\n";
t << ":skip\r\n";
t << "endlocal\r\n";
t << "%MKIDX_CMD% %MANUAL_FILE%.idx\r\n";
t << "%LATEX_CMD% %MANUAL_FILE%\r\n";
t << "@if ERRORLEVEL 1 goto :error\r\n";
}
t<< "\r\n";
t << "goto :end\r\n";
t << ":error\r\n";
t << "@echo ===============\r\n";
t << "@echo Please consult %MANUAL_FILE%.log to see the error messages\r\n";
t << "@echo ===============\r\n";
t<< "\r\n";
t<< ":end\r\n";
t<< "@REM reset environment\r\n";
t<< "popd\r\n";
t<< "set LATEX_CMD=%ORG_LATEX_CMD%\r\n";
t<< "set ORG_LATEX_CMD=\r\n";
t<< "set MKIDX_CMD=%ORG_MKIDX_CMD%\r\n";
t<< "set ORG_MKIDX_CMD=\r\n";
t<< "set BIBTEX_CMD=%ORG_BIBTEX_CMD%\r\n";
t<< "set ORG_BIBTEX_CMD=\r\n";
t<< "set MANUAL_FILE=%ORG_MANUAL_FILE%\r\n";
t<< "set ORG_MANUAL_FILE=\r\n";
t<< "set LATEX_COUNT=%ORG_LATEX_COUNT%\r\n";
t<< "set ORG_LATEX_COUNT=\r\n";
t<< "\r\n";
t<< ":end1\r\n";
#endif
}
void LatexGenerator::init()
{
QCString dname = Config_getString(LATEX_OUTPUT);
Dir d(dname.str());
if (!d.exists() && !d.mkdir(dname.str()))
{
term("Could not create output directory %s\n",qPrint(dname));
}
if (!Config_getString(LATEX_HEADER).isEmpty())
{
g_header=fileToString(Config_getString(LATEX_HEADER));
//printf("g_header='%s'\n",qPrint(g_header));
QCString result = substituteLatexKeywords(g_header,QCString());
checkBlocks(result,Config_getString(LATEX_HEADER),latexMarkerInfo);
}
else
{
g_header = ResourceMgr::instance().getAsString("header.tex");
QCString result = substituteLatexKeywords(g_header,QCString());
checkBlocks(result,"<default header.tex>",latexMarkerInfo);
}
if (!Config_getString(LATEX_FOOTER).isEmpty())
{
g_footer=fileToString(Config_getString(LATEX_FOOTER));
//printf("g_footer='%s'\n",qPrint(g_footer));
QCString result = substituteLatexKeywords(g_footer,QCString());
checkBlocks(result,Config_getString(LATEX_FOOTER),latexMarkerInfo);
}
else
{
g_footer = ResourceMgr::instance().getAsString("footer.tex");
QCString result = substituteLatexKeywords(g_footer,QCString());
checkBlocks(result,"<default footer.tex>",latexMarkerInfo);
}
writeLatexMakefile();
writeMakeBat();
createSubDirs(d);
}
void LatexGenerator::cleanup()
{
QCString dname = Config_getString(LATEX_OUTPUT);
Dir d(dname.str());
clearSubDirs(d);
}
static void writeDefaultStyleSheet(TextStream &t)
{
t << ResourceMgr::instance().getAsString("doxygen.sty");
}
void LatexGenerator::writeHeaderFile(TextStream &t)
{
t << "% Latex header for doxygen " << getDoxygenVersion() << "\n";
t << ResourceMgr::instance().getAsString("header.tex");
}
void LatexGenerator::writeFooterFile(TextStream &t)
{
t << "% Latex footer for doxygen " << getDoxygenVersion() << "\n";
t << ResourceMgr::instance().getAsString("footer.tex");
}
void LatexGenerator::writeStyleSheetFile(TextStream &t)
{
t << "% stylesheet for doxygen " << getDoxygenVersion() << "\n";
writeDefaultStyleSheet(t);
}
void LatexGenerator::startFile(const QCString &name,const QCString &,const QCString &,int,int hierarchyLevel)
{
#if 0
setEncoding(Config_getString(LATEX_OUTPUT_ENCODING));
#endif
QCString fileName=name;
m_hierarchyLevel = hierarchyLevel;
m_relPath = relativePathToRoot(fileName);
if (!fileName.endsWith(".tex") && !fileName.endsWith(".sty")) fileName+=".tex";
startPlainFile(fileName);
m_codeGen->setRelativePath(m_relPath);
m_codeGen->setSourceFileName(stripPath(fileName));
}
void LatexGenerator::endFile()
{
endPlainFile();
m_codeGen->setSourceFileName("");
}
//void LatexGenerator::writeIndex()
//{
// startFile("refman.tex");
//}
void LatexGenerator::startProjectNumber()
{
m_t << "\\\\[1ex]\\large ";
}
static QCString extraLatexStyleSheet()
{
QCString result;
const StringVector &extraLatexStyles = Config_getList(LATEX_EXTRA_STYLESHEET);
for (const auto &fileName : extraLatexStyles)
{
if (!fileName.empty())
{
FileInfo fi(fileName);
if (fi.exists())
{
result += "\\usepackage{";
if (checkExtension(fi.fileName().c_str(), LATEX_STYLE_EXTENSION))
{
// strip the extension, it will be added by the usepackage in the tex conversion process
result += stripExtensionGeneral(fi.fileName().c_str(), LATEX_STYLE_EXTENSION);
}
else
{
result += fi.fileName();
}
result += "}\n";
}
}
}
return result;
}
static QCString makeIndex()
{
QCString result;
QCString latex_mkidx_command = Config_getString(LATEX_MAKEINDEX_CMD);
if (!latex_mkidx_command.isEmpty())
{
if (latex_mkidx_command[0] == '\\')
result += latex_mkidx_command;
else
result += "\\"+latex_mkidx_command;
}
else
{
result += "\\makeindex";
}
return result;
}
static QCString latex_batchmode()
{
switch (Config_getEnum(LATEX_BATCHMODE))
{
case LATEX_BATCHMODE_t::NO: return "";
case LATEX_BATCHMODE_t::YES: return "\\batchmode";
case LATEX_BATCHMODE_t::BATCH: return "\\batchmode";
case LATEX_BATCHMODE_t::NON_STOP: return "\\nonstopmode";
case LATEX_BATCHMODE_t::SCROLL: return "\\scrollmode";
case LATEX_BATCHMODE_t::ERROR_STOP: return "\\errorstopmode";
}
return "";
}
static QCString substituteLatexKeywords(const QCString &str,
const QCString &title)
{
bool compactLatex = Config_getBool(COMPACT_LATEX);
bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
bool usePdfLatex = Config_getBool(USE_PDFLATEX);
QCString paperType = Config_getEnumAsString(PAPER_TYPE);
QCString style = Config_getString(LATEX_BIB_STYLE);
if (style.isEmpty())
{
style="plain";
}
TextStream tg;
QCString generatedBy;
auto timeStamp = Config_getEnum(TIMESTAMP);
switch (timeStamp)
{
case TIMESTAMP_t::YES:
case TIMESTAMP_t::DATETIME:
generatedBy = theTranslator->trGeneratedAt(dateToString(DateTimeType::DateTime),
Config_getString(PROJECT_NAME));
break;
case TIMESTAMP_t::DATE:
generatedBy = theTranslator->trGeneratedAt(dateToString(DateTimeType::Date),
Config_getString(PROJECT_NAME));
break;
case TIMESTAMP_t::NO:
generatedBy = theTranslator->trGeneratedBy();
break;
}
filterLatexString(tg, generatedBy,
false, // insideTabbing
false, // insidePre
false, // insideItem
false, // insideTable
false // keepSpaces
);
generatedBy = tg.str();
QCString latexFontenc = theTranslator->latexFontenc();
QCString latexEmojiDirectory = Config_getString(LATEX_EMOJI_DIRECTORY);
if (latexEmojiDirectory.isEmpty()) latexEmojiDirectory = ".";
latexEmojiDirectory = substitute(latexEmojiDirectory,"\\","/");
TextStream tg1;
writeExtraLatexPackages(tg1);
QCString extraLatexPackages = tg1.str();
TextStream tg2;
writeLatexSpecialFormulaChars(tg2);
QCString latexSpecialFormulaChars = tg2.str();
QCString formulaMacrofile = Config_getString(FORMULA_MACROFILE);
QCString stripMacroFile;
if (!formulaMacrofile.isEmpty())
{
FileInfo fi(formulaMacrofile.str());
formulaMacrofile=fi.absFilePath();
stripMacroFile = fi.fileName();
copyFile(formulaMacrofile,Config_getString(LATEX_OUTPUT) + "/" + stripMacroFile);
}
QCString projectNumber = Config_getString(PROJECT_NUMBER);
// first substitute generic keywords
QCString result = substituteKeywords(str,title,
convertToLaTeX(Config_getString(PROJECT_NAME),false),
convertToLaTeX(projectNumber,false),
convertToLaTeX(Config_getString(PROJECT_BRIEF),false));
// additional LaTeX only keywords
result = substituteKeywords(result,
{
// keyword value getter
{ "$latexdocumentpre", [&]() { return theTranslator->latexDocumentPre(); } },
{ "$latexdocumentpost", [&]() { return theTranslator->latexDocumentPost(); } },
{ "$generatedby", [&]() { return generatedBy; } },
{ "$latexbibstyle", [&]() { return style; } },
{ "$latexcitereference", [&]() { return theTranslator->trCiteReferences(); } },
{ "$latexbibfiles", [&]() { return CitationManager::instance().latexBibFiles(); } },
{ "$papertype", [&]() { return paperType+"paper"; } },
{ "$extralatexstylesheet", [&]() { return extraLatexStyleSheet(); } },
{ "$languagesupport", [&]() { return theTranslator->latexLanguageSupportCommand(); } },
{ "$latexfontenc", [&]() { return latexFontenc; } },
{ "$latexfont", [&]() { return theTranslator->latexFont(); } },
{ "$latexemojidirectory", [&]() { return latexEmojiDirectory; } },
{ "$makeindex", [&]() { return makeIndex(); } },
{ "$extralatexpackages", [&]() { return extraLatexPackages; } },
{ "$latexspecialformulachars", [&]() { return latexSpecialFormulaChars; } },
{ "$formulamacrofile", [&]() { return stripMacroFile; } },
{ "$latex_batchmode", [&]() { return latex_batchmode(); } }
});
// remove conditional blocks
result = selectBlocks(result,
{
// marker is enabled
{ "CITATIONS_PRESENT", !CitationManager::instance().isEmpty() },
{ "COMPACT_LATEX", compactLatex },
{ "PDF_HYPERLINKS", pdfHyperlinks },
{ "USE_PDFLATEX", usePdfLatex },
{ "TIMESTAMP", timeStamp!=TIMESTAMP_t::NO },
{ "LATEX_FONTENC", !latexFontenc.isEmpty() },
{ "FORMULA_MACROFILE", !formulaMacrofile.isEmpty() },
{ "PROJECT_NUMBER", !projectNumber.isEmpty() }
},latexMarkerInfo);
result = removeEmptyLines(result);
return result;
}
void LatexGenerator::startIndexSection(IndexSection is)
{
bool compactLatex = Config_getBool(COMPACT_LATEX);
switch (is)
{
case IndexSection::isTitlePageStart:
m_t << substituteLatexKeywords(g_header,convertToLaTeX(Config_getString(PROJECT_NAME),m_codeGen->insideTabbing()));
break;
case IndexSection::isTitlePageAuthor:
break;
case IndexSection::isMainPage:
break;
case IndexSection::isModuleIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Module Index}\n"
break;
case IndexSection::isTopicIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Topic Index}\n"
break;
case IndexSection::isDirIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Directory Index}\n"
break;
case IndexSection::isNamespaceIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Namespace Index}\n"
break;
case IndexSection::isConceptIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Concept Index}\n"
break;
case IndexSection::isClassHierarchyIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Hierarchical Index}\n"
break;
case IndexSection::isCompoundIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Annotated Compound Index}\n"
break;
case IndexSection::isFileIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Annotated File Index}\n"
break;
case IndexSection::isPageIndex:
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Annotated Page Index}\n"
break;
case IndexSection::isTopicDocumentation:
{
for (const auto &gd : *Doxygen::groupLinkedMap)
{
if (!gd->isReference())
{
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Topic Documentation}\n";
break;
}
}
}
break;
case IndexSection::isModuleDocumentation:
{
for (const auto &mod : ModuleManager::instance().modules())
{
if (!mod->isReference() && mod->isPrimaryInterface())
{
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Topic Documentation}\n";
break;
}
}
}
break;
case IndexSection::isDirDocumentation:
{
for (const auto &dd : *Doxygen::dirLinkedMap)
{
if (dd->isLinkableInProject())
{
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Dir Documentation}\n";
break;
}
}
}
break;
case IndexSection::isNamespaceDocumentation:
{
for (const auto &nd : *Doxygen::namespaceLinkedMap)
{
if (nd->isLinkableInProject() && !nd->isAlias())
{
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; // Namespace Documentation}\n":
break;
}
}
}
break;
case IndexSection::isConceptDocumentation:
{
for (const auto &cd : *Doxygen::conceptLinkedMap)
{
if (cd->isLinkableInProject() && !cd->isAlias())
{
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; // Concept Documentation}\n":
break;
}
}
}
break;
case IndexSection::isClassDocumentation:
{
for (const auto &cd : *Doxygen::classLinkedMap)
{
if (cd->isLinkableInProject() &&
cd->templateMaster()==nullptr &&
!cd->isEmbeddedInOuterScope() &&
!cd->isAlias()
)
{
if (compactLatex) m_t << "\\doxysection"; else m_t << "\\chapter";
m_t << "{"; //Compound Documentation}\n";
break;
}
}
}
break;
case IndexSection::isFileDocumentation:
{
bool isFirst=TRUE;
for (const auto &fn : *Doxygen::inputNameLinkedMap)
{
for (const auto &fd : *fn)
{