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
;
63 extern wxHashTable TexReferences
;
66 // Are we in verbatim mode? If so, format differently.
67 static bool inVerbatim
= FALSE
;
69 // We're in a series of PopRef topics, so don't output section headings
70 bool inPopRefSection
= FALSE
;
73 static bool hotSpotColour
= TRUE
;
74 static bool hotSpotUnderline
= TRUE
;
76 // Transparency (WHITE = transparent)
77 static bool bitmapTransparency
= TRUE
;
79 // Linear RTF requires us to set the style per section.
80 static char *currentNumberStyle
= NULL
;
81 static int currentItemSep
= 8;
82 static int CurrentTextWidth
= 8640; // Say, six inches
83 static int CurrentLeftMarginOdd
= 400;
84 static int CurrentLeftMarginEven
= 1440;
85 static int CurrentRightMarginOdd
= 1440;
86 static int CurrentRightMarginEven
= 400;
87 static int CurrentMarginParWidth
= 2000;
88 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
89 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
90 static int GutterWidth
= 2300;
92 // Two-column table dimensions, in twips
93 static int TwoColWidthA
= 1500;
94 static int TwoColWidthB
= 3000;
96 const int PageWidth
= 12242; // 8.25 inches wide for A4
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 curly 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 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3350 if (macroId
!= ltHELPREFN
)
3355 char *refName
= GetArgData();
3360 char *s
= GetArgData();
3362 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3364 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3368 // Only print section name if we're not in Word mode,
3369 // so can't do page references
3370 TexRef
*texRef
= FindReference(refName
);
3373 TexOutput(texRef
->sectionName
) ; TexOutput(" "); TexOutput(texRef
->sectionNumber
);
3378 sprintf(buf
, "Warning: unresolved reference %s.", refName
);
3383 else TexOutput("??");
3385 else TexOutput(")");
3398 else if (arg_no
== 2)
3403 TexOutput(" ({\\f3 ");
3418 if ((GetNoArgs() - arg_no
) == 1)
3421 TexOutput("{\\ul ");
3425 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3431 // Remove green colour/underlining if specified
3432 if (!hotSpotUnderline
&& !hotSpotColour
)
3434 else if (!hotSpotColour
)
3437 else TexOutput("}");
3440 else // A linear document...
3442 if ((GetNoArgs() - arg_no
) == 1)
3444 // In a linear document we just display the anchor text in italic
3455 case ltADDCONTENTSLINE
:
3457 if (start
&& !winHelp
)
3460 contentsLineSection
= copystring(GetArgData());
3461 else if (arg_no
== 3)
3462 contentsLineValue
= copystring(GetArgData());
3477 static int imageWidth
= 0;
3478 static int imageHeight
= 0;
3480 if (start
&& (arg_no
== 1))
3482 char *imageDimensions
= copystring(GetArgData());
3484 strcpy(buf1
, imageDimensions
);
3485 char *tok1
= strtok(buf1
, ";:");
3486 char *tok2
= strtok(NULL
, ";:");
3487 // Convert points to TWIPS (1 twip = 1/20th of point)
3488 imageWidth
= (int)(20*(tok1
? ParseUnitArgument(tok1
) : 0));
3489 imageHeight
= (int)(20*(tok2
? ParseUnitArgument(tok2
) : 0));
3490 if (imageDimensions
) // glt
3491 delete [] imageDimensions
;
3494 else if (start
&& (arg_no
== 2 ))
3496 char *filename
= copystring(GetArgData());
3498 if ((winHelp
|| (strcmp(bitmapMethod
, "includepicture") == 0) || (strcmp(bitmapMethod
, "import") == 0)) && useWord
)
3500 if (f
== "") // Try for a .shg (segmented hypergraphics file)
3502 strcpy(buf
, filename
);
3503 StripExtension(buf
);
3504 strcat(buf
, ".shg");
3505 f
= TexPathList
.FindValidPath(buf
);
3507 if (f
== "") // Try for a .bmp
3509 strcpy(buf
, filename
);
3510 StripExtension(buf
);
3511 strcat(buf
, ".bmp");
3512 f
= TexPathList
.FindValidPath(buf
);
3514 if (f
== "") // Try for a metafile instead
3516 strcpy(buf
, filename
);
3517 StripExtension(buf
);
3518 strcat(buf
, ".wmf");
3519 f
= TexPathList
.FindValidPath(buf
);
3525 if (bitmapTransparency
&& (winHelpVersion
> 3))
3526 TexOutput("\\{bmct ");
3528 TexOutput("\\{bmc ");
3529 wxString str
= wxFileNameFromPath(f
);
3530 TexOutput((char*) (const char*) str
);
3535 // Microsoft Word method
3536 if (strcmp(bitmapMethod
, "import") == 0)
3537 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3539 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3541 // Full path appears not to be valid!
3542 wxString str
= wxFileNameFromPath(f
);
3543 TexOutput((char*)(const char*) str
);
3545 int len = strlen(f);
3546 char smallBuf[2]; smallBuf[1] = 0;
3547 for (int i = 0; i < len; i++)
3550 TexOutput(smallBuf);
3551 if (smallBuf[0] == '\\')
3552 TexOutput(smallBuf);
3555 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3560 TexOutput("[No BMP or WMF for image file ");
3561 TexOutput(filename
);
3563 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3566 if (filename
) // glt
3571 if (f
== "") // Try for a .bmp
3573 strcpy(buf
, filename
);
3574 StripExtension(buf
);
3575 strcat(buf
, ".bmp");
3576 f
= TexPathList
.FindValidPath(buf
);
3580 FILE *fd
= fopen(f
, "rb");
3581 if (OutputBitmapHeader(fd
, winHelp
))
3582 OutputBitmapData(fd
);
3585 sprintf(buf
, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f
);
3590 else // Try for a metafile instead
3593 strcpy(buf
, filename
);
3594 StripExtension(buf
);
3595 strcat(buf
, ".wmf");
3596 f
= TexPathList
.FindValidPath(buf
);
3599 // HFILE handle = _lopen(f, READ);
3600 FILE *fd
= fopen(f
, "rb");
3601 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3603 OutputMetafileData(fd
);
3607 sprintf(buf
, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f
);
3615 TexOutput("[No BMP or WMF for image file ");
3616 TexOutput(filename
);
3618 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3632 case ltSUPERTABULAR
:
3638 currentRowNumber
= 0;
3641 tableVerticalLineLeft
= FALSE
;
3642 tableVerticalLineRight
= FALSE
;
3643 int currentWidth
= 0;
3645 char *alignString
= copystring(GetArgData());
3646 ParseTableArgument(alignString
);
3648 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3649 TexOutput("\\trowd\\trgaph108");
3651 // Write the first row formatting for compatibility
3652 // with standard Latex
3653 if (compatibilityMode
)
3655 for (int i
= 0; i
< noColumns
; i
++)
3657 currentWidth
+= TableData
[i
].width
;
3658 sprintf(buf
, "\\cellx%d", currentWidth
);
3661 TexOutput("\\pard\\intbl\n");
3663 delete[] alignString
;
3668 else if (arg_no
== 2 && !start
)
3670 TexOutput("\\pard\n");
3671 WriteEnvironmentStyles();
3682 TexOutput("\\li360\n");
3684 PushEnvironmentStyle("\\li360");
3689 PopEnvironmentStyle();
3690 OnMacro(ltPAR
, 0, TRUE
);
3691 OnMacro(ltPAR
, 0, FALSE
);
3699 TexOutput("\\li360\n");
3700 PushEnvironmentStyle("\\li360");
3704 PopEnvironmentStyle();
3705 OnMacro(ltPAR
, 0, TRUE
);
3706 OnMacro(ltPAR
, 0, FALSE
);
3718 sprintf(buf
, "\\box\\trgaph108%s\n", ((macroId
== ltNORMALBOXD
) ? "\\brdrdb" : "\\brdrs"));
3720 PushEnvironmentStyle(buf
);
3724 PopEnvironmentStyle();
3725 OnMacro(ltPAR
, 0, TRUE
);
3726 OnMacro(ltPAR
, 0, FALSE
);
3730 case ltHELPFONTSIZE
:
3734 char *data
= GetArgData();
3735 if (strcmp(data
, "10") == 0)
3737 else if (strcmp(data
, "11") == 0)
3739 else if (strcmp(data
, "12") == 0)
3741 sprintf(buf
, "\\fs%d\n", normalFont
*2);
3748 case ltHELPFONTFAMILY
:
3752 char *data
= GetArgData();
3753 if (strcmp(data
, "Swiss") == 0)
3754 TexOutput("\\f2\n");
3755 else if (strcmp(data
, "Symbol") == 0)
3756 TexOutput("\\f1\n");
3757 else if (strcmp(data
, "Times") == 0)
3758 TexOutput("\\f0\n");
3766 if (start
&& arg_no
== 1)
3768 char *data
= GetArgData();
3769 ParIndent
= ParseUnitArgument(data
);
3770 if (ParIndent
== 0 || forbidParindent
== 0)
3772 sprintf(buf
, "\\fi%d\n", ParIndent
*20);
3781 if (start
&& IsArgOptional())
3783 descriptionItemArg
= GetArgChunk();
3789 case ltTWOCOLITEMRULED
:
3796 TexOutput("\\tab ");
3803 if (macroId
== ltTWOCOLITEMRULED
)
3804 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3805 TexOutput("\\par\\pard\n");
3806 issuedNewParagraph
= 1;
3807 WriteEnvironmentStyles();
3819 case ltACCENT_GRAVE
:
3823 char *val
= GetArgData();
3866 case ltACCENT_ACUTE
:
3870 char *val
= GetArgData();
3919 case ltACCENT_CARET
:
3923 char *val
= GetArgData();
3966 case ltACCENT_TILDE
:
3970 char *val
= GetArgData();
4004 case ltACCENT_UMLAUT
:
4008 char *val
= GetArgData();
4064 char *val
= GetArgData();
4083 case ltACCENT_CADILLA
:
4087 char *val
= GetArgData();
4108 static char *helpTopic
= NULL
;
4109 static FILE *savedOutput
= NULL
;
4116 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4119 sprintf(footBuf
, "(%d)", footnoteCount
);
4121 TexOutput(" {\\ul ");
4124 helpTopic
= FindTopicName(NULL
);
4127 // Remove green colour/underlining if specified
4128 if (!hotSpotUnderline
&& !hotSpotColour
)
4130 else if (!hotSpotColour
)
4133 TexOutput(helpTopic
);
4136 fprintf(Popups
, "\\page\n");
4137 // fprintf(Popups, "\n${\\footnote }"); // No title
4138 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4139 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4140 savedOutput
= CurrentOutput1
;
4141 SetCurrentOutput(Popups
);
4145 SetCurrentOutput(savedOutput
);
4155 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4159 TexOutput("}}", TRUE
);
4165 case ltFOOTNOTEPOPUP
:
4167 static char *helpTopic
= NULL
;
4168 static FILE *savedOutput
= NULL
;
4175 TexOutput("{\\ul ");
4177 else TexOutput("}");
4180 else if (arg_no
== 2)
4184 helpTopic
= FindTopicName(NULL
);
4187 // Remove green colour/underlining if specified
4188 if (!hotSpotUnderline
&& !hotSpotColour
)
4190 else if (!hotSpotColour
)
4193 TexOutput(helpTopic
);
4196 fprintf(Popups
, "\\page\n");
4197 // fprintf(Popups, "\n${\\footnote }"); // No title
4198 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4199 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4200 savedOutput
= CurrentOutput1
;
4201 SetCurrentOutput(Popups
);
4205 SetCurrentOutput(savedOutput
);
4216 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4220 TexOutput("}}", TRUE
);
4228 if (start
&& (arg_no
== 1))
4241 if (winHelp
) return FALSE
;
4247 LeftHeaderEven
= GetArgChunk();
4248 if (strlen(GetArgData(LeftHeaderEven
)) == 0)
4249 LeftHeaderEven
= NULL
;
4252 CentreHeaderEven
= GetArgChunk();
4253 if (strlen(GetArgData(CentreHeaderEven
)) == 0)
4254 CentreHeaderEven
= NULL
;
4257 RightHeaderEven
= GetArgChunk();
4258 if (strlen(GetArgData(RightHeaderEven
)) == 0)
4259 RightHeaderEven
= NULL
;
4262 LeftHeaderOdd
= GetArgChunk();
4263 if (strlen(GetArgData(LeftHeaderOdd
)) == 0)
4264 LeftHeaderOdd
= NULL
;
4267 CentreHeaderOdd
= GetArgChunk();
4268 if (strlen(GetArgData(CentreHeaderOdd
)) == 0)
4269 CentreHeaderOdd
= NULL
;
4272 RightHeaderOdd
= GetArgChunk();
4273 if (strlen(GetArgData(RightHeaderOdd
)) == 0)
4274 RightHeaderOdd
= NULL
;
4275 OutputRTFHeaderCommands();
4291 if (winHelp
) return FALSE
;
4297 LeftFooterEven
= GetArgChunk();
4298 if (strlen(GetArgData(LeftFooterEven
)) == 0)
4299 LeftFooterEven
= NULL
;
4302 CentreFooterEven
= GetArgChunk();
4303 if (strlen(GetArgData(CentreFooterEven
)) == 0)
4304 CentreFooterEven
= NULL
;
4307 RightFooterEven
= GetArgChunk();
4308 if (strlen(GetArgData(RightFooterEven
)) == 0)
4309 RightFooterEven
= NULL
;
4312 LeftFooterOdd
= GetArgChunk();
4313 if (strlen(GetArgData(LeftFooterOdd
)) == 0)
4314 LeftFooterOdd
= NULL
;
4317 CentreFooterOdd
= GetArgChunk();
4318 if (strlen(GetArgData(CentreFooterOdd
)) == 0)
4319 CentreFooterOdd
= NULL
;
4322 RightFooterOdd
= GetArgChunk();
4323 if (strlen(GetArgData(RightFooterOdd
)) == 0)
4324 RightFooterOdd
= NULL
;
4325 OutputRTFFooterCommands();
4336 if (winHelp
) return FALSE
;
4337 // Fake a SetHeader command
4340 LeftHeaderOdd
= NULL
;
4341 CentreHeaderOdd
= NULL
;
4342 RightHeaderOdd
= NULL
;
4343 LeftHeaderEven
= NULL
;
4344 CentreHeaderEven
= NULL
;
4345 RightHeaderEven
= NULL
;
4346 OnInform("Consider using setheader/setfooter rather than markright.");
4348 RTFOnArgument(ltSETHEADER
, 4, start
);
4350 OutputRTFHeaderCommands();
4356 if (winHelp
) return FALSE
;
4357 // Fake a SetHeader command
4364 LeftHeaderOdd
= NULL
;
4365 CentreHeaderOdd
= NULL
;
4366 RightHeaderOdd
= NULL
;
4367 LeftHeaderEven
= NULL
;
4368 CentreHeaderEven
= NULL
;
4369 RightHeaderEven
= NULL
;
4370 OnInform("Consider using setheader/setfooter rather than markboth.");
4372 return RTFOnArgument(ltSETHEADER
, 1, start
);
4377 RTFOnArgument(ltSETHEADER
, 4, start
);
4379 OutputRTFHeaderCommands();
4386 case ltPAGENUMBERING
:
4393 if (winHelp
) return FALSE
;
4396 TexOutput("\\pgnrestart");
4397 char *data
= GetArgData();
4398 if (currentNumberStyle
) delete[] currentNumberStyle
;
4399 currentNumberStyle
= copystring(data
);
4400 OutputNumberStyle(currentNumberStyle
);
4409 if (winHelp
) return FALSE
;
4418 char *val
= GetArgData();
4419 currentItemSep
= ParseUnitArgument(val
);
4424 case ltEVENSIDEMARGIN
:
4429 case ltODDSIDEMARGIN
:
4433 char *val
= GetArgData();
4434 int twips
= (int)(20*ParseUnitArgument(val
));
4435 // Add an inch since in LaTeX it's specified minus an inch
4437 CurrentLeftMarginOdd
= twips
;
4438 sprintf(buf
, "\\margl%d\n", twips
);
4441 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4445 case ltMARGINPARWIDTH
:
4449 char *val
= GetArgData();
4450 int twips
= (int)(20*ParseUnitArgument(val
));
4451 CurrentMarginParWidth
= twips
;
4455 case ltMARGINPARSEP
:
4459 char *val
= GetArgData();
4460 int twips
= (int)(20*ParseUnitArgument(val
));
4461 CurrentMarginParSep
= twips
;
4462 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4470 char *val
= GetArgData();
4471 int twips
= (int)(20*ParseUnitArgument(val
));
4472 CurrentTextWidth
= twips
;
4474 // Need to set an implicit right margin
4475 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4476 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4477 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4478 sprintf(buf
, "\\margr%d\n", CurrentRightMarginOdd
);
4484 case ltMARGINPARODD
:
4490 TexOutput("\\box\n");
4491 PushEnvironmentStyle("\\box");
4495 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4504 TexOutput("\\par\\pard\n");
4505 PopEnvironmentStyle();
4506 WriteEnvironmentStyles();
4509 TexOutput("\\par\\pard\n");
4510 issuedNewParagraph
= 1;
4514 case ltMARGINPAREVEN
:
4520 TexOutput("\\box\n");
4521 PushEnvironmentStyle("\\box");
4527 // Have to calculate what the margins are changed to in WfW margin
4528 // mirror mode, on an even (left-hand) page.
4529 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4530 - CurrentTextWidth
+ GutterWidth
;
4531 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", x
, CurrentMarginParWidth
);
4536 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4546 TexOutput("\\par\\pard\n");
4547 PopEnvironmentStyle();
4548 WriteEnvironmentStyles();
4551 issuedNewParagraph
= 1;
4552 TexOutput("\\par\\pard\n");
4556 case ltTWOCOLWIDTHA
:
4560 char *val
= GetArgData();
4561 int twips
= (int)(20*ParseUnitArgument(val
));
4562 TwoColWidthA
= twips
;
4567 case ltTWOCOLWIDTHB
:
4571 char *val
= GetArgData();
4572 int twips
= (int)(20*ParseUnitArgument(val
));
4573 TwoColWidthB
= twips
;
4583 int currentWidth
= 0;
4585 if (!compatibilityMode
|| (currentRowNumber
> 0))
4587 TexOutput("\\pard\\intbl");
4589 if (macroId
== ltRULEDROW
)
4591 for (int i
= 0; i
< noColumns
; i
++)
4593 currentWidth
+= TableData
[i
].width
;
4596 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4598 else if (ruleTop
> 1)
4600 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4602 if (ruleBottom
== 1)
4604 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4606 else if (ruleBottom
> 1)
4608 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4611 if (TableData
[i
].rightBorder
)
4612 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4614 if (TableData
[i
].leftBorder
)
4615 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4617 sprintf(buf
, "\\cellx%d", currentWidth
);
4620 TexOutput("\\pard\\intbl\n");
4624 currentRowNumber
++;
4629 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4630 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4636 static int noMultiColumns
= 0;
4643 noMultiColumns
= atoi(GetArgData());
4661 for (int i
= 1; i
< noMultiColumns
; i
++)
4662 TexOutput("\\cell");
4669 if (start
&& (arg_no
== 1))
4672 // TexOutput("\\fi0\n");
4674 wxNode
*node
= itemizeStack
.First();
4676 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
4678 int indentValue
= 20*ParseUnitArgument(GetArgData());
4679 int indentSize
= indentValue
+ oldIndent
;
4681 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4682 itemizeStack
.Insert(struc
);
4684 sprintf(buf
, "\\tx%d\\li%d ", indentSize
, indentSize
);
4685 PushEnvironmentStyle(buf
);
4689 if (!start
&& (arg_no
== 2))
4691 PopEnvironmentStyle();
4692 if (itemizeStack
.First())
4694 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
4696 delete itemizeStack
.First();
4698 if (itemizeStack
.Number() == 0)
4700 TexOutput("\\par\\pard\n");
4701 issuedNewParagraph
= 1;
4702 WriteEnvironmentStyles();
4712 if (start && (arg_no == 1))
4715 wxNode *node = itemizeStack.First();
4717 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4719 int boxWidth = 20*ParseUnitArgument(GetArgData());
4721 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4722 int indentSize = indentValue + oldIndent;
4723 int indentSizeRight = indentSize + boxWidth;
4725 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4726 itemizeStack.Insert(struc);
4728 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4729 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4730 PushEnvironmentStyle(buf);
4734 if (!start && (arg_no == 2))
4736 PopEnvironmentStyle();
4737 if (itemizeStack.First())
4739 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4741 delete itemizeStack.First();
4743 if (itemizeStack.Number() == 0)
4745 TexOutput("\\par\\pard\n");
4746 issuedNewParagraph = 1;
4747 WriteEnvironmentStyles();
4754 case ltDOCUMENTSTYLE
:
4756 DefaultOnArgument(macroId
, arg_no
, start
);
4757 if (!start
&& !IsArgOptional())
4759 if (MinorDocumentStyleString
)
4761 if (StringMatch("twoside", MinorDocumentStyleString
))
4762 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4763 TexOutput("\\margmirror\\facingp\\sbkodd");
4764 if (StringMatch("twocolumn", MinorDocumentStyleString
))
4765 TexOutput("\\cols2");
4771 case ltSETHOTSPOTCOLOUR
:
4772 case ltSETHOTSPOTCOLOR
:
4776 char *text
= GetArgData();
4777 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4778 hotSpotColour
= TRUE
;
4780 hotSpotColour
= FALSE
;
4784 case ltSETTRANSPARENCY
:
4788 char *text
= GetArgData();
4789 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4790 bitmapTransparency
= TRUE
;
4792 bitmapTransparency
= FALSE
;
4796 case ltSETHOTSPOTUNDERLINE
:
4800 char *text
= GetArgData();
4801 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4802 hotSpotUnderline
= TRUE
;
4804 hotSpotUnderline
= FALSE
;
4810 if (arg_no
== 1 && start
)
4812 char *citeKey
= GetArgData();
4813 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4816 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4817 sprintf(buf
, "[%d]", citeCount
);
4818 ref
->sectionNumber
= copystring(buf
);
4821 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4822 sprintf(buf
, "{\\b [%d]} ", citeCount
);
4827 if (arg_no
== 2 && !start
)
4828 TexOutput("\\par\\pard\\par\n\n");
4832 case ltTHEBIBLIOGRAPHY
:
4834 if (start
&& (arg_no
== 1))
4838 SetCurrentOutputs(Contents
, Chapters
);
4842 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
4844 // If a non-custom page style, we generate the header now.
4845 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
4846 strcmp(PageStyle
, "empty") == 0 ||
4847 strcmp(PageStyle
, "headings") == 0))
4849 OutputRTFHeaderCommands();
4850 OutputRTFFooterCommands();
4853 // Need to reset the current numbering style, or RTF forgets it.
4854 OutputNumberStyle(currentNumberStyle
);
4855 SetCurrentOutput(Contents
);
4858 fprintf(Chapters
, "\\page\n");
4861 fprintf(Contents
, "\n{\\uldb %s}", ReferencesNameString
);
4863 fprintf(Contents
, "\\par\n\\pard{\\b %s}", ReferencesNameString
);
4865 startedSections
= TRUE
;
4868 fprintf(Chapters
, "\n${\\footnote %s}", ReferencesNameString
);
4870 char *topicName
= "bibliography";
4873 fprintf(Contents
, "{\\v %s}\\par\\pard\n", topicName
);
4875 fprintf(Contents
, "\\par\\par\\pard\n");
4879 fprintf(Chapters
, "\n#{\\footnote %s}\n", topicName
);
4880 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
4881 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ReferencesNameString
);
4882 GenerateKeywordsForTopic(topicName
);
4885 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4886 FileNameFromPath(FileRoot
), "Contents");
4890 SetCurrentOutput(Chapters
);
4891 char *styleCommand
= "";
4892 if (!winHelp
&& useHeadingStyles
)
4893 styleCommand
= "\\s1";
4894 fprintf(Chapters
, "\\pard{%s", (winHelp
? "\\keepn\\sa140\\sb140" : styleCommand
));
4895 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " References\\par\\pard}\n");
4905 * In Windows help, all keywords should be at the start of the
4906 * topic, but Latex \index commands can be anywhere in the text.
4907 * So we're going to have to build up lists of keywords for a topic,
4908 * and insert them on the second pass.
4910 * In linear RTF, we can embed the index entry now.
4915 // char *entry = GetArgData();
4917 OutputChunkToString(GetArgChunk(), buf
);
4922 AddKeyWordForTopic(CurrentTopic
, buf
);
4925 else GenerateIndexEntry(buf
);
4939 char *name
= GetArgData();
4940 int pos
= FindColourPosition(name
);
4943 sprintf(buf
, "{%s%d ", ((macroId
== ltFCOL
) ? "\\cf" : "\\cb"), pos
);
4948 sprintf(buf
, "Could not find colour name %s", name
);
4964 if (arg_no
== 2) TexOutput("}");
4971 if (start
&& !winHelp
&& useWord
)
4973 char *s
= GetArgData();
4974 // Only insert a bookmark here if it's not just been inserted
4975 // in a section heading.
4976 if ( !CurrentTopic
|| !(strcmp(CurrentTopic
, s
) == 0) )
4978 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4979 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4980 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
4984 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", s
,s
);
4992 if (start
&& useWord
&& !winHelp
)
4994 char *s
= GetArgData();
4995 fprintf(Chapters
, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
5004 inPopRefSection
= TRUE
;
5006 inPopRefSection
= FALSE
;
5009 case ltINSERTATLEVEL
:
5011 // This macro allows you to insert text at a different level
5012 // from the current level, e.g. into the Sections from within a subsubsection.
5013 if (!winHelp
& useWord
)
5015 static int currentLevelNo
= 1;
5016 static FILE* oldLevelFile
= Chapters
;
5023 oldLevelFile
= CurrentOutput1
;
5025 char *str
= GetArgData();
5026 currentLevelNo
= atoi(str
);
5028 // TODO: cope with article style (no chapters)
5029 switch (currentLevelNo
)
5033 outputFile
= Chapters
;
5038 outputFile
= Sections
;
5043 outputFile
= Subsections
;
5048 outputFile
= Subsubsections
;
5058 CurrentOutput1
= outputFile
;
5076 CurrentOutput1
= oldLevelFile
;
5084 return DefaultOnArgument(macroId
, arg_no
, start
);
5095 forbidParindent
= 0;
5096 contentsLineSection
= NULL
;
5097 contentsLineValue
= NULL
;
5098 descriptionItemArg
= NULL
;
5103 tableVerticalLineLeft
= FALSE
;
5104 tableVerticalLineRight
= FALSE
;
5106 startedSections
= FALSE
;
5110 if (InputFile
&& OutputFile
)
5112 // Do some RTF-specific transformations on all the strings,
5114 Text2RTF(GetTopLevelChunk());
5116 Contents
= fopen(TmpContentsName
, "w");
5117 Chapters
= fopen("chapters.rtf", "w");
5120 Sections
= fopen("sections.rtf", "w");
5121 Subsections
= fopen("subsections.rtf", "w");
5122 Subsubsections
= fopen("subsubsections.rtf", "w");
5123 Popups
= fopen("popups.rtf", "w");
5124 if (winHelpContents
)
5126 WinHelpContentsFile
= fopen(WinHelpContentsFileName
, "w");
5127 if (WinHelpContentsFile
)
5128 fprintf(WinHelpContentsFile
, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot
));
5131 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5133 OnError("Ouch! Could not open temporary file(s) for writing.");
5137 if (!Contents
|| !Chapters
)
5139 OnError("Ouch! Could not open temporary file(s) for writing.");
5145 fprintf(Chapters
, "\n#{\\footnote Contents}\n");
5146 fprintf(Chapters
, "${\\footnote Contents}\n");
5147 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
5148 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ContentsNameString
);
5149 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
5153 fprintf(Chapters
, "\\titlepg\n");
5154 fprintf(Contents
, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5157 // In WinHelp, Contents title takes font of title.
5158 // In linear RTF, same as chapter headings.
5159 fprintf(Contents
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5160 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5162 // By default, Swiss, 10 point.
5163 fprintf(Chapters
, "\\f2\\fs20\n");
5165 SetCurrentOutput(Chapters
);
5167 OnInform("Converting...");
5171 FILE *Header
= fopen("header.rtf", "w");
5174 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5177 WriteRTFHeader(Header
);
5178 fclose(Header
); Header
= NULL
;
5183 // fprintf(Contents, "\\page\n");
5184 fprintf(Chapters
, "\\page\n");
5185 fprintf(Sections
, "\\page\n");
5186 fprintf(Subsections
, "\\page\n");
5187 fprintf(Subsubsections
, "\\page\n\n");
5188 fprintf(Popups
, "\\page\n}\n");
5191 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5194 fclose(Contents
); Contents
= NULL
;
5195 fclose(Chapters
); Chapters
= NULL
;
5198 fclose(Sections
); Sections
= NULL
;
5199 fclose(Subsections
); Subsections
= NULL
;
5200 fclose(Subsubsections
); Subsubsections
= NULL
;
5201 fclose(Popups
); Popups
= NULL
;
5202 if (winHelpContents
)
5204 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5210 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5212 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5214 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5216 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5218 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile
);
5221 wxRemoveFile("tmp1.rtf");
5222 wxRemoveFile("tmp2.rtf");
5223 wxRemoveFile("tmp3.rtf");
5224 wxRemoveFile("tmp4.rtf");
5228 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5230 if (FileExists(OutputFile
))
5231 wxRemoveFile(OutputFile
);
5234 cwdStr
= wxGetWorkingDirectory();
5236 wxString outputDirStr
;
5237 outputDirStr
= wxPathOnly(OutputFile
);
5239 // Determine if the temp file and the output file are in the same directory,
5240 // and if they are, then just rename the temp file rather than copying
5241 // it, as this is much faster when working with large (multi-megabyte files)
5242 if ((wxStrcmp(outputDirStr
.c_str(),"") == 0) || // no path specified on output file
5243 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5245 wxRenameFile("tmp1.rtf", OutputFile
);
5249 wxCopyFile("tmp1.rtf", OutputFile
);
5253 wxRemoveFile("tmp1.rtf");
5256 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5258 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5260 wxCopyFile(TmpContentsName
, ContentsName
);
5261 wxRemoveFile(TmpContentsName
);
5264 wxRemoveFile("chapters.rtf");
5265 wxRemoveFile("header.rtf");
5269 wxRemoveFile("sections.rtf");
5270 wxRemoveFile("subsections.rtf");
5271 wxRemoveFile("subsubsections.rtf");
5272 wxRemoveFile("popups.rtf");
5274 if (winHelp
&& generateHPJ
)
5275 WriteHPJ(OutputFile
);