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
;
61 // Are we in verbatim mode? If so, format differently.
62 static bool inVerbatim
= FALSE
;
64 // We're in a series of PopRef topics, so don't output section headings
65 bool inPopRefSection
= FALSE
;
68 static bool hotSpotColour
= TRUE
;
69 static bool hotSpotUnderline
= TRUE
;
71 // Transparency (WHITE = transparent)
72 static bool bitmapTransparency
= TRUE
;
74 // Linear RTF requires us to set the style per section.
75 static char *currentNumberStyle
= NULL
;
76 static int currentItemSep
= 8;
77 static int CurrentTextWidth
= 8640; // Say, six inches
78 static int CurrentLeftMarginOdd
= 400;
79 static int CurrentLeftMarginEven
= 1440;
80 static int CurrentRightMarginOdd
= 1440;
81 static int CurrentRightMarginEven
= 400;
82 static int CurrentMarginParWidth
= 2000;
83 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
84 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
85 static int GutterWidth
= 2300;
87 // Two-column table dimensions, in twips
88 static int TwoColWidthA
= 1500;
89 static int TwoColWidthB
= 3000;
91 const int PageWidth
= 12242; // 8.25 inches wide for A4
95 * Flag to say we've just issued a \par\pard command, so don't
96 * repeat this unnecessarily.
100 int issuedNewParagraph
= 0;
102 // Need to know whether we're in a table or figure for benefit
103 // of listoffigures/listoftables
104 static bool inFigure
= FALSE
;
105 static bool inTable
= FALSE
;
111 static char *CurrentChapterName
= NULL
;
112 static char *CurrentSectionName
= NULL
;
113 static char *CurrentSubsectionName
= NULL
;
114 static char *CurrentTopic
= NULL
;
116 static bool InPopups()
118 if (CurrentChapterName
&& (strcmp(CurrentChapterName
, "popups") == 0))
120 if (CurrentSectionName
&& (strcmp(CurrentSectionName
, "popups") == 0))
125 static void SetCurrentTopic(char *s
)
127 if (CurrentTopic
) delete[] CurrentTopic
;
128 CurrentTopic
= copystring(s
);
131 void SetCurrentChapterName(char *s
)
133 if (CurrentChapterName
) delete[] CurrentChapterName
;
134 CurrentChapterName
= copystring(s
);
137 void SetCurrentSectionName(char *s
)
139 if (CurrentSectionName
) delete[] CurrentSectionName
;
140 CurrentSectionName
= copystring(s
);
143 void SetCurrentSubsectionName(char *s
)
145 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
146 CurrentSubsectionName
= copystring(s
);
150 // Indicate that a parent topic at level 'level' has children.
151 // Level 1 is a chapter, 2 is a section, etc.
152 void NotifyParentHasChildren(int parentLevel
)
154 char *parentTopic
= NULL
;
159 parentTopic
= CurrentChapterName
;
164 parentTopic
= CurrentSectionName
;
169 parentTopic
= CurrentSubsectionName
;
179 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
182 texTopic
= new TexTopic
;
183 TopicTable
.Put(parentTopic
, texTopic
);
185 texTopic
->hasChildren
= TRUE
;
189 // Have to keep a count of what levels are books, what are pages,
190 // in order to correct for a Win95 bug which means that if you
191 // have a book at level n, and then a page at level n, the page
192 // ends up on level n + 1.
194 bool ContentsLevels
[5];
196 // Reset below this level (starts from 1)
197 void ResetContentsLevels(int l
)
200 for (i
= l
; i
< 5; i
++)
201 ContentsLevels
[i
] = FALSE
;
203 // There are always books on the top level
204 ContentsLevels
[0] = TRUE
;
207 // Output a WinHelp section as a keyword, substituting
209 void OutputSectionKeyword(FILE *fd
)
211 OutputCurrentSectionToString(wxBuffer
);
214 for (i
= 0; i
< strlen(wxBuffer
); i
++)
215 if (wxBuffer
[i
] == ':')
217 // Don't write to index if there's some RTF in the string
218 else if ( wxBuffer
[i
] == '{' )
221 fprintf(fd
, "K{\\footnote {K} ");
222 fprintf(fd
, "%s", wxBuffer
);
227 // Write a line for the .cnt file, if we're doing this.
228 void WriteWinHelpContentsFileLine(char *topicName
, char *xitle
, int level
)
230 // First, convert any RTF characters to ASCII
234 while ( (xitle
[s
]!=0)&&(d
<255) )
236 char ch
=xitle
[s
]&0xff;
238 char ch1
=xitle
[s
+1]&0xff;
239 char ch2
=xitle
[s
+2]&0xff;
240 char ch3
=xitle
[s
+3]&0xff;
241 char ch4
=xitle
[s
+4]&0xff;
242 s
+=4; // next character
244 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]='ö'; a
=1; }
245 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]='ä'; a
=1; }
246 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]='ü'; a
=1; }
247 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]='Ö'; a
=1; }
248 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]='Ä'; a
=1; }
249 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]='Ü'; a
=1; }
251 // printf("!!!!! %04X %04X %04X %04X! \n",ch1,ch2,ch3,ch4);
259 // Section (2) becomes level 1 if it's an article.
260 if (DocumentStyle
== LATEX_ARTICLE
)
263 if (level
== 0) // Means we had a Chapter in an article, oops.
266 ResetContentsLevels(level
);
271 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
273 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
276 // If a previous section at this level was a book, we *have* to have a
277 // book not a page, because of a bug in WHC (or WinHelp 4).
278 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
280 // At this level, we have a pointer to a further hierarchy.
281 // So we need a 'book' consisting of (say) Chapter 1.
282 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
284 // Then we have a 'page' consisting of the text for this chapter
285 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
287 // Then we'll be writing out further pages or books at level + 1...
289 // Remember that at this level, we had a book and *must* for the
290 // remainder of sections at this level.
291 ContentsLevels
[level
-1] = TRUE
;
295 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
300 if (level
== 1 || ContentsLevels
[level
-1])
302 // Always have a book at level 1
303 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
304 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
305 ContentsLevels
[level
-1] = TRUE
;
308 // Probably doesn't have children if it hasn't been added to the topic table
309 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
314 void SplitIndexEntry(char *entry
, char *buf1
, char *buf2
)
316 int len
= strlen(entry
); int i
= 0;
317 while ((i
< len
) && entry
[i
] != '!')
318 { buf1
[i
] = entry
[i
]; i
++; }
319 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
324 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
330 * Output topic index entries in WinHelp RTF
333 void GenerateKeywordsForTopic(char *topic
)
335 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
339 wxStringList
*list
= texTopic
->keywords
;
342 wxNode
*node
= list
->First();
345 char *s
= (char *)node
->Data();
347 // Must separate out main entry form subentry (only 1 subentry allowed)
348 char buf1
[100]; char buf2
[100];
349 SplitIndexEntry(s
, buf1
, buf2
);
351 // Check for ':' which messes up index
353 for (i
= 0; i
< strlen(buf1
) ; i
++)
356 for (i
= 0; i
< strlen(buf2
) ; i
++)
360 // {K} is a strange fix to prevent words beginning with K not
361 // being indexed properly
362 TexOutput("K{\\footnote {K} ");
364 if (strlen(buf2
) > 0)
377 * Output index entry in linear RTF
381 void GenerateIndexEntry(char *entry
)
385 char buf1
[100]; char buf2
[100];
386 SplitIndexEntry(entry
, buf1
, buf2
);
388 TexOutput("{\\xe\\v {");
390 if (strlen(buf2
) > 0)
400 * Write a suitable RTF header.
404 void WriteColourTable(FILE *fd
)
406 fprintf(fd
, "{\\colortbl");
407 wxNode
*node
= ColourTable
.First();
410 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->Data();
411 fprintf(fd
, "\\red%d\\green%d\\blue%d;\n", entry
->red
, entry
->green
, entry
->blue
);
418 * Write heading style
422 void WriteHeadingStyle(FILE *fd
, int heading
)
428 fprintf(fd
, "\\b\\fs%d", chapterFont
*2);
433 fprintf(fd
, "\\b\\fs%d", sectionFont
*2);
438 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
443 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
451 void WriteRTFHeader(FILE *fd
)
453 fprintf(fd
, "{\\rtf1\\%s \\deff0\n", RTFCharset
);
454 fprintf(fd
, "{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n");
455 fprintf(fd
, "{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}");
459 fprintf(fd
, "{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n");
461 fprintf(fd
, "{\\s1 "); WriteHeadingStyle(fd
, 1); fprintf(fd
, "\\sbasedon0\\snext0 heading 1;}\n");
462 fprintf(fd
, "{\\s2 "); WriteHeadingStyle(fd
, 2); fprintf(fd
, "\\sbasedon0\\snext0 heading 2;}\n");
463 fprintf(fd
, "{\\s3 "); WriteHeadingStyle(fd
, 3); fprintf(fd
, "\\sbasedon0\\snext0 heading 3;}\n");
464 fprintf(fd
, "{\\s4 "); WriteHeadingStyle(fd
, 4); fprintf(fd
, "\\sbasedon0\\snext0 heading 4;}\n");
465 // Table of contents styles
466 fprintf(fd
, "{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n");
468 fprintf(fd
, "{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n");
469 fprintf(fd
, "{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n");
470 fprintf(fd
, "{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n");
473 fprintf(fd
, "{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n");
474 fprintf(fd
, "{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n");
475 fprintf(fd
, "{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n");
476 fprintf(fd
, "{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n");
477 fprintf(fd
, "{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n");
480 WriteColourTable(fd
);
481 fprintf(fd
, "\n\\ftnbj\\ftnrestart"); // Latex default is footnotes at bottom of page, not section.
485 void OutputNumberStyle(char *numberStyle
)
489 if (strcmp(numberStyle
, "arabic") == 0)
491 TexOutput("\\pgndec");
493 else if (strcmp(numberStyle
, "roman") == 0)
495 TexOutput("\\pgnlcrm");
497 else if (strcmp(numberStyle
, "Roman") == 0)
499 TexOutput("\\pgnucrm");
501 else if (strcmp(numberStyle
, "alph") == 0)
503 TexOutput("\\pgnlcltr");
505 else if (strcmp(numberStyle
, "Alph") == 0)
507 TexOutput("\\pgnucltr");
513 * Write a Windows help project file
516 bool WriteHPJ(char *filename
)
518 char hpjFilename
[256];
521 strcpy(hpjFilename
, filename
);
522 StripExtension(hpjFilename
);
523 strcat(hpjFilename
, ".hpj");
525 strcpy(helpFile
, FileNameFromPath(filename
));
526 StripExtension(helpFile
);
527 strcpy(rtfFile
, helpFile
);
528 strcat(helpFile
, ".hlp");
529 strcat(rtfFile
, ".rtf");
531 FILE *fd
= fopen(hpjFilename
, "w");
535 char *helpTitle
= winHelpTitle
;
537 helpTitle
= "Untitled";
539 char *thePath
= wxPathOnly(InputFile
);
542 fprintf(fd
, "[OPTIONS]\n");
543 fprintf(fd
, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath
);
544 fprintf(fd
, "TITLE=%s\n", helpTitle
);
545 fprintf(fd
, "CONTENTS=Contents\n");
547 if (winHelpVersion
> 3)
549 fprintf(fd
, "; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n");
550 fprintf(fd
, "COMPRESS=8 Zeck\n");
551 fprintf(fd
, "LCID=0x809 0x0 0x0 ;English (British)\n");
552 fprintf(fd
, "HLP=.\\%s.hlp\n", wxFileNameFromPath(FileRoot
));
556 fprintf(fd
, "COMPRESS=HIGH\n");
560 if (winHelpVersion
> 3)
562 fprintf(fd
, "[WINDOWS]\n");
563 fprintf(fd
, "Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n");
567 fprintf(fd
, "[FILES]\n%s\n\n", rtfFile
);
568 fprintf(fd
, "[CONFIG]\n");
570 fprintf(fd
, "CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n", helpFile
);
571 fprintf(fd
, "BrowseButtons()\n\n");
572 fprintf(fd
, "[MAP]\n\n[BITMAPS]\n\n");
579 * Given a TexChunk with a string value, scans through the string
580 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
581 * and inserting spaces at the start of lines since in Latex, a newline
582 * implies a space, but not in RTF.
586 void ProcessText2RTF(TexChunk
*chunk
)
588 bool changed
= FALSE
;
592 int len
= strlen(chunk
->value
);
595 ch
= chunk
->value
[i
];
601 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "\\par\n"); ptr
+= 5;
607 // If the first character of the next line is ASCII,
608 // put a space in. Implicit in Latex, not in RTF.
610 The reason this is difficult is that you don't really know
611 where a space would be appropriate. If you always put in a space
612 when you find a newline, unwanted spaces appear in the text.
614 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
615 !isspace(chunk
->value
[i
+1])) ||
616 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
617 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
618 !isspace(chunk
->value
[i
+2]))))
621 // DOS files have a 13 after the 10
625 if (chunk
->value
[i
] == 13)
632 BigBuffer
[ptr
] = ' ';
635 // Note that the actual ASCII character seen is dealt with in the next
646 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
648 BigBuffer
[ptr
] = '"'; ptr
++;
652 else if (!inVerbatim
&& ch
== '`') // Change ` to '
654 BigBuffer
[ptr
] = 39; ptr
++;
658 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
660 BigBuffer
[ptr
] = '\\'; ptr
++;
661 BigBuffer
[ptr
] = '\\'; ptr
++;
665 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curly bracket
667 BigBuffer
[ptr
] = '\\'; ptr
++;
668 BigBuffer
[ptr
] = ch
; ptr
++;
683 delete[] chunk
->value
;
684 chunk
->value
= copystring(BigBuffer
);
689 * Scan through all chunks starting from the given one,
690 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
691 * This should be called after Tex2Any has parsed the file,
692 * and before TraverseDocument is called.
696 void Text2RTF(TexChunk
*chunk
)
699 if (stopRunning
) return;
703 case CHUNK_TYPE_MACRO
:
705 TexMacroDef
*def
= chunk
->def
;
706 if (def
&& def
->ignore
)
709 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
712 wxNode
*node
= chunk
->children
.First();
715 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
716 Text2RTF(child_chunk
);
720 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
727 wxNode
*node
= chunk
->children
.First();
730 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
731 Text2RTF(child_chunk
);
737 case CHUNK_TYPE_STRING
:
740 ProcessText2RTF(chunk
);
752 static long browseId
= 0;
753 char *GetBrowseString(void)
757 sprintf(buf
, "%ld", browseId
);
758 int noZeroes
= 5-strlen(buf
);
759 strcpy(browseBuf
, "browse");
760 for (int i
= 0; i
< noZeroes
; i
++)
761 strcat(browseBuf
, "0");
762 strcat(browseBuf
, buf
);
767 * Keeping track of environments to restore the styles after \pard.
768 * Push strings like "\qc" onto stack.
772 void PushEnvironmentStyle(char *style
)
774 environmentStack
.Add(style
);
777 void PopEnvironmentStyle(void)
779 wxNode
*node
= environmentStack
.Last();
782 char *val
= (char *)node
->Data();
788 // Write out the styles, most recent first.
789 void WriteEnvironmentStyles(void)
791 wxNode
*node
= environmentStack
.Last();
794 char *val
= (char *)node
->Data();
798 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
801 sprintf(buf
, "\\fi%d", ParIndent
*20); // Convert points to TWIPS
804 if (environmentStack
.Number() > 0 || (ParIndent
> 0))
814 void OutputRTFHeaderCommands(void)
817 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
819 TexOutput("{\\headerl }{\\headerr }");
821 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
823 TexOutput("{\\headerl }{\\headerr }");
825 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
828 TexOutput("{\\headerl\\fi0 ");
831 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
833 TexOutput("{\\i \\qr ");
834 if (DocumentStyle
== LATEX_ARTICLE
)
836 sprintf(buf
, "SECTION %d", sectionNo
);
841 sprintf(buf
, "CHAPTER %d: ", chapterNo
);
844 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
845 TexOutput("}\\par\\pard}");
848 TexOutput("{\\headerr\\fi0 ");
851 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
853 TexOutput("{\\i \\qc ");
854 if (DocumentStyle
== LATEX_ARTICLE
)
856 sprintf(buf
, "SECTION %d", sectionNo
);
861 sprintf(buf
, "CHAPTER %d", chapterNo
);
864 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
865 TexOutput("}\\par\\pard}");
869 int oldForbidResetPar
= forbidResetPar
;
872 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
874 TexOutput("{\\headerl\\fi0 ");
877 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
881 if (!CentreHeaderEven
&& !RightHeaderEven
)
883 TraverseChildrenFromChunk(LeftHeaderEven
);
885 if (CentreHeaderEven
)
887 if (!LeftHeaderEven
&& !RightHeaderEven
)
890 TexOutput("\\tab\\tab\\tab ");
891 TraverseChildrenFromChunk(CentreHeaderEven
);
895 if (!LeftHeaderEven
&& !CentreHeaderEven
)
898 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
899 TraverseChildrenFromChunk(RightHeaderEven
);
901 TexOutput("\\par\\pard}");
904 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
906 TexOutput("{\\headerr\\fi0 ");
909 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
913 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
915 TraverseChildrenFromChunk(LeftHeaderOdd
);
919 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
922 TexOutput("\\tab\\tab\\tab ");
923 TraverseChildrenFromChunk(CentreHeaderOdd
);
927 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
930 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
931 TraverseChildrenFromChunk(RightHeaderOdd
);
933 TexOutput("\\par\\pard}");
935 // As an approximation, don't put a header on the first page of a section.
936 // This may not always be desired, but it's a reasonable guess.
937 TexOutput("{\\headerf }");
939 forbidResetPar
= oldForbidResetPar
;
943 void OutputRTFFooterCommands(void)
945 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
947 TexOutput("{\\footerl\\fi0 ");
949 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
951 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
952 TexOutput("}\\par\\pard}");
954 TexOutput("{\\footerr\\fi0 ");
956 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
958 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
959 TexOutput("}\\par\\pard}");
961 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
963 TexOutput("{\\footerl }{\\footerr }");
965 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
967 TexOutput("{\\footerl }{\\footerr }");
971 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
973 TexOutput("{\\footerl\\fi0 ");
975 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
978 if (!CentreFooterEven
&& !RightFooterEven
)
980 TraverseChildrenFromChunk(LeftFooterEven
);
982 if (CentreFooterEven
)
984 if (!LeftFooterEven
&& !RightFooterEven
)
987 TexOutput("\\tab\\tab\\tab ");
988 TraverseChildrenFromChunk(CentreFooterEven
);
992 if (!LeftFooterEven
&& !CentreFooterEven
)
995 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
996 TraverseChildrenFromChunk(RightFooterEven
);
998 TexOutput("\\par\\pard}");
1001 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1003 TexOutput("{\\footerr\\fi0 ");
1005 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
1008 if (!CentreFooterOdd
&& !RightFooterOdd
)
1010 TraverseChildrenFromChunk(LeftFooterOdd
);
1012 if (CentreFooterOdd
)
1014 if (!LeftFooterOdd
&& !RightFooterOdd
)
1017 TexOutput("\\tab\\tab\\tab ");
1018 TraverseChildrenFromChunk(CentreFooterOdd
);
1022 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1025 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1026 TraverseChildrenFromChunk(RightFooterOdd
);
1028 TexOutput("\\par\\pard}");
1031 // As an approximation, put a footer on the first page of a section.
1032 // This may not always be desired, but it's a reasonable guess.
1033 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1035 TexOutput("{\\footerf\\fi0 ");
1038 if (!CentreFooterOdd
&& !RightFooterOdd
)
1040 TraverseChildrenFromChunk(LeftFooterOdd
);
1042 if (CentreFooterOdd
)
1044 if (!LeftFooterOdd
&& !RightFooterOdd
)
1047 TexOutput("\\tab\\tab\\tab ");
1048 TraverseChildrenFromChunk(CentreFooterOdd
);
1052 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1055 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1056 TraverseChildrenFromChunk(RightFooterOdd
);
1058 TexOutput("\\par\\pard}");
1063 // Called on start/end of macro examination
1064 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1068 sprintf(tmpBuf, "%d (%d)", macroId, (int)start);
1069 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1070 OutputDebugString("\n"); wxYield();
1073 // ltLABEL is included here because after a section but BEFORE
1074 // the label is seen, a new paragraph is issued. Don't upset this by
1075 // immediately forgetting we've done it.
1076 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1077 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1078 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1079 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1080 macroId
!= ltPAGENUMBERING
&&
1081 (forbidResetPar
== 0)))
1083 issuedNewParagraph
= 0;
1091 case ltCHAPTERHEADING
:
1092 case ltCHAPTERHEADINGSTAR
:
1100 subsubsectionNo
= 0;
1103 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1106 char *topicName
= FindTopicName(GetNextChunk());
1107 SetCurrentChapterName(topicName
);
1109 if (winHelpContents
&& winHelp
&& !InPopups())
1111 OutputCurrentSectionToString(wxBuffer
);
1112 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 1);
1114 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1119 fprintf(Contents
, "\n{\\uldb ");
1120 fprintf(Chapters
, "\\page");
1121 fprintf(Chapters
, "\n${\\footnote ");
1123 SetCurrentOutputs(Contents
, Chapters
);
1125 SetCurrentOutput(Chapters
);
1129 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
1131 // If a non-custom page style, we generate the header now.
1132 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1133 strcmp(PageStyle
, "empty") == 0 ||
1134 strcmp(PageStyle
, "headings") == 0))
1136 OutputRTFHeaderCommands();
1137 OutputRTFFooterCommands();
1140 // Need to reset the current numbering style, or RTF forgets it.
1141 SetCurrentOutput(Chapters
);
1142 OutputNumberStyle(currentNumberStyle
);
1144 SetCurrentOutput(Contents
);
1148 if (macroId
== ltCHAPTER
)
1151 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", chapterNo
);
1153 else if (macroId
== ltCHAPTERHEADING
)
1155 fprintf(Contents
, "\\par\n\\pard{\\b ");
1157 else SetCurrentOutput(NULL
); // No entry in table of contents
1161 startedSections
= TRUE
;
1163 // Output heading to contents page
1166 OutputCurrentSection();
1169 fprintf(Contents
, "}{\\v %s}\\par\\pard\n", topicName
);
1170 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1171 fprintf(Contents
, "}\\par\\par\\pard\n");
1173 // From here, just output to chapter
1174 SetCurrentOutput(Chapters
);
1179 fprintf(Chapters
, "}\n#{\\footnote %s}\n", topicName
);
1180 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
1182 OutputSectionKeyword(Chapters
);
1184 GenerateKeywordsForTopic(topicName
);
1187 // If we're generating a .cnt file, we don't want to be able
1188 // jump up to the old-style contents page, so disable it.
1189 if (winHelpContents
)
1190 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
1192 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1193 FileNameFromPath(FileRoot
), "Contents");
1199 char *styleCommand
= "";
1200 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1201 styleCommand
= "\\s1";
1202 fprintf(Chapters
, "\\pard{%s", ((winHelp
&& !InPopups()) ? "\\keepn\\sa140\\sb140" : styleCommand
));
1203 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " ");
1206 if (macroId
== ltCHAPTER
)
1209 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1210 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1212 fprintf(Chapters
, "%d. ", chapterNo
);
1216 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1219 OutputCurrentSection();
1220 TexOutput("\\par\\pard}\\par\n");
1222 issuedNewParagraph
= 2;
1228 case ltSECTIONHEADING
:
1229 case ltSECTIONHEADINGSTAR
:
1233 if (DocumentStyle
== LATEX_ARTICLE
)
1234 jumpFrom
= Contents
;
1236 jumpFrom
= Chapters
;
1241 subsubsectionNo
= 0;
1242 if (DocumentStyle
== LATEX_ARTICLE
)
1245 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1248 char *topicName
= FindTopicName(GetNextChunk());
1249 SetCurrentSectionName(topicName
);
1250 NotifyParentHasChildren(1);
1251 if (winHelpContents
&& winHelp
&& !InPopups())
1253 OutputCurrentSectionToString(wxBuffer
);
1254 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 2);
1256 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1260 SetCurrentOutputs(jumpFrom
, Sections
);
1261 // Newline for a new section if this is an article
1262 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1263 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1264 fprintf(Sections
, "\\page\n");
1267 fprintf(jumpFrom
, "\n{\\uldb ");
1271 if (DocumentStyle
== LATEX_ARTICLE
)
1273 TexOutput("\\sect\\pgncont\n");
1274 // If a non-custom page style, we generate the header now.
1275 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1276 strcmp(PageStyle
, "empty") == 0 ||
1277 strcmp(PageStyle
, "headings") == 0))
1279 OutputRTFHeaderCommands();
1280 OutputRTFFooterCommands();
1283 SetCurrentOutput(Contents
);
1285 if (macroId
== ltSECTION
)
1289 if (DocumentStyle
== LATEX_REPORT
)
1290 fprintf(Contents
, "\n\\pard{\\tab %d.%d\\tab ", chapterNo
, sectionNo
);
1292 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", sectionNo
);
1295 else if (macroId
== ltSECTIONHEADING
)
1299 if (DocumentStyle
== LATEX_REPORT
)
1300 fprintf(Contents
, "\n\\pard{\\tab "); //, chapterNo, sectionNo);
1302 fprintf(Contents
, "\\par\n\\pard{\\b "); //, sectionNo);
1305 else SetCurrentOutput(NULL
);
1308 if (startedSections
)
1311 fprintf(Sections
, "\\page\n");
1313 startedSections
= TRUE
;
1316 fprintf(Sections
, "\n${\\footnote ");
1318 // Output heading to contents page
1320 OutputCurrentSection();
1325 fprintf(jumpFrom
, "}{\\v %s}\\par\\pard\n", topicName
);
1327 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1329 if (DocumentStyle
== LATEX_REPORT
)
1330 fprintf(Contents
, "}\\par\\pard\n");
1332 fprintf(Contents
, "}\\par\\par\\pard\n");
1335 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1339 fprintf(Sections
, "}\n#{\\footnote %s}\n", topicName
);
1340 fprintf(Sections
, "+{\\footnote %s}\n", GetBrowseString());
1341 OutputSectionKeyword(Sections
);
1342 GenerateKeywordsForTopic(topicName
);
1345 if (DocumentStyle
== LATEX_ARTICLE
)
1347 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1348 FileNameFromPath(FileRoot
), "Contents");
1350 else if (CurrentChapterName
)
1352 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1353 FileNameFromPath(FileRoot
), CurrentChapterName
);
1360 char *styleCommand
= "";
1361 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1363 if (DocumentStyle
== LATEX_ARTICLE
)
1364 styleCommand
= "\\s1";
1366 styleCommand
= "\\s2";
1369 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1370 keep
= "\\keepn\\sa140\\sb140";
1372 fprintf(winHelp
? Sections
: Chapters
, "\\pard{%s%s",
1373 keep
, styleCommand
);
1375 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1376 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1377 fprintf(winHelp
? Sections
: Chapters
, " ");
1381 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1383 if (DocumentStyle
== LATEX_REPORT
)
1386 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo,
1387 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1390 fprintf(Chapters
, "%d.%d. ", chapterNo
, sectionNo
);
1395 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1396 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1399 fprintf(Chapters
, "%d. ", sectionNo
);
1404 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1407 OutputCurrentSection();
1408 TexOutput("\\par\\pard}\\par\n");
1410 issuedNewParagraph
= 2;
1415 case ltSUBSECTIONSTAR
:
1416 case ltMEMBERSECTION
:
1417 case ltFUNCTIONSECTION
:
1421 if (winHelp
&& !Sections
)
1423 OnError("You cannot have a subsection before a section!");
1427 subsubsectionNo
= 0;
1429 if (macroId
!= ltSUBSECTIONSTAR
)
1432 char *topicName
= FindTopicName(GetNextChunk());
1433 SetCurrentSubsectionName(topicName
);
1434 NotifyParentHasChildren(2);
1435 if (winHelpContents
&& winHelp
&& !InPopups())
1437 OutputCurrentSectionToString(wxBuffer
);
1438 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 3);
1440 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1444 SetCurrentOutputs(Sections
, Subsections
);
1445 SetCurrentOutputs(Sections
, Subsections
);
1447 fprintf(Sections
, "\n{\\uldb ");
1451 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1452 (macroId
!= ltFUNCTIONSECTION
))
1454 SetCurrentOutput(Contents
);
1455 if (DocumentStyle
== LATEX_REPORT
)
1456 fprintf(Contents
, "\n\\pard\\tab\\tab %d.%d.%d\\tab ", chapterNo
, sectionNo
, subsectionNo
);
1458 fprintf(Contents
, "\n\\pard\\tab %d.%d\\tab ", sectionNo
, subsectionNo
);
1459 } else SetCurrentOutput(NULL
);
1461 if (startedSections
)
1466 fprintf(Subsections
, "\\page\n");
1469 fprintf(Chapters
, "\\par\n");
1471 startedSections
= TRUE
;
1474 fprintf(Subsections
, "\n${\\footnote ");
1476 // Output to contents page
1478 OutputCurrentSection();
1483 fprintf(Sections
, "}{\\v %s}\\par\\pard\n", topicName
);
1485 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1486 (macroId
!= ltFUNCTIONSECTION
))
1487 fprintf(Contents
, "\\par\\pard\n");
1489 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1492 fprintf(Subsections
, "}\n#{\\footnote %s}\n", topicName
);
1493 fprintf(Subsections
, "+{\\footnote %s}\n", GetBrowseString());
1494 OutputSectionKeyword(Subsections
);
1495 GenerateKeywordsForTopic(topicName
);
1496 if (useUpButton
&& CurrentSectionName
)
1498 fprintf(Subsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1499 FileNameFromPath(FileRoot
), CurrentSectionName
);
1502 if (!winHelp
&& indexSubsections
&& useWord
)
1504 // Insert index entry for this subsection
1505 TexOutput("{\\xe\\v {");
1506 OutputCurrentSection();
1512 char *styleCommand
= "";
1513 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1515 if (DocumentStyle
== LATEX_ARTICLE
)
1516 styleCommand
= "\\s2";
1518 styleCommand
= "\\s3";
1521 if (winHelp
&& !InPopups())
1522 keep
= "\\keepn\\sa140\\sb140";
1524 fprintf(winHelp
? Subsections
: Chapters
, "\\pard{%s%s",
1525 keep
, styleCommand
);
1527 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1528 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1529 fprintf(winHelp
? Subsections
: Chapters
, " ");
1533 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1534 (macroId
!= ltFUNCTIONSECTION
))
1536 if (DocumentStyle
== LATEX_REPORT
)
1539 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo,
1540 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1543 fprintf(Chapters
, "%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
);
1548 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo,
1549 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1552 fprintf(Chapters
, "%d.%d. ", sectionNo
, subsectionNo
);
1557 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1560 OutputCurrentSection(); // Repeat section header
1561 TexOutput("\\par\\pard}\\par\n");
1563 issuedNewParagraph
= 2;
1568 case ltSUBSUBSECTION
:
1569 case ltSUBSUBSECTIONSTAR
:
1573 if (winHelp
&& !Subsections
)
1575 OnError("You cannot have a subsubsection before a subsection!");
1579 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1582 char *topicName
= FindTopicName(GetNextChunk());
1583 SetCurrentTopic(topicName
);
1584 NotifyParentHasChildren(3);
1585 if (winHelpContents
&& winHelp
)
1587 OutputCurrentSectionToString(wxBuffer
);
1588 WriteWinHelpContentsFileLine(topicName
, wxBuffer
, 4);
1590 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1594 SetCurrentOutputs(Subsections
, Subsubsections
);
1595 fprintf(Subsections
, "\n{\\uldb ");
1599 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1601 if (DocumentStyle
== LATEX_ARTICLE
)
1603 SetCurrentOutput(Contents
);
1604 fprintf(Contents
, "\n\\tab\\tab %d.%d.%d\\tab ",
1605 sectionNo
, subsectionNo
, subsubsectionNo
);
1608 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1611 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1614 if (startedSections
)
1617 fprintf(Subsubsections
, "\\page\n");
1619 fprintf(Chapters
, "\\par\n");
1622 startedSections
= TRUE
;
1625 fprintf(Subsubsections
, "\n${\\footnote ");
1627 // Output header to contents page
1628 OutputCurrentSection();
1631 fprintf(Subsections
, "}{\\v %s}\\par\\pard\n", topicName
);
1632 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1633 fprintf(Contents
, "\\par\\pard\n");
1635 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1638 fprintf(Subsubsections
, "}\n#{\\footnote %s}\n", topicName
);
1639 fprintf(Subsubsections
, "+{\\footnote %s}\n", GetBrowseString());
1640 OutputSectionKeyword(Subsubsections
);
1641 GenerateKeywordsForTopic(topicName
);
1642 if (useUpButton
&& CurrentSubsectionName
)
1644 fprintf(Subsubsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1645 FileNameFromPath(FileRoot
), CurrentSubsectionName
);
1648 if (!winHelp
&& indexSubsections
&& useWord
)
1650 // Insert index entry for this subsubsection
1651 TexOutput("{\\xe\\v {");
1652 OutputCurrentSection();
1656 char *styleCommand
= "";
1657 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1659 if (DocumentStyle
== LATEX_ARTICLE
)
1660 styleCommand
= "\\s3";
1662 styleCommand
= "\\s4";
1666 keep
= "\\keepn\\sa140\\sb140";
1668 fprintf(winHelp
? Subsubsections
: Chapters
, "\\pard{%s%s",
1669 keep
, styleCommand
);
1671 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1672 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1673 fprintf(winHelp
? Subsubsections
: Chapters
, " ");
1677 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1679 if (DocumentStyle
== LATEX_ARTICLE
)
1682 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo, subsubsectionNo,
1683 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1686 fprintf(Chapters
, "%d.%d.%d. ", sectionNo
, subsectionNo
, subsubsectionNo
);
1691 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1692 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1695 fprintf(Chapters
, "%d.%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1700 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1703 OutputCurrentSection(); // Repeat section header
1704 TexOutput("\\par\\pard}\\par\n");
1705 issuedNewParagraph
= 2;
1706 // if (winHelp) TexOutput("\\pard");
1716 char *topicName
= FindTopicName(GetNextChunk());
1717 SetCurrentTopic(topicName
);
1719 TexOutput("\\pard\\par");
1726 if (winHelp
|| !useWord
)
1728 if (DocumentStyle
!= LATEX_ARTICLE
)
1729 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1731 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1735 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1736 FigureNameString
, topicName
, topicName
);
1743 if (winHelp
|| !useWord
)
1745 if (DocumentStyle
!= LATEX_ARTICLE
)
1746 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1748 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1752 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1753 TableNameString
, topicName
, topicName
);
1757 int n
= (inTable
? tableNo
: figureNo
);
1758 AddTexRef(topicName
, NULL
, NULL
,
1759 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1760 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1763 TexOutput("\\qc{\\b ");
1765 TexOutput("\\ql{\\b ");
1768 OutputCurrentSection();
1770 TexOutput("}\\par\\pard\n");
1771 WriteEnvironmentStyles();
1778 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1788 TexOutput("K{\\footnote {K} ");
1789 suppressNameDecoration
= TRUE
;
1790 TraverseChildrenFromChunk(currentMember
);
1791 suppressNameDecoration
= FALSE
;
1794 if (!winHelp
&& useWord
)
1796 // Insert index entry for this function
1797 TexOutput("{\\xe\\v {");
1798 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1799 TraverseChildrenFromChunk(currentMember
);
1800 suppressNameDecoration
= FALSE
;
1808 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1818 TexOutput("K{\\footnote {K} ");
1819 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1820 TraverseChildrenFromChunk(currentMember
);
1821 suppressNameDecoration
= FALSE
;
1824 if (!winHelp
&& useWord
)
1826 // Insert index entry for this function
1827 TexOutput("{\\xe\\v {");
1828 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1829 TraverseChildrenFromChunk(currentMember
);
1830 suppressNameDecoration
= FALSE
;
1838 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1848 TexOutput("K{\\footnote {K} ");
1849 TraverseChildrenFromChunk(currentMember
);
1852 if (!winHelp
&& useWord
)
1854 // Insert index entry for this function
1855 TexOutput("{\\xe\\v {");
1856 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1857 TraverseChildrenFromChunk(currentMember
);
1858 suppressNameDecoration
= FALSE
;
1867 SetCurrentOutput(Chapters
);
1870 case ltTABLEOFCONTENTS
:
1874 if (!winHelp
&& useWord
)
1876 // Insert Word for Windows table of contents
1877 TexOutput("\\par\\pard\\pgnrestart\\sect\\titlepg");
1879 // In linear RTF, same as chapter headings.
1880 sprintf(buf
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n", chapterFont
*2, ContentsNameString
);
1883 sprintf(buf
, "{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n", contentsDepth
);
1885 // TexOutput("\\sect\\sectd");
1889 FILE *fd
= fopen(ContentsName
, "r");
1902 TexOutput("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n");
1903 OnInform("Run Tex2RTF again to include contents page.");
1912 // TexOutput("{\\b void}");
1918 TexOutput("{\\scaps HARDY}");
1924 TexOutput("wxCLIPS");
1927 case ltSPECIALAMPERSAND
:
1932 TexOutput("\\cell ");
1938 case ltSPECIALTILDE
:
1949 case ltBACKSLASHCHAR
:
1955 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
1956 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
1957 int currentWidth
= 0;
1958 for (int i
= 0; i
< noColumns
; i
++)
1960 currentWidth
+= TableData
[i
].width
;
1961 if (TableData
[i
].rightBorder
)
1962 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
1964 if (TableData
[i
].leftBorder
)
1965 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
1967 sprintf(buf
, "\\cellx%d", currentWidth
);
1970 TexOutput("\\pard\\intbl\n");
1973 TexOutput("\\line\n");
1983 case ltRTFSP
: // Explicit space, RTF only
1995 if (indentLevel
> 0)
1997 TexOutput("\\par\\par\n");
1998 issuedNewParagraph
= 2;
2002 // Top-level list: issue a new paragraph if we haven't
2004 if (!issuedNewParagraph
)
2006 TexOutput("\\par\\pard");
2007 WriteEnvironmentStyles();
2008 issuedNewParagraph
= 1;
2010 else issuedNewParagraph
= 0;
2013 TexOutput("\\fi0\n");
2015 if (macroId
== ltENUMERATE
)
2016 listType
= LATEX_ENUMERATE
;
2017 else if (macroId
== ltITEMIZE
)
2018 listType
= LATEX_ITEMIZE
;
2020 listType
= LATEX_DESCRIPTION
;
2023 wxNode
*node
= itemizeStack
.First();
2025 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2027 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2028 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2030 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2031 itemizeStack
.Insert(struc
);
2033 sprintf(buf
, "\\tx%d\\tx%d\\li%d", indentSize1
, indentSize2
, indentSize2
);
2034 PushEnvironmentStyle(buf
);
2038 currentItemSep
= 8; // Reset to the default
2040 PopEnvironmentStyle();
2042 if (itemizeStack
.First())
2044 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2046 delete itemizeStack
.First();
2048 /* Change 18/7/97 - don't know why we wish to do this
2049 if (itemizeStack.Number() == 0)
2051 OnMacro(ltPAR, 0, TRUE);
2052 OnMacro(ltPAR, 0, FALSE);
2053 issuedNewParagraph = 2;
2065 wxNode
*node
= itemizeStack
.First();
2067 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2069 int indentSize
= oldIndent
+ TwoColWidthA
;
2071 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2072 itemizeStack
.Insert(struc
);
2074 // sprintf(buf, "\\tx%d\\li%d\\ri%d", indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2075 sprintf(buf
, "\\tx%d\\li%d", indentSize
, indentSize
);
2076 PushEnvironmentStyle(buf
);
2081 PopEnvironmentStyle();
2082 if (itemizeStack
.First())
2084 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2086 delete itemizeStack
.First();
2090 TexOutput("\\pard\n");
2091 WriteEnvironmentStyles();
2093 /* why do we need this? */
2094 if (itemizeStack
.Number() == 0)
2096 issuedNewParagraph
= 0;
2097 OnMacro(ltPAR
, 0, TRUE
);
2098 OnMacro(ltPAR
, 0, FALSE
);
2105 wxNode
*node
= itemizeStack
.First();
2108 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2111 struc
->currentItem
+= 1;
2114 int indentSize1
= struc
->labelIndentation
;
2115 int indentSize2
= struc
->indentation
;
2118 if (struc
->currentItem
> 1)
2120 if (currentItemSep
> 0)
2124 // WriteEnvironmentStyles();
2127 sprintf(buf
, "\\tx%d\\tx%d\\li%d\\fi-%d\n", indentSize1
, indentSize2
,
2128 indentSize2
, 20*itemIndentTab
);
2131 switch (struc
->listType
)
2133 case LATEX_ENUMERATE
:
2135 if (descriptionItemArg
)
2137 TexOutput("\\tab{ ");
2138 TraverseChildrenFromChunk(descriptionItemArg
);
2139 TexOutput("}\\tab");
2140 descriptionItemArg
= NULL
;
2144 sprintf(indentBuf
, "\\tab{\\b %d.}\\tab", struc
->currentItem
);
2145 TexOutput(indentBuf
);
2151 if (descriptionItemArg
)
2153 TexOutput("\\tab{ ");
2154 TraverseChildrenFromChunk(descriptionItemArg
);
2155 TexOutput("}\\tab");
2156 descriptionItemArg
= NULL
;
2160 if (bulletFile
&& winHelp
)
2162 if (winHelpVersion
> 3) // Transparent bitmap
2163 sprintf(indentBuf
, "\\tab\\{bmct %s\\}\\tab", bulletFile
);
2165 sprintf(indentBuf
, "\\tab\\{bmc %s\\}\\tab", bulletFile
);
2168 sprintf(indentBuf
, "\\tab{\\b o}\\tab");
2170 sprintf(indentBuf
, "\\tab{\\f1\\'b7}\\tab");
2171 TexOutput(indentBuf
);
2176 case LATEX_DESCRIPTION
:
2178 if (descriptionItemArg
)
2180 TexOutput("\\tab{\\b ");
2181 TraverseChildrenFromChunk(descriptionItemArg
);
2183 descriptionItemArg
= NULL
;
2193 case ltTWOCOLITEMRULED
:
2195 wxNode
*node
= itemizeStack
.First();
2198 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2201 struc
->currentItem
+= 1;
2203 int indentSize
= struc
->indentation
;
2205 wxNode
*node2
= NULL
;
2206 if (itemizeStack
.Number() > 1) // TODO: do I actually mean Nth(0) here??
2207 node2
= itemizeStack
.Nth(1);
2209 oldIndent
= ((ItemizeStruc
*)node2
->Data())->indentation
;
2212 if (struc
->currentItem
> 1)
2214 if (currentItemSep
> 0)
2217 // WriteEnvironmentStyles();
2220 // sprintf(buf, "\\tx%d\\li%d\\fi-%d\\ri%d\n", TwoColWidthA,
2221 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2223 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA,
2224 TwoColWidthA, TwoColWidthA);
2226 sprintf(buf
, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA
+ oldIndent
,
2227 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2238 if (macroId
== ltVERBATIM
)
2240 if (!issuedNewParagraph
)
2242 TexOutput("\\par\\pard");
2243 WriteEnvironmentStyles();
2244 issuedNewParagraph
= 1;
2246 else issuedNewParagraph
= 0;
2248 sprintf(buf
, "{\\f3\\fs20 ");
2254 if (macroId
== ltVERBATIM
)
2256 TexOutput("\\pard\n");
2257 // issuedNewParagraph = 1;
2258 WriteEnvironmentStyles();
2268 TexOutput("\\fi0\\qc ");
2270 PushEnvironmentStyle("\\qc");
2274 TexOutput("\\par\\pard\n");
2275 issuedNewParagraph
= 1;
2277 PopEnvironmentStyle();
2278 WriteEnvironmentStyles();
2286 TexOutput("\\fi0\\ql ");
2288 PushEnvironmentStyle("\\ql");
2292 TexOutput("\\par\\pard\n");
2293 issuedNewParagraph
= 1;
2295 PopEnvironmentStyle();
2296 WriteEnvironmentStyles();
2304 TexOutput("\\fi0\\qr ");
2306 PushEnvironmentStyle("\\qr");
2310 TexOutput("\\par\\pard\n");
2311 issuedNewParagraph
= 1;
2313 PopEnvironmentStyle();
2314 WriteEnvironmentStyles();
2319 case ltFOOTNOTESIZE
:
2323 sprintf(buf
, "{\\fs%d\n", smallFont
*2);
2326 else TexOutput("}\n");
2334 sprintf(buf
, "{\\fs%d\n", tinyFont
*2);
2337 else TexOutput("}\n");
2344 sprintf(buf
, "{\\fs%d\n", normalFont
*2);
2347 else TexOutput("}\n");
2354 sprintf(buf
, "{\\fs%d\n", largeFont1
*2);
2357 else TexOutput("}\n");
2364 sprintf(buf
, "{\\fs%d\n", LargeFont2
*2);
2367 else TexOutput("}\n");
2374 sprintf(buf
, "{\\fs%d\n", LARGEFont3
*2);
2377 else TexOutput("}\n");
2384 sprintf(buf
, "{\\fs%d\n", hugeFont1
*2);
2387 else TexOutput("}\n");
2394 sprintf(buf
, "{\\fs%d\n", HugeFont2
*2);
2397 else TexOutput("}\n");
2404 sprintf(buf
, "{\\fs%d\n", HUGEFont3
*2);
2407 else TexOutput("}\n");
2418 else TexOutput("}");
2425 TexOutput("{\\ul ");
2427 else TexOutput("}");
2440 else TexOutput("}");
2443 // Roman font: do nothing. Should really switch between
2452 TexOutput("{\\plain ");
2454 else TexOutput("}");
2458 // Medium-weight font. Unbolden...
2463 TexOutput("{\\b0 ");
2465 else TexOutput("}");
2468 // Upright (un-italic or slant)
2473 TexOutput("{\\i0 ");
2475 else TexOutput("}");
2484 TexOutput("{\\scaps ");
2486 else TexOutput("}");
2495 TexOutput("{\\f3 ");
2497 else TexOutput("}");
2522 if ( issuedNewParagraph
== 0 )
2524 TexOutput("\\par\\pard");
2525 issuedNewParagraph
++;
2527 // Extra par if parskip is more than zero (usually looks best.)
2528 if (!inTabular
&& (ParSkip
> 0))
2531 issuedNewParagraph
++;
2533 WriteEnvironmentStyles();
2535 // 1 is a whole paragraph if ParSkip == 0,
2536 // half a paragraph if ParSkip > 0
2537 else if ( issuedNewParagraph
== 1 )
2539 // Don't need a par at all if we've already had one,
2540 // and ParSkip == 0.
2542 // Extra par if parskip is more than zero (usually looks best.)
2543 if (!inTabular
&& (ParSkip
> 0))
2546 issuedNewParagraph
++;
2548 WriteEnvironmentStyles();
2551 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2553 TexOutput("\\par\\pard");
2555 // Extra par if parskip is more than zero (usually looks best.)
2556 if (!inTabular && (ParSkip > 0))
2558 WriteEnvironmentStyles();
2568 // In Windows Help, no newpages until we've started some chapters or sections
2569 if (!(winHelp
&& !startedSections
))
2571 TexOutput("\\page\n");
2576 if (start
&& DocumentTitle
)
2578 TexOutput("\\par\\pard");
2581 sprintf(buf
, "\\qc{\\fs%d\\b ", titleFont
*2);
2583 TraverseChildrenFromChunk(DocumentTitle
);
2584 TexOutput("}\\par\\pard\n");
2590 sprintf(buf
, "\\par\\qc{\\fs%d ", authorFont
*2);
2592 TraverseChildrenFromChunk(DocumentAuthor
);
2594 TexOutput("\\par\\pard\n");
2599 sprintf(buf
, "\\qc{\\fs%d ", authorFont
*2);
2601 TraverseChildrenFromChunk(DocumentDate
);
2602 TexOutput("}\\par\\pard\n");
2604 // If linear RTF, we want this titlepage to be in a separate
2605 // section with its own (blank) header and footer
2606 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2608 TexOutput("{\\header }{\\footer }\n");
2609 // Not sure about this: we get too many sections.
2610 // TexOutput("\\sect");
2615 case ltADDCONTENTSLINE
:
2619 if (contentsLineSection
&& contentsLineValue
)
2621 if (strcmp(contentsLineSection
, "chapter") == 0)
2623 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2625 else if (strcmp(contentsLineSection
, "section") == 0)
2627 if (DocumentStyle
!= LATEX_ARTICLE
)
2628 fprintf(Contents
, "\n\\tab%s\\par\n", contentsLineValue
);
2630 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2640 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2641 issuedNewParagraph
= 1;
2642 WriteEnvironmentStyles();
2650 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2651 issuedNewParagraph
= 1;
2652 WriteEnvironmentStyles();
2662 case ltNUMBEREDBIBITEM
:
2665 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
2667 TexOutput("\\par\\pard\\par\n\n");
2674 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2682 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2683 sprintf(buf
, "%d", chapterNo
);
2692 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2693 sprintf(buf
, "%d", sectionNo
);
2700 if (!start
&& !winHelp
)
2702 TexOutput("\\cols2\n");
2708 if (!start
&& !winHelp
)
2710 TexOutput("\\cols1\n");
2716 if (start
&& useWord
&& !winHelp
)
2718 FakeCurrentSection("Index");
2719 OnMacro(ltPAR
, 0, TRUE
);
2720 OnMacro(ltPAR
, 0, FALSE
);
2721 TexOutput("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n");
2725 case ltLISTOFFIGURES
:
2727 if (start
&& useWord
&& !winHelp
)
2729 FakeCurrentSection(FiguresNameString
, FALSE
);
2730 OnMacro(ltPAR
, 0, TRUE
);
2731 OnMacro(ltPAR
, 0, FALSE
);
2732 OnMacro(ltPAR
, 0, TRUE
);
2733 OnMacro(ltPAR
, 0, FALSE
);
2735 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n",
2741 case ltLISTOFTABLES
:
2743 if (start
&& useWord
&& !winHelp
)
2745 FakeCurrentSection(TablesNameString
, FALSE
);
2746 OnMacro(ltPAR
, 0, TRUE
);
2747 OnMacro(ltPAR
, 0, FALSE
);
2748 OnMacro(ltPAR
, 0, TRUE
);
2749 OnMacro(ltPAR
, 0, FALSE
);
2751 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n",
2759 if (start
) TexOutput("{\\f1\\'61}");
2762 if (start
) TexOutput("{\\f1\\'62}");
2765 if (start
) TexOutput("{\\f1\\'63}");
2768 if (start
) TexOutput("{\\f1\\'64}");
2772 if (start
) TexOutput("{\\f1\\'65}");
2775 if (start
) TexOutput("{\\f1\\'7A}");
2778 if (start
) TexOutput("{\\f1\\'68}");
2782 if (start
) TexOutput("{\\f1\\'71}");
2785 if (start
) TexOutput("{\\f1\\'69}");
2788 if (start
) TexOutput("{\\f1\\'6B}");
2791 if (start
) TexOutput("{\\f1\\'6C}");
2794 if (start
) TexOutput("{\\f1\\'6D}");
2797 if (start
) TexOutput("{\\f1\\'6E}");
2800 if (start
) TexOutput("{\\f1\\'78}");
2803 if (start
) TexOutput("{\\f1\\'70}");
2806 if (start
) TexOutput("{\\f1\\'76}");
2810 if (start
) TexOutput("{\\f1\\'72}");
2813 if (start
) TexOutput("{\\f1\\'73}");
2816 if (start
) TexOutput("{\\f1\\'56}");
2819 if (start
) TexOutput("{\\f1\\'74}");
2822 if (start
) TexOutput("{\\f1\\'75}");
2826 if (start
) TexOutput("{\\f1\\'66}");
2829 if (start
) TexOutput("{\\f1\\'63}");
2832 if (start
) TexOutput("{\\f1\\'79}");
2835 if (start
) TexOutput("{\\f1\\'77}");
2838 if (start
) TexOutput("{\\f1\\'47}");
2841 if (start
) TexOutput("{\\f1\\'44}");
2844 if (start
) TexOutput("{\\f1\\'51}");
2847 if (start
) TexOutput("{\\f1\\'4C}");
2850 if (start
) TexOutput("{\\f1\\'58}");
2853 if (start
) TexOutput("{\\f1\\'50}");
2856 if (start
) TexOutput("{\\f1\\'53}");
2859 if (start
) TexOutput("{\\f1\\'54}");
2862 if (start
) TexOutput("{\\f1\\'46}");
2865 if (start
) TexOutput("{\\f1\\'59}");
2868 if (start
) TexOutput("{\\f1\\'57}");
2870 // Binary operation symbols
2873 if (start
) TexOutput("{\\f1\\'A3}");
2876 if (start
) TexOutput("<<");
2879 if (start
) TexOutput("{\\f1\\'CC}");
2882 if (start
) TexOutput("{\\f1\\'CD}");
2885 if (start
) TexOutput("{\\f1\\'CE}");
2889 if (start
) TexOutput("{\\f1\\'B3}");
2892 if (start
) TexOutput(">>");
2895 if (start
) TexOutput("{\\f1\\'C9}");
2898 if (start
) TexOutput("{\\f1\\'CD}");
2901 if (start
) TexOutput("{\\f1\\'27}");
2904 if (start
) TexOutput("{\\f1\\'5E}");
2907 if (start
) TexOutput("{\\f1\\'B9}");
2910 if (start
) TexOutput("{\\f1\\'BB}");
2913 if (start
) TexOutput("{\\f1\\'40}");
2916 if (start
) TexOutput("{\\f1\\'BA}");
2919 if (start
) TexOutput("{\\f1\\'B5}");
2922 if (start
) TexOutput("{\\f1\\'7E}");
2925 if (start
) TexOutput("{\\f4\\'4A}");
2928 if (start
) TexOutput("{\\f4\\'4C}");
2931 if (start
) TexOutput("|");
2934 // Negated relation symbols
2936 if (start
) TexOutput("{\\f1\\'B9}");
2939 if (start
) TexOutput("{\\f1\\'CF}");
2942 if (start
) TexOutput("{\\f1\\'CB}");
2947 if (start
) TexOutput("{\\f1\\'AC}");
2950 if (start
) TexOutput("{\\f1\\'DC}");
2953 if (start
) TexOutput("{\\f1\\'AE}");
2956 if (start
) TexOutput("{\\f1\\'DE}");
2958 case ltLEFTRIGHTARROW
:
2959 if (start
) TexOutput("{\\f1\\'AB}");
2961 case ltLEFTRIGHTARROW2
:
2962 if (start
) TexOutput("{\\f1\\'DB}");
2965 if (start
) TexOutput("{\\f1\\'AD}");
2968 if (start
) TexOutput("{\\f1\\'DD}");
2971 if (start
) TexOutput("{\\f1\\'AF}");
2974 if (start
) TexOutput("{\\f1\\'DF}");
2977 // Miscellaneous symbols
2979 if (start
) TexOutput("{\\f1\\'CO}");
2982 if (start
) TexOutput("{\\f1\\'C3}");
2985 if (start
) TexOutput("{\\f1\\'C2}");
2988 if (start
) TexOutput("{\\f1\\'C1}");
2991 if (start
) TexOutput("{\\f1\\'C6}");
2994 if (start
) TexOutput("{\\f1\\'D1}");
2997 if (start
) TexOutput("{\\f1\\'D6}");
3000 if (start
) TexOutput("{\\f1\\'B6}");
3003 if (start
) TexOutput("{\\f1\\'5E}");
3006 if (start
) TexOutput("{\\f1\\'22}");
3009 if (start
) TexOutput("{\\f1\\'24}");
3012 if (start
) TexOutput("{\\f1\\'D8}");
3015 if (start
) TexOutput("{\\f1\\'23}");
3018 if (start
) TexOutput("{\\f1\\'D0}");
3021 if (start
) TexOutput("{\\f5\\'73}");
3024 if (start
) TexOutput("{\\f5\\'A8}");
3027 if (start
) TexOutput("{\\f5\\'A9}");
3030 if (start
) TexOutput("{\\f5\\'AA}");
3033 if (start
) TexOutput("{\\f5\\'AB}");
3036 if (start
) TexOutput("{\\f1\\'A5}");
3039 if (start
) TexOutput("{\\f0\\'A9}");
3042 if (start
) TexOutput("{\\f0\\'AE}");
3045 if (start
) TexOutput("{\\f1\\'B1}");
3048 if (start
) TexOutput("{\\f1\\'B1}");
3051 if (start
) TexOutput("{\\f1\\'B4}");
3054 if (start
) TexOutput("{\\f1\\'B8}");
3057 if (start
) TexOutput("{\\f1\\'D7}");
3060 if (start
) TexOutput("{\\f1\\'2A}");
3063 if (start
) TexOutput("{\\f5\\'AB}");
3066 if (start
) TexOutput("{\\f1\\'C7}");
3069 if (start
) TexOutput("{\\f1\\'C8}");
3072 if (start
) TexOutput("{\\f1\\'DA}");
3075 if (start
) TexOutput("{\\f1\\'D9}");
3078 if (start
) TexOutput("{\\f1\\'B0}");
3081 if (start
) TexOutput("{\\f1\\'B7}");
3084 if (start
) TexOutput("{\\f1\\'E0}");
3087 if (start
) TexOutput("{\\f1\\'C6}");
3090 if (start
) TexOutput("{\\f1\\'E0}");
3092 case ltBIGTRIANGLEDOWN
:
3093 if (start
) TexOutput("{\\f1\\'D1}");
3096 if (start
) TexOutput("{\\f1\\'C5}");
3099 if (start
) TexOutput("{\\f1\\'C4}");
3102 if (start
) TexOutput("{\\'DF}");
3106 if (start
) inFigure
= TRUE
;
3107 else inFigure
= FALSE
;
3112 if (start
) inTable
= TRUE
;
3113 else inTable
= FALSE
;
3118 DefaultOnMacro(macroId
, no_args
, start
);
3124 // Called on start/end of argument examination
3125 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3132 case ltCHAPTERHEADING
:
3135 case ltSECTIONHEADING
:
3137 case ltSUBSECTIONSTAR
:
3138 case ltSUBSUBSECTION
:
3139 case ltSUBSUBSECTIONSTAR
:
3141 case ltMEMBERSECTION
:
3142 case ltFUNCTIONSECTION
:
3146 if (!start
&& (arg_no
== 1))
3147 currentSection
= GetArgChunk();
3153 if (start
&& (arg_no
== 1))
3154 TexOutput("\\pard\\li600\\fi-600{\\b ");
3156 if (!start
&& (arg_no
== 1))
3159 if (start
&& (arg_no
== 2))
3161 if (!suppressNameDecoration
) TexOutput("{\\b ");
3162 currentMember
= GetArgChunk();
3164 if (!start
&& (arg_no
== 2))
3166 if (!suppressNameDecoration
) TexOutput("}");
3169 if (start
&& (arg_no
== 3))
3171 if (!start
&& (arg_no
== 3))
3173 // TexOutput(")\\li0\\fi0");
3174 // TexOutput(")\\par\\pard\\li0\\fi0");
3175 // issuedNewParagraph = 1;
3177 WriteEnvironmentStyles();
3183 if (start
&& (arg_no
== 1))
3184 TexOutput("\\pard\\li260\\fi-260{\\b ");
3185 if (!start
&& (arg_no
== 1))
3188 if (start
&& (arg_no
== 2))
3190 if (!suppressNameDecoration
) TexOutput("({\\b ");
3191 currentMember
= GetArgChunk();
3193 if (!start
&& (arg_no
== 2))
3195 if (!suppressNameDecoration
) TexOutput("}");
3198 if (!start
&& (arg_no
== 3))
3200 TexOutput(")\\li0\\fi0");
3201 WriteEnvironmentStyles();
3207 if (start
&& (arg_no
== 1))
3208 TexOutput("\\pard\\li260\\fi-260");
3210 if (!start
&& (arg_no
== 1))
3213 if (start
&& (arg_no
== 2))
3215 if (!start
&& (arg_no
== 2))
3218 if (start
&& (arg_no
== 2))
3219 currentMember
= GetArgChunk();
3221 if (start
&& (arg_no
== 3))
3223 if (!start
&& (arg_no
== 3))
3225 TexOutput(")\\li0\\fi0");
3226 WriteEnvironmentStyles();
3232 if (start
&& (arg_no
== 1))
3234 if (!start
&& (arg_no
== 1))
3236 if (start
&& (arg_no
== 2))
3240 if (!start
&& (arg_no
== 2))
3248 if (start
&& (arg_no
== 1))
3250 if (!start
&& (arg_no
== 1))
3251 TexOutput("} "); // This is the difference from param - one space!
3252 if (start
&& (arg_no
== 2))
3256 if (!start
&& (arg_no
== 2))
3264 if (!start
&& (arg_no
== 1))
3267 if (start
&& (arg_no
== 2))
3268 currentMember
= GetArgChunk();
3276 char *secName
= NULL
;
3278 char *refName
= GetArgData();
3279 if (winHelp
|| !useWord
)
3283 TexRef
*texRef
= FindReference(refName
);
3286 sec
= texRef
->sectionNumber
;
3287 secName
= texRef
->sectionName
;
3297 fprintf(Chapters
, "{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
3309 if ((GetNoArgs() - arg_no
) == 1)
3312 TexOutput("{\\uldb ");
3316 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3322 // Remove green colour/underlining if specified
3323 if (!hotSpotUnderline
&& !hotSpotColour
)
3325 else if (!hotSpotColour
)
3328 else TexOutput("}");
3331 else // If a linear document, must resolve the references ourselves
3333 if ((GetNoArgs() - arg_no
) == 1)
3335 // In a linear document we display the anchor text in italic plus
3343 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3345 if (macroId
!= ltHELPREFN
)
3350 char *refName
= GetArgData();
3355 char *s
= GetArgData();
3357 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3359 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3363 // Only print section name if we're not in Word mode,
3364 // so can't do page references
3365 TexRef
*texRef
= FindReference(refName
);
3368 TexOutput(texRef
->sectionName
) ; TexOutput(" "); TexOutput(texRef
->sectionNumber
);
3373 sprintf(buf
, "Warning: unresolved reference %s.", refName
);
3378 else TexOutput("??");
3380 else TexOutput(")");
3393 else if (arg_no
== 2)
3398 TexOutput(" ({\\f3 ");
3413 if ((GetNoArgs() - arg_no
) == 1)
3416 TexOutput("{\\ul ");
3420 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3426 // Remove green colour/underlining if specified
3427 if (!hotSpotUnderline
&& !hotSpotColour
)
3429 else if (!hotSpotColour
)
3432 else TexOutput("}");
3435 else // A linear document...
3437 if ((GetNoArgs() - arg_no
) == 1)
3439 // In a linear document we just display the anchor text in italic
3450 case ltADDCONTENTSLINE
:
3452 if (start
&& !winHelp
)
3455 contentsLineSection
= copystring(GetArgData());
3456 else if (arg_no
== 3)
3457 contentsLineValue
= copystring(GetArgData());
3472 static int imageWidth
= 0;
3473 static int imageHeight
= 0;
3475 if (start
&& (arg_no
== 1))
3477 char *imageDimensions
= copystring(GetArgData());
3479 strcpy(buf1
, imageDimensions
);
3480 char *tok1
= strtok(buf1
, ";:");
3481 char *tok2
= strtok(NULL
, ";:");
3482 // Convert points to TWIPS (1 twip = 1/20th of point)
3483 imageWidth
= (int)(20*(tok1
? ParseUnitArgument(tok1
) : 0));
3484 imageHeight
= (int)(20*(tok2
? ParseUnitArgument(tok2
) : 0));
3487 else if (start
&& (arg_no
== 2 ))
3489 char *filename
= copystring(GetArgData());
3491 if ((winHelp
|| (strcmp(bitmapMethod
, "includepicture") == 0) || (strcmp(bitmapMethod
, "import") == 0)) && useWord
)
3493 if (f
== "") // Try for a .shg (segmented hypergraphics file)
3495 strcpy(buf
, filename
);
3496 StripExtension(buf
);
3497 strcat(buf
, ".shg");
3498 f
= TexPathList
.FindValidPath(buf
);
3500 if (f
== "") // Try for a .bmp
3502 strcpy(buf
, filename
);
3503 StripExtension(buf
);
3504 strcat(buf
, ".bmp");
3505 f
= TexPathList
.FindValidPath(buf
);
3507 if (f
== "") // Try for a metafile instead
3509 strcpy(buf
, filename
);
3510 StripExtension(buf
);
3511 strcat(buf
, ".wmf");
3512 f
= TexPathList
.FindValidPath(buf
);
3518 if (bitmapTransparency
&& (winHelpVersion
> 3))
3519 TexOutput("\\{bmct ");
3521 TexOutput("\\{bmc ");
3522 wxString str
= wxFileNameFromPath(f
);
3523 TexOutput((char*) (const char*) str
);
3528 // Microsoft Word method
3529 if (strcmp(bitmapMethod
, "import") == 0)
3530 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3532 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3534 // Full path appears not to be valid!
3535 wxString str
= wxFileNameFromPath(f
);
3536 TexOutput((char*)(const char*) str
);
3538 int len = strlen(f);
3539 char smallBuf[2]; smallBuf[1] = 0;
3540 for (int i = 0; i < len; i++)
3543 TexOutput(smallBuf);
3544 if (smallBuf[0] == '\\')
3545 TexOutput(smallBuf);
3548 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3553 TexOutput("[No BMP or WMF for image file ");
3554 TexOutput(filename
);
3556 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3562 if (f
== "") // Try for a .bmp
3564 strcpy(buf
, filename
);
3565 StripExtension(buf
);
3566 strcat(buf
, ".bmp");
3567 f
= TexPathList
.FindValidPath(buf
);
3571 FILE *fd
= fopen(f
, "rb");
3572 if (OutputBitmapHeader(fd
, winHelp
))
3573 OutputBitmapData(fd
);
3576 sprintf(buf
, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f
);
3581 else // Try for a metafile instead
3584 strcpy(buf
, filename
);
3585 StripExtension(buf
);
3586 strcat(buf
, ".wmf");
3587 f
= TexPathList
.FindValidPath(buf
);
3590 // HFILE handle = _lopen(f, READ);
3591 FILE *fd
= fopen(f
, "rb");
3592 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3594 OutputMetafileData(fd
);
3598 sprintf(buf
, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f
);
3606 TexOutput("[No BMP or WMF for image file ");
3607 TexOutput(filename
);
3609 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3623 case ltSUPERTABULAR
:
3629 currentRowNumber
= 0;
3632 tableVerticalLineLeft
= FALSE
;
3633 tableVerticalLineRight
= FALSE
;
3634 int currentWidth
= 0;
3636 char *alignString
= copystring(GetArgData());
3637 ParseTableArgument(alignString
);
3639 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3640 TexOutput("\\trowd\\trgaph108");
3642 // Write the first row formatting for compatibility
3643 // with standard Latex
3644 if (compatibilityMode
)
3646 for (int i
= 0; i
< noColumns
; i
++)
3648 currentWidth
+= TableData
[i
].width
;
3649 sprintf(buf
, "\\cellx%d", currentWidth
);
3652 TexOutput("\\pard\\intbl\n");
3654 delete[] alignString
;
3659 else if (arg_no
== 2 && !start
)
3661 TexOutput("\\pard\n");
3662 WriteEnvironmentStyles();
3673 TexOutput("\\li360\n");
3675 PushEnvironmentStyle("\\li360");
3680 PopEnvironmentStyle();
3681 OnMacro(ltPAR
, 0, TRUE
);
3682 OnMacro(ltPAR
, 0, FALSE
);
3690 TexOutput("\\li360\n");
3691 PushEnvironmentStyle("\\li360");
3695 PopEnvironmentStyle();
3696 OnMacro(ltPAR
, 0, TRUE
);
3697 OnMacro(ltPAR
, 0, FALSE
);
3709 sprintf(buf
, "\\box\\trgaph108%s\n", ((macroId
== ltNORMALBOXD
) ? "\\brdrdb" : "\\brdrs"));
3711 PushEnvironmentStyle(buf
);
3715 PopEnvironmentStyle();
3716 OnMacro(ltPAR
, 0, TRUE
);
3717 OnMacro(ltPAR
, 0, FALSE
);
3721 case ltHELPFONTSIZE
:
3725 char *data
= GetArgData();
3726 if (strcmp(data
, "10") == 0)
3728 else if (strcmp(data
, "11") == 0)
3730 else if (strcmp(data
, "12") == 0)
3732 sprintf(buf
, "\\fs%d\n", normalFont
*2);
3739 case ltHELPFONTFAMILY
:
3743 char *data
= GetArgData();
3744 if (strcmp(data
, "Swiss") == 0)
3745 TexOutput("\\f2\n");
3746 else if (strcmp(data
, "Symbol") == 0)
3747 TexOutput("\\f1\n");
3748 else if (strcmp(data
, "Times") == 0)
3749 TexOutput("\\f0\n");
3757 if (start
&& arg_no
== 1)
3759 char *data
= GetArgData();
3760 ParIndent
= ParseUnitArgument(data
);
3761 if (ParIndent
== 0 || forbidParindent
== 0)
3763 sprintf(buf
, "\\fi%d\n", ParIndent
*20);
3772 if (start
&& IsArgOptional())
3774 descriptionItemArg
= GetArgChunk();
3780 case ltTWOCOLITEMRULED
:
3787 TexOutput("\\tab ");
3794 if (macroId
== ltTWOCOLITEMRULED
)
3795 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3796 TexOutput("\\par\\pard\n");
3797 issuedNewParagraph
= 1;
3798 WriteEnvironmentStyles();
3810 case ltACCENT_GRAVE
:
3814 char *val
= GetArgData();
3857 case ltACCENT_ACUTE
:
3861 char *val
= GetArgData();
3910 case ltACCENT_CARET
:
3914 char *val
= GetArgData();
3957 case ltACCENT_TILDE
:
3961 char *val
= GetArgData();
3995 case ltACCENT_UMLAUT
:
3999 char *val
= GetArgData();
4055 char *val
= GetArgData();
4074 case ltACCENT_CADILLA
:
4078 char *val
= GetArgData();
4099 static char *helpTopic
= NULL
;
4100 static FILE *savedOutput
= NULL
;
4107 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4110 sprintf(footBuf
, "(%d)", footnoteCount
);
4112 TexOutput(" {\\ul ");
4115 helpTopic
= FindTopicName(NULL
);
4118 // Remove green colour/underlining if specified
4119 if (!hotSpotUnderline
&& !hotSpotColour
)
4121 else if (!hotSpotColour
)
4124 TexOutput(helpTopic
);
4127 fprintf(Popups
, "\\page\n");
4128 // fprintf(Popups, "\n${\\footnote }"); // No title
4129 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4130 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4131 savedOutput
= CurrentOutput1
;
4132 SetCurrentOutput(Popups
);
4136 SetCurrentOutput(savedOutput
);
4146 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4150 TexOutput("}}", TRUE
);
4156 case ltFOOTNOTEPOPUP
:
4158 static char *helpTopic
= NULL
;
4159 static FILE *savedOutput
= NULL
;
4166 TexOutput("{\\ul ");
4168 else TexOutput("}");
4171 else if (arg_no
== 2)
4175 helpTopic
= FindTopicName(NULL
);
4178 // Remove green colour/underlining if specified
4179 if (!hotSpotUnderline
&& !hotSpotColour
)
4181 else if (!hotSpotColour
)
4184 TexOutput(helpTopic
);
4187 fprintf(Popups
, "\\page\n");
4188 // fprintf(Popups, "\n${\\footnote }"); // No title
4189 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4190 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4191 savedOutput
= CurrentOutput1
;
4192 SetCurrentOutput(Popups
);
4196 SetCurrentOutput(savedOutput
);
4207 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4211 TexOutput("}}", TRUE
);
4219 if (start
&& (arg_no
== 1))
4232 if (winHelp
) return FALSE
;
4238 LeftHeaderEven
= GetArgChunk();
4239 if (strlen(GetArgData(LeftHeaderEven
)) == 0)
4240 LeftHeaderEven
= NULL
;
4243 CentreHeaderEven
= GetArgChunk();
4244 if (strlen(GetArgData(CentreHeaderEven
)) == 0)
4245 CentreHeaderEven
= NULL
;
4248 RightHeaderEven
= GetArgChunk();
4249 if (strlen(GetArgData(RightHeaderEven
)) == 0)
4250 RightHeaderEven
= NULL
;
4253 LeftHeaderOdd
= GetArgChunk();
4254 if (strlen(GetArgData(LeftHeaderOdd
)) == 0)
4255 LeftHeaderOdd
= NULL
;
4258 CentreHeaderOdd
= GetArgChunk();
4259 if (strlen(GetArgData(CentreHeaderOdd
)) == 0)
4260 CentreHeaderOdd
= NULL
;
4263 RightHeaderOdd
= GetArgChunk();
4264 if (strlen(GetArgData(RightHeaderOdd
)) == 0)
4265 RightHeaderOdd
= NULL
;
4266 OutputRTFHeaderCommands();
4282 if (winHelp
) return FALSE
;
4288 LeftFooterEven
= GetArgChunk();
4289 if (strlen(GetArgData(LeftFooterEven
)) == 0)
4290 LeftFooterEven
= NULL
;
4293 CentreFooterEven
= GetArgChunk();
4294 if (strlen(GetArgData(CentreFooterEven
)) == 0)
4295 CentreFooterEven
= NULL
;
4298 RightFooterEven
= GetArgChunk();
4299 if (strlen(GetArgData(RightFooterEven
)) == 0)
4300 RightFooterEven
= NULL
;
4303 LeftFooterOdd
= GetArgChunk();
4304 if (strlen(GetArgData(LeftFooterOdd
)) == 0)
4305 LeftFooterOdd
= NULL
;
4308 CentreFooterOdd
= GetArgChunk();
4309 if (strlen(GetArgData(CentreFooterOdd
)) == 0)
4310 CentreFooterOdd
= NULL
;
4313 RightFooterOdd
= GetArgChunk();
4314 if (strlen(GetArgData(RightFooterOdd
)) == 0)
4315 RightFooterOdd
= NULL
;
4316 OutputRTFFooterCommands();
4327 if (winHelp
) return FALSE
;
4328 // Fake a SetHeader command
4331 LeftHeaderOdd
= NULL
;
4332 CentreHeaderOdd
= NULL
;
4333 RightHeaderOdd
= NULL
;
4334 LeftHeaderEven
= NULL
;
4335 CentreHeaderEven
= NULL
;
4336 RightHeaderEven
= NULL
;
4337 OnInform("Consider using setheader/setfooter rather than markright.");
4339 RTFOnArgument(ltSETHEADER
, 4, start
);
4341 OutputRTFHeaderCommands();
4347 if (winHelp
) return FALSE
;
4348 // Fake a SetHeader command
4355 LeftHeaderOdd
= NULL
;
4356 CentreHeaderOdd
= NULL
;
4357 RightHeaderOdd
= NULL
;
4358 LeftHeaderEven
= NULL
;
4359 CentreHeaderEven
= NULL
;
4360 RightHeaderEven
= NULL
;
4361 OnInform("Consider using setheader/setfooter rather than markboth.");
4363 return RTFOnArgument(ltSETHEADER
, 1, start
);
4368 RTFOnArgument(ltSETHEADER
, 4, start
);
4370 OutputRTFHeaderCommands();
4377 case ltPAGENUMBERING
:
4384 if (winHelp
) return FALSE
;
4387 TexOutput("\\pgnrestart");
4388 char *data
= GetArgData();
4389 if (currentNumberStyle
) delete[] currentNumberStyle
;
4390 currentNumberStyle
= copystring(data
);
4391 OutputNumberStyle(currentNumberStyle
);
4400 if (winHelp
) return FALSE
;
4409 char *val
= GetArgData();
4410 currentItemSep
= ParseUnitArgument(val
);
4415 case ltEVENSIDEMARGIN
:
4420 case ltODDSIDEMARGIN
:
4424 char *val
= GetArgData();
4425 int twips
= (int)(20*ParseUnitArgument(val
));
4426 // Add an inch since in LaTeX it's specified minus an inch
4428 CurrentLeftMarginOdd
= twips
;
4429 sprintf(buf
, "\\margl%d\n", twips
);
4432 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4436 case ltMARGINPARWIDTH
:
4440 char *val
= GetArgData();
4441 int twips
= (int)(20*ParseUnitArgument(val
));
4442 CurrentMarginParWidth
= twips
;
4446 case ltMARGINPARSEP
:
4450 char *val
= GetArgData();
4451 int twips
= (int)(20*ParseUnitArgument(val
));
4452 CurrentMarginParSep
= twips
;
4453 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4461 char *val
= GetArgData();
4462 int twips
= (int)(20*ParseUnitArgument(val
));
4463 CurrentTextWidth
= twips
;
4465 // Need to set an implicit right margin
4466 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4467 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4468 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4469 sprintf(buf
, "\\margr%d\n", CurrentRightMarginOdd
);
4475 case ltMARGINPARODD
:
4481 TexOutput("\\box\n");
4482 PushEnvironmentStyle("\\box");
4486 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4495 TexOutput("\\par\\pard\n");
4496 PopEnvironmentStyle();
4497 WriteEnvironmentStyles();
4500 TexOutput("\\par\\pard\n");
4501 issuedNewParagraph
= 1;
4505 case ltMARGINPAREVEN
:
4511 TexOutput("\\box\n");
4512 PushEnvironmentStyle("\\box");
4518 // Have to calculate what the margins are changed to in WfW margin
4519 // mirror mode, on an even (left-hand) page.
4520 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4521 - CurrentTextWidth
+ GutterWidth
;
4522 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", x
, CurrentMarginParWidth
);
4527 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4537 TexOutput("\\par\\pard\n");
4538 PopEnvironmentStyle();
4539 WriteEnvironmentStyles();
4542 issuedNewParagraph
= 1;
4543 TexOutput("\\par\\pard\n");
4547 case ltTWOCOLWIDTHA
:
4551 char *val
= GetArgData();
4552 int twips
= (int)(20*ParseUnitArgument(val
));
4553 TwoColWidthA
= twips
;
4558 case ltTWOCOLWIDTHB
:
4562 char *val
= GetArgData();
4563 int twips
= (int)(20*ParseUnitArgument(val
));
4564 TwoColWidthB
= twips
;
4574 int currentWidth
= 0;
4576 if (!compatibilityMode
|| (currentRowNumber
> 0))
4578 TexOutput("\\pard\\intbl");
4580 if (macroId
== ltRULEDROW
)
4582 for (int i
= 0; i
< noColumns
; i
++)
4584 currentWidth
+= TableData
[i
].width
;
4587 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4589 else if (ruleTop
> 1)
4591 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4593 if (ruleBottom
== 1)
4595 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4597 else if (ruleBottom
> 1)
4599 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4602 if (TableData
[i
].rightBorder
)
4603 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4605 if (TableData
[i
].leftBorder
)
4606 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4608 sprintf(buf
, "\\cellx%d", currentWidth
);
4611 TexOutput("\\pard\\intbl\n");
4615 currentRowNumber
++;
4620 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4621 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4627 static int noMultiColumns
= 0;
4634 noMultiColumns
= atoi(GetArgData());
4652 for (int i
= 1; i
< noMultiColumns
; i
++)
4653 TexOutput("\\cell");
4660 if (start
&& (arg_no
== 1))
4663 // TexOutput("\\fi0\n");
4665 wxNode
*node
= itemizeStack
.First();
4667 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
4669 int indentValue
= 20*ParseUnitArgument(GetArgData());
4670 int indentSize
= indentValue
+ oldIndent
;
4672 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4673 itemizeStack
.Insert(struc
);
4675 sprintf(buf
, "\\tx%d\\li%d ", indentSize
, indentSize
);
4676 PushEnvironmentStyle(buf
);
4680 if (!start
&& (arg_no
== 2))
4682 PopEnvironmentStyle();
4683 if (itemizeStack
.First())
4685 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
4687 delete itemizeStack
.First();
4689 if (itemizeStack
.Number() == 0)
4691 TexOutput("\\par\\pard\n");
4692 issuedNewParagraph
= 1;
4693 WriteEnvironmentStyles();
4703 if (start && (arg_no == 1))
4706 wxNode *node = itemizeStack.First();
4708 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4710 int boxWidth = 20*ParseUnitArgument(GetArgData());
4712 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4713 int indentSize = indentValue + oldIndent;
4714 int indentSizeRight = indentSize + boxWidth;
4716 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4717 itemizeStack.Insert(struc);
4719 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4720 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4721 PushEnvironmentStyle(buf);
4725 if (!start && (arg_no == 2))
4727 PopEnvironmentStyle();
4728 if (itemizeStack.First())
4730 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4732 delete itemizeStack.First();
4734 if (itemizeStack.Number() == 0)
4736 TexOutput("\\par\\pard\n");
4737 issuedNewParagraph = 1;
4738 WriteEnvironmentStyles();
4745 case ltDOCUMENTSTYLE
:
4747 DefaultOnArgument(macroId
, arg_no
, start
);
4748 if (!start
&& !IsArgOptional())
4750 if (MinorDocumentStyleString
)
4752 if (StringMatch("twoside", MinorDocumentStyleString
))
4753 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4754 TexOutput("\\margmirror\\facingp\\sbkodd");
4755 if (StringMatch("twocolumn", MinorDocumentStyleString
))
4756 TexOutput("\\cols2");
4762 case ltSETHOTSPOTCOLOUR
:
4763 case ltSETHOTSPOTCOLOR
:
4767 char *text
= GetArgData();
4768 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4769 hotSpotColour
= TRUE
;
4771 hotSpotColour
= FALSE
;
4775 case ltSETTRANSPARENCY
:
4779 char *text
= GetArgData();
4780 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4781 bitmapTransparency
= TRUE
;
4783 bitmapTransparency
= FALSE
;
4787 case ltSETHOTSPOTUNDERLINE
:
4791 char *text
= GetArgData();
4792 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4793 hotSpotUnderline
= TRUE
;
4795 hotSpotUnderline
= FALSE
;
4801 if (arg_no
== 1 && start
)
4803 char *citeKey
= GetArgData();
4804 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4807 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4808 sprintf(buf
, "[%d]", citeCount
);
4809 ref
->sectionNumber
= copystring(buf
);
4812 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4813 sprintf(buf
, "{\\b [%d]} ", citeCount
);
4818 if (arg_no
== 2 && !start
)
4819 TexOutput("\\par\\pard\\par\n\n");
4823 case ltTHEBIBLIOGRAPHY
:
4825 if (start
&& (arg_no
== 1))
4829 SetCurrentOutputs(Contents
, Chapters
);
4833 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
4835 // If a non-custom page style, we generate the header now.
4836 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
4837 strcmp(PageStyle
, "empty") == 0 ||
4838 strcmp(PageStyle
, "headings") == 0))
4840 OutputRTFHeaderCommands();
4841 OutputRTFFooterCommands();
4844 // Need to reset the current numbering style, or RTF forgets it.
4845 OutputNumberStyle(currentNumberStyle
);
4846 SetCurrentOutput(Contents
);
4849 fprintf(Chapters
, "\\page\n");
4852 fprintf(Contents
, "\n{\\uldb %s}", ReferencesNameString
);
4854 fprintf(Contents
, "\\par\n\\pard{\\b %s}", ReferencesNameString
);
4856 startedSections
= TRUE
;
4859 fprintf(Chapters
, "\n${\\footnote %s}", ReferencesNameString
);
4861 char *topicName
= "bibliography";
4864 fprintf(Contents
, "{\\v %s}\\par\\pard\n", topicName
);
4866 fprintf(Contents
, "\\par\\par\\pard\n");
4870 fprintf(Chapters
, "\n#{\\footnote %s}\n", topicName
);
4871 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
4872 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ReferencesNameString
);
4873 GenerateKeywordsForTopic(topicName
);
4876 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4877 FileNameFromPath(FileRoot
), "Contents");
4881 SetCurrentOutput(Chapters
);
4882 char *styleCommand
= "";
4883 if (!winHelp
&& useHeadingStyles
)
4884 styleCommand
= "\\s1";
4885 fprintf(Chapters
, "\\pard{%s", (winHelp
? "\\keepn\\sa140\\sb140" : styleCommand
));
4886 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " References\\par\\pard}\n");
4896 * In Windows help, all keywords should be at the start of the
4897 * topic, but Latex \index commands can be anywhere in the text.
4898 * So we're going to have to build up lists of keywords for a topic,
4899 * and insert them on the second pass.
4901 * In linear RTF, we can embed the index entry now.
4906 // char *entry = GetArgData();
4908 OutputChunkToString(GetArgChunk(), buf
);
4913 AddKeyWordForTopic(CurrentTopic
, buf
);
4916 else GenerateIndexEntry(buf
);
4930 char *name
= GetArgData();
4931 int pos
= FindColourPosition(name
);
4934 sprintf(buf
, "{%s%d ", ((macroId
== ltFCOL
) ? "\\cf" : "\\cb"), pos
);
4939 sprintf(buf
, "Could not find colour name %s", name
);
4955 if (arg_no
== 2) TexOutput("}");
4962 if (start
&& !winHelp
&& useWord
)
4964 char *s
= GetArgData();
4965 // Only insert a bookmark here if it's not just been inserted
4966 // in a section heading.
4967 if ( !CurrentTopic
|| !(strcmp(CurrentTopic
, s
) == 0) )
4969 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4970 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4971 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
4975 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", s
,s
);
4983 if (start
&& useWord
&& !winHelp
)
4985 char *s
= GetArgData();
4986 fprintf(Chapters
, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
4995 inPopRefSection
= TRUE
;
4997 inPopRefSection
= FALSE
;
5000 case ltINSERTATLEVEL
:
5002 // This macro allows you to insert text at a different level
5003 // from the current level, e.g. into the Sections from within a subsubsection.
5004 if (!winHelp
& useWord
)
5006 static int currentLevelNo
= 1;
5007 static FILE* oldLevelFile
= Chapters
;
5014 oldLevelFile
= CurrentOutput1
;
5016 char *str
= GetArgData();
5017 currentLevelNo
= atoi(str
);
5019 // TODO: cope with article style (no chapters)
5020 switch (currentLevelNo
)
5024 outputFile
= Chapters
;
5029 outputFile
= Sections
;
5034 outputFile
= Subsections
;
5039 outputFile
= Subsubsections
;
5049 CurrentOutput1
= outputFile
;
5067 CurrentOutput1
= oldLevelFile
;
5075 return DefaultOnArgument(macroId
, arg_no
, start
);
5086 forbidParindent
= 0;
5087 contentsLineSection
= NULL
;
5088 contentsLineValue
= NULL
;
5089 descriptionItemArg
= NULL
;
5094 tableVerticalLineLeft
= FALSE
;
5095 tableVerticalLineRight
= FALSE
;
5097 startedSections
= FALSE
;
5101 if (InputFile
&& OutputFile
)
5103 // Do some RTF-specific transformations on all the strings,
5105 Text2RTF(GetTopLevelChunk());
5107 Contents
= fopen(TmpContentsName
, "w");
5108 Chapters
= fopen("chapters.rtf", "w");
5111 Sections
= fopen("sections.rtf", "w");
5112 Subsections
= fopen("subsections.rtf", "w");
5113 Subsubsections
= fopen("subsubsections.rtf", "w");
5114 Popups
= fopen("popups.rtf", "w");
5115 if (winHelpContents
)
5117 WinHelpContentsFile
= fopen(WinHelpContentsFileName
, "w");
5118 if (WinHelpContentsFile
)
5119 fprintf(WinHelpContentsFile
, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot
));
5122 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5124 OnError("Ouch! Could not open temporary file(s) for writing.");
5128 if (!Contents
|| !Chapters
)
5130 OnError("Ouch! Could not open temporary file(s) for writing.");
5136 fprintf(Chapters
, "\n#{\\footnote Contents}\n");
5137 fprintf(Chapters
, "${\\footnote Contents}\n");
5138 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
5139 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ContentsNameString
);
5140 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
5144 fprintf(Chapters
, "\\titlepg\n");
5145 fprintf(Contents
, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5148 // In WinHelp, Contents title takes font of title.
5149 // In linear RTF, same as chapter headings.
5150 fprintf(Contents
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5151 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5153 // By default, Swiss, 10 point.
5154 fprintf(Chapters
, "\\f2\\fs20\n");
5156 SetCurrentOutput(Chapters
);
5158 OnInform("Converting...");
5162 FILE *Header
= fopen("header.rtf", "w");
5165 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5168 WriteRTFHeader(Header
);
5169 fclose(Header
); Header
= NULL
;
5174 // fprintf(Contents, "\\page\n");
5175 fprintf(Chapters
, "\\page\n");
5176 fprintf(Sections
, "\\page\n");
5177 fprintf(Subsections
, "\\page\n");
5178 fprintf(Subsubsections
, "\\page\n\n");
5179 fprintf(Popups
, "\\page\n}\n");
5182 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5185 fclose(Contents
); Contents
= NULL
;
5186 fclose(Chapters
); Chapters
= NULL
;
5189 fclose(Sections
); Sections
= NULL
;
5190 fclose(Subsections
); Subsections
= NULL
;
5191 fclose(Subsubsections
); Subsubsections
= NULL
;
5192 fclose(Popups
); Popups
= NULL
;
5193 if (winHelpContents
)
5195 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5201 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5203 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5205 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5207 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5209 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile
);
5212 wxRemoveFile("tmp1.rtf");
5213 wxRemoveFile("tmp2.rtf");
5214 wxRemoveFile("tmp3.rtf");
5215 wxRemoveFile("tmp4.rtf");
5219 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5221 if (FileExists(OutputFile
)) wxRemoveFile(OutputFile
);
5222 wxCopyFile("tmp1.rtf", OutputFile
);
5224 wxRemoveFile("tmp1.rtf");
5227 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5229 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5231 wxCopyFile(TmpContentsName
, ContentsName
);
5232 wxRemoveFile(TmpContentsName
);
5235 wxRemoveFile("chapters.rtf");
5236 wxRemoveFile("header.rtf");
5240 wxRemoveFile("sections.rtf");
5241 wxRemoveFile("subsections.rtf");
5242 wxRemoveFile("subsubsections.rtf");
5243 wxRemoveFile("popups.rtf");
5245 if (winHelp
&& generateHPJ
)
5246 WriteHPJ(OutputFile
);