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(wxTex2RTFBuffer
);
219 for (i
= 0; i
< strlen(wxTex2RTFBuffer
); i
++)
220 if (wxTex2RTFBuffer
[i
] == ':')
221 wxTex2RTFBuffer
[i
] = ' ';
222 // Don't write to index if there's some RTF in the string
223 else if ( wxTex2RTFBuffer
[i
] == '{' )
226 fprintf(fd
, "K{\\footnote {K} ");
227 fprintf(fd
, "%s", wxTex2RTFBuffer
);
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(wxTex2RTFBuffer
);
1117 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 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(wxTex2RTFBuffer
);
1259 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 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(wxTex2RTFBuffer
);
1443 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 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(wxTex2RTFBuffer
);
1593 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 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;
2209 wxNode
*node2
= NULL
;
2210 if (itemizeStack
.Number() > 1) // TODO: do I actually mean Nth(0) here??
2211 node2
= itemizeStack
.Nth(1);
2213 oldIndent
= ((ItemizeStruc
*)node2
->Data())->indentation
;
2216 if (struc
->currentItem
> 1)
2218 if (currentItemSep
> 0)
2221 // WriteEnvironmentStyles();
2224 // sprintf(buf, "\\tx%d\\li%d\\fi-%d\\ri%d\n", TwoColWidthA,
2225 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2227 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA,
2228 TwoColWidthA, TwoColWidthA);
2230 sprintf(buf
, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA
+ oldIndent
,
2231 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2242 if (macroId
== ltVERBATIM
)
2244 if (!issuedNewParagraph
)
2246 TexOutput("\\par\\pard");
2247 WriteEnvironmentStyles();
2248 issuedNewParagraph
= 1;
2250 else issuedNewParagraph
= 0;
2252 sprintf(buf
, "{\\f3\\fs20 ");
2258 if (macroId
== ltVERBATIM
)
2260 TexOutput("\\pard\n");
2261 // issuedNewParagraph = 1;
2262 WriteEnvironmentStyles();
2272 TexOutput("\\fi0\\qc ");
2274 PushEnvironmentStyle("\\qc");
2278 TexOutput("\\par\\pard\n");
2279 issuedNewParagraph
= 1;
2281 PopEnvironmentStyle();
2282 WriteEnvironmentStyles();
2290 TexOutput("\\fi0\\ql ");
2292 PushEnvironmentStyle("\\ql");
2296 TexOutput("\\par\\pard\n");
2297 issuedNewParagraph
= 1;
2299 PopEnvironmentStyle();
2300 WriteEnvironmentStyles();
2308 TexOutput("\\fi0\\qr ");
2310 PushEnvironmentStyle("\\qr");
2314 TexOutput("\\par\\pard\n");
2315 issuedNewParagraph
= 1;
2317 PopEnvironmentStyle();
2318 WriteEnvironmentStyles();
2323 case ltFOOTNOTESIZE
:
2327 sprintf(buf
, "{\\fs%d\n", smallFont
*2);
2330 else TexOutput("}\n");
2338 sprintf(buf
, "{\\fs%d\n", tinyFont
*2);
2341 else TexOutput("}\n");
2348 sprintf(buf
, "{\\fs%d\n", normalFont
*2);
2351 else TexOutput("}\n");
2358 sprintf(buf
, "{\\fs%d\n", largeFont1
*2);
2361 else TexOutput("}\n");
2368 sprintf(buf
, "{\\fs%d\n", LargeFont2
*2);
2371 else TexOutput("}\n");
2378 sprintf(buf
, "{\\fs%d\n", LARGEFont3
*2);
2381 else TexOutput("}\n");
2388 sprintf(buf
, "{\\fs%d\n", hugeFont1
*2);
2391 else TexOutput("}\n");
2398 sprintf(buf
, "{\\fs%d\n", HugeFont2
*2);
2401 else TexOutput("}\n");
2408 sprintf(buf
, "{\\fs%d\n", HUGEFont3
*2);
2411 else TexOutput("}\n");
2422 else TexOutput("}");
2429 TexOutput("{\\ul ");
2431 else TexOutput("}");
2444 else TexOutput("}");
2447 // Roman font: do nothing. Should really switch between
2456 TexOutput("{\\plain ");
2458 else TexOutput("}");
2462 // Medium-weight font. Unbolden...
2467 TexOutput("{\\b0 ");
2469 else TexOutput("}");
2472 // Upright (un-italic or slant)
2477 TexOutput("{\\i0 ");
2479 else TexOutput("}");
2488 TexOutput("{\\scaps ");
2490 else TexOutput("}");
2499 TexOutput("{\\f3 ");
2501 else TexOutput("}");
2526 if ( issuedNewParagraph
== 0 )
2528 TexOutput("\\par\\pard");
2529 issuedNewParagraph
++;
2531 // Extra par if parskip is more than zero (usually looks best.)
2532 if (!inTabular
&& (ParSkip
> 0))
2535 issuedNewParagraph
++;
2537 WriteEnvironmentStyles();
2539 // 1 is a whole paragraph if ParSkip == 0,
2540 // half a paragraph if ParSkip > 0
2541 else if ( issuedNewParagraph
== 1 )
2543 // Don't need a par at all if we've already had one,
2544 // and ParSkip == 0.
2546 // Extra par if parskip is more than zero (usually looks best.)
2547 if (!inTabular
&& (ParSkip
> 0))
2550 issuedNewParagraph
++;
2552 WriteEnvironmentStyles();
2555 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2557 TexOutput("\\par\\pard");
2559 // Extra par if parskip is more than zero (usually looks best.)
2560 if (!inTabular && (ParSkip > 0))
2562 WriteEnvironmentStyles();
2572 // In Windows Help, no newpages until we've started some chapters or sections
2573 if (!(winHelp
&& !startedSections
))
2575 TexOutput("\\page\n");
2580 if (start
&& DocumentTitle
)
2582 TexOutput("\\par\\pard");
2585 sprintf(buf
, "\\qc{\\fs%d\\b ", titleFont
*2);
2587 TraverseChildrenFromChunk(DocumentTitle
);
2588 TexOutput("}\\par\\pard\n");
2594 sprintf(buf
, "\\par\\qc{\\fs%d ", authorFont
*2);
2596 TraverseChildrenFromChunk(DocumentAuthor
);
2598 TexOutput("\\par\\pard\n");
2603 sprintf(buf
, "\\qc{\\fs%d ", authorFont
*2);
2605 TraverseChildrenFromChunk(DocumentDate
);
2606 TexOutput("}\\par\\pard\n");
2608 // If linear RTF, we want this titlepage to be in a separate
2609 // section with its own (blank) header and footer
2610 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2612 TexOutput("{\\header }{\\footer }\n");
2613 // Not sure about this: we get too many sections.
2614 // TexOutput("\\sect");
2619 case ltADDCONTENTSLINE
:
2623 if (contentsLineSection
&& contentsLineValue
)
2625 if (strcmp(contentsLineSection
, "chapter") == 0)
2627 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2629 else if (strcmp(contentsLineSection
, "section") == 0)
2631 if (DocumentStyle
!= LATEX_ARTICLE
)
2632 fprintf(Contents
, "\n\\tab%s\\par\n", contentsLineValue
);
2634 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2644 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2645 issuedNewParagraph
= 1;
2646 WriteEnvironmentStyles();
2654 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2655 issuedNewParagraph
= 1;
2656 WriteEnvironmentStyles();
2666 case ltNUMBEREDBIBITEM
:
2669 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
2671 TexOutput("\\par\\pard\\par\n\n");
2678 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2686 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2687 sprintf(buf
, "%d", chapterNo
);
2696 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2697 sprintf(buf
, "%d", sectionNo
);
2704 if (!start
&& !winHelp
)
2706 TexOutput("\\cols2\n");
2712 if (!start
&& !winHelp
)
2714 TexOutput("\\cols1\n");
2720 if (start
&& useWord
&& !winHelp
)
2722 FakeCurrentSection("Index");
2723 OnMacro(ltPAR
, 0, TRUE
);
2724 OnMacro(ltPAR
, 0, FALSE
);
2725 TexOutput("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n");
2729 case ltLISTOFFIGURES
:
2731 if (start
&& useWord
&& !winHelp
)
2733 FakeCurrentSection(FiguresNameString
, FALSE
);
2734 OnMacro(ltPAR
, 0, TRUE
);
2735 OnMacro(ltPAR
, 0, FALSE
);
2736 OnMacro(ltPAR
, 0, TRUE
);
2737 OnMacro(ltPAR
, 0, FALSE
);
2739 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n",
2745 case ltLISTOFTABLES
:
2747 if (start
&& useWord
&& !winHelp
)
2749 FakeCurrentSection(TablesNameString
, FALSE
);
2750 OnMacro(ltPAR
, 0, TRUE
);
2751 OnMacro(ltPAR
, 0, FALSE
);
2752 OnMacro(ltPAR
, 0, TRUE
);
2753 OnMacro(ltPAR
, 0, FALSE
);
2755 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n",
2763 if (start
) TexOutput("{\\f1\\'61}");
2766 if (start
) TexOutput("{\\f1\\'62}");
2769 if (start
) TexOutput("{\\f1\\'63}");
2772 if (start
) TexOutput("{\\f1\\'64}");
2776 if (start
) TexOutput("{\\f1\\'65}");
2779 if (start
) TexOutput("{\\f1\\'7A}");
2782 if (start
) TexOutput("{\\f1\\'68}");
2786 if (start
) TexOutput("{\\f1\\'71}");
2789 if (start
) TexOutput("{\\f1\\'69}");
2792 if (start
) TexOutput("{\\f1\\'6B}");
2795 if (start
) TexOutput("{\\f1\\'6C}");
2798 if (start
) TexOutput("{\\f1\\'6D}");
2801 if (start
) TexOutput("{\\f1\\'6E}");
2804 if (start
) TexOutput("{\\f1\\'78}");
2807 if (start
) TexOutput("{\\f1\\'70}");
2810 if (start
) TexOutput("{\\f1\\'76}");
2814 if (start
) TexOutput("{\\f1\\'72}");
2817 if (start
) TexOutput("{\\f1\\'73}");
2820 if (start
) TexOutput("{\\f1\\'56}");
2823 if (start
) TexOutput("{\\f1\\'74}");
2826 if (start
) TexOutput("{\\f1\\'75}");
2830 if (start
) TexOutput("{\\f1\\'66}");
2833 if (start
) TexOutput("{\\f1\\'63}");
2836 if (start
) TexOutput("{\\f1\\'79}");
2839 if (start
) TexOutput("{\\f1\\'77}");
2842 if (start
) TexOutput("{\\f1\\'47}");
2845 if (start
) TexOutput("{\\f1\\'44}");
2848 if (start
) TexOutput("{\\f1\\'51}");
2851 if (start
) TexOutput("{\\f1\\'4C}");
2854 if (start
) TexOutput("{\\f1\\'58}");
2857 if (start
) TexOutput("{\\f1\\'50}");
2860 if (start
) TexOutput("{\\f1\\'53}");
2863 if (start
) TexOutput("{\\f1\\'54}");
2866 if (start
) TexOutput("{\\f1\\'46}");
2869 if (start
) TexOutput("{\\f1\\'59}");
2872 if (start
) TexOutput("{\\f1\\'57}");
2874 // Binary operation symbols
2877 if (start
) TexOutput("{\\f1\\'A3}");
2880 if (start
) TexOutput("<<");
2883 if (start
) TexOutput("{\\f1\\'CC}");
2886 if (start
) TexOutput("{\\f1\\'CD}");
2889 if (start
) TexOutput("{\\f1\\'CE}");
2893 if (start
) TexOutput("{\\f1\\'B3}");
2896 if (start
) TexOutput(">>");
2899 if (start
) TexOutput("{\\f1\\'C9}");
2902 if (start
) TexOutput("{\\f1\\'CD}");
2905 if (start
) TexOutput("{\\f1\\'27}");
2908 if (start
) TexOutput("{\\f1\\'5E}");
2911 if (start
) TexOutput("{\\f1\\'B9}");
2914 if (start
) TexOutput("{\\f1\\'BB}");
2917 if (start
) TexOutput("{\\f1\\'40}");
2920 if (start
) TexOutput("{\\f1\\'BA}");
2923 if (start
) TexOutput("{\\f1\\'B5}");
2926 if (start
) TexOutput("{\\f1\\'7E}");
2929 if (start
) TexOutput("{\\f4\\'4A}");
2932 if (start
) TexOutput("{\\f4\\'4C}");
2935 if (start
) TexOutput("|");
2938 // Negated relation symbols
2940 if (start
) TexOutput("{\\f1\\'B9}");
2943 if (start
) TexOutput("{\\f1\\'CF}");
2946 if (start
) TexOutput("{\\f1\\'CB}");
2951 if (start
) TexOutput("{\\f1\\'AC}");
2954 if (start
) TexOutput("{\\f1\\'DC}");
2957 if (start
) TexOutput("{\\f1\\'AE}");
2960 if (start
) TexOutput("{\\f1\\'DE}");
2962 case ltLEFTRIGHTARROW
:
2963 if (start
) TexOutput("{\\f1\\'AB}");
2965 case ltLEFTRIGHTARROW2
:
2966 if (start
) TexOutput("{\\f1\\'DB}");
2969 if (start
) TexOutput("{\\f1\\'AD}");
2972 if (start
) TexOutput("{\\f1\\'DD}");
2975 if (start
) TexOutput("{\\f1\\'AF}");
2978 if (start
) TexOutput("{\\f1\\'DF}");
2981 // Miscellaneous symbols
2983 if (start
) TexOutput("{\\f1\\'CO}");
2986 if (start
) TexOutput("{\\f1\\'C3}");
2989 if (start
) TexOutput("{\\f1\\'C2}");
2992 if (start
) TexOutput("{\\f1\\'C1}");
2995 if (start
) TexOutput("{\\f1\\'C6}");
2998 if (start
) TexOutput("{\\f1\\'D1}");
3001 if (start
) TexOutput("{\\f1\\'D6}");
3004 if (start
) TexOutput("{\\f1\\'B6}");
3007 if (start
) TexOutput("{\\f1\\'5E}");
3010 if (start
) TexOutput("{\\f1\\'22}");
3013 if (start
) TexOutput("{\\f1\\'24}");
3016 if (start
) TexOutput("{\\f1\\'D8}");
3019 if (start
) TexOutput("{\\f1\\'23}");
3022 if (start
) TexOutput("{\\f1\\'D0}");
3025 if (start
) TexOutput("{\\f5\\'73}");
3028 if (start
) TexOutput("{\\f5\\'A8}");
3031 if (start
) TexOutput("{\\f5\\'A9}");
3034 if (start
) TexOutput("{\\f5\\'AA}");
3037 if (start
) TexOutput("{\\f5\\'AB}");
3040 if (start
) TexOutput("{\\f1\\'A5}");
3043 if (start
) TexOutput("{\\f0\\'A9}");
3046 if (start
) TexOutput("{\\f0\\'AE}");
3049 if (start
) TexOutput("{\\f1\\'B1}");
3052 if (start
) TexOutput("{\\f1\\'B1}");
3055 if (start
) TexOutput("{\\f1\\'B4}");
3058 if (start
) TexOutput("{\\f1\\'B8}");
3061 if (start
) TexOutput("{\\f1\\'D7}");
3064 if (start
) TexOutput("{\\f1\\'2A}");
3067 if (start
) TexOutput("{\\f5\\'AB}");
3070 if (start
) TexOutput("{\\f1\\'C7}");
3073 if (start
) TexOutput("{\\f1\\'C8}");
3076 if (start
) TexOutput("{\\f1\\'DA}");
3079 if (start
) TexOutput("{\\f1\\'D9}");
3082 if (start
) TexOutput("{\\f1\\'B0}");
3085 if (start
) TexOutput("{\\f1\\'B7}");
3088 if (start
) TexOutput("{\\f1\\'E0}");
3091 if (start
) TexOutput("{\\f1\\'C6}");
3094 if (start
) TexOutput("{\\f1\\'E0}");
3096 case ltBIGTRIANGLEDOWN
:
3097 if (start
) TexOutput("{\\f1\\'D1}");
3100 if (start
) TexOutput("{\\f1\\'C5}");
3103 if (start
) TexOutput("{\\f1\\'C4}");
3106 if (start
) TexOutput("{\\'DF}");
3110 if (start
) inFigure
= TRUE
;
3111 else inFigure
= FALSE
;
3116 if (start
) inTable
= TRUE
;
3117 else inTable
= FALSE
;
3122 DefaultOnMacro(macroId
, no_args
, start
);
3128 // Called on start/end of argument examination
3129 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3136 case ltCHAPTERHEADING
:
3139 case ltSECTIONHEADING
:
3141 case ltSUBSECTIONSTAR
:
3142 case ltSUBSUBSECTION
:
3143 case ltSUBSUBSECTIONSTAR
:
3145 case ltMEMBERSECTION
:
3146 case ltFUNCTIONSECTION
:
3150 if (!start
&& (arg_no
== 1))
3151 currentSection
= GetArgChunk();
3157 if (start
&& (arg_no
== 1))
3158 TexOutput("\\pard\\li600\\fi-600{\\b ");
3160 if (!start
&& (arg_no
== 1))
3163 if (start
&& (arg_no
== 2))
3165 if (!suppressNameDecoration
) TexOutput("{\\b ");
3166 currentMember
= GetArgChunk();
3168 if (!start
&& (arg_no
== 2))
3170 if (!suppressNameDecoration
) TexOutput("}");
3173 if (start
&& (arg_no
== 3))
3175 if (!start
&& (arg_no
== 3))
3177 // TexOutput(")\\li0\\fi0");
3178 // TexOutput(")\\par\\pard\\li0\\fi0");
3179 // issuedNewParagraph = 1;
3181 WriteEnvironmentStyles();
3187 if (start
&& (arg_no
== 1))
3188 TexOutput("\\pard\\li260\\fi-260{\\b ");
3189 if (!start
&& (arg_no
== 1))
3192 if (start
&& (arg_no
== 2))
3194 if (!suppressNameDecoration
) TexOutput("({\\b ");
3195 currentMember
= GetArgChunk();
3197 if (!start
&& (arg_no
== 2))
3199 if (!suppressNameDecoration
) TexOutput("}");
3202 if (!start
&& (arg_no
== 3))
3204 TexOutput(")\\li0\\fi0");
3205 WriteEnvironmentStyles();
3211 if (start
&& (arg_no
== 1))
3212 TexOutput("\\pard\\li260\\fi-260");
3214 if (!start
&& (arg_no
== 1))
3217 if (start
&& (arg_no
== 2))
3219 if (!start
&& (arg_no
== 2))
3222 if (start
&& (arg_no
== 2))
3223 currentMember
= GetArgChunk();
3225 if (start
&& (arg_no
== 3))
3227 if (!start
&& (arg_no
== 3))
3229 TexOutput(")\\li0\\fi0");
3230 WriteEnvironmentStyles();
3236 if (start
&& (arg_no
== 1))
3238 if (!start
&& (arg_no
== 1))
3240 if (start
&& (arg_no
== 2))
3244 if (!start
&& (arg_no
== 2))
3252 if (start
&& (arg_no
== 1))
3254 if (!start
&& (arg_no
== 1))
3255 TexOutput("} "); // This is the difference from param - one space!
3256 if (start
&& (arg_no
== 2))
3260 if (!start
&& (arg_no
== 2))
3268 if (!start
&& (arg_no
== 1))
3271 if (start
&& (arg_no
== 2))
3272 currentMember
= GetArgChunk();
3280 char *secName
= NULL
;
3282 char *refName
= GetArgData();
3283 if (winHelp
|| !useWord
)
3287 TexRef
*texRef
= FindReference(refName
);
3290 sec
= texRef
->sectionNumber
;
3291 secName
= texRef
->sectionName
;
3301 fprintf(Chapters
, "{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
3313 if ((GetNoArgs() - arg_no
) == 1)
3316 TexOutput("{\\uldb ");
3320 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3326 // Remove green colour/underlining if specified
3327 if (!hotSpotUnderline
&& !hotSpotColour
)
3329 else if (!hotSpotColour
)
3332 else TexOutput("}");
3335 else // If a linear document, must resolve the references ourselves
3337 if ((GetNoArgs() - arg_no
) == 1)
3339 // In a linear document we display the anchor text in italic plus
3347 helpRefText
= GetArgChunk();
3351 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3353 if (macroId
!= ltHELPREFN
)
3355 char *refName
= GetArgData();
3356 TexRef
*texRef
= NULL
;
3358 texRef
= FindReference(refName
);
3361 if (texRef
|| !ignoreBadRefs
)
3365 if (texRef
|| !ignoreBadRefs
)
3369 char *s
= GetArgData();
3371 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3373 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3377 // Only print section name if we're not in Word mode,
3378 // so can't do page references
3381 TexOutput(texRef
->sectionName
) ; TexOutput(" "); TexOutput(texRef
->sectionNumber
);
3387 sprintf(buf
, "Warning: unresolved reference '%s'", refName
);
3393 else TexOutput("??");
3397 if (texRef
|| !ignoreBadRefs
)
3412 else if (arg_no
== 2)
3417 TexOutput(" ({\\f3 ");
3432 if ((GetNoArgs() - arg_no
) == 1)
3435 TexOutput("{\\ul ");
3439 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3445 // Remove green colour/underlining if specified
3446 if (!hotSpotUnderline
&& !hotSpotColour
)
3448 else if (!hotSpotColour
)
3451 else TexOutput("}");
3454 else // A linear document...
3456 if ((GetNoArgs() - arg_no
) == 1)
3458 // In a linear document we just display the anchor text in italic
3469 case ltADDCONTENTSLINE
:
3471 if (start
&& !winHelp
)
3474 contentsLineSection
= copystring(GetArgData());
3475 else if (arg_no
== 3)
3476 contentsLineValue
= copystring(GetArgData());
3491 static int imageWidth
= 0;
3492 static int imageHeight
= 0;
3494 if (start
&& (arg_no
== 1))
3496 char *imageDimensions
= copystring(GetArgData());
3498 strcpy(buf1
, imageDimensions
);
3499 char *tok1
= strtok(buf1
, ";:");
3500 char *tok2
= strtok(NULL
, ";:");
3501 // Convert points to TWIPS (1 twip = 1/20th of point)
3502 imageWidth
= (int)(20*(tok1
? ParseUnitArgument(tok1
) : 0));
3503 imageHeight
= (int)(20*(tok2
? ParseUnitArgument(tok2
) : 0));
3504 if (imageDimensions
) // glt
3505 delete [] imageDimensions
;
3508 else if (start
&& (arg_no
== 2 ))
3510 char *filename
= copystring(GetArgData());
3512 if ((winHelp
|| (strcmp(bitmapMethod
, "includepicture") == 0) || (strcmp(bitmapMethod
, "import") == 0)) && useWord
)
3514 if (f
== "") // Try for a .shg (segmented hypergraphics file)
3516 strcpy(buf
, filename
);
3517 StripExtension(buf
);
3518 strcat(buf
, ".shg");
3519 f
= TexPathList
.FindValidPath(buf
);
3521 if (f
== "") // Try for a .bmp
3523 strcpy(buf
, filename
);
3524 StripExtension(buf
);
3525 strcat(buf
, ".bmp");
3526 f
= TexPathList
.FindValidPath(buf
);
3528 if (f
== "") // Try for a metafile instead
3530 strcpy(buf
, filename
);
3531 StripExtension(buf
);
3532 strcat(buf
, ".wmf");
3533 f
= TexPathList
.FindValidPath(buf
);
3539 if (bitmapTransparency
&& (winHelpVersion
> 3))
3540 TexOutput("\\{bmct ");
3542 TexOutput("\\{bmc ");
3543 wxString str
= wxFileNameFromPath(f
);
3544 TexOutput((char*) (const char*) str
);
3549 // Microsoft Word method
3550 if (strcmp(bitmapMethod
, "import") == 0)
3551 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3553 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3555 // Full path appears not to be valid!
3556 wxString str
= wxFileNameFromPath(f
);
3557 TexOutput((char*)(const char*) str
);
3559 int len = strlen(f);
3560 char smallBuf[2]; smallBuf[1] = 0;
3561 for (int i = 0; i < len; i++)
3564 TexOutput(smallBuf);
3565 if (smallBuf[0] == '\\')
3566 TexOutput(smallBuf);
3569 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3574 TexOutput("[No BMP or WMF for image file ");
3575 TexOutput(filename
);
3577 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3580 if (filename
) // glt
3585 if (f
== "") // Try for a .bmp
3587 strcpy(buf
, filename
);
3588 StripExtension(buf
);
3589 strcat(buf
, ".bmp");
3590 f
= TexPathList
.FindValidPath(buf
);
3594 FILE *fd
= fopen(f
, "rb");
3595 if (OutputBitmapHeader(fd
, winHelp
))
3596 OutputBitmapData(fd
);
3599 sprintf(buf
, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f
);
3604 else // Try for a metafile instead
3607 strcpy(buf
, filename
);
3608 StripExtension(buf
);
3609 strcat(buf
, ".wmf");
3610 f
= TexPathList
.FindValidPath(buf
);
3613 // HFILE handle = _lopen(f, READ);
3614 FILE *fd
= fopen(f
, "rb");
3615 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3617 OutputMetafileData(fd
);
3621 sprintf(buf
, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f
);
3629 TexOutput("[No BMP or WMF for image file ");
3630 TexOutput(filename
);
3632 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3646 case ltSUPERTABULAR
:
3652 currentRowNumber
= 0;
3655 tableVerticalLineLeft
= FALSE
;
3656 tableVerticalLineRight
= FALSE
;
3657 int currentWidth
= 0;
3659 char *alignString
= copystring(GetArgData());
3660 ParseTableArgument(alignString
);
3662 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3663 TexOutput("\\trowd\\trgaph108");
3665 // Write the first row formatting for compatibility
3666 // with standard Latex
3667 if (compatibilityMode
)
3669 for (int i
= 0; i
< noColumns
; i
++)
3671 currentWidth
+= TableData
[i
].width
;
3672 sprintf(buf
, "\\cellx%d", currentWidth
);
3675 TexOutput("\\pard\\intbl\n");
3677 delete[] alignString
;
3682 else if (arg_no
== 2 && !start
)
3684 TexOutput("\\pard\n");
3685 WriteEnvironmentStyles();
3696 TexOutput("\\li360\n");
3698 PushEnvironmentStyle("\\li360");
3703 PopEnvironmentStyle();
3704 OnMacro(ltPAR
, 0, TRUE
);
3705 OnMacro(ltPAR
, 0, FALSE
);
3713 TexOutput("\\li360\n");
3714 PushEnvironmentStyle("\\li360");
3718 PopEnvironmentStyle();
3719 OnMacro(ltPAR
, 0, TRUE
);
3720 OnMacro(ltPAR
, 0, FALSE
);
3732 sprintf(buf
, "\\box\\trgaph108%s\n", ((macroId
== ltNORMALBOXD
) ? "\\brdrdb" : "\\brdrs"));
3734 PushEnvironmentStyle(buf
);
3738 PopEnvironmentStyle();
3739 OnMacro(ltPAR
, 0, TRUE
);
3740 OnMacro(ltPAR
, 0, FALSE
);
3744 case ltHELPFONTSIZE
:
3748 char *data
= GetArgData();
3749 if (strcmp(data
, "10") == 0)
3751 else if (strcmp(data
, "11") == 0)
3753 else if (strcmp(data
, "12") == 0)
3755 sprintf(buf
, "\\fs%d\n", normalFont
*2);
3762 case ltHELPFONTFAMILY
:
3766 char *data
= GetArgData();
3767 if (strcmp(data
, "Swiss") == 0)
3768 TexOutput("\\f2\n");
3769 else if (strcmp(data
, "Symbol") == 0)
3770 TexOutput("\\f1\n");
3771 else if (strcmp(data
, "Times") == 0)
3772 TexOutput("\\f0\n");
3780 if (start
&& arg_no
== 1)
3782 char *data
= GetArgData();
3783 ParIndent
= ParseUnitArgument(data
);
3784 if (ParIndent
== 0 || forbidParindent
== 0)
3786 sprintf(buf
, "\\fi%d\n", ParIndent
*20);
3795 if (start
&& IsArgOptional())
3797 descriptionItemArg
= GetArgChunk();
3803 case ltTWOCOLITEMRULED
:
3810 TexOutput("\\tab ");
3817 if (macroId
== ltTWOCOLITEMRULED
)
3818 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3819 TexOutput("\\par\\pard\n");
3820 issuedNewParagraph
= 1;
3821 WriteEnvironmentStyles();
3833 case ltACCENT_GRAVE
:
3837 char *val
= GetArgData();
3880 case ltACCENT_ACUTE
:
3884 char *val
= GetArgData();
3933 case ltACCENT_CARET
:
3937 char *val
= GetArgData();
3980 case ltACCENT_TILDE
:
3984 char *val
= GetArgData();
4018 case ltACCENT_UMLAUT
:
4022 char *val
= GetArgData();
4078 char *val
= GetArgData();
4097 case ltACCENT_CADILLA
:
4101 char *val
= GetArgData();
4122 static char *helpTopic
= NULL
;
4123 static FILE *savedOutput
= NULL
;
4130 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4133 sprintf(footBuf
, "(%d)", footnoteCount
);
4135 TexOutput(" {\\ul ");
4138 helpTopic
= FindTopicName(NULL
);
4141 // Remove green colour/underlining if specified
4142 if (!hotSpotUnderline
&& !hotSpotColour
)
4144 else if (!hotSpotColour
)
4147 TexOutput(helpTopic
);
4150 fprintf(Popups
, "\\page\n");
4151 // fprintf(Popups, "\n${\\footnote }"); // No title
4152 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4153 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4154 savedOutput
= CurrentOutput1
;
4155 SetCurrentOutput(Popups
);
4159 SetCurrentOutput(savedOutput
);
4169 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4173 TexOutput("}}", TRUE
);
4179 case ltFOOTNOTEPOPUP
:
4181 static char *helpTopic
= NULL
;
4182 static FILE *savedOutput
= NULL
;
4189 TexOutput("{\\ul ");
4191 else TexOutput("}");
4194 else if (arg_no
== 2)
4198 helpTopic
= FindTopicName(NULL
);
4201 // Remove green colour/underlining if specified
4202 if (!hotSpotUnderline
&& !hotSpotColour
)
4204 else if (!hotSpotColour
)
4207 TexOutput(helpTopic
);
4210 fprintf(Popups
, "\\page\n");
4211 // fprintf(Popups, "\n${\\footnote }"); // No title
4212 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4213 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4214 savedOutput
= CurrentOutput1
;
4215 SetCurrentOutput(Popups
);
4219 SetCurrentOutput(savedOutput
);
4230 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4234 TexOutput("}}", TRUE
);
4242 if (start
&& (arg_no
== 1))
4255 if (winHelp
) return FALSE
;
4261 LeftHeaderEven
= GetArgChunk();
4262 if (strlen(GetArgData(LeftHeaderEven
)) == 0)
4263 LeftHeaderEven
= NULL
;
4266 CentreHeaderEven
= GetArgChunk();
4267 if (strlen(GetArgData(CentreHeaderEven
)) == 0)
4268 CentreHeaderEven
= NULL
;
4271 RightHeaderEven
= GetArgChunk();
4272 if (strlen(GetArgData(RightHeaderEven
)) == 0)
4273 RightHeaderEven
= NULL
;
4276 LeftHeaderOdd
= GetArgChunk();
4277 if (strlen(GetArgData(LeftHeaderOdd
)) == 0)
4278 LeftHeaderOdd
= NULL
;
4281 CentreHeaderOdd
= GetArgChunk();
4282 if (strlen(GetArgData(CentreHeaderOdd
)) == 0)
4283 CentreHeaderOdd
= NULL
;
4286 RightHeaderOdd
= GetArgChunk();
4287 if (strlen(GetArgData(RightHeaderOdd
)) == 0)
4288 RightHeaderOdd
= NULL
;
4289 OutputRTFHeaderCommands();
4305 if (winHelp
) return FALSE
;
4311 LeftFooterEven
= GetArgChunk();
4312 if (strlen(GetArgData(LeftFooterEven
)) == 0)
4313 LeftFooterEven
= NULL
;
4316 CentreFooterEven
= GetArgChunk();
4317 if (strlen(GetArgData(CentreFooterEven
)) == 0)
4318 CentreFooterEven
= NULL
;
4321 RightFooterEven
= GetArgChunk();
4322 if (strlen(GetArgData(RightFooterEven
)) == 0)
4323 RightFooterEven
= NULL
;
4326 LeftFooterOdd
= GetArgChunk();
4327 if (strlen(GetArgData(LeftFooterOdd
)) == 0)
4328 LeftFooterOdd
= NULL
;
4331 CentreFooterOdd
= GetArgChunk();
4332 if (strlen(GetArgData(CentreFooterOdd
)) == 0)
4333 CentreFooterOdd
= NULL
;
4336 RightFooterOdd
= GetArgChunk();
4337 if (strlen(GetArgData(RightFooterOdd
)) == 0)
4338 RightFooterOdd
= NULL
;
4339 OutputRTFFooterCommands();
4350 if (winHelp
) return FALSE
;
4351 // Fake a SetHeader command
4354 LeftHeaderOdd
= NULL
;
4355 CentreHeaderOdd
= NULL
;
4356 RightHeaderOdd
= NULL
;
4357 LeftHeaderEven
= NULL
;
4358 CentreHeaderEven
= NULL
;
4359 RightHeaderEven
= NULL
;
4360 OnInform("Consider using setheader/setfooter rather than markright.");
4362 RTFOnArgument(ltSETHEADER
, 4, start
);
4364 OutputRTFHeaderCommands();
4370 if (winHelp
) return FALSE
;
4371 // Fake a SetHeader command
4378 LeftHeaderOdd
= NULL
;
4379 CentreHeaderOdd
= NULL
;
4380 RightHeaderOdd
= NULL
;
4381 LeftHeaderEven
= NULL
;
4382 CentreHeaderEven
= NULL
;
4383 RightHeaderEven
= NULL
;
4384 OnInform("Consider using setheader/setfooter rather than markboth.");
4386 return RTFOnArgument(ltSETHEADER
, 1, start
);
4391 RTFOnArgument(ltSETHEADER
, 4, start
);
4393 OutputRTFHeaderCommands();
4400 case ltPAGENUMBERING
:
4407 if (winHelp
) return FALSE
;
4410 TexOutput("\\pgnrestart");
4411 char *data
= GetArgData();
4412 if (currentNumberStyle
) delete[] currentNumberStyle
;
4413 currentNumberStyle
= copystring(data
);
4414 OutputNumberStyle(currentNumberStyle
);
4423 if (winHelp
) return FALSE
;
4432 char *val
= GetArgData();
4433 currentItemSep
= ParseUnitArgument(val
);
4438 case ltEVENSIDEMARGIN
:
4443 case ltODDSIDEMARGIN
:
4447 char *val
= GetArgData();
4448 int twips
= (int)(20*ParseUnitArgument(val
));
4449 // Add an inch since in LaTeX it's specified minus an inch
4451 CurrentLeftMarginOdd
= twips
;
4452 sprintf(buf
, "\\margl%d\n", twips
);
4455 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4459 case ltMARGINPARWIDTH
:
4463 char *val
= GetArgData();
4464 int twips
= (int)(20*ParseUnitArgument(val
));
4465 CurrentMarginParWidth
= twips
;
4469 case ltMARGINPARSEP
:
4473 char *val
= GetArgData();
4474 int twips
= (int)(20*ParseUnitArgument(val
));
4475 CurrentMarginParSep
= twips
;
4476 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4484 char *val
= GetArgData();
4485 int twips
= (int)(20*ParseUnitArgument(val
));
4486 CurrentTextWidth
= twips
;
4488 // Need to set an implicit right margin
4489 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4490 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4491 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4492 sprintf(buf
, "\\margr%d\n", CurrentRightMarginOdd
);
4498 case ltMARGINPARODD
:
4504 TexOutput("\\box\n");
4505 PushEnvironmentStyle("\\box");
4509 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4518 TexOutput("\\par\\pard\n");
4519 PopEnvironmentStyle();
4520 WriteEnvironmentStyles();
4523 TexOutput("\\par\\pard\n");
4524 issuedNewParagraph
= 1;
4528 case ltMARGINPAREVEN
:
4534 TexOutput("\\box\n");
4535 PushEnvironmentStyle("\\box");
4541 // Have to calculate what the margins are changed to in WfW margin
4542 // mirror mode, on an even (left-hand) page.
4543 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4544 - CurrentTextWidth
+ GutterWidth
;
4545 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", x
, CurrentMarginParWidth
);
4550 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4560 TexOutput("\\par\\pard\n");
4561 PopEnvironmentStyle();
4562 WriteEnvironmentStyles();
4565 issuedNewParagraph
= 1;
4566 TexOutput("\\par\\pard\n");
4570 case ltTWOCOLWIDTHA
:
4574 char *val
= GetArgData();
4575 int twips
= (int)(20*ParseUnitArgument(val
));
4576 TwoColWidthA
= twips
;
4581 case ltTWOCOLWIDTHB
:
4585 char *val
= GetArgData();
4586 int twips
= (int)(20*ParseUnitArgument(val
));
4587 TwoColWidthB
= twips
;
4597 int currentWidth
= 0;
4599 if (!compatibilityMode
|| (currentRowNumber
> 0))
4601 TexOutput("\\pard\\intbl");
4603 if (macroId
== ltRULEDROW
)
4605 for (int i
= 0; i
< noColumns
; i
++)
4607 currentWidth
+= TableData
[i
].width
;
4610 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4612 else if (ruleTop
> 1)
4614 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4616 if (ruleBottom
== 1)
4618 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4620 else if (ruleBottom
> 1)
4622 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4625 if (TableData
[i
].rightBorder
)
4626 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4628 if (TableData
[i
].leftBorder
)
4629 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4631 sprintf(buf
, "\\cellx%d", currentWidth
);
4634 TexOutput("\\pard\\intbl\n");
4638 currentRowNumber
++;
4643 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4644 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4650 static int noMultiColumns
= 0;
4657 noMultiColumns
= atoi(GetArgData());
4675 for (int i
= 1; i
< noMultiColumns
; i
++)
4676 TexOutput("\\cell");
4683 if (start
&& (arg_no
== 1))
4686 // TexOutput("\\fi0\n");
4688 wxNode
*node
= itemizeStack
.First();
4690 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
4692 int indentValue
= 20*ParseUnitArgument(GetArgData());
4693 int indentSize
= indentValue
+ oldIndent
;
4695 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4696 itemizeStack
.Insert(struc
);
4698 sprintf(buf
, "\\tx%d\\li%d ", indentSize
, indentSize
);
4699 PushEnvironmentStyle(buf
);
4703 if (!start
&& (arg_no
== 2))
4705 PopEnvironmentStyle();
4706 if (itemizeStack
.First())
4708 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
4710 delete itemizeStack
.First();
4712 if (itemizeStack
.Number() == 0)
4714 TexOutput("\\par\\pard\n");
4715 issuedNewParagraph
= 1;
4716 WriteEnvironmentStyles();
4726 if (start && (arg_no == 1))
4729 wxNode *node = itemizeStack.First();
4731 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4733 int boxWidth = 20*ParseUnitArgument(GetArgData());
4735 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4736 int indentSize = indentValue + oldIndent;
4737 int indentSizeRight = indentSize + boxWidth;
4739 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4740 itemizeStack.Insert(struc);
4742 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4743 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4744 PushEnvironmentStyle(buf);
4748 if (!start && (arg_no == 2))
4750 PopEnvironmentStyle();
4751 if (itemizeStack.First())
4753 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4755 delete itemizeStack.First();
4757 if (itemizeStack.Number() == 0)
4759 TexOutput("\\par\\pard\n");
4760 issuedNewParagraph = 1;
4761 WriteEnvironmentStyles();
4768 case ltDOCUMENTSTYLE
:
4770 DefaultOnArgument(macroId
, arg_no
, start
);
4771 if (!start
&& !IsArgOptional())
4773 if (MinorDocumentStyleString
)
4775 if (StringMatch("twoside", MinorDocumentStyleString
))
4776 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4777 TexOutput("\\margmirror\\facingp\\sbkodd");
4778 if (StringMatch("twocolumn", MinorDocumentStyleString
))
4779 TexOutput("\\cols2");
4785 case ltSETHOTSPOTCOLOUR
:
4786 case ltSETHOTSPOTCOLOR
:
4790 char *text
= GetArgData();
4791 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4792 hotSpotColour
= TRUE
;
4794 hotSpotColour
= FALSE
;
4798 case ltSETTRANSPARENCY
:
4802 char *text
= GetArgData();
4803 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4804 bitmapTransparency
= TRUE
;
4806 bitmapTransparency
= FALSE
;
4810 case ltSETHOTSPOTUNDERLINE
:
4814 char *text
= GetArgData();
4815 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4816 hotSpotUnderline
= TRUE
;
4818 hotSpotUnderline
= FALSE
;
4824 if (arg_no
== 1 && start
)
4826 char *citeKey
= GetArgData();
4827 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4830 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4831 sprintf(buf
, "[%d]", citeCount
);
4832 ref
->sectionNumber
= copystring(buf
);
4835 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4836 sprintf(buf
, "{\\b [%d]} ", citeCount
);
4841 if (arg_no
== 2 && !start
)
4842 TexOutput("\\par\\pard\\par\n\n");
4846 case ltTHEBIBLIOGRAPHY
:
4848 if (start
&& (arg_no
== 1))
4852 SetCurrentOutputs(Contents
, Chapters
);
4856 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
4858 // If a non-custom page style, we generate the header now.
4859 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
4860 strcmp(PageStyle
, "empty") == 0 ||
4861 strcmp(PageStyle
, "headings") == 0))
4863 OutputRTFHeaderCommands();
4864 OutputRTFFooterCommands();
4867 // Need to reset the current numbering style, or RTF forgets it.
4868 OutputNumberStyle(currentNumberStyle
);
4869 SetCurrentOutput(Contents
);
4872 fprintf(Chapters
, "\\page\n");
4875 fprintf(Contents
, "\n{\\uldb %s}", ReferencesNameString
);
4877 fprintf(Contents
, "\\par\n\\pard{\\b %s}", ReferencesNameString
);
4879 startedSections
= TRUE
;
4882 fprintf(Chapters
, "\n${\\footnote %s}", ReferencesNameString
);
4884 char *topicName
= "bibliography";
4887 fprintf(Contents
, "{\\v %s}\\par\\pard\n", topicName
);
4889 fprintf(Contents
, "\\par\\par\\pard\n");
4893 fprintf(Chapters
, "\n#{\\footnote %s}\n", topicName
);
4894 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
4895 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ReferencesNameString
);
4896 GenerateKeywordsForTopic(topicName
);
4899 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4900 FileNameFromPath(FileRoot
), "Contents");
4904 SetCurrentOutput(Chapters
);
4905 char *styleCommand
= "";
4906 if (!winHelp
&& useHeadingStyles
)
4907 styleCommand
= "\\s1";
4908 fprintf(Chapters
, "\\pard{%s", (winHelp
? "\\keepn\\sa140\\sb140" : styleCommand
));
4909 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " References\\par\\pard}\n");
4919 * In Windows help, all keywords should be at the start of the
4920 * topic, but Latex \index commands can be anywhere in the text.
4921 * So we're going to have to build up lists of keywords for a topic,
4922 * and insert them on the second pass.
4924 * In linear RTF, we can embed the index entry now.
4929 // char *entry = GetArgData();
4931 OutputChunkToString(GetArgChunk(), buf
);
4936 AddKeyWordForTopic(CurrentTopic
, buf
);
4939 else GenerateIndexEntry(buf
);
4953 char *name
= GetArgData();
4954 int pos
= FindColourPosition(name
);
4957 sprintf(buf
, "{%s%d ", ((macroId
== ltFCOL
) ? "\\cf" : "\\cb"), pos
);
4962 sprintf(buf
, "Could not find colour name %s", name
);
4978 if (arg_no
== 2) TexOutput("}");
4985 if (start
&& !winHelp
&& useWord
)
4987 char *s
= GetArgData();
4988 // Only insert a bookmark here if it's not just been inserted
4989 // in a section heading.
4990 if ( !CurrentTopic
|| !(strcmp(CurrentTopic
, s
) == 0) )
4992 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4993 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4994 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
4998 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", s
,s
);
5006 if (start
&& useWord
&& !winHelp
)
5008 char *s
= GetArgData();
5009 fprintf(Chapters
, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
5018 inPopRefSection
= TRUE
;
5020 inPopRefSection
= FALSE
;
5023 case ltINSERTATLEVEL
:
5025 // This macro allows you to insert text at a different level
5026 // from the current level, e.g. into the Sections from within a subsubsection.
5027 if (!winHelp
& useWord
)
5029 static int currentLevelNo
= 1;
5030 static FILE* oldLevelFile
= Chapters
;
5037 oldLevelFile
= CurrentOutput1
;
5039 char *str
= GetArgData();
5040 currentLevelNo
= atoi(str
);
5042 // TODO: cope with article style (no chapters)
5043 switch (currentLevelNo
)
5047 outputFile
= Chapters
;
5052 outputFile
= Sections
;
5057 outputFile
= Subsections
;
5062 outputFile
= Subsubsections
;
5072 CurrentOutput1
= outputFile
;
5090 CurrentOutput1
= oldLevelFile
;
5098 return DefaultOnArgument(macroId
, arg_no
, start
);
5112 forbidParindent
= 0;
5113 contentsLineSection
= NULL
;
5114 contentsLineValue
= NULL
;
5115 descriptionItemArg
= NULL
;
5120 tableVerticalLineLeft
= FALSE
;
5121 tableVerticalLineRight
= FALSE
;
5123 startedSections
= FALSE
;
5127 if (InputFile
&& OutputFile
)
5129 // Do some RTF-specific transformations on all the strings,
5131 Text2RTF(GetTopLevelChunk());
5133 Contents
= fopen(TmpContentsName
, "w");
5134 Chapters
= fopen("chapters.rtf", "w");
5137 Sections
= fopen("sections.rtf", "w");
5138 Subsections
= fopen("subsections.rtf", "w");
5139 Subsubsections
= fopen("subsubsections.rtf", "w");
5140 Popups
= fopen("popups.rtf", "w");
5141 if (winHelpContents
)
5143 WinHelpContentsFile
= fopen(WinHelpContentsFileName
, "w");
5144 if (WinHelpContentsFile
)
5145 fprintf(WinHelpContentsFile
, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot
));
5148 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5150 OnError("Ouch! Could not open temporary file(s) for writing.");
5154 if (!Contents
|| !Chapters
)
5156 OnError("Ouch! Could not open temporary file(s) for writing.");
5162 fprintf(Chapters
, "\n#{\\footnote Contents}\n");
5163 fprintf(Chapters
, "${\\footnote Contents}\n");
5164 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
5165 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ContentsNameString
);
5166 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
5170 fprintf(Chapters
, "\\titlepg\n");
5171 fprintf(Contents
, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5174 // In WinHelp, Contents title takes font of title.
5175 // In linear RTF, same as chapter headings.
5176 fprintf(Contents
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5177 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5179 // By default, Swiss, 10 point.
5180 fprintf(Chapters
, "\\f2\\fs20\n");
5182 SetCurrentOutput(Chapters
);
5187 OnInform("Converting...");
5191 FILE *Header
= fopen("header.rtf", "w");
5194 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5197 WriteRTFHeader(Header
);
5198 fclose(Header
); Header
= NULL
;
5203 // fprintf(Contents, "\\page\n");
5204 fprintf(Chapters
, "\\page\n");
5205 fprintf(Sections
, "\\page\n");
5206 fprintf(Subsections
, "\\page\n");
5207 fprintf(Subsubsections
, "\\page\n\n");
5208 fprintf(Popups
, "\\page\n}\n");
5211 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5214 fclose(Contents
); Contents
= NULL
;
5215 fclose(Chapters
); Chapters
= NULL
;
5218 fclose(Sections
); Sections
= NULL
;
5219 fclose(Subsections
); Subsections
= NULL
;
5220 fclose(Subsubsections
); Subsubsections
= NULL
;
5221 fclose(Popups
); Popups
= NULL
;
5222 if (winHelpContents
)
5224 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5230 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5232 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5234 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5236 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5238 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile
);
5241 wxRemoveFile("tmp1.rtf");
5242 wxRemoveFile("tmp2.rtf");
5243 wxRemoveFile("tmp3.rtf");
5244 wxRemoveFile("tmp4.rtf");
5248 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5250 if (FileExists(OutputFile
))
5251 wxRemoveFile(OutputFile
);
5254 cwdStr
= wxGetWorkingDirectory();
5256 wxString outputDirStr
;
5257 outputDirStr
= wxPathOnly(OutputFile
);
5259 // Determine if the temp file and the output file are in the same directory,
5260 // and if they are, then just rename the temp file rather than copying
5261 // it, as this is much faster when working with large (multi-megabyte files)
5262 if ((wxStrcmp(outputDirStr
.c_str(),"") == 0) || // no path specified on output file
5263 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5265 wxRenameFile("tmp1.rtf", OutputFile
);
5269 wxCopyFile("tmp1.rtf", OutputFile
);
5273 wxRemoveFile("tmp1.rtf");
5276 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5278 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5280 wxCopyFile(TmpContentsName
, ContentsName
);
5281 wxRemoveFile(TmpContentsName
);
5284 wxRemoveFile("chapters.rtf");
5285 wxRemoveFile("header.rtf");
5289 wxRemoveFile("sections.rtf");
5290 wxRemoveFile("subsections.rtf");
5291 wxRemoveFile("subsubsections.rtf");
5292 wxRemoveFile("popups.rtf");
5294 if (winHelp
&& generateHPJ
)
5295 WriteHPJ(OutputFile
);