1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to Word RTF/WinHelp RTF
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
41 static int indentLevel
= 0;
42 static int forbidParindent
= 0; // if > 0, no parindent (e.g. in center environment)
43 int forbidResetPar
= 0; // If > 0, don't reset memory of having output a new par
45 static char *contentsLineSection
= NULL
;
46 static char *contentsLineValue
= NULL
;
47 static TexChunk
*descriptionItemArg
= NULL
;
48 static wxStringList environmentStack
; // Stack of paragraph styles we need to remember
49 static int footnoteCount
= 0;
50 static int citeCount
= 1;
51 extern char *FileRoot
;
53 extern bool startedSections
;
54 extern FILE *Contents
;
55 extern FILE *Chapters
;
57 extern FILE *WinHelpContentsFile
;
58 extern char *RTFCharset
;
59 // This is defined in the Tex2Any library and isn't in use after parsing
60 extern char *BigBuffer
;
62 extern wxHashTable TexReferences
;
64 // Are we in verbatim mode? If so, format differently.
65 static bool inVerbatim
= FALSE
;
67 // We're in a series of PopRef topics, so don't output section headings
68 bool inPopRefSection
= FALSE
;
71 static bool hotSpotColour
= TRUE
;
72 static bool hotSpotUnderline
= TRUE
;
74 // Transparency (WHITE = transparent)
75 static bool bitmapTransparency
= TRUE
;
77 // Linear RTF requires us to set the style per section.
78 static char *currentNumberStyle
= NULL
;
79 static int currentItemSep
= 8;
80 static int CurrentTextWidth
= 8640; // Say, six inches
81 static int CurrentLeftMarginOdd
= 400;
82 static int CurrentLeftMarginEven
= 1440;
83 static int CurrentRightMarginOdd
= 1440;
84 static int CurrentRightMarginEven
= 400;
85 static int CurrentMarginParWidth
= 2000;
86 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
87 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
88 static int GutterWidth
= 2300;
90 // Two-column table dimensions, in twips
91 static int TwoColWidthA
= 1500;
92 static int TwoColWidthB
= 3000;
94 const int PageWidth
= 12242; // 8.25 inches wide for A4
96 // Remember the anchor in a helpref
97 static TexChunk
*helpRefText
= NULL
;
100 * Flag to say we've just issued a \par\pard command, so don't
101 * repeat this unnecessarily.
105 int issuedNewParagraph
= 0;
107 // Need to know whether we're in a table or figure for benefit
108 // of listoffigures/listoftables
109 static bool inFigure
= FALSE
;
110 static bool inTable
= FALSE
;
116 static char *CurrentChapterName
= NULL
;
117 static char *CurrentSectionName
= NULL
;
118 static char *CurrentSubsectionName
= NULL
;
119 static char *CurrentTopic
= NULL
;
121 static bool InPopups()
123 if (CurrentChapterName
&& (strcmp(CurrentChapterName
, "popups") == 0))
125 if (CurrentSectionName
&& (strcmp(CurrentSectionName
, "popups") == 0))
130 static void SetCurrentTopic(char *s
)
132 if (CurrentTopic
) delete[] CurrentTopic
;
133 CurrentTopic
= copystring(s
);
136 void SetCurrentChapterName(char *s
)
138 if (CurrentChapterName
) delete[] CurrentChapterName
;
139 CurrentChapterName
= copystring(s
);
142 void SetCurrentSectionName(char *s
)
144 if (CurrentSectionName
) delete[] CurrentSectionName
;
145 CurrentSectionName
= copystring(s
);
148 void SetCurrentSubsectionName(char *s
)
150 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
151 CurrentSubsectionName
= copystring(s
);
155 // Indicate that a parent topic at level 'level' has children.
156 // Level 1 is a chapter, 2 is a section, etc.
157 void NotifyParentHasChildren(int parentLevel
)
159 char *parentTopic
= NULL
;
164 parentTopic
= CurrentChapterName
;
169 parentTopic
= CurrentSectionName
;
174 parentTopic
= CurrentSubsectionName
;
184 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
187 texTopic
= new TexTopic
;
188 TopicTable
.Put(parentTopic
, texTopic
);
190 texTopic
->hasChildren
= TRUE
;
194 // Have to keep a count of what levels are books, what are pages,
195 // in order to correct for a Win95 bug which means that if you
196 // have a book at level n, and then a page at level n, the page
197 // ends up on level n + 1.
199 bool ContentsLevels
[5];
201 // Reset below this level (starts from 1)
202 void ResetContentsLevels(int l
)
205 for (i
= l
; i
< 5; i
++)
206 ContentsLevels
[i
] = FALSE
;
208 // There are always books on the top level
209 ContentsLevels
[0] = TRUE
;
212 // Output a WinHelp section as a keyword, substituting
214 void OutputSectionKeyword(FILE *fd
)
216 OutputCurrentSectionToString(wxBuffer
);
219 for (i
= 0; i
< strlen(wxBuffer
); i
++)
220 if (wxBuffer
[i
] == ':')
222 // Don't write to index if there's some RTF in the string
223 else if ( wxBuffer
[i
] == '{' )
226 fprintf(fd
, "K{\\footnote {K} ");
227 fprintf(fd
, "%s", wxBuffer
);
232 // Write a line for the .cnt file, if we're doing this.
233 void WriteWinHelpContentsFileLine(char *topicName
, char *xitle
, int level
)
235 // First, convert any RTF characters to ASCII
239 while ( (xitle
[s
]!=0)&&(d
<255) )
241 char ch
=xitle
[s
]&0xff;
243 char ch1
=xitle
[s
+1]&0xff;
244 char ch2
=xitle
[s
+2]&0xff;
245 char ch3
=xitle
[s
+3]&0xff;
246 char ch4
=xitle
[s
+4]&0xff;
247 s
+=4; // next character
249 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]='ö'; a
=1; }
250 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]='ä'; a
=1; }
251 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]='ü'; a
=1; }
252 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]='Ö'; a
=1; }
253 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]='Ä'; a
=1; }
254 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]='Ü'; a
=1; }
256 // printf("!!!!! %04X %04X %04X %04X! \n",ch1,ch2,ch3,ch4);
264 // Section (2) becomes level 1 if it's an article.
265 if (DocumentStyle
== LATEX_ARTICLE
)
268 if (level
== 0) // Means we had a Chapter in an article, oops.
271 ResetContentsLevels(level
);
276 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
278 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
281 // If a previous section at this level was a book, we *have* to have a
282 // book not a page, because of a bug in WHC (or WinHelp 4).
283 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
285 // At this level, we have a pointer to a further hierarchy.
286 // So we need a 'book' consisting of (say) Chapter 1.
287 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
289 // Then we have a 'page' consisting of the text for this chapter
290 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
292 // Then we'll be writing out further pages or books at level + 1...
294 // Remember that at this level, we had a book and *must* for the
295 // remainder of sections at this level.
296 ContentsLevels
[level
-1] = TRUE
;
300 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
305 if (level
== 1 || ContentsLevels
[level
-1])
307 // Always have a book at level 1
308 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
309 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
310 ContentsLevels
[level
-1] = TRUE
;
313 // Probably doesn't have children if it hasn't been added to the topic table
314 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
319 void SplitIndexEntry(char *entry
, char *buf1
, char *buf2
)
321 int len
= strlen(entry
); int i
= 0;
322 while ((i
< len
) && entry
[i
] != '!')
323 { buf1
[i
] = entry
[i
]; i
++; }
324 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
329 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
335 * Output topic index entries in WinHelp RTF
338 void GenerateKeywordsForTopic(char *topic
)
340 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
344 wxStringList
*list
= texTopic
->keywords
;
347 wxNode
*node
= list
->First();
350 char *s
= (char *)node
->Data();
352 // Must separate out main entry form subentry (only 1 subentry allowed)
353 char buf1
[100]; char buf2
[100];
354 SplitIndexEntry(s
, buf1
, buf2
);
356 // Check for ':' which messes up index
358 for (i
= 0; i
< strlen(buf1
) ; i
++)
361 for (i
= 0; i
< strlen(buf2
) ; i
++)
365 // {K} is a strange fix to prevent words beginning with K not
366 // being indexed properly
367 TexOutput("K{\\footnote {K} ");
369 if (strlen(buf2
) > 0)
382 * Output index entry in linear RTF
386 void GenerateIndexEntry(char *entry
)
390 char buf1
[100]; char buf2
[100];
391 SplitIndexEntry(entry
, buf1
, buf2
);
393 TexOutput("{\\xe\\v {");
395 if (strlen(buf2
) > 0)
405 * Write a suitable RTF header.
409 void WriteColourTable(FILE *fd
)
411 fprintf(fd
, "{\\colortbl");
412 wxNode
*node
= ColourTable
.First();
415 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->Data();
416 fprintf(fd
, "\\red%d\\green%d\\blue%d;\n", entry
->red
, entry
->green
, entry
->blue
);
423 * Write heading style
427 void WriteHeadingStyle(FILE *fd
, int heading
)
433 fprintf(fd
, "\\b\\fs%d", chapterFont
*2);
438 fprintf(fd
, "\\b\\fs%d", sectionFont
*2);
443 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
448 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
456 void WriteRTFHeader(FILE *fd
)
458 fprintf(fd
, "{\\rtf1\\%s \\deff0\n", RTFCharset
);
459 fprintf(fd
, "{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n");
460 fprintf(fd
, "{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}");
464 fprintf(fd
, "{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n");
466 fprintf(fd
, "{\\s1 "); WriteHeadingStyle(fd
, 1); fprintf(fd
, "\\sbasedon0\\snext0 heading 1;}\n");
467 fprintf(fd
, "{\\s2 "); WriteHeadingStyle(fd
, 2); fprintf(fd
, "\\sbasedon0\\snext0 heading 2;}\n");
468 fprintf(fd
, "{\\s3 "); WriteHeadingStyle(fd
, 3); fprintf(fd
, "\\sbasedon0\\snext0 heading 3;}\n");
469 fprintf(fd
, "{\\s4 "); WriteHeadingStyle(fd
, 4); fprintf(fd
, "\\sbasedon0\\snext0 heading 4;}\n");
470 // Table of contents styles
471 fprintf(fd
, "{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n");
473 fprintf(fd
, "{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n");
474 fprintf(fd
, "{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n");
475 fprintf(fd
, "{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n");
478 fprintf(fd
, "{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n");
479 fprintf(fd
, "{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n");
480 fprintf(fd
, "{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n");
481 fprintf(fd
, "{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n");
482 fprintf(fd
, "{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n");
485 WriteColourTable(fd
);
486 fprintf(fd
, "\n\\ftnbj\\ftnrestart"); // Latex default is footnotes at bottom of page, not section.
490 void OutputNumberStyle(char *numberStyle
)
494 if (strcmp(numberStyle
, "arabic") == 0)
496 TexOutput("\\pgndec");
498 else if (strcmp(numberStyle
, "roman") == 0)
500 TexOutput("\\pgnlcrm");
502 else if (strcmp(numberStyle
, "Roman") == 0)
504 TexOutput("\\pgnucrm");
506 else if (strcmp(numberStyle
, "alph") == 0)
508 TexOutput("\\pgnlcltr");
510 else if (strcmp(numberStyle
, "Alph") == 0)
512 TexOutput("\\pgnucltr");
518 * Write a Windows help project file
521 bool WriteHPJ(char *filename
)
523 char hpjFilename
[256];
526 strcpy(hpjFilename
, filename
);
527 StripExtension(hpjFilename
);
528 strcat(hpjFilename
, ".hpj");
530 strcpy(helpFile
, FileNameFromPath(filename
));
531 StripExtension(helpFile
);
532 strcpy(rtfFile
, helpFile
);
533 strcat(helpFile
, ".hlp");
534 strcat(rtfFile
, ".rtf");
536 FILE *fd
= fopen(hpjFilename
, "w");
540 char *helpTitle
= winHelpTitle
;
542 helpTitle
= "Untitled";
544 wxString thePath
= wxPathOnly(InputFile
);
545 if (thePath
.IsEmpty())
547 fprintf(fd
, "[OPTIONS]\n");
548 fprintf(fd
, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath
.c_str());
549 fprintf(fd
, "TITLE=%s\n", helpTitle
);
550 fprintf(fd
, "CONTENTS=Contents\n");
552 if (winHelpVersion
> 3)
554 fprintf(fd
, "; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n");
555 fprintf(fd
, "COMPRESS=8 Zeck\n");
556 fprintf(fd
, "LCID=0x809 0x0 0x0 ;English (British)\n");
557 fprintf(fd
, "HLP=.\\%s.hlp\n", wxFileNameFromPath(FileRoot
));
561 fprintf(fd
, "COMPRESS=HIGH\n");
565 if (winHelpVersion
> 3)
567 fprintf(fd
, "[WINDOWS]\n");
568 fprintf(fd
, "Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n");
572 fprintf(fd
, "[FILES]\n%s\n\n", rtfFile
);
573 fprintf(fd
, "[CONFIG]\n");
575 fprintf(fd
, "CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n", helpFile
);
576 fprintf(fd
, "BrowseButtons()\n\n");
577 fprintf(fd
, "[MAP]\n\n[BITMAPS]\n\n");
584 * Given a TexChunk with a string value, scans through the string
585 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
586 * and inserting spaces at the start of lines since in Latex, a newline
587 * implies a space, but not in RTF.
591 void ProcessText2RTF(TexChunk
*chunk
)
593 bool changed
= FALSE
;
597 int len
= strlen(chunk
->value
);
600 ch
= chunk
->value
[i
];
606 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "\\par\n"); ptr
+= 5;
612 // If the first character of the next line is ASCII,
613 // put a space in. Implicit in Latex, not in RTF.
615 The reason this is difficult is that you don't really know
616 where a space would be appropriate. If you always put in a space
617 when you find a newline, unwanted spaces appear in the text.
619 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
620 !isspace(chunk
->value
[i
+1])) ||
621 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
622 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
623 !isspace(chunk
->value
[i
+2]))))
626 // DOS files have a 13 after the 10
630 if (chunk
->value
[i
] == 13)
637 BigBuffer
[ptr
] = ' ';
640 // Note that the actual ASCII character seen is dealt with in the next
651 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
653 BigBuffer
[ptr
] = '"'; ptr
++;
657 else if (!inVerbatim
&& ch
== '`') // Change ` to '
659 BigBuffer
[ptr
] = 39; ptr
++;
663 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
665 BigBuffer
[ptr
] = '\\'; ptr
++;
666 BigBuffer
[ptr
] = '\\'; ptr
++;
670 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curley bracket
672 BigBuffer
[ptr
] = '\\'; ptr
++;
673 BigBuffer
[ptr
] = ch
; ptr
++;
688 delete[] chunk
->value
;
689 chunk
->value
= copystring(BigBuffer
);
694 * Scan through all chunks starting from the given one,
695 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
696 * This should be called after Tex2Any has parsed the file,
697 * and before TraverseDocument is called.
701 void Text2RTF(TexChunk
*chunk
)
704 if (stopRunning
) return;
708 case CHUNK_TYPE_MACRO
:
710 TexMacroDef
*def
= chunk
->def
;
711 if (def
&& def
->ignore
)
714 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
717 wxNode
*node
= chunk
->children
.First();
720 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
721 Text2RTF(child_chunk
);
725 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
732 wxNode
*node
= chunk
->children
.First();
735 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
736 Text2RTF(child_chunk
);
742 case CHUNK_TYPE_STRING
:
745 ProcessText2RTF(chunk
);
757 static long browseId
= 0;
758 char *GetBrowseString(void)
762 sprintf(buf
, "%ld", browseId
);
763 int noZeroes
= 5-strlen(buf
);
764 strcpy(browseBuf
, "browse");
765 for (int i
= 0; i
< noZeroes
; i
++)
766 strcat(browseBuf
, "0");
767 strcat(browseBuf
, buf
);
772 * Keeping track of environments to restore the styles after \pard.
773 * Push strings like "\qc" onto stack.
777 void PushEnvironmentStyle(char *style
)
779 environmentStack
.Add(style
);
782 void PopEnvironmentStyle(void)
784 wxNode
*node
= environmentStack
.Last();
787 char *val
= (char *)node
->Data();
793 // Write out the styles, most recent first.
794 void WriteEnvironmentStyles(void)
796 wxNode
*node
= environmentStack
.Last();
799 char *val
= (char *)node
->Data();
803 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
806 sprintf(buf
, "\\fi%d", ParIndent
*20); // Convert points to TWIPS
809 if (environmentStack
.Number() > 0 || (ParIndent
> 0))
819 void OutputRTFHeaderCommands(void)
822 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
824 TexOutput("{\\headerl }{\\headerr }");
826 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
828 TexOutput("{\\headerl }{\\headerr }");
830 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
833 TexOutput("{\\headerl\\fi0 ");
836 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
838 TexOutput("{\\i \\qr ");
839 if (DocumentStyle
== LATEX_ARTICLE
)
841 sprintf(buf
, "SECTION %d", sectionNo
);
846 sprintf(buf
, "CHAPTER %d: ", chapterNo
);
849 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
850 TexOutput("}\\par\\pard}");
853 TexOutput("{\\headerr\\fi0 ");
856 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
858 TexOutput("{\\i \\qc ");
859 if (DocumentStyle
== LATEX_ARTICLE
)
861 sprintf(buf
, "SECTION %d", sectionNo
);
866 sprintf(buf
, "CHAPTER %d", chapterNo
);
869 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
870 TexOutput("}\\par\\pard}");
874 int oldForbidResetPar
= forbidResetPar
;
877 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
879 TexOutput("{\\headerl\\fi0 ");
882 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
886 if (!CentreHeaderEven
&& !RightHeaderEven
)
888 TraverseChildrenFromChunk(LeftHeaderEven
);
890 if (CentreHeaderEven
)
892 if (!LeftHeaderEven
&& !RightHeaderEven
)
895 TexOutput("\\tab\\tab\\tab ");
896 TraverseChildrenFromChunk(CentreHeaderEven
);
900 if (!LeftHeaderEven
&& !CentreHeaderEven
)
903 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
904 TraverseChildrenFromChunk(RightHeaderEven
);
906 TexOutput("\\par\\pard}");
909 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
911 TexOutput("{\\headerr\\fi0 ");
914 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
918 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
920 TraverseChildrenFromChunk(LeftHeaderOdd
);
924 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
927 TexOutput("\\tab\\tab\\tab ");
928 TraverseChildrenFromChunk(CentreHeaderOdd
);
932 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
935 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
936 TraverseChildrenFromChunk(RightHeaderOdd
);
938 TexOutput("\\par\\pard}");
940 // As an approximation, don't put a header on the first page of a section.
941 // This may not always be desired, but it's a reasonable guess.
942 TexOutput("{\\headerf }");
944 forbidResetPar
= oldForbidResetPar
;
948 void OutputRTFFooterCommands(void)
950 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
952 TexOutput("{\\footerl\\fi0 ");
954 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
956 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
957 TexOutput("}\\par\\pard}");
959 TexOutput("{\\footerr\\fi0 ");
961 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
963 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
964 TexOutput("}\\par\\pard}");
966 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
968 TexOutput("{\\footerl }{\\footerr }");
970 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
972 TexOutput("{\\footerl }{\\footerr }");
976 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
978 TexOutput("{\\footerl\\fi0 ");
980 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
983 if (!CentreFooterEven
&& !RightFooterEven
)
985 TraverseChildrenFromChunk(LeftFooterEven
);
987 if (CentreFooterEven
)
989 if (!LeftFooterEven
&& !RightFooterEven
)
992 TexOutput("\\tab\\tab\\tab ");
993 TraverseChildrenFromChunk(CentreFooterEven
);
997 if (!LeftFooterEven
&& !CentreFooterEven
)
1000 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1001 TraverseChildrenFromChunk(RightFooterEven
);
1003 TexOutput("\\par\\pard}");
1006 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1008 TexOutput("{\\footerr\\fi0 ");
1010 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
1013 if (!CentreFooterOdd
&& !RightFooterOdd
)
1015 TraverseChildrenFromChunk(LeftFooterOdd
);
1017 if (CentreFooterOdd
)
1019 if (!LeftFooterOdd
&& !RightFooterOdd
)
1022 TexOutput("\\tab\\tab\\tab ");
1023 TraverseChildrenFromChunk(CentreFooterOdd
);
1027 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1030 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1031 TraverseChildrenFromChunk(RightFooterOdd
);
1033 TexOutput("\\par\\pard}");
1036 // As an approximation, put a footer on the first page of a section.
1037 // This may not always be desired, but it's a reasonable guess.
1038 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1040 TexOutput("{\\footerf\\fi0 ");
1043 if (!CentreFooterOdd
&& !RightFooterOdd
)
1045 TraverseChildrenFromChunk(LeftFooterOdd
);
1047 if (CentreFooterOdd
)
1049 if (!LeftFooterOdd
&& !RightFooterOdd
)
1052 TexOutput("\\tab\\tab\\tab ");
1053 TraverseChildrenFromChunk(CentreFooterOdd
);
1057 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1060 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1061 TraverseChildrenFromChunk(RightFooterOdd
);
1063 TexOutput("\\par\\pard}");
1068 // Called on start/end of macro examination
1069 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1073 sprintf(tmpBuf, "%d (%d)", macroId, (int)start);
1074 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1075 OutputDebugString("\n"); wxYield();
1078 // ltLABEL is included here because after a section but BEFORE
1079 // the label is seen, a new paragraph is issued. Don't upset this by
1080 // immediately forgetting we've done it.
1081 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1082 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1083 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1084 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1085 macroId
!= ltPAGENUMBERING
&&
1086 (forbidResetPar
== 0)))
1088 issuedNewParagraph
= 0;
1096 case ltCHAPTERHEADING
:
1097 case ltCHAPTERHEADINGSTAR
:
1105 subsubsectionNo
= 0;
1108 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1111 char *topicName
= FindTopicName(GetNextChunk());
1112 SetCurrentChapterName(topicName
);
1114 if (winHelpContents
&& winHelp
&& !InPopups())
1116 OutputCurrentSectionToString(wxBuffer
);
1117 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 1);
1119 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1124 fprintf(Contents
, "\n{\\uldb ");
1125 fprintf(Chapters
, "\\page");
1126 fprintf(Chapters
, "\n${\\footnote ");
1128 SetCurrentOutputs(Contents
, Chapters
);
1130 SetCurrentOutput(Chapters
);
1134 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
1136 // If a non-custom page style, we generate the header now.
1137 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1138 strcmp(PageStyle
, "empty") == 0 ||
1139 strcmp(PageStyle
, "headings") == 0))
1141 OutputRTFHeaderCommands();
1142 OutputRTFFooterCommands();
1145 // Need to reset the current numbering style, or RTF forgets it.
1146 SetCurrentOutput(Chapters
);
1147 OutputNumberStyle(currentNumberStyle
);
1149 SetCurrentOutput(Contents
);
1153 if (macroId
== ltCHAPTER
)
1156 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", chapterNo
);
1158 else if (macroId
== ltCHAPTERHEADING
)
1160 fprintf(Contents
, "\\par\n\\pard{\\b ");
1162 else SetCurrentOutput(NULL
); // No entry in table of contents
1166 startedSections
= TRUE
;
1168 // Output heading to contents page
1171 OutputCurrentSection();
1174 fprintf(Contents
, "}{\\v %s}\\par\\pard\n", topicName
);
1175 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1176 fprintf(Contents
, "}\\par\\par\\pard\n");
1178 // From here, just output to chapter
1179 SetCurrentOutput(Chapters
);
1184 fprintf(Chapters
, "}\n#{\\footnote %s}\n", topicName
);
1185 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
1187 OutputSectionKeyword(Chapters
);
1189 GenerateKeywordsForTopic(topicName
);
1192 // If we're generating a .cnt file, we don't want to be able
1193 // jump up to the old-style contents page, so disable it.
1194 if (winHelpContents
)
1195 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
1197 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1198 FileNameFromPath(FileRoot
), "Contents");
1204 char *styleCommand
= "";
1205 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1206 styleCommand
= "\\s1";
1207 fprintf(Chapters
, "\\pard{%s", ((winHelp
&& !InPopups()) ? "\\keepn\\sa140\\sb140" : styleCommand
));
1208 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " ");
1211 if (macroId
== ltCHAPTER
)
1214 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1215 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1217 fprintf(Chapters
, "%d. ", chapterNo
);
1221 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1224 OutputCurrentSection();
1225 TexOutput("\\par\\pard}\\par\n");
1227 issuedNewParagraph
= 2;
1233 case ltSECTIONHEADING
:
1234 case ltSECTIONHEADINGSTAR
:
1238 if (DocumentStyle
== LATEX_ARTICLE
)
1239 jumpFrom
= Contents
;
1241 jumpFrom
= Chapters
;
1246 subsubsectionNo
= 0;
1247 if (DocumentStyle
== LATEX_ARTICLE
)
1250 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1253 char *topicName
= FindTopicName(GetNextChunk());
1254 SetCurrentSectionName(topicName
);
1255 NotifyParentHasChildren(1);
1256 if (winHelpContents
&& winHelp
&& !InPopups())
1258 OutputCurrentSectionToString(wxBuffer
);
1259 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 2);
1261 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1265 SetCurrentOutputs(jumpFrom
, Sections
);
1266 // Newline for a new section if this is an article
1267 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1268 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1269 fprintf(Sections
, "\\page\n");
1272 fprintf(jumpFrom
, "\n{\\uldb ");
1276 if (DocumentStyle
== LATEX_ARTICLE
)
1278 TexOutput("\\sect\\pgncont\n");
1279 // If a non-custom page style, we generate the header now.
1280 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1281 strcmp(PageStyle
, "empty") == 0 ||
1282 strcmp(PageStyle
, "headings") == 0))
1284 OutputRTFHeaderCommands();
1285 OutputRTFFooterCommands();
1288 SetCurrentOutput(Contents
);
1290 if (macroId
== ltSECTION
)
1294 if (DocumentStyle
== LATEX_REPORT
)
1295 fprintf(Contents
, "\n\\pard{\\tab %d.%d\\tab ", chapterNo
, sectionNo
);
1297 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", sectionNo
);
1300 else if (macroId
== ltSECTIONHEADING
)
1304 if (DocumentStyle
== LATEX_REPORT
)
1305 fprintf(Contents
, "\n\\pard{\\tab "); //, chapterNo, sectionNo);
1307 fprintf(Contents
, "\\par\n\\pard{\\b "); //, sectionNo);
1310 else SetCurrentOutput(NULL
);
1313 if (startedSections
)
1316 fprintf(Sections
, "\\page\n");
1318 startedSections
= TRUE
;
1321 fprintf(Sections
, "\n${\\footnote ");
1323 // Output heading to contents page
1325 OutputCurrentSection();
1330 fprintf(jumpFrom
, "}{\\v %s}\\par\\pard\n", topicName
);
1332 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1334 if (DocumentStyle
== LATEX_REPORT
)
1335 fprintf(Contents
, "}\\par\\pard\n");
1337 fprintf(Contents
, "}\\par\\par\\pard\n");
1340 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1344 fprintf(Sections
, "}\n#{\\footnote %s}\n", topicName
);
1345 fprintf(Sections
, "+{\\footnote %s}\n", GetBrowseString());
1346 OutputSectionKeyword(Sections
);
1347 GenerateKeywordsForTopic(topicName
);
1350 if (DocumentStyle
== LATEX_ARTICLE
)
1352 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1353 FileNameFromPath(FileRoot
), "Contents");
1355 else if (CurrentChapterName
)
1357 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1358 FileNameFromPath(FileRoot
), CurrentChapterName
);
1365 char *styleCommand
= "";
1366 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1368 if (DocumentStyle
== LATEX_ARTICLE
)
1369 styleCommand
= "\\s1";
1371 styleCommand
= "\\s2";
1374 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1375 keep
= "\\keepn\\sa140\\sb140";
1377 fprintf(winHelp
? Sections
: Chapters
, "\\pard{%s%s",
1378 keep
, styleCommand
);
1380 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1381 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1382 fprintf(winHelp
? Sections
: Chapters
, " ");
1386 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1388 if (DocumentStyle
== LATEX_REPORT
)
1391 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo,
1392 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1395 fprintf(Chapters
, "%d.%d. ", chapterNo
, sectionNo
);
1400 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1401 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1404 fprintf(Chapters
, "%d. ", sectionNo
);
1409 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1412 OutputCurrentSection();
1413 TexOutput("\\par\\pard}\\par\n");
1415 issuedNewParagraph
= 2;
1420 case ltSUBSECTIONSTAR
:
1421 case ltMEMBERSECTION
:
1422 case ltFUNCTIONSECTION
:
1426 if (winHelp
&& !Sections
)
1428 OnError("You cannot have a subsection before a section!");
1432 subsubsectionNo
= 0;
1434 if (macroId
!= ltSUBSECTIONSTAR
)
1437 char *topicName
= FindTopicName(GetNextChunk());
1438 SetCurrentSubsectionName(topicName
);
1439 NotifyParentHasChildren(2);
1440 if (winHelpContents
&& winHelp
&& !InPopups())
1442 OutputCurrentSectionToString(wxBuffer
);
1443 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 3);
1445 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1449 SetCurrentOutputs(Sections
, Subsections
);
1450 SetCurrentOutputs(Sections
, Subsections
);
1452 fprintf(Sections
, "\n{\\uldb ");
1456 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1457 (macroId
!= ltFUNCTIONSECTION
))
1459 SetCurrentOutput(Contents
);
1460 if (DocumentStyle
== LATEX_REPORT
)
1461 fprintf(Contents
, "\n\\pard\\tab\\tab %d.%d.%d\\tab ", chapterNo
, sectionNo
, subsectionNo
);
1463 fprintf(Contents
, "\n\\pard\\tab %d.%d\\tab ", sectionNo
, subsectionNo
);
1464 } else SetCurrentOutput(NULL
);
1466 if (startedSections
)
1471 fprintf(Subsections
, "\\page\n");
1474 fprintf(Chapters
, "\\par\n");
1476 startedSections
= TRUE
;
1479 fprintf(Subsections
, "\n${\\footnote ");
1481 // Output to contents page
1483 OutputCurrentSection();
1488 fprintf(Sections
, "}{\\v %s}\\par\\pard\n", topicName
);
1490 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1491 (macroId
!= ltFUNCTIONSECTION
))
1492 fprintf(Contents
, "\\par\\pard\n");
1494 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1497 fprintf(Subsections
, "}\n#{\\footnote %s}\n", topicName
);
1498 fprintf(Subsections
, "+{\\footnote %s}\n", GetBrowseString());
1499 OutputSectionKeyword(Subsections
);
1500 GenerateKeywordsForTopic(topicName
);
1501 if (useUpButton
&& CurrentSectionName
)
1503 fprintf(Subsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1504 FileNameFromPath(FileRoot
), CurrentSectionName
);
1507 if (!winHelp
&& indexSubsections
&& useWord
)
1509 // Insert index entry for this subsection
1510 TexOutput("{\\xe\\v {");
1511 OutputCurrentSection();
1517 char *styleCommand
= "";
1518 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1520 if (DocumentStyle
== LATEX_ARTICLE
)
1521 styleCommand
= "\\s2";
1523 styleCommand
= "\\s3";
1526 if (winHelp
&& !InPopups())
1527 keep
= "\\keepn\\sa140\\sb140";
1529 fprintf(winHelp
? Subsections
: Chapters
, "\\pard{%s%s",
1530 keep
, styleCommand
);
1532 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1533 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1534 fprintf(winHelp
? Subsections
: Chapters
, " ");
1538 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1539 (macroId
!= ltFUNCTIONSECTION
))
1541 if (DocumentStyle
== LATEX_REPORT
)
1544 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo,
1545 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1548 fprintf(Chapters
, "%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
);
1553 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo,
1554 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1557 fprintf(Chapters
, "%d.%d. ", sectionNo
, subsectionNo
);
1562 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1565 OutputCurrentSection(); // Repeat section header
1566 TexOutput("\\par\\pard}\\par\n");
1568 issuedNewParagraph
= 2;
1573 case ltSUBSUBSECTION
:
1574 case ltSUBSUBSECTIONSTAR
:
1578 if (winHelp
&& !Subsections
)
1580 OnError("You cannot have a subsubsection before a subsection!");
1584 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1587 char *topicName
= FindTopicName(GetNextChunk());
1588 SetCurrentTopic(topicName
);
1589 NotifyParentHasChildren(3);
1590 if (winHelpContents
&& winHelp
)
1592 OutputCurrentSectionToString(wxBuffer
);
1593 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 4);
1595 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1599 SetCurrentOutputs(Subsections
, Subsubsections
);
1600 fprintf(Subsections
, "\n{\\uldb ");
1604 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1606 if (DocumentStyle
== LATEX_ARTICLE
)
1608 SetCurrentOutput(Contents
);
1609 fprintf(Contents
, "\n\\tab\\tab %d.%d.%d\\tab ",
1610 sectionNo
, subsectionNo
, subsubsectionNo
);
1613 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1616 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1619 if (startedSections
)
1622 fprintf(Subsubsections
, "\\page\n");
1624 fprintf(Chapters
, "\\par\n");
1627 startedSections
= TRUE
;
1630 fprintf(Subsubsections
, "\n${\\footnote ");
1632 // Output header to contents page
1633 OutputCurrentSection();
1636 fprintf(Subsections
, "}{\\v %s}\\par\\pard\n", topicName
);
1637 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1638 fprintf(Contents
, "\\par\\pard\n");
1640 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1643 fprintf(Subsubsections
, "}\n#{\\footnote %s}\n", topicName
);
1644 fprintf(Subsubsections
, "+{\\footnote %s}\n", GetBrowseString());
1645 OutputSectionKeyword(Subsubsections
);
1646 GenerateKeywordsForTopic(topicName
);
1647 if (useUpButton
&& CurrentSubsectionName
)
1649 fprintf(Subsubsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1650 FileNameFromPath(FileRoot
), CurrentSubsectionName
);
1653 if (!winHelp
&& indexSubsections
&& useWord
)
1655 // Insert index entry for this subsubsection
1656 TexOutput("{\\xe\\v {");
1657 OutputCurrentSection();
1661 char *styleCommand
= "";
1662 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1664 if (DocumentStyle
== LATEX_ARTICLE
)
1665 styleCommand
= "\\s3";
1667 styleCommand
= "\\s4";
1671 keep
= "\\keepn\\sa140\\sb140";
1673 fprintf(winHelp
? Subsubsections
: Chapters
, "\\pard{%s%s",
1674 keep
, styleCommand
);
1676 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1677 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1678 fprintf(winHelp
? Subsubsections
: Chapters
, " ");
1682 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1684 if (DocumentStyle
== LATEX_ARTICLE
)
1687 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo, subsubsectionNo,
1688 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1691 fprintf(Chapters
, "%d.%d.%d. ", sectionNo
, subsectionNo
, subsubsectionNo
);
1696 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1697 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1700 fprintf(Chapters
, "%d.%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1705 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1708 OutputCurrentSection(); // Repeat section header
1709 TexOutput("\\par\\pard}\\par\n");
1710 issuedNewParagraph
= 2;
1711 // if (winHelp) TexOutput("\\pard");
1721 char *topicName
= FindTopicName(GetNextChunk());
1722 SetCurrentTopic(topicName
);
1724 TexOutput("\\pard\\par");
1731 if (winHelp
|| !useWord
)
1733 if (DocumentStyle
!= LATEX_ARTICLE
)
1734 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1736 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1740 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1741 FigureNameString
, topicName
, topicName
);
1748 if (winHelp
|| !useWord
)
1750 if (DocumentStyle
!= LATEX_ARTICLE
)
1751 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1753 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1757 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1758 TableNameString
, topicName
, topicName
);
1762 int n
= (inTable
? tableNo
: figureNo
);
1763 AddTexRef(topicName
, NULL
, NULL
,
1764 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1765 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1768 TexOutput("\\qc{\\b ");
1770 TexOutput("\\ql{\\b ");
1773 OutputCurrentSection();
1775 TexOutput("}\\par\\pard\n");
1776 WriteEnvironmentStyles();
1783 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1793 TexOutput("K{\\footnote {K} ");
1794 suppressNameDecoration
= TRUE
;
1795 TraverseChildrenFromChunk(currentMember
);
1796 suppressNameDecoration
= FALSE
;
1799 if (!winHelp
&& useWord
)
1801 // Insert index entry for this function
1802 TexOutput("{\\xe\\v {");
1803 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1804 TraverseChildrenFromChunk(currentMember
);
1805 suppressNameDecoration
= FALSE
;
1813 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1823 TexOutput("K{\\footnote {K} ");
1824 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1825 TraverseChildrenFromChunk(currentMember
);
1826 suppressNameDecoration
= FALSE
;
1829 if (!winHelp
&& useWord
)
1831 // Insert index entry for this function
1832 TexOutput("{\\xe\\v {");
1833 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1834 TraverseChildrenFromChunk(currentMember
);
1835 suppressNameDecoration
= FALSE
;
1843 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1853 TexOutput("K{\\footnote {K} ");
1854 TraverseChildrenFromChunk(currentMember
);
1857 if (!winHelp
&& useWord
)
1859 // Insert index entry for this function
1860 TexOutput("{\\xe\\v {");
1861 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1862 TraverseChildrenFromChunk(currentMember
);
1863 suppressNameDecoration
= FALSE
;
1872 SetCurrentOutput(Chapters
);
1875 case ltTABLEOFCONTENTS
:
1879 if (!winHelp
&& useWord
)
1881 // Insert Word for Windows table of contents
1882 TexOutput("\\par\\pard\\pgnrestart\\sect\\titlepg");
1884 // In linear RTF, same as chapter headings.
1885 sprintf(buf
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n", chapterFont
*2, ContentsNameString
);
1888 sprintf(buf
, "{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n", contentsDepth
);
1890 // TexOutput("\\sect\\sectd");
1894 FILE *fd
= fopen(ContentsName
, "r");
1907 TexOutput("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n");
1908 OnInform("Run Tex2RTF again to include contents page.");
1917 // TexOutput("{\\b void}");
1923 TexOutput("{\\scaps HARDY}");
1929 TexOutput("wxCLIPS");
1932 case ltSPECIALAMPERSAND
:
1937 TexOutput("\\cell ");
1943 case ltSPECIALTILDE
:
1954 case ltBACKSLASHCHAR
:
1960 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
1961 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
1962 int currentWidth
= 0;
1963 for (int i
= 0; i
< noColumns
; i
++)
1965 currentWidth
+= TableData
[i
].width
;
1966 if (TableData
[i
].rightBorder
)
1967 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
1969 if (TableData
[i
].leftBorder
)
1970 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
1972 sprintf(buf
, "\\cellx%d", currentWidth
);
1975 TexOutput("\\pard\\intbl\n");
1978 TexOutput("\\line\n");
1988 case ltRTFSP
: // Explicit space, RTF only
2000 if (indentLevel
> 0)
2002 TexOutput("\\par\\par\n");
2003 issuedNewParagraph
= 2;
2007 // Top-level list: issue a new paragraph if we haven't
2009 if (!issuedNewParagraph
)
2011 TexOutput("\\par\\pard");
2012 WriteEnvironmentStyles();
2013 issuedNewParagraph
= 1;
2015 else issuedNewParagraph
= 0;
2018 TexOutput("\\fi0\n");
2020 if (macroId
== ltENUMERATE
)
2021 listType
= LATEX_ENUMERATE
;
2022 else if (macroId
== ltITEMIZE
)
2023 listType
= LATEX_ITEMIZE
;
2025 listType
= LATEX_DESCRIPTION
;
2028 wxNode
*node
= itemizeStack
.First();
2030 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2032 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2033 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2035 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2036 itemizeStack
.Insert(struc
);
2038 sprintf(buf
, "\\tx%d\\tx%d\\li%d", indentSize1
, indentSize2
, indentSize2
);
2039 PushEnvironmentStyle(buf
);
2043 currentItemSep
= 8; // Reset to the default
2045 PopEnvironmentStyle();
2047 if (itemizeStack
.First())
2049 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2051 delete itemizeStack
.First();
2053 /* Change 18/7/97 - don't know why we wish to do this
2054 if (itemizeStack.Number() == 0)
2056 OnMacro(ltPAR, 0, TRUE);
2057 OnMacro(ltPAR, 0, FALSE);
2058 issuedNewParagraph = 2;
2070 wxNode
*node
= itemizeStack
.First();
2072 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2074 int indentSize
= oldIndent
+ TwoColWidthA
;
2076 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2077 itemizeStack
.Insert(struc
);
2079 // sprintf(buf, "\\tx%d\\li%d\\ri%d", indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2080 sprintf(buf
, "\\tx%d\\li%d", indentSize
, indentSize
);
2081 PushEnvironmentStyle(buf
);
2086 PopEnvironmentStyle();
2087 if (itemizeStack
.First())
2089 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2091 delete itemizeStack
.First();
2095 TexOutput("\\pard\n");
2096 WriteEnvironmentStyles();
2098 /* why do we need this? */
2099 if (itemizeStack
.Number() == 0)
2101 issuedNewParagraph
= 0;
2102 OnMacro(ltPAR
, 0, TRUE
);
2103 OnMacro(ltPAR
, 0, FALSE
);
2110 wxNode
*node
= itemizeStack
.First();
2113 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2116 struc
->currentItem
+= 1;
2119 int indentSize1
= struc
->labelIndentation
;
2120 int indentSize2
= struc
->indentation
;
2123 if (struc
->currentItem
> 1)
2125 if (currentItemSep
> 0)
2129 // WriteEnvironmentStyles();
2132 sprintf(buf
, "\\tx%d\\tx%d\\li%d\\fi-%d\n", indentSize1
, indentSize2
,
2133 indentSize2
, 20*itemIndentTab
);
2136 switch (struc
->listType
)
2138 case LATEX_ENUMERATE
:
2140 if (descriptionItemArg
)
2142 TexOutput("\\tab{ ");
2143 TraverseChildrenFromChunk(descriptionItemArg
);
2144 TexOutput("}\\tab");
2145 descriptionItemArg
= NULL
;
2149 sprintf(indentBuf
, "\\tab{\\b %d.}\\tab", struc
->currentItem
);
2150 TexOutput(indentBuf
);
2156 if (descriptionItemArg
)
2158 TexOutput("\\tab{ ");
2159 TraverseChildrenFromChunk(descriptionItemArg
);
2160 TexOutput("}\\tab");
2161 descriptionItemArg
= NULL
;
2165 if (bulletFile
&& winHelp
)
2167 if (winHelpVersion
> 3) // Transparent bitmap
2168 sprintf(indentBuf
, "\\tab\\{bmct %s\\}\\tab", bulletFile
);
2170 sprintf(indentBuf
, "\\tab\\{bmc %s\\}\\tab", bulletFile
);
2173 sprintf(indentBuf
, "\\tab{\\b o}\\tab");
2175 sprintf(indentBuf
, "\\tab{\\f1\\'b7}\\tab");
2176 TexOutput(indentBuf
);
2181 case LATEX_DESCRIPTION
:
2183 if (descriptionItemArg
)
2185 TexOutput("\\tab{\\b ");
2186 TraverseChildrenFromChunk(descriptionItemArg
);
2188 descriptionItemArg
= NULL
;
2198 case ltTWOCOLITEMRULED
:
2200 wxNode
*node
= itemizeStack
.First();
2203 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2206 struc
->currentItem
+= 1;
2208 int indentSize
= struc
->indentation
;
2210 wxNode
*node2
= NULL
;
2211 if (itemizeStack
.Number() > 1) // TODO: do I actually mean Nth(0) here??
2212 node2
= itemizeStack
.Nth(1);
2214 oldIndent
= ((ItemizeStruc
*)node2
->Data())->indentation
;
2217 if (struc
->currentItem
> 1)
2219 if (currentItemSep
> 0)
2222 // WriteEnvironmentStyles();
2225 // sprintf(buf, "\\tx%d\\li%d\\fi-%d\\ri%d\n", TwoColWidthA,
2226 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2228 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA,
2229 TwoColWidthA, TwoColWidthA);
2231 sprintf(buf
, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA
+ oldIndent
,
2232 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2243 if (macroId
== ltVERBATIM
)
2245 if (!issuedNewParagraph
)
2247 TexOutput("\\par\\pard");
2248 WriteEnvironmentStyles();
2249 issuedNewParagraph
= 1;
2251 else issuedNewParagraph
= 0;
2253 sprintf(buf
, "{\\f3\\fs20 ");
2259 if (macroId
== ltVERBATIM
)
2261 TexOutput("\\pard\n");
2262 // issuedNewParagraph = 1;
2263 WriteEnvironmentStyles();
2273 TexOutput("\\fi0\\qc ");
2275 PushEnvironmentStyle("\\qc");
2279 TexOutput("\\par\\pard\n");
2280 issuedNewParagraph
= 1;
2282 PopEnvironmentStyle();
2283 WriteEnvironmentStyles();
2291 TexOutput("\\fi0\\ql ");
2293 PushEnvironmentStyle("\\ql");
2297 TexOutput("\\par\\pard\n");
2298 issuedNewParagraph
= 1;
2300 PopEnvironmentStyle();
2301 WriteEnvironmentStyles();
2309 TexOutput("\\fi0\\qr ");
2311 PushEnvironmentStyle("\\qr");
2315 TexOutput("\\par\\pard\n");
2316 issuedNewParagraph
= 1;
2318 PopEnvironmentStyle();
2319 WriteEnvironmentStyles();
2324 case ltFOOTNOTESIZE
:
2328 sprintf(buf
, "{\\fs%d\n", smallFont
*2);
2331 else TexOutput("}\n");
2339 sprintf(buf
, "{\\fs%d\n", tinyFont
*2);
2342 else TexOutput("}\n");
2349 sprintf(buf
, "{\\fs%d\n", normalFont
*2);
2352 else TexOutput("}\n");
2359 sprintf(buf
, "{\\fs%d\n", largeFont1
*2);
2362 else TexOutput("}\n");
2369 sprintf(buf
, "{\\fs%d\n", LargeFont2
*2);
2372 else TexOutput("}\n");
2379 sprintf(buf
, "{\\fs%d\n", LARGEFont3
*2);
2382 else TexOutput("}\n");
2389 sprintf(buf
, "{\\fs%d\n", hugeFont1
*2);
2392 else TexOutput("}\n");
2399 sprintf(buf
, "{\\fs%d\n", HugeFont2
*2);
2402 else TexOutput("}\n");
2409 sprintf(buf
, "{\\fs%d\n", HUGEFont3
*2);
2412 else TexOutput("}\n");
2423 else TexOutput("}");
2430 TexOutput("{\\ul ");
2432 else TexOutput("}");
2445 else TexOutput("}");
2448 // Roman font: do nothing. Should really switch between
2457 TexOutput("{\\plain ");
2459 else TexOutput("}");
2463 // Medium-weight font. Unbolden...
2468 TexOutput("{\\b0 ");
2470 else TexOutput("}");
2473 // Upright (un-italic or slant)
2478 TexOutput("{\\i0 ");
2480 else TexOutput("}");
2489 TexOutput("{\\scaps ");
2491 else TexOutput("}");
2500 TexOutput("{\\f3 ");
2502 else TexOutput("}");
2527 if ( issuedNewParagraph
== 0 )
2529 TexOutput("\\par\\pard");
2530 issuedNewParagraph
++;
2532 // Extra par if parskip is more than zero (usually looks best.)
2533 if (!inTabular
&& (ParSkip
> 0))
2536 issuedNewParagraph
++;
2538 WriteEnvironmentStyles();
2540 // 1 is a whole paragraph if ParSkip == 0,
2541 // half a paragraph if ParSkip > 0
2542 else if ( issuedNewParagraph
== 1 )
2544 // Don't need a par at all if we've already had one,
2545 // and ParSkip == 0.
2547 // Extra par if parskip is more than zero (usually looks best.)
2548 if (!inTabular
&& (ParSkip
> 0))
2551 issuedNewParagraph
++;
2553 WriteEnvironmentStyles();
2556 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2558 TexOutput("\\par\\pard");
2560 // Extra par if parskip is more than zero (usually looks best.)
2561 if (!inTabular && (ParSkip > 0))
2563 WriteEnvironmentStyles();
2573 // In Windows Help, no newpages until we've started some chapters or sections
2574 if (!(winHelp
&& !startedSections
))
2576 TexOutput("\\page\n");
2581 if (start
&& DocumentTitle
)
2583 TexOutput("\\par\\pard");
2586 sprintf(buf
, "\\qc{\\fs%d\\b ", titleFont
*2);
2588 TraverseChildrenFromChunk(DocumentTitle
);
2589 TexOutput("}\\par\\pard\n");
2595 sprintf(buf
, "\\par\\qc{\\fs%d ", authorFont
*2);
2597 TraverseChildrenFromChunk(DocumentAuthor
);
2599 TexOutput("\\par\\pard\n");
2604 sprintf(buf
, "\\qc{\\fs%d ", authorFont
*2);
2606 TraverseChildrenFromChunk(DocumentDate
);
2607 TexOutput("}\\par\\pard\n");
2609 // If linear RTF, we want this titlepage to be in a separate
2610 // section with its own (blank) header and footer
2611 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2613 TexOutput("{\\header }{\\footer }\n");
2614 // Not sure about this: we get too many sections.
2615 // TexOutput("\\sect");
2620 case ltADDCONTENTSLINE
:
2624 if (contentsLineSection
&& contentsLineValue
)
2626 if (strcmp(contentsLineSection
, "chapter") == 0)
2628 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2630 else if (strcmp(contentsLineSection
, "section") == 0)
2632 if (DocumentStyle
!= LATEX_ARTICLE
)
2633 fprintf(Contents
, "\n\\tab%s\\par\n", contentsLineValue
);
2635 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2645 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2646 issuedNewParagraph
= 1;
2647 WriteEnvironmentStyles();
2655 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2656 issuedNewParagraph
= 1;
2657 WriteEnvironmentStyles();
2667 case ltNUMBEREDBIBITEM
:
2670 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
2672 TexOutput("\\par\\pard\\par\n\n");
2679 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2687 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2688 sprintf(buf
, "%d", chapterNo
);
2697 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2698 sprintf(buf
, "%d", sectionNo
);
2705 if (!start
&& !winHelp
)
2707 TexOutput("\\cols2\n");
2713 if (!start
&& !winHelp
)
2715 TexOutput("\\cols1\n");
2721 if (start
&& useWord
&& !winHelp
)
2723 FakeCurrentSection("Index");
2724 OnMacro(ltPAR
, 0, TRUE
);
2725 OnMacro(ltPAR
, 0, FALSE
);
2726 TexOutput("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n");
2730 case ltLISTOFFIGURES
:
2732 if (start
&& useWord
&& !winHelp
)
2734 FakeCurrentSection(FiguresNameString
, FALSE
);
2735 OnMacro(ltPAR
, 0, TRUE
);
2736 OnMacro(ltPAR
, 0, FALSE
);
2737 OnMacro(ltPAR
, 0, TRUE
);
2738 OnMacro(ltPAR
, 0, FALSE
);
2740 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n",
2746 case ltLISTOFTABLES
:
2748 if (start
&& useWord
&& !winHelp
)
2750 FakeCurrentSection(TablesNameString
, FALSE
);
2751 OnMacro(ltPAR
, 0, TRUE
);
2752 OnMacro(ltPAR
, 0, FALSE
);
2753 OnMacro(ltPAR
, 0, TRUE
);
2754 OnMacro(ltPAR
, 0, FALSE
);
2756 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n",
2764 if (start
) TexOutput("{\\f1\\'61}");
2767 if (start
) TexOutput("{\\f1\\'62}");
2770 if (start
) TexOutput("{\\f1\\'63}");
2773 if (start
) TexOutput("{\\f1\\'64}");
2777 if (start
) TexOutput("{\\f1\\'65}");
2780 if (start
) TexOutput("{\\f1\\'7A}");
2783 if (start
) TexOutput("{\\f1\\'68}");
2787 if (start
) TexOutput("{\\f1\\'71}");
2790 if (start
) TexOutput("{\\f1\\'69}");
2793 if (start
) TexOutput("{\\f1\\'6B}");
2796 if (start
) TexOutput("{\\f1\\'6C}");
2799 if (start
) TexOutput("{\\f1\\'6D}");
2802 if (start
) TexOutput("{\\f1\\'6E}");
2805 if (start
) TexOutput("{\\f1\\'78}");
2808 if (start
) TexOutput("{\\f1\\'70}");
2811 if (start
) TexOutput("{\\f1\\'76}");
2815 if (start
) TexOutput("{\\f1\\'72}");
2818 if (start
) TexOutput("{\\f1\\'73}");
2821 if (start
) TexOutput("{\\f1\\'56}");
2824 if (start
) TexOutput("{\\f1\\'74}");
2827 if (start
) TexOutput("{\\f1\\'75}");
2831 if (start
) TexOutput("{\\f1\\'66}");
2834 if (start
) TexOutput("{\\f1\\'63}");
2837 if (start
) TexOutput("{\\f1\\'79}");
2840 if (start
) TexOutput("{\\f1\\'77}");
2843 if (start
) TexOutput("{\\f1\\'47}");
2846 if (start
) TexOutput("{\\f1\\'44}");
2849 if (start
) TexOutput("{\\f1\\'51}");
2852 if (start
) TexOutput("{\\f1\\'4C}");
2855 if (start
) TexOutput("{\\f1\\'58}");
2858 if (start
) TexOutput("{\\f1\\'50}");
2861 if (start
) TexOutput("{\\f1\\'53}");
2864 if (start
) TexOutput("{\\f1\\'54}");
2867 if (start
) TexOutput("{\\f1\\'46}");
2870 if (start
) TexOutput("{\\f1\\'59}");
2873 if (start
) TexOutput("{\\f1\\'57}");
2875 // Binary operation symbols
2878 if (start
) TexOutput("{\\f1\\'A3}");
2881 if (start
) TexOutput("<<");
2884 if (start
) TexOutput("{\\f1\\'CC}");
2887 if (start
) TexOutput("{\\f1\\'CD}");
2890 if (start
) TexOutput("{\\f1\\'CE}");
2894 if (start
) TexOutput("{\\f1\\'B3}");
2897 if (start
) TexOutput(">>");
2900 if (start
) TexOutput("{\\f1\\'C9}");
2903 if (start
) TexOutput("{\\f1\\'CD}");
2906 if (start
) TexOutput("{\\f1\\'27}");
2909 if (start
) TexOutput("{\\f1\\'5E}");
2912 if (start
) TexOutput("{\\f1\\'B9}");
2915 if (start
) TexOutput("{\\f1\\'BB}");
2918 if (start
) TexOutput("{\\f1\\'40}");
2921 if (start
) TexOutput("{\\f1\\'BA}");
2924 if (start
) TexOutput("{\\f1\\'B5}");
2927 if (start
) TexOutput("{\\f1\\'7E}");
2930 if (start
) TexOutput("{\\f4\\'4A}");
2933 if (start
) TexOutput("{\\f4\\'4C}");
2936 if (start
) TexOutput("|");
2939 // Negated relation symbols
2941 if (start
) TexOutput("{\\f1\\'B9}");
2944 if (start
) TexOutput("{\\f1\\'CF}");
2947 if (start
) TexOutput("{\\f1\\'CB}");
2952 if (start
) TexOutput("{\\f1\\'AC}");
2955 if (start
) TexOutput("{\\f1\\'DC}");
2958 if (start
) TexOutput("{\\f1\\'AE}");
2961 if (start
) TexOutput("{\\f1\\'DE}");
2963 case ltLEFTRIGHTARROW
:
2964 if (start
) TexOutput("{\\f1\\'AB}");
2966 case ltLEFTRIGHTARROW2
:
2967 if (start
) TexOutput("{\\f1\\'DB}");
2970 if (start
) TexOutput("{\\f1\\'AD}");
2973 if (start
) TexOutput("{\\f1\\'DD}");
2976 if (start
) TexOutput("{\\f1\\'AF}");
2979 if (start
) TexOutput("{\\f1\\'DF}");
2982 // Miscellaneous symbols
2984 if (start
) TexOutput("{\\f1\\'CO}");
2987 if (start
) TexOutput("{\\f1\\'C3}");
2990 if (start
) TexOutput("{\\f1\\'C2}");
2993 if (start
) TexOutput("{\\f1\\'C1}");
2996 if (start
) TexOutput("{\\f1\\'C6}");
2999 if (start
) TexOutput("{\\f1\\'D1}");
3002 if (start
) TexOutput("{\\f1\\'D6}");
3005 if (start
) TexOutput("{\\f1\\'B6}");
3008 if (start
) TexOutput("{\\f1\\'5E}");
3011 if (start
) TexOutput("{\\f1\\'22}");
3014 if (start
) TexOutput("{\\f1\\'24}");
3017 if (start
) TexOutput("{\\f1\\'D8}");
3020 if (start
) TexOutput("{\\f1\\'23}");
3023 if (start
) TexOutput("{\\f1\\'D0}");
3026 if (start
) TexOutput("{\\f5\\'73}");
3029 if (start
) TexOutput("{\\f5\\'A8}");
3032 if (start
) TexOutput("{\\f5\\'A9}");
3035 if (start
) TexOutput("{\\f5\\'AA}");
3038 if (start
) TexOutput("{\\f5\\'AB}");
3041 if (start
) TexOutput("{\\f1\\'A5}");
3044 if (start
) TexOutput("{\\f0\\'A9}");
3047 if (start
) TexOutput("{\\f0\\'AE}");
3050 if (start
) TexOutput("{\\f1\\'B1}");
3053 if (start
) TexOutput("{\\f1\\'B1}");
3056 if (start
) TexOutput("{\\f1\\'B4}");
3059 if (start
) TexOutput("{\\f1\\'B8}");
3062 if (start
) TexOutput("{\\f1\\'D7}");
3065 if (start
) TexOutput("{\\f1\\'2A}");
3068 if (start
) TexOutput("{\\f5\\'AB}");
3071 if (start
) TexOutput("{\\f1\\'C7}");
3074 if (start
) TexOutput("{\\f1\\'C8}");
3077 if (start
) TexOutput("{\\f1\\'DA}");
3080 if (start
) TexOutput("{\\f1\\'D9}");
3083 if (start
) TexOutput("{\\f1\\'B0}");
3086 if (start
) TexOutput("{\\f1\\'B7}");
3089 if (start
) TexOutput("{\\f1\\'E0}");
3092 if (start
) TexOutput("{\\f1\\'C6}");
3095 if (start
) TexOutput("{\\f1\\'E0}");
3097 case ltBIGTRIANGLEDOWN
:
3098 if (start
) TexOutput("{\\f1\\'D1}");
3101 if (start
) TexOutput("{\\f1\\'C5}");
3104 if (start
) TexOutput("{\\f1\\'C4}");
3107 if (start
) TexOutput("{\\'DF}");
3111 if (start
) inFigure
= TRUE
;
3112 else inFigure
= FALSE
;
3117 if (start
) inTable
= TRUE
;
3118 else inTable
= FALSE
;
3123 DefaultOnMacro(macroId
, no_args
, start
);
3129 // Called on start/end of argument examination
3130 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3137 case ltCHAPTERHEADING
:
3140 case ltSECTIONHEADING
:
3142 case ltSUBSECTIONSTAR
:
3143 case ltSUBSUBSECTION
:
3144 case ltSUBSUBSECTIONSTAR
:
3146 case ltMEMBERSECTION
:
3147 case ltFUNCTIONSECTION
:
3151 if (!start
&& (arg_no
== 1))
3152 currentSection
= GetArgChunk();
3158 if (start
&& (arg_no
== 1))
3159 TexOutput("\\pard\\li600\\fi-600{\\b ");
3161 if (!start
&& (arg_no
== 1))
3164 if (start
&& (arg_no
== 2))
3166 if (!suppressNameDecoration
) TexOutput("{\\b ");
3167 currentMember
= GetArgChunk();
3169 if (!start
&& (arg_no
== 2))
3171 if (!suppressNameDecoration
) TexOutput("}");
3174 if (start
&& (arg_no
== 3))
3176 if (!start
&& (arg_no
== 3))
3178 // TexOutput(")\\li0\\fi0");
3179 // TexOutput(")\\par\\pard\\li0\\fi0");
3180 // issuedNewParagraph = 1;
3182 WriteEnvironmentStyles();
3188 if (start
&& (arg_no
== 1))
3189 TexOutput("\\pard\\li260\\fi-260{\\b ");
3190 if (!start
&& (arg_no
== 1))
3193 if (start
&& (arg_no
== 2))
3195 if (!suppressNameDecoration
) TexOutput("({\\b ");
3196 currentMember
= GetArgChunk();
3198 if (!start
&& (arg_no
== 2))
3200 if (!suppressNameDecoration
) TexOutput("}");
3203 if (!start
&& (arg_no
== 3))
3205 TexOutput(")\\li0\\fi0");
3206 WriteEnvironmentStyles();
3212 if (start
&& (arg_no
== 1))
3213 TexOutput("\\pard\\li260\\fi-260");
3215 if (!start
&& (arg_no
== 1))
3218 if (start
&& (arg_no
== 2))
3220 if (!start
&& (arg_no
== 2))
3223 if (start
&& (arg_no
== 2))
3224 currentMember
= GetArgChunk();
3226 if (start
&& (arg_no
== 3))
3228 if (!start
&& (arg_no
== 3))
3230 TexOutput(")\\li0\\fi0");
3231 WriteEnvironmentStyles();
3237 if (start
&& (arg_no
== 1))
3239 if (!start
&& (arg_no
== 1))
3241 if (start
&& (arg_no
== 2))
3245 if (!start
&& (arg_no
== 2))
3253 if (start
&& (arg_no
== 1))
3255 if (!start
&& (arg_no
== 1))
3256 TexOutput("} "); // This is the difference from param - one space!
3257 if (start
&& (arg_no
== 2))
3261 if (!start
&& (arg_no
== 2))
3269 if (!start
&& (arg_no
== 1))
3272 if (start
&& (arg_no
== 2))
3273 currentMember
= GetArgChunk();
3281 char *secName
= NULL
;
3283 char *refName
= GetArgData();
3284 if (winHelp
|| !useWord
)
3288 TexRef
*texRef
= FindReference(refName
);
3291 sec
= texRef
->sectionNumber
;
3292 secName
= texRef
->sectionName
;
3302 fprintf(Chapters
, "{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
3314 if ((GetNoArgs() - arg_no
) == 1)
3317 TexOutput("{\\uldb ");
3321 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3327 // Remove green colour/underlining if specified
3328 if (!hotSpotUnderline
&& !hotSpotColour
)
3330 else if (!hotSpotColour
)
3333 else TexOutput("}");
3336 else // If a linear document, must resolve the references ourselves
3338 if ((GetNoArgs() - arg_no
) == 1)
3340 // In a linear document we display the anchor text in italic plus
3348 helpRefText
= GetArgChunk();
3352 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3354 if (macroId
!= ltHELPREFN
)
3356 char *refName
= GetArgData();
3357 TexRef
*texRef
= NULL
;
3359 texRef
= FindReference(refName
);
3362 if (texRef
|| !ignoreBadRefs
)
3366 if (texRef
|| !ignoreBadRefs
)
3370 char *s
= GetArgData();
3372 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3374 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3378 // Only print section name if we're not in Word mode,
3379 // so can't do page references
3382 TexOutput(texRef
->sectionName
) ; TexOutput(" "); TexOutput(texRef
->sectionNumber
);
3388 sprintf(buf
, "Warning: unresolved reference '%s'", refName
);
3394 else TexOutput("??");
3398 if (texRef
|| !ignoreBadRefs
)
3413 else if (arg_no
== 2)
3418 TexOutput(" ({\\f3 ");
3433 if ((GetNoArgs() - arg_no
) == 1)
3436 TexOutput("{\\ul ");
3440 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3446 // Remove green colour/underlining if specified
3447 if (!hotSpotUnderline
&& !hotSpotColour
)
3449 else if (!hotSpotColour
)
3452 else TexOutput("}");
3455 else // A linear document...
3457 if ((GetNoArgs() - arg_no
) == 1)
3459 // In a linear document we just display the anchor text in italic
3470 case ltADDCONTENTSLINE
:
3472 if (start
&& !winHelp
)
3475 contentsLineSection
= copystring(GetArgData());
3476 else if (arg_no
== 3)
3477 contentsLineValue
= copystring(GetArgData());
3492 static int imageWidth
= 0;
3493 static int imageHeight
= 0;
3495 if (start
&& (arg_no
== 1))
3497 char *imageDimensions
= copystring(GetArgData());
3499 strcpy(buf1
, imageDimensions
);
3500 char *tok1
= strtok(buf1
, ";:");
3501 char *tok2
= strtok(NULL
, ";:");
3502 // Convert points to TWIPS (1 twip = 1/20th of point)
3503 imageWidth
= (int)(20*(tok1
? ParseUnitArgument(tok1
) : 0));
3504 imageHeight
= (int)(20*(tok2
? ParseUnitArgument(tok2
) : 0));
3505 if (imageDimensions
) // glt
3506 delete [] imageDimensions
;
3509 else if (start
&& (arg_no
== 2 ))
3511 char *filename
= copystring(GetArgData());
3513 if ((winHelp
|| (strcmp(bitmapMethod
, "includepicture") == 0) || (strcmp(bitmapMethod
, "import") == 0)) && useWord
)
3515 if (f
== "") // Try for a .shg (segmented hypergraphics file)
3517 strcpy(buf
, filename
);
3518 StripExtension(buf
);
3519 strcat(buf
, ".shg");
3520 f
= TexPathList
.FindValidPath(buf
);
3522 if (f
== "") // Try for a .bmp
3524 strcpy(buf
, filename
);
3525 StripExtension(buf
);
3526 strcat(buf
, ".bmp");
3527 f
= TexPathList
.FindValidPath(buf
);
3529 if (f
== "") // Try for a metafile instead
3531 strcpy(buf
, filename
);
3532 StripExtension(buf
);
3533 strcat(buf
, ".wmf");
3534 f
= TexPathList
.FindValidPath(buf
);
3540 if (bitmapTransparency
&& (winHelpVersion
> 3))
3541 TexOutput("\\{bmct ");
3543 TexOutput("\\{bmc ");
3544 wxString str
= wxFileNameFromPath(f
);
3545 TexOutput((char*) (const char*) str
);
3550 // Microsoft Word method
3551 if (strcmp(bitmapMethod
, "import") == 0)
3552 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3554 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3556 // Full path appears not to be valid!
3557 wxString str
= wxFileNameFromPath(f
);
3558 TexOutput((char*)(const char*) str
);
3560 int len = strlen(f);
3561 char smallBuf[2]; smallBuf[1] = 0;
3562 for (int i = 0; i < len; i++)
3565 TexOutput(smallBuf);
3566 if (smallBuf[0] == '\\')
3567 TexOutput(smallBuf);
3570 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3575 TexOutput("[No BMP or WMF for image file ");
3576 TexOutput(filename
);
3578 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3581 if (filename
) // glt
3586 if (f
== "") // Try for a .bmp
3588 strcpy(buf
, filename
);
3589 StripExtension(buf
);
3590 strcat(buf
, ".bmp");
3591 f
= TexPathList
.FindValidPath(buf
);
3595 FILE *fd
= fopen(f
, "rb");
3596 if (OutputBitmapHeader(fd
, winHelp
))
3597 OutputBitmapData(fd
);
3600 sprintf(buf
, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f
);
3605 else // Try for a metafile instead
3608 strcpy(buf
, filename
);
3609 StripExtension(buf
);
3610 strcat(buf
, ".wmf");
3611 f
= TexPathList
.FindValidPath(buf
);
3614 // HFILE handle = _lopen(f, READ);
3615 FILE *fd
= fopen(f
, "rb");
3616 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3618 OutputMetafileData(fd
);
3622 sprintf(buf
, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f
);
3630 TexOutput("[No BMP or WMF for image file ");
3631 TexOutput(filename
);
3633 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3647 case ltSUPERTABULAR
:
3653 currentRowNumber
= 0;
3656 tableVerticalLineLeft
= FALSE
;
3657 tableVerticalLineRight
= FALSE
;
3658 int currentWidth
= 0;
3660 char *alignString
= copystring(GetArgData());
3661 ParseTableArgument(alignString
);
3663 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3664 TexOutput("\\trowd\\trgaph108");
3666 // Write the first row formatting for compatibility
3667 // with standard Latex
3668 if (compatibilityMode
)
3670 for (int i
= 0; i
< noColumns
; i
++)
3672 currentWidth
+= TableData
[i
].width
;
3673 sprintf(buf
, "\\cellx%d", currentWidth
);
3676 TexOutput("\\pard\\intbl\n");
3678 delete[] alignString
;
3683 else if (arg_no
== 2 && !start
)
3685 TexOutput("\\pard\n");
3686 WriteEnvironmentStyles();
3697 TexOutput("\\li360\n");
3699 PushEnvironmentStyle("\\li360");
3704 PopEnvironmentStyle();
3705 OnMacro(ltPAR
, 0, TRUE
);
3706 OnMacro(ltPAR
, 0, FALSE
);
3714 TexOutput("\\li360\n");
3715 PushEnvironmentStyle("\\li360");
3719 PopEnvironmentStyle();
3720 OnMacro(ltPAR
, 0, TRUE
);
3721 OnMacro(ltPAR
, 0, FALSE
);
3733 sprintf(buf
, "\\box\\trgaph108%s\n", ((macroId
== ltNORMALBOXD
) ? "\\brdrdb" : "\\brdrs"));
3735 PushEnvironmentStyle(buf
);
3739 PopEnvironmentStyle();
3740 OnMacro(ltPAR
, 0, TRUE
);
3741 OnMacro(ltPAR
, 0, FALSE
);
3745 case ltHELPFONTSIZE
:
3749 char *data
= GetArgData();
3750 if (strcmp(data
, "10") == 0)
3752 else if (strcmp(data
, "11") == 0)
3754 else if (strcmp(data
, "12") == 0)
3756 sprintf(buf
, "\\fs%d\n", normalFont
*2);
3763 case ltHELPFONTFAMILY
:
3767 char *data
= GetArgData();
3768 if (strcmp(data
, "Swiss") == 0)
3769 TexOutput("\\f2\n");
3770 else if (strcmp(data
, "Symbol") == 0)
3771 TexOutput("\\f1\n");
3772 else if (strcmp(data
, "Times") == 0)
3773 TexOutput("\\f0\n");
3781 if (start
&& arg_no
== 1)
3783 char *data
= GetArgData();
3784 ParIndent
= ParseUnitArgument(data
);
3785 if (ParIndent
== 0 || forbidParindent
== 0)
3787 sprintf(buf
, "\\fi%d\n", ParIndent
*20);
3796 if (start
&& IsArgOptional())
3798 descriptionItemArg
= GetArgChunk();
3804 case ltTWOCOLITEMRULED
:
3811 TexOutput("\\tab ");
3818 if (macroId
== ltTWOCOLITEMRULED
)
3819 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3820 TexOutput("\\par\\pard\n");
3821 issuedNewParagraph
= 1;
3822 WriteEnvironmentStyles();
3834 case ltACCENT_GRAVE
:
3838 char *val
= GetArgData();
3881 case ltACCENT_ACUTE
:
3885 char *val
= GetArgData();
3934 case ltACCENT_CARET
:
3938 char *val
= GetArgData();
3981 case ltACCENT_TILDE
:
3985 char *val
= GetArgData();
4019 case ltACCENT_UMLAUT
:
4023 char *val
= GetArgData();
4079 char *val
= GetArgData();
4098 case ltACCENT_CADILLA
:
4102 char *val
= GetArgData();
4123 static char *helpTopic
= NULL
;
4124 static FILE *savedOutput
= NULL
;
4131 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4134 sprintf(footBuf
, "(%d)", footnoteCount
);
4136 TexOutput(" {\\ul ");
4139 helpTopic
= FindTopicName(NULL
);
4142 // Remove green colour/underlining if specified
4143 if (!hotSpotUnderline
&& !hotSpotColour
)
4145 else if (!hotSpotColour
)
4148 TexOutput(helpTopic
);
4151 fprintf(Popups
, "\\page\n");
4152 // fprintf(Popups, "\n${\\footnote }"); // No title
4153 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4154 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4155 savedOutput
= CurrentOutput1
;
4156 SetCurrentOutput(Popups
);
4160 SetCurrentOutput(savedOutput
);
4170 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4174 TexOutput("}}", TRUE
);
4180 case ltFOOTNOTEPOPUP
:
4182 static char *helpTopic
= NULL
;
4183 static FILE *savedOutput
= NULL
;
4190 TexOutput("{\\ul ");
4192 else TexOutput("}");
4195 else if (arg_no
== 2)
4199 helpTopic
= FindTopicName(NULL
);
4202 // Remove green colour/underlining if specified
4203 if (!hotSpotUnderline
&& !hotSpotColour
)
4205 else if (!hotSpotColour
)
4208 TexOutput(helpTopic
);
4211 fprintf(Popups
, "\\page\n");
4212 // fprintf(Popups, "\n${\\footnote }"); // No title
4213 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4214 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4215 savedOutput
= CurrentOutput1
;
4216 SetCurrentOutput(Popups
);
4220 SetCurrentOutput(savedOutput
);
4231 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4235 TexOutput("}}", TRUE
);
4243 if (start
&& (arg_no
== 1))
4256 if (winHelp
) return FALSE
;
4262 LeftHeaderEven
= GetArgChunk();
4263 if (strlen(GetArgData(LeftHeaderEven
)) == 0)
4264 LeftHeaderEven
= NULL
;
4267 CentreHeaderEven
= GetArgChunk();
4268 if (strlen(GetArgData(CentreHeaderEven
)) == 0)
4269 CentreHeaderEven
= NULL
;
4272 RightHeaderEven
= GetArgChunk();
4273 if (strlen(GetArgData(RightHeaderEven
)) == 0)
4274 RightHeaderEven
= NULL
;
4277 LeftHeaderOdd
= GetArgChunk();
4278 if (strlen(GetArgData(LeftHeaderOdd
)) == 0)
4279 LeftHeaderOdd
= NULL
;
4282 CentreHeaderOdd
= GetArgChunk();
4283 if (strlen(GetArgData(CentreHeaderOdd
)) == 0)
4284 CentreHeaderOdd
= NULL
;
4287 RightHeaderOdd
= GetArgChunk();
4288 if (strlen(GetArgData(RightHeaderOdd
)) == 0)
4289 RightHeaderOdd
= NULL
;
4290 OutputRTFHeaderCommands();
4306 if (winHelp
) return FALSE
;
4312 LeftFooterEven
= GetArgChunk();
4313 if (strlen(GetArgData(LeftFooterEven
)) == 0)
4314 LeftFooterEven
= NULL
;
4317 CentreFooterEven
= GetArgChunk();
4318 if (strlen(GetArgData(CentreFooterEven
)) == 0)
4319 CentreFooterEven
= NULL
;
4322 RightFooterEven
= GetArgChunk();
4323 if (strlen(GetArgData(RightFooterEven
)) == 0)
4324 RightFooterEven
= NULL
;
4327 LeftFooterOdd
= GetArgChunk();
4328 if (strlen(GetArgData(LeftFooterOdd
)) == 0)
4329 LeftFooterOdd
= NULL
;
4332 CentreFooterOdd
= GetArgChunk();
4333 if (strlen(GetArgData(CentreFooterOdd
)) == 0)
4334 CentreFooterOdd
= NULL
;
4337 RightFooterOdd
= GetArgChunk();
4338 if (strlen(GetArgData(RightFooterOdd
)) == 0)
4339 RightFooterOdd
= NULL
;
4340 OutputRTFFooterCommands();
4351 if (winHelp
) return FALSE
;
4352 // Fake a SetHeader command
4355 LeftHeaderOdd
= NULL
;
4356 CentreHeaderOdd
= NULL
;
4357 RightHeaderOdd
= NULL
;
4358 LeftHeaderEven
= NULL
;
4359 CentreHeaderEven
= NULL
;
4360 RightHeaderEven
= NULL
;
4361 OnInform("Consider using setheader/setfooter rather than markright.");
4363 RTFOnArgument(ltSETHEADER
, 4, start
);
4365 OutputRTFHeaderCommands();
4371 if (winHelp
) return FALSE
;
4372 // Fake a SetHeader command
4379 LeftHeaderOdd
= NULL
;
4380 CentreHeaderOdd
= NULL
;
4381 RightHeaderOdd
= NULL
;
4382 LeftHeaderEven
= NULL
;
4383 CentreHeaderEven
= NULL
;
4384 RightHeaderEven
= NULL
;
4385 OnInform("Consider using setheader/setfooter rather than markboth.");
4387 return RTFOnArgument(ltSETHEADER
, 1, start
);
4392 RTFOnArgument(ltSETHEADER
, 4, start
);
4394 OutputRTFHeaderCommands();
4401 case ltPAGENUMBERING
:
4408 if (winHelp
) return FALSE
;
4411 TexOutput("\\pgnrestart");
4412 char *data
= GetArgData();
4413 if (currentNumberStyle
) delete[] currentNumberStyle
;
4414 currentNumberStyle
= copystring(data
);
4415 OutputNumberStyle(currentNumberStyle
);
4424 if (winHelp
) return FALSE
;
4433 char *val
= GetArgData();
4434 currentItemSep
= ParseUnitArgument(val
);
4439 case ltEVENSIDEMARGIN
:
4444 case ltODDSIDEMARGIN
:
4448 char *val
= GetArgData();
4449 int twips
= (int)(20*ParseUnitArgument(val
));
4450 // Add an inch since in LaTeX it's specified minus an inch
4452 CurrentLeftMarginOdd
= twips
;
4453 sprintf(buf
, "\\margl%d\n", twips
);
4456 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4460 case ltMARGINPARWIDTH
:
4464 char *val
= GetArgData();
4465 int twips
= (int)(20*ParseUnitArgument(val
));
4466 CurrentMarginParWidth
= twips
;
4470 case ltMARGINPARSEP
:
4474 char *val
= GetArgData();
4475 int twips
= (int)(20*ParseUnitArgument(val
));
4476 CurrentMarginParSep
= twips
;
4477 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4485 char *val
= GetArgData();
4486 int twips
= (int)(20*ParseUnitArgument(val
));
4487 CurrentTextWidth
= twips
;
4489 // Need to set an implicit right margin
4490 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4491 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4492 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4493 sprintf(buf
, "\\margr%d\n", CurrentRightMarginOdd
);
4499 case ltMARGINPARODD
:
4505 TexOutput("\\box\n");
4506 PushEnvironmentStyle("\\box");
4510 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4519 TexOutput("\\par\\pard\n");
4520 PopEnvironmentStyle();
4521 WriteEnvironmentStyles();
4524 TexOutput("\\par\\pard\n");
4525 issuedNewParagraph
= 1;
4529 case ltMARGINPAREVEN
:
4535 TexOutput("\\box\n");
4536 PushEnvironmentStyle("\\box");
4542 // Have to calculate what the margins are changed to in WfW margin
4543 // mirror mode, on an even (left-hand) page.
4544 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4545 - CurrentTextWidth
+ GutterWidth
;
4546 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", x
, CurrentMarginParWidth
);
4551 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4561 TexOutput("\\par\\pard\n");
4562 PopEnvironmentStyle();
4563 WriteEnvironmentStyles();
4566 issuedNewParagraph
= 1;
4567 TexOutput("\\par\\pard\n");
4571 case ltTWOCOLWIDTHA
:
4575 char *val
= GetArgData();
4576 int twips
= (int)(20*ParseUnitArgument(val
));
4577 TwoColWidthA
= twips
;
4582 case ltTWOCOLWIDTHB
:
4586 char *val
= GetArgData();
4587 int twips
= (int)(20*ParseUnitArgument(val
));
4588 TwoColWidthB
= twips
;
4598 int currentWidth
= 0;
4600 if (!compatibilityMode
|| (currentRowNumber
> 0))
4602 TexOutput("\\pard\\intbl");
4604 if (macroId
== ltRULEDROW
)
4606 for (int i
= 0; i
< noColumns
; i
++)
4608 currentWidth
+= TableData
[i
].width
;
4611 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4613 else if (ruleTop
> 1)
4615 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4617 if (ruleBottom
== 1)
4619 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4621 else if (ruleBottom
> 1)
4623 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4626 if (TableData
[i
].rightBorder
)
4627 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4629 if (TableData
[i
].leftBorder
)
4630 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4632 sprintf(buf
, "\\cellx%d", currentWidth
);
4635 TexOutput("\\pard\\intbl\n");
4639 currentRowNumber
++;
4644 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4645 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4651 static int noMultiColumns
= 0;
4658 noMultiColumns
= atoi(GetArgData());
4676 for (int i
= 1; i
< noMultiColumns
; i
++)
4677 TexOutput("\\cell");
4684 if (start
&& (arg_no
== 1))
4687 // TexOutput("\\fi0\n");
4689 wxNode
*node
= itemizeStack
.First();
4691 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
4693 int indentValue
= 20*ParseUnitArgument(GetArgData());
4694 int indentSize
= indentValue
+ oldIndent
;
4696 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4697 itemizeStack
.Insert(struc
);
4699 sprintf(buf
, "\\tx%d\\li%d ", indentSize
, indentSize
);
4700 PushEnvironmentStyle(buf
);
4704 if (!start
&& (arg_no
== 2))
4706 PopEnvironmentStyle();
4707 if (itemizeStack
.First())
4709 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
4711 delete itemizeStack
.First();
4713 if (itemizeStack
.Number() == 0)
4715 TexOutput("\\par\\pard\n");
4716 issuedNewParagraph
= 1;
4717 WriteEnvironmentStyles();
4727 if (start && (arg_no == 1))
4730 wxNode *node = itemizeStack.First();
4732 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4734 int boxWidth = 20*ParseUnitArgument(GetArgData());
4736 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4737 int indentSize = indentValue + oldIndent;
4738 int indentSizeRight = indentSize + boxWidth;
4740 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4741 itemizeStack.Insert(struc);
4743 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4744 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4745 PushEnvironmentStyle(buf);
4749 if (!start && (arg_no == 2))
4751 PopEnvironmentStyle();
4752 if (itemizeStack.First())
4754 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4756 delete itemizeStack.First();
4758 if (itemizeStack.Number() == 0)
4760 TexOutput("\\par\\pard\n");
4761 issuedNewParagraph = 1;
4762 WriteEnvironmentStyles();
4769 case ltDOCUMENTSTYLE
:
4771 DefaultOnArgument(macroId
, arg_no
, start
);
4772 if (!start
&& !IsArgOptional())
4774 if (MinorDocumentStyleString
)
4776 if (StringMatch("twoside", MinorDocumentStyleString
))
4777 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4778 TexOutput("\\margmirror\\facingp\\sbkodd");
4779 if (StringMatch("twocolumn", MinorDocumentStyleString
))
4780 TexOutput("\\cols2");
4786 case ltSETHOTSPOTCOLOUR
:
4787 case ltSETHOTSPOTCOLOR
:
4791 char *text
= GetArgData();
4792 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4793 hotSpotColour
= TRUE
;
4795 hotSpotColour
= FALSE
;
4799 case ltSETTRANSPARENCY
:
4803 char *text
= GetArgData();
4804 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4805 bitmapTransparency
= TRUE
;
4807 bitmapTransparency
= FALSE
;
4811 case ltSETHOTSPOTUNDERLINE
:
4815 char *text
= GetArgData();
4816 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4817 hotSpotUnderline
= TRUE
;
4819 hotSpotUnderline
= FALSE
;
4825 if (arg_no
== 1 && start
)
4827 char *citeKey
= GetArgData();
4828 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4831 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4832 sprintf(buf
, "[%d]", citeCount
);
4833 ref
->sectionNumber
= copystring(buf
);
4836 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4837 sprintf(buf
, "{\\b [%d]} ", citeCount
);
4842 if (arg_no
== 2 && !start
)
4843 TexOutput("\\par\\pard\\par\n\n");
4847 case ltTHEBIBLIOGRAPHY
:
4849 if (start
&& (arg_no
== 1))
4853 SetCurrentOutputs(Contents
, Chapters
);
4857 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
4859 // If a non-custom page style, we generate the header now.
4860 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
4861 strcmp(PageStyle
, "empty") == 0 ||
4862 strcmp(PageStyle
, "headings") == 0))
4864 OutputRTFHeaderCommands();
4865 OutputRTFFooterCommands();
4868 // Need to reset the current numbering style, or RTF forgets it.
4869 OutputNumberStyle(currentNumberStyle
);
4870 SetCurrentOutput(Contents
);
4873 fprintf(Chapters
, "\\page\n");
4876 fprintf(Contents
, "\n{\\uldb %s}", ReferencesNameString
);
4878 fprintf(Contents
, "\\par\n\\pard{\\b %s}", ReferencesNameString
);
4880 startedSections
= TRUE
;
4883 fprintf(Chapters
, "\n${\\footnote %s}", ReferencesNameString
);
4885 char *topicName
= "bibliography";
4888 fprintf(Contents
, "{\\v %s}\\par\\pard\n", topicName
);
4890 fprintf(Contents
, "\\par\\par\\pard\n");
4894 fprintf(Chapters
, "\n#{\\footnote %s}\n", topicName
);
4895 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
4896 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ReferencesNameString
);
4897 GenerateKeywordsForTopic(topicName
);
4900 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4901 FileNameFromPath(FileRoot
), "Contents");
4905 SetCurrentOutput(Chapters
);
4906 char *styleCommand
= "";
4907 if (!winHelp
&& useHeadingStyles
)
4908 styleCommand
= "\\s1";
4909 fprintf(Chapters
, "\\pard{%s", (winHelp
? "\\keepn\\sa140\\sb140" : styleCommand
));
4910 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " References\\par\\pard}\n");
4920 * In Windows help, all keywords should be at the start of the
4921 * topic, but Latex \index commands can be anywhere in the text.
4922 * So we're going to have to build up lists of keywords for a topic,
4923 * and insert them on the second pass.
4925 * In linear RTF, we can embed the index entry now.
4930 // char *entry = GetArgData();
4932 OutputChunkToString(GetArgChunk(), buf
);
4937 AddKeyWordForTopic(CurrentTopic
, buf
);
4940 else GenerateIndexEntry(buf
);
4954 char *name
= GetArgData();
4955 int pos
= FindColourPosition(name
);
4958 sprintf(buf
, "{%s%d ", ((macroId
== ltFCOL
) ? "\\cf" : "\\cb"), pos
);
4963 sprintf(buf
, "Could not find colour name %s", name
);
4979 if (arg_no
== 2) TexOutput("}");
4986 if (start
&& !winHelp
&& useWord
)
4988 char *s
= GetArgData();
4989 // Only insert a bookmark here if it's not just been inserted
4990 // in a section heading.
4991 if ( !CurrentTopic
|| !(strcmp(CurrentTopic
, s
) == 0) )
4993 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4994 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4995 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
4999 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", s
,s
);
5007 if (start
&& useWord
&& !winHelp
)
5009 char *s
= GetArgData();
5010 fprintf(Chapters
, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
5019 inPopRefSection
= TRUE
;
5021 inPopRefSection
= FALSE
;
5024 case ltINSERTATLEVEL
:
5026 // This macro allows you to insert text at a different level
5027 // from the current level, e.g. into the Sections from within a subsubsection.
5028 if (!winHelp
& useWord
)
5030 static int currentLevelNo
= 1;
5031 static FILE* oldLevelFile
= Chapters
;
5038 oldLevelFile
= CurrentOutput1
;
5040 char *str
= GetArgData();
5041 currentLevelNo
= atoi(str
);
5043 // TODO: cope with article style (no chapters)
5044 switch (currentLevelNo
)
5048 outputFile
= Chapters
;
5053 outputFile
= Sections
;
5058 outputFile
= Subsections
;
5063 outputFile
= Subsubsections
;
5073 CurrentOutput1
= outputFile
;
5091 CurrentOutput1
= oldLevelFile
;
5099 return DefaultOnArgument(macroId
, arg_no
, start
);
5113 forbidParindent
= 0;
5114 contentsLineSection
= NULL
;
5115 contentsLineValue
= NULL
;
5116 descriptionItemArg
= NULL
;
5121 tableVerticalLineLeft
= FALSE
;
5122 tableVerticalLineRight
= FALSE
;
5124 startedSections
= FALSE
;
5128 if (InputFile
&& OutputFile
)
5130 // Do some RTF-specific transformations on all the strings,
5132 Text2RTF(GetTopLevelChunk());
5134 Contents
= fopen(TmpContentsName
, "w");
5135 Chapters
= fopen("chapters.rtf", "w");
5138 Sections
= fopen("sections.rtf", "w");
5139 Subsections
= fopen("subsections.rtf", "w");
5140 Subsubsections
= fopen("subsubsections.rtf", "w");
5141 Popups
= fopen("popups.rtf", "w");
5142 if (winHelpContents
)
5144 WinHelpContentsFile
= fopen(WinHelpContentsFileName
, "w");
5145 if (WinHelpContentsFile
)
5146 fprintf(WinHelpContentsFile
, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot
));
5149 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5151 OnError("Ouch! Could not open temporary file(s) for writing.");
5155 if (!Contents
|| !Chapters
)
5157 OnError("Ouch! Could not open temporary file(s) for writing.");
5163 fprintf(Chapters
, "\n#{\\footnote Contents}\n");
5164 fprintf(Chapters
, "${\\footnote Contents}\n");
5165 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
5166 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ContentsNameString
);
5167 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
5171 fprintf(Chapters
, "\\titlepg\n");
5172 fprintf(Contents
, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5175 // In WinHelp, Contents title takes font of title.
5176 // In linear RTF, same as chapter headings.
5177 fprintf(Contents
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5178 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5180 // By default, Swiss, 10 point.
5181 fprintf(Chapters
, "\\f2\\fs20\n");
5183 SetCurrentOutput(Chapters
);
5188 OnInform("Converting...");
5192 FILE *Header
= fopen("header.rtf", "w");
5195 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5198 WriteRTFHeader(Header
);
5199 fclose(Header
); Header
= NULL
;
5204 // fprintf(Contents, "\\page\n");
5205 fprintf(Chapters
, "\\page\n");
5206 fprintf(Sections
, "\\page\n");
5207 fprintf(Subsections
, "\\page\n");
5208 fprintf(Subsubsections
, "\\page\n\n");
5209 fprintf(Popups
, "\\page\n}\n");
5212 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5215 fclose(Contents
); Contents
= NULL
;
5216 fclose(Chapters
); Chapters
= NULL
;
5219 fclose(Sections
); Sections
= NULL
;
5220 fclose(Subsections
); Subsections
= NULL
;
5221 fclose(Subsubsections
); Subsubsections
= NULL
;
5222 fclose(Popups
); Popups
= NULL
;
5223 if (winHelpContents
)
5225 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5231 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5233 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5235 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5237 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5239 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile
);
5242 wxRemoveFile("tmp1.rtf");
5243 wxRemoveFile("tmp2.rtf");
5244 wxRemoveFile("tmp3.rtf");
5245 wxRemoveFile("tmp4.rtf");
5249 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5251 if (FileExists(OutputFile
))
5252 wxRemoveFile(OutputFile
);
5255 cwdStr
= wxGetWorkingDirectory();
5257 wxString outputDirStr
;
5258 outputDirStr
= wxPathOnly(OutputFile
);
5260 // Determine if the temp file and the output file are in the same directory,
5261 // and if they are, then just rename the temp file rather than copying
5262 // it, as this is much faster when working with large (multi-megabyte files)
5263 if ((wxStrcmp(outputDirStr
.c_str(),"") == 0) || // no path specified on output file
5264 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5266 wxRenameFile("tmp1.rtf", OutputFile
);
5270 wxCopyFile("tmp1.rtf", OutputFile
);
5274 wxRemoveFile("tmp1.rtf");
5277 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5279 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5281 wxCopyFile(TmpContentsName
, ContentsName
);
5282 wxRemoveFile(TmpContentsName
);
5285 wxRemoveFile("chapters.rtf");
5286 wxRemoveFile("header.rtf");
5290 wxRemoveFile("sections.rtf");
5291 wxRemoveFile("subsections.rtf");
5292 wxRemoveFile("subsubsections.rtf");
5293 wxRemoveFile("popups.rtf");
5295 if (winHelp
&& generateHPJ
)
5296 WriteHPJ(OutputFile
);