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"
39 #if !WXWIN_COMPATIBILITY_2_4
40 static inline wxChar
* copystring(const wxChar
* s
)
41 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
45 static int indentLevel
= 0;
46 static int forbidParindent
= 0; // if > 0, no parindent (e.g. in center environment)
47 int forbidResetPar
= 0; // If > 0, don't reset memory of having output a new par
49 static char *contentsLineSection
= NULL
;
50 static char *contentsLineValue
= NULL
;
51 static TexChunk
*descriptionItemArg
= NULL
;
52 static wxStringList environmentStack
; // Stack of paragraph styles we need to remember
53 static int footnoteCount
= 0;
54 static int citeCount
= 1;
55 extern char *FileRoot
;
57 extern bool startedSections
;
58 extern FILE *Contents
;
59 extern FILE *Chapters
;
61 extern FILE *WinHelpContentsFile
;
62 extern char *RTFCharset
;
63 // This is defined in the Tex2Any library and isn't in use after parsing
64 extern char *BigBuffer
;
66 extern wxHashTable TexReferences
;
68 // Are we in verbatim mode? If so, format differently.
69 static bool inVerbatim
= FALSE
;
71 // We're in a series of PopRef topics, so don't output section headings
72 bool inPopRefSection
= FALSE
;
75 static bool hotSpotColour
= TRUE
;
76 static bool hotSpotUnderline
= TRUE
;
78 // Transparency (WHITE = transparent)
79 static bool bitmapTransparency
= TRUE
;
81 // Linear RTF requires us to set the style per section.
82 static char *currentNumberStyle
= NULL
;
83 static int currentItemSep
= 8;
84 static int CurrentTextWidth
= 8640; // Say, six inches
85 static int CurrentLeftMarginOdd
= 400;
86 static int CurrentLeftMarginEven
= 1440;
87 static int CurrentRightMarginOdd
= 1440;
88 static int CurrentRightMarginEven
= 400;
89 static int CurrentMarginParWidth
= 2000;
90 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
91 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
92 static int GutterWidth
= 2300;
94 // Two-column table dimensions, in twips
95 static int TwoColWidthA
= 1500;
96 static int TwoColWidthB
= 3000;
98 const int PageWidth
= 12242; // 8.25 inches wide for A4
100 // Remember the anchor in a helpref
101 static TexChunk
*helpRefText
= NULL
;
104 * Flag to say we've just issued a \par\pard command, so don't
105 * repeat this unnecessarily.
109 int issuedNewParagraph
= 0;
111 // Need to know whether we're in a table or figure for benefit
112 // of listoffigures/listoftables
113 static bool inFigure
= FALSE
;
114 static bool inTable
= FALSE
;
120 static char *CurrentChapterName
= NULL
;
121 static char *CurrentSectionName
= NULL
;
122 static char *CurrentSubsectionName
= NULL
;
123 static char *CurrentTopic
= NULL
;
125 static bool InPopups()
127 if (CurrentChapterName
&& (strcmp(CurrentChapterName
, "popups") == 0))
129 if (CurrentSectionName
&& (strcmp(CurrentSectionName
, "popups") == 0))
134 static void SetCurrentTopic(char *s
)
136 if (CurrentTopic
) delete[] CurrentTopic
;
137 CurrentTopic
= copystring(s
);
140 void SetCurrentChapterName(char *s
)
142 if (CurrentChapterName
) delete[] CurrentChapterName
;
143 CurrentChapterName
= copystring(s
);
146 void SetCurrentSectionName(char *s
)
148 if (CurrentSectionName
) delete[] CurrentSectionName
;
149 CurrentSectionName
= copystring(s
);
152 void SetCurrentSubsectionName(char *s
)
154 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
155 CurrentSubsectionName
= copystring(s
);
159 // Indicate that a parent topic at level 'level' has children.
160 // Level 1 is a chapter, 2 is a section, etc.
161 void NotifyParentHasChildren(int parentLevel
)
163 char *parentTopic
= NULL
;
168 parentTopic
= CurrentChapterName
;
173 parentTopic
= CurrentSectionName
;
178 parentTopic
= CurrentSubsectionName
;
188 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
191 texTopic
= new TexTopic
;
192 TopicTable
.Put(parentTopic
, texTopic
);
194 texTopic
->hasChildren
= TRUE
;
198 // Have to keep a count of what levels are books, what are pages,
199 // in order to correct for a Win95 bug which means that if you
200 // have a book at level n, and then a page at level n, the page
201 // ends up on level n + 1.
203 bool ContentsLevels
[5];
205 // Reset below this level (starts from 1)
206 void ResetContentsLevels(int l
)
209 for (i
= l
; i
< 5; i
++)
210 ContentsLevels
[i
] = FALSE
;
212 // There are always books on the top level
213 ContentsLevels
[0] = TRUE
;
216 // Output a WinHelp section as a keyword, substituting
218 void OutputSectionKeyword(FILE *fd
)
220 OutputCurrentSectionToString(wxTex2RTFBuffer
);
223 for (i
= 0; i
< strlen(wxTex2RTFBuffer
); i
++)
224 if (wxTex2RTFBuffer
[i
] == ':')
225 wxTex2RTFBuffer
[i
] = ' ';
226 // Don't write to index if there's some RTF in the string
227 else if ( wxTex2RTFBuffer
[i
] == '{' )
230 fprintf(fd
, "K{\\footnote {K} ");
231 fprintf(fd
, "%s", wxTex2RTFBuffer
);
236 // Write a line for the .cnt file, if we're doing this.
237 void WriteWinHelpContentsFileLine(char *topicName
, char *xitle
, int level
)
239 // First, convert any RTF characters to ASCII
243 while ( (xitle
[s
]!=0)&&(d
<255) )
245 char ch
=xitle
[s
]&0xff;
247 char ch1
=xitle
[s
+1]&0xff;
248 char ch2
=xitle
[s
+2]&0xff;
249 char ch3
=xitle
[s
+3]&0xff;
250 char ch4
=xitle
[s
+4]&0xff;
251 s
+=4; // next character
253 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]='ö'; a
=1; }
254 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]='ä'; a
=1; }
255 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]='ü'; a
=1; }
256 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]='Ö'; a
=1; }
257 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]='Ä'; a
=1; }
258 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]='Ü'; a
=1; }
260 // printf("!!!!! %04X %04X %04X %04X! \n",ch1,ch2,ch3,ch4);
268 // Section (2) becomes level 1 if it's an article.
269 if (DocumentStyle
== LATEX_ARTICLE
)
272 if (level
== 0) // Means we had a Chapter in an article, oops.
275 ResetContentsLevels(level
);
280 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
282 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
285 // If a previous section at this level was a book, we *have* to have a
286 // book not a page, because of a bug in WHC (or WinHelp 4).
287 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
289 // At this level, we have a pointer to a further hierarchy.
290 // So we need a 'book' consisting of (say) Chapter 1.
291 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
293 // Then we have a 'page' consisting of the text for this chapter
294 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
296 // Then we'll be writing out further pages or books at level + 1...
298 // Remember that at this level, we had a book and *must* for the
299 // remainder of sections at this level.
300 ContentsLevels
[level
-1] = TRUE
;
304 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
309 if (level
== 1 || ContentsLevels
[level
-1])
311 // Always have a book at level 1
312 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
313 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
314 ContentsLevels
[level
-1] = TRUE
;
317 // Probably doesn't have children if it hasn't been added to the topic table
318 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
323 void SplitIndexEntry(char *entry
, char *buf1
, char *buf2
)
325 int len
= strlen(entry
); int i
= 0;
326 while ((i
< len
) && entry
[i
] != '!')
327 { buf1
[i
] = entry
[i
]; i
++; }
328 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
333 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
339 * Output topic index entries in WinHelp RTF
342 void GenerateKeywordsForTopic(char *topic
)
344 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
348 wxStringList
*list
= texTopic
->keywords
;
351 wxNode
*node
= list
->First();
354 char *s
= (char *)node
->Data();
356 // Must separate out main entry form subentry (only 1 subentry allowed)
357 char buf1
[100]; char buf2
[100];
358 SplitIndexEntry(s
, buf1
, buf2
);
360 // Check for ':' which messes up index
362 for (i
= 0; i
< strlen(buf1
) ; i
++)
365 for (i
= 0; i
< strlen(buf2
) ; i
++)
369 // {K} is a strange fix to prevent words beginning with K not
370 // being indexed properly
371 TexOutput("K{\\footnote {K} ");
373 if (strlen(buf2
) > 0)
386 * Output index entry in linear RTF
390 void GenerateIndexEntry(char *entry
)
394 char buf1
[100]; char buf2
[100];
395 SplitIndexEntry(entry
, buf1
, buf2
);
397 TexOutput("{\\xe\\v {");
399 if (strlen(buf2
) > 0)
409 * Write a suitable RTF header.
413 void WriteColourTable(FILE *fd
)
415 fprintf(fd
, "{\\colortbl");
416 wxNode
*node
= ColourTable
.First();
419 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->Data();
420 fprintf(fd
, "\\red%d\\green%d\\blue%d;\n", entry
->red
, entry
->green
, entry
->blue
);
427 * Write heading style
431 void WriteHeadingStyle(FILE *fd
, int heading
)
437 fprintf(fd
, "\\b\\fs%d", chapterFont
*2);
442 fprintf(fd
, "\\b\\fs%d", sectionFont
*2);
447 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
452 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
460 void WriteRTFHeader(FILE *fd
)
462 fprintf(fd
, "{\\rtf1\\%s \\deff0\n", RTFCharset
);
463 fprintf(fd
, "{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n");
464 fprintf(fd
, "{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}");
468 fprintf(fd
, "{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n");
470 fprintf(fd
, "{\\s1 "); WriteHeadingStyle(fd
, 1); fprintf(fd
, "\\sbasedon0\\snext0 heading 1;}\n");
471 fprintf(fd
, "{\\s2 "); WriteHeadingStyle(fd
, 2); fprintf(fd
, "\\sbasedon0\\snext0 heading 2;}\n");
472 fprintf(fd
, "{\\s3 "); WriteHeadingStyle(fd
, 3); fprintf(fd
, "\\sbasedon0\\snext0 heading 3;}\n");
473 fprintf(fd
, "{\\s4 "); WriteHeadingStyle(fd
, 4); fprintf(fd
, "\\sbasedon0\\snext0 heading 4;}\n");
474 // Table of contents styles
475 fprintf(fd
, "{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n");
477 fprintf(fd
, "{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n");
478 fprintf(fd
, "{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n");
479 fprintf(fd
, "{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n");
482 fprintf(fd
, "{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n");
483 fprintf(fd
, "{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n");
484 fprintf(fd
, "{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n");
485 fprintf(fd
, "{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n");
486 fprintf(fd
, "{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n");
489 WriteColourTable(fd
);
490 fprintf(fd
, "\n\\ftnbj\\ftnrestart"); // Latex default is footnotes at bottom of page, not section.
494 void OutputNumberStyle(char *numberStyle
)
498 if (strcmp(numberStyle
, "arabic") == 0)
500 TexOutput("\\pgndec");
502 else if (strcmp(numberStyle
, "roman") == 0)
504 TexOutput("\\pgnlcrm");
506 else if (strcmp(numberStyle
, "Roman") == 0)
508 TexOutput("\\pgnucrm");
510 else if (strcmp(numberStyle
, "alph") == 0)
512 TexOutput("\\pgnlcltr");
514 else if (strcmp(numberStyle
, "Alph") == 0)
516 TexOutput("\\pgnucltr");
522 * Write a Windows help project file
525 bool WriteHPJ(char *filename
)
527 char hpjFilename
[256];
530 strcpy(hpjFilename
, filename
);
531 StripExtension(hpjFilename
);
532 strcat(hpjFilename
, ".hpj");
534 strcpy(helpFile
, wxFileNameFromPath(filename
));
535 StripExtension(helpFile
);
536 strcpy(rtfFile
, helpFile
);
537 strcat(helpFile
, ".hlp");
538 strcat(rtfFile
, ".rtf");
540 FILE *fd
= fopen(hpjFilename
, "w");
544 char *helpTitle
= winHelpTitle
;
546 helpTitle
= "Untitled";
548 wxString thePath
= wxPathOnly(InputFile
);
549 if (thePath
.IsEmpty())
551 fprintf(fd
, "[OPTIONS]\n");
552 fprintf(fd
, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath
.c_str());
553 fprintf(fd
, "TITLE=%s\n", helpTitle
);
554 fprintf(fd
, "CONTENTS=Contents\n");
556 if (winHelpVersion
> 3)
558 fprintf(fd
, "; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n");
559 fprintf(fd
, "COMPRESS=8 Zeck\n");
560 fprintf(fd
, "LCID=0x809 0x0 0x0 ;English (British)\n");
561 fprintf(fd
, "HLP=.\\%s.hlp\n", wxFileNameFromPath(FileRoot
));
565 fprintf(fd
, "COMPRESS=HIGH\n");
569 if (winHelpVersion
> 3)
571 fprintf(fd
, "[WINDOWS]\n");
572 fprintf(fd
, "Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n");
576 fprintf(fd
, "[FILES]\n%s\n\n", rtfFile
);
577 fprintf(fd
, "[CONFIG]\n");
579 fprintf(fd
, "CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n", helpFile
);
580 fprintf(fd
, "BrowseButtons()\n\n");
581 fprintf(fd
, "[MAP]\n\n[BITMAPS]\n\n");
588 * Given a TexChunk with a string value, scans through the string
589 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
590 * and inserting spaces at the start of lines since in Latex, a newline
591 * implies a space, but not in RTF.
595 void ProcessText2RTF(TexChunk
*chunk
)
597 bool changed
= FALSE
;
601 int len
= strlen(chunk
->value
);
604 ch
= chunk
->value
[i
];
610 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "\\par\n"); ptr
+= 5;
616 // If the first character of the next line is ASCII,
617 // put a space in. Implicit in Latex, not in RTF.
619 The reason this is difficult is that you don't really know
620 where a space would be appropriate. If you always put in a space
621 when you find a newline, unwanted spaces appear in the text.
623 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
624 !isspace(chunk
->value
[i
+1])) ||
625 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
626 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
627 !isspace(chunk
->value
[i
+2]))))
630 // DOS files have a 13 after the 10
634 if (chunk
->value
[i
] == 13)
641 BigBuffer
[ptr
] = ' ';
644 // Note that the actual ASCII character seen is dealt with in the next
655 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
657 BigBuffer
[ptr
] = '"'; ptr
++;
661 else if (!inVerbatim
&& ch
== '`') // Change ` to '
663 BigBuffer
[ptr
] = 39; ptr
++;
667 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
669 BigBuffer
[ptr
] = '\\'; ptr
++;
670 BigBuffer
[ptr
] = '\\'; ptr
++;
674 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curley bracket
676 BigBuffer
[ptr
] = '\\'; ptr
++;
677 BigBuffer
[ptr
] = ch
; ptr
++;
692 delete[] chunk
->value
;
693 chunk
->value
= copystring(BigBuffer
);
698 * Scan through all chunks starting from the given one,
699 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
700 * This should be called after Tex2Any has parsed the file,
701 * and before TraverseDocument is called.
705 void Text2RTF(TexChunk
*chunk
)
708 if (stopRunning
) return;
712 case CHUNK_TYPE_MACRO
:
714 TexMacroDef
*def
= chunk
->def
;
715 if (def
&& def
->ignore
)
718 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
721 wxNode
*node
= chunk
->children
.First();
724 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
725 Text2RTF(child_chunk
);
729 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
736 wxNode
*node
= chunk
->children
.First();
739 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
740 Text2RTF(child_chunk
);
746 case CHUNK_TYPE_STRING
:
749 ProcessText2RTF(chunk
);
761 static long browseId
= 0;
762 char *GetBrowseString(void)
766 sprintf(buf
, "%ld", browseId
);
767 int noZeroes
= 5-strlen(buf
);
768 strcpy(browseBuf
, "browse");
769 for (int i
= 0; i
< noZeroes
; i
++)
770 strcat(browseBuf
, "0");
771 strcat(browseBuf
, buf
);
776 * Keeping track of environments to restore the styles after \pard.
777 * Push strings like "\qc" onto stack.
781 void PushEnvironmentStyle(char *style
)
783 environmentStack
.Add(style
);
786 void PopEnvironmentStyle(void)
788 wxNode
*node
= environmentStack
.Last();
791 char *val
= (char *)node
->Data();
797 // Write out the styles, most recent first.
798 void WriteEnvironmentStyles(void)
800 wxNode
*node
= environmentStack
.Last();
803 char *val
= (char *)node
->Data();
807 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
810 sprintf(buf
, "\\fi%d", ParIndent
*20); // Convert points to TWIPS
813 if (environmentStack
.Number() > 0 || (ParIndent
> 0))
823 void OutputRTFHeaderCommands(void)
826 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
828 TexOutput("{\\headerl }{\\headerr }");
830 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
832 TexOutput("{\\headerl }{\\headerr }");
834 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
837 TexOutput("{\\headerl\\fi0 ");
840 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
842 TexOutput("{\\i \\qr ");
843 if (DocumentStyle
== LATEX_ARTICLE
)
845 sprintf(buf
, "SECTION %d", sectionNo
);
850 sprintf(buf
, "CHAPTER %d: ", chapterNo
);
853 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
854 TexOutput("}\\par\\pard}");
857 TexOutput("{\\headerr\\fi0 ");
860 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
862 TexOutput("{\\i \\qc ");
863 if (DocumentStyle
== LATEX_ARTICLE
)
865 sprintf(buf
, "SECTION %d", sectionNo
);
870 sprintf(buf
, "CHAPTER %d", chapterNo
);
873 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
874 TexOutput("}\\par\\pard}");
878 int oldForbidResetPar
= forbidResetPar
;
881 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
883 TexOutput("{\\headerl\\fi0 ");
886 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
890 if (!CentreHeaderEven
&& !RightHeaderEven
)
892 TraverseChildrenFromChunk(LeftHeaderEven
);
894 if (CentreHeaderEven
)
896 if (!LeftHeaderEven
&& !RightHeaderEven
)
899 TexOutput("\\tab\\tab\\tab ");
900 TraverseChildrenFromChunk(CentreHeaderEven
);
904 if (!LeftHeaderEven
&& !CentreHeaderEven
)
907 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
908 TraverseChildrenFromChunk(RightHeaderEven
);
910 TexOutput("\\par\\pard}");
913 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
915 TexOutput("{\\headerr\\fi0 ");
918 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
922 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
924 TraverseChildrenFromChunk(LeftHeaderOdd
);
928 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
931 TexOutput("\\tab\\tab\\tab ");
932 TraverseChildrenFromChunk(CentreHeaderOdd
);
936 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
939 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
940 TraverseChildrenFromChunk(RightHeaderOdd
);
942 TexOutput("\\par\\pard}");
944 // As an approximation, don't put a header on the first page of a section.
945 // This may not always be desired, but it's a reasonable guess.
946 TexOutput("{\\headerf }");
948 forbidResetPar
= oldForbidResetPar
;
952 void OutputRTFFooterCommands(void)
954 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
956 TexOutput("{\\footerl\\fi0 ");
958 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
960 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
961 TexOutput("}\\par\\pard}");
963 TexOutput("{\\footerr\\fi0 ");
965 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
967 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
968 TexOutput("}\\par\\pard}");
970 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
972 TexOutput("{\\footerl }{\\footerr }");
974 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
976 TexOutput("{\\footerl }{\\footerr }");
980 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
982 TexOutput("{\\footerl\\fi0 ");
984 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
987 if (!CentreFooterEven
&& !RightFooterEven
)
989 TraverseChildrenFromChunk(LeftFooterEven
);
991 if (CentreFooterEven
)
993 if (!LeftFooterEven
&& !RightFooterEven
)
996 TexOutput("\\tab\\tab\\tab ");
997 TraverseChildrenFromChunk(CentreFooterEven
);
1001 if (!LeftFooterEven
&& !CentreFooterEven
)
1004 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1005 TraverseChildrenFromChunk(RightFooterEven
);
1007 TexOutput("\\par\\pard}");
1010 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1012 TexOutput("{\\footerr\\fi0 ");
1014 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
1017 if (!CentreFooterOdd
&& !RightFooterOdd
)
1019 TraverseChildrenFromChunk(LeftFooterOdd
);
1021 if (CentreFooterOdd
)
1023 if (!LeftFooterOdd
&& !RightFooterOdd
)
1026 TexOutput("\\tab\\tab\\tab ");
1027 TraverseChildrenFromChunk(CentreFooterOdd
);
1031 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1034 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1035 TraverseChildrenFromChunk(RightFooterOdd
);
1037 TexOutput("\\par\\pard}");
1040 // As an approximation, put a footer on the first page of a section.
1041 // This may not always be desired, but it's a reasonable guess.
1042 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1044 TexOutput("{\\footerf\\fi0 ");
1047 if (!CentreFooterOdd
&& !RightFooterOdd
)
1049 TraverseChildrenFromChunk(LeftFooterOdd
);
1051 if (CentreFooterOdd
)
1053 if (!LeftFooterOdd
&& !RightFooterOdd
)
1056 TexOutput("\\tab\\tab\\tab ");
1057 TraverseChildrenFromChunk(CentreFooterOdd
);
1061 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1064 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1065 TraverseChildrenFromChunk(RightFooterOdd
);
1067 TexOutput("\\par\\pard}");
1072 // Called on start/end of macro examination
1073 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1077 sprintf(tmpBuf, "%d (%d)", macroId, (int)start);
1078 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1079 OutputDebugString("\n"); wxYield();
1082 // ltLABEL is included here because after a section but BEFORE
1083 // the label is seen, a new paragraph is issued. Don't upset this by
1084 // immediately forgetting we've done it.
1085 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1086 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1087 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1088 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1089 macroId
!= ltPAGENUMBERING
&&
1090 (forbidResetPar
== 0)))
1092 issuedNewParagraph
= 0;
1100 case ltCHAPTERHEADING
:
1101 case ltCHAPTERHEADINGSTAR
:
1109 subsubsectionNo
= 0;
1112 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1115 char *topicName
= FindTopicName(GetNextChunk());
1116 SetCurrentChapterName(topicName
);
1118 if (winHelpContents
&& winHelp
&& !InPopups())
1120 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1121 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1123 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1128 fprintf(Contents
, "\n{\\uldb ");
1129 fprintf(Chapters
, "\\page");
1130 fprintf(Chapters
, "\n${\\footnote ");
1132 SetCurrentOutputs(Contents
, Chapters
);
1134 SetCurrentOutput(Chapters
);
1138 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
1140 // If a non-custom page style, we generate the header now.
1141 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1142 strcmp(PageStyle
, "empty") == 0 ||
1143 strcmp(PageStyle
, "headings") == 0))
1145 OutputRTFHeaderCommands();
1146 OutputRTFFooterCommands();
1149 // Need to reset the current numbering style, or RTF forgets it.
1150 SetCurrentOutput(Chapters
);
1151 OutputNumberStyle(currentNumberStyle
);
1153 SetCurrentOutput(Contents
);
1157 if (macroId
== ltCHAPTER
)
1160 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", chapterNo
);
1162 else if (macroId
== ltCHAPTERHEADING
)
1164 fprintf(Contents
, "\\par\n\\pard{\\b ");
1166 else SetCurrentOutput(NULL
); // No entry in table of contents
1170 startedSections
= TRUE
;
1172 // Output heading to contents page
1175 OutputCurrentSection();
1178 fprintf(Contents
, "}{\\v %s}\\par\\pard\n", topicName
);
1179 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1180 fprintf(Contents
, "}\\par\\par\\pard\n");
1182 // From here, just output to chapter
1183 SetCurrentOutput(Chapters
);
1188 fprintf(Chapters
, "}\n#{\\footnote %s}\n", topicName
);
1189 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
1191 OutputSectionKeyword(Chapters
);
1193 GenerateKeywordsForTopic(topicName
);
1196 // If we're generating a .cnt file, we don't want to be able
1197 // jump up to the old-style contents page, so disable it.
1198 if (winHelpContents
)
1199 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
1201 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1202 wxFileNameFromPath(FileRoot
), "Contents");
1208 char *styleCommand
= "";
1209 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1210 styleCommand
= "\\s1";
1211 fprintf(Chapters
, "\\pard{%s", ((winHelp
&& !InPopups()) ? "\\keepn\\sa140\\sb140" : styleCommand
));
1212 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " ");
1215 if (macroId
== ltCHAPTER
)
1218 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1219 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1221 fprintf(Chapters
, "%d. ", chapterNo
);
1225 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1228 OutputCurrentSection();
1229 TexOutput("\\par\\pard}\\par\n");
1231 issuedNewParagraph
= 2;
1237 case ltSECTIONHEADING
:
1238 case ltSECTIONHEADINGSTAR
:
1242 if (DocumentStyle
== LATEX_ARTICLE
)
1243 jumpFrom
= Contents
;
1245 jumpFrom
= Chapters
;
1250 subsubsectionNo
= 0;
1251 if (DocumentStyle
== LATEX_ARTICLE
)
1254 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1257 char *topicName
= FindTopicName(GetNextChunk());
1258 SetCurrentSectionName(topicName
);
1259 NotifyParentHasChildren(1);
1260 if (winHelpContents
&& winHelp
&& !InPopups())
1262 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1263 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1265 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1269 SetCurrentOutputs(jumpFrom
, Sections
);
1270 // Newline for a new section if this is an article
1271 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1272 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1273 fprintf(Sections
, "\\page\n");
1276 fprintf(jumpFrom
, "\n{\\uldb ");
1280 if (DocumentStyle
== LATEX_ARTICLE
)
1282 TexOutput("\\sect\\pgncont\n");
1283 // If a non-custom page style, we generate the header now.
1284 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1285 strcmp(PageStyle
, "empty") == 0 ||
1286 strcmp(PageStyle
, "headings") == 0))
1288 OutputRTFHeaderCommands();
1289 OutputRTFFooterCommands();
1292 SetCurrentOutput(Contents
);
1294 if (macroId
== ltSECTION
)
1298 if (DocumentStyle
== LATEX_REPORT
)
1299 fprintf(Contents
, "\n\\pard{\\tab %d.%d\\tab ", chapterNo
, sectionNo
);
1301 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", sectionNo
);
1304 else if (macroId
== ltSECTIONHEADING
)
1308 if (DocumentStyle
== LATEX_REPORT
)
1309 fprintf(Contents
, "\n\\pard{\\tab "); //, chapterNo, sectionNo);
1311 fprintf(Contents
, "\\par\n\\pard{\\b "); //, sectionNo);
1314 else SetCurrentOutput(NULL
);
1317 if (startedSections
)
1320 fprintf(Sections
, "\\page\n");
1322 startedSections
= TRUE
;
1325 fprintf(Sections
, "\n${\\footnote ");
1327 // Output heading to contents page
1329 OutputCurrentSection();
1334 fprintf(jumpFrom
, "}{\\v %s}\\par\\pard\n", topicName
);
1336 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1338 if (DocumentStyle
== LATEX_REPORT
)
1339 fprintf(Contents
, "}\\par\\pard\n");
1341 fprintf(Contents
, "}\\par\\par\\pard\n");
1344 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1348 fprintf(Sections
, "}\n#{\\footnote %s}\n", topicName
);
1349 fprintf(Sections
, "+{\\footnote %s}\n", GetBrowseString());
1350 OutputSectionKeyword(Sections
);
1351 GenerateKeywordsForTopic(topicName
);
1354 if (DocumentStyle
== LATEX_ARTICLE
)
1356 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1357 wxFileNameFromPath(FileRoot
), "Contents");
1359 else if (CurrentChapterName
)
1361 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1362 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1369 char *styleCommand
= "";
1370 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1372 if (DocumentStyle
== LATEX_ARTICLE
)
1373 styleCommand
= "\\s1";
1375 styleCommand
= "\\s2";
1378 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1379 keep
= "\\keepn\\sa140\\sb140";
1381 fprintf(winHelp
? Sections
: Chapters
, "\\pard{%s%s",
1382 keep
, styleCommand
);
1384 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1385 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1386 fprintf(winHelp
? Sections
: Chapters
, " ");
1390 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1392 if (DocumentStyle
== LATEX_REPORT
)
1395 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo,
1396 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1399 fprintf(Chapters
, "%d.%d. ", chapterNo
, sectionNo
);
1404 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1405 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1408 fprintf(Chapters
, "%d. ", sectionNo
);
1413 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1416 OutputCurrentSection();
1417 TexOutput("\\par\\pard}\\par\n");
1419 issuedNewParagraph
= 2;
1424 case ltSUBSECTIONSTAR
:
1425 case ltMEMBERSECTION
:
1426 case ltFUNCTIONSECTION
:
1430 if (winHelp
&& !Sections
)
1432 OnError("You cannot have a subsection before a section!");
1436 subsubsectionNo
= 0;
1438 if (macroId
!= ltSUBSECTIONSTAR
)
1441 char *topicName
= FindTopicName(GetNextChunk());
1442 SetCurrentSubsectionName(topicName
);
1443 NotifyParentHasChildren(2);
1444 if (winHelpContents
&& winHelp
&& !InPopups())
1446 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1447 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1449 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1453 SetCurrentOutputs(Sections
, Subsections
);
1454 SetCurrentOutputs(Sections
, Subsections
);
1456 fprintf(Sections
, "\n{\\uldb ");
1460 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1461 (macroId
!= ltFUNCTIONSECTION
))
1463 SetCurrentOutput(Contents
);
1464 if (DocumentStyle
== LATEX_REPORT
)
1465 fprintf(Contents
, "\n\\pard\\tab\\tab %d.%d.%d\\tab ", chapterNo
, sectionNo
, subsectionNo
);
1467 fprintf(Contents
, "\n\\pard\\tab %d.%d\\tab ", sectionNo
, subsectionNo
);
1468 } else SetCurrentOutput(NULL
);
1470 if (startedSections
)
1475 fprintf(Subsections
, "\\page\n");
1478 fprintf(Chapters
, "\\par\n");
1480 startedSections
= TRUE
;
1483 fprintf(Subsections
, "\n${\\footnote ");
1485 // Output to contents page
1487 OutputCurrentSection();
1492 fprintf(Sections
, "}{\\v %s}\\par\\pard\n", topicName
);
1494 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1495 (macroId
!= ltFUNCTIONSECTION
))
1496 fprintf(Contents
, "\\par\\pard\n");
1498 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1501 fprintf(Subsections
, "}\n#{\\footnote %s}\n", topicName
);
1502 fprintf(Subsections
, "+{\\footnote %s}\n", GetBrowseString());
1503 OutputSectionKeyword(Subsections
);
1504 GenerateKeywordsForTopic(topicName
);
1505 if (useUpButton
&& CurrentSectionName
)
1507 fprintf(Subsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1508 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1511 if (!winHelp
&& indexSubsections
&& useWord
)
1513 // Insert index entry for this subsection
1514 TexOutput("{\\xe\\v {");
1515 OutputCurrentSection();
1521 char *styleCommand
= "";
1522 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1524 if (DocumentStyle
== LATEX_ARTICLE
)
1525 styleCommand
= "\\s2";
1527 styleCommand
= "\\s3";
1530 if (winHelp
&& !InPopups())
1531 keep
= "\\keepn\\sa140\\sb140";
1533 fprintf(winHelp
? Subsections
: Chapters
, "\\pard{%s%s",
1534 keep
, styleCommand
);
1536 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1537 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1538 fprintf(winHelp
? Subsections
: Chapters
, " ");
1542 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1543 (macroId
!= ltFUNCTIONSECTION
))
1545 if (DocumentStyle
== LATEX_REPORT
)
1548 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo,
1549 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1552 fprintf(Chapters
, "%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
);
1557 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo,
1558 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1561 fprintf(Chapters
, "%d.%d. ", sectionNo
, subsectionNo
);
1566 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1569 OutputCurrentSection(); // Repeat section header
1570 TexOutput("\\par\\pard}\\par\n");
1572 issuedNewParagraph
= 2;
1577 case ltSUBSUBSECTION
:
1578 case ltSUBSUBSECTIONSTAR
:
1582 if (winHelp
&& !Subsections
)
1584 OnError("You cannot have a subsubsection before a subsection!");
1588 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1591 char *topicName
= FindTopicName(GetNextChunk());
1592 SetCurrentTopic(topicName
);
1593 NotifyParentHasChildren(3);
1594 if (winHelpContents
&& winHelp
)
1596 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1597 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1599 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1603 SetCurrentOutputs(Subsections
, Subsubsections
);
1604 fprintf(Subsections
, "\n{\\uldb ");
1608 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1610 if (DocumentStyle
== LATEX_ARTICLE
)
1612 SetCurrentOutput(Contents
);
1613 fprintf(Contents
, "\n\\tab\\tab %d.%d.%d\\tab ",
1614 sectionNo
, subsectionNo
, subsubsectionNo
);
1617 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1620 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1623 if (startedSections
)
1626 fprintf(Subsubsections
, "\\page\n");
1628 fprintf(Chapters
, "\\par\n");
1631 startedSections
= TRUE
;
1634 fprintf(Subsubsections
, "\n${\\footnote ");
1636 // Output header to contents page
1637 OutputCurrentSection();
1640 fprintf(Subsections
, "}{\\v %s}\\par\\pard\n", topicName
);
1641 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1642 fprintf(Contents
, "\\par\\pard\n");
1644 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1647 fprintf(Subsubsections
, "}\n#{\\footnote %s}\n", topicName
);
1648 fprintf(Subsubsections
, "+{\\footnote %s}\n", GetBrowseString());
1649 OutputSectionKeyword(Subsubsections
);
1650 GenerateKeywordsForTopic(topicName
);
1651 if (useUpButton
&& CurrentSubsectionName
)
1653 fprintf(Subsubsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1654 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1657 if (!winHelp
&& indexSubsections
&& useWord
)
1659 // Insert index entry for this subsubsection
1660 TexOutput("{\\xe\\v {");
1661 OutputCurrentSection();
1665 char *styleCommand
= "";
1666 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1668 if (DocumentStyle
== LATEX_ARTICLE
)
1669 styleCommand
= "\\s3";
1671 styleCommand
= "\\s4";
1675 keep
= "\\keepn\\sa140\\sb140";
1677 fprintf(winHelp
? Subsubsections
: Chapters
, "\\pard{%s%s",
1678 keep
, styleCommand
);
1680 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1681 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1682 fprintf(winHelp
? Subsubsections
: Chapters
, " ");
1686 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1688 if (DocumentStyle
== LATEX_ARTICLE
)
1691 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo, subsubsectionNo,
1692 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1695 fprintf(Chapters
, "%d.%d.%d. ", sectionNo
, subsectionNo
, subsubsectionNo
);
1700 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1701 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1704 fprintf(Chapters
, "%d.%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1709 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1712 OutputCurrentSection(); // Repeat section header
1713 TexOutput("\\par\\pard}\\par\n");
1714 issuedNewParagraph
= 2;
1715 // if (winHelp) TexOutput("\\pard");
1725 char *topicName
= FindTopicName(GetNextChunk());
1726 SetCurrentTopic(topicName
);
1728 TexOutput("\\pard\\par");
1735 if (winHelp
|| !useWord
)
1737 if (DocumentStyle
!= LATEX_ARTICLE
)
1738 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1740 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1744 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1745 FigureNameString
, topicName
, topicName
);
1752 if (winHelp
|| !useWord
)
1754 if (DocumentStyle
!= LATEX_ARTICLE
)
1755 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1757 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1761 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1762 TableNameString
, topicName
, topicName
);
1766 int n
= (inTable
? tableNo
: figureNo
);
1767 AddTexRef(topicName
, NULL
, NULL
,
1768 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1769 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1772 TexOutput("\\qc{\\b ");
1774 TexOutput("\\ql{\\b ");
1777 OutputCurrentSection();
1779 TexOutput("}\\par\\pard\n");
1780 WriteEnvironmentStyles();
1787 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1797 TexOutput("K{\\footnote {K} ");
1798 suppressNameDecoration
= TRUE
;
1799 TraverseChildrenFromChunk(currentMember
);
1800 suppressNameDecoration
= FALSE
;
1803 if (!winHelp
&& useWord
)
1805 // Insert index entry for this function
1806 TexOutput("{\\xe\\v {");
1807 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1808 TraverseChildrenFromChunk(currentMember
);
1809 suppressNameDecoration
= FALSE
;
1817 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1827 TexOutput("K{\\footnote {K} ");
1828 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1829 TraverseChildrenFromChunk(currentMember
);
1830 suppressNameDecoration
= FALSE
;
1833 if (!winHelp
&& useWord
)
1835 // Insert index entry for this function
1836 TexOutput("{\\xe\\v {");
1837 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1838 TraverseChildrenFromChunk(currentMember
);
1839 suppressNameDecoration
= FALSE
;
1847 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1857 TexOutput("K{\\footnote {K} ");
1858 TraverseChildrenFromChunk(currentMember
);
1861 if (!winHelp
&& useWord
)
1863 // Insert index entry for this function
1864 TexOutput("{\\xe\\v {");
1865 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1866 TraverseChildrenFromChunk(currentMember
);
1867 suppressNameDecoration
= FALSE
;
1876 SetCurrentOutput(Chapters
);
1879 case ltTABLEOFCONTENTS
:
1883 if (!winHelp
&& useWord
)
1885 // Insert Word for Windows table of contents
1886 TexOutput("\\par\\pard\\pgnrestart\\sect\\titlepg");
1888 // In linear RTF, same as chapter headings.
1889 sprintf(buf
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n", chapterFont
*2, ContentsNameString
);
1892 sprintf(buf
, "{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n", contentsDepth
);
1894 // TexOutput("\\sect\\sectd");
1898 FILE *fd
= fopen(ContentsName
, "r");
1911 TexOutput("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n");
1912 OnInform("Run Tex2RTF again to include contents page.");
1921 // TexOutput("{\\b void}");
1927 TexOutput("{\\scaps HARDY}");
1933 TexOutput("wxCLIPS");
1936 case ltSPECIALAMPERSAND
:
1941 TexOutput("\\cell ");
1947 case ltSPECIALTILDE
:
1958 case ltBACKSLASHCHAR
:
1964 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
1965 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
1966 int currentWidth
= 0;
1967 for (int i
= 0; i
< noColumns
; i
++)
1969 currentWidth
+= TableData
[i
].width
;
1970 if (TableData
[i
].rightBorder
)
1971 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
1973 if (TableData
[i
].leftBorder
)
1974 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
1976 sprintf(buf
, "\\cellx%d", currentWidth
);
1979 TexOutput("\\pard\\intbl\n");
1982 TexOutput("\\line\n");
1992 case ltRTFSP
: // Explicit space, RTF only
2004 if (indentLevel
> 0)
2006 TexOutput("\\par\\par\n");
2007 issuedNewParagraph
= 2;
2011 // Top-level list: issue a new paragraph if we haven't
2013 if (!issuedNewParagraph
)
2015 TexOutput("\\par\\pard");
2016 WriteEnvironmentStyles();
2017 issuedNewParagraph
= 1;
2019 else issuedNewParagraph
= 0;
2022 TexOutput("\\fi0\n");
2024 if (macroId
== ltENUMERATE
)
2025 listType
= LATEX_ENUMERATE
;
2026 else if (macroId
== ltITEMIZE
)
2027 listType
= LATEX_ITEMIZE
;
2029 listType
= LATEX_DESCRIPTION
;
2032 wxNode
*node
= itemizeStack
.First();
2034 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2036 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2037 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2039 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2040 itemizeStack
.Insert(struc
);
2042 sprintf(buf
, "\\tx%d\\tx%d\\li%d", indentSize1
, indentSize2
, indentSize2
);
2043 PushEnvironmentStyle(buf
);
2047 currentItemSep
= 8; // Reset to the default
2049 PopEnvironmentStyle();
2051 if (itemizeStack
.First())
2053 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2055 delete itemizeStack
.First();
2057 /* Change 18/7/97 - don't know why we wish to do this
2058 if (itemizeStack.Number() == 0)
2060 OnMacro(ltPAR, 0, TRUE);
2061 OnMacro(ltPAR, 0, FALSE);
2062 issuedNewParagraph = 2;
2074 wxNode
*node
= itemizeStack
.First();
2076 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2078 int indentSize
= oldIndent
+ TwoColWidthA
;
2080 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2081 itemizeStack
.Insert(struc
);
2083 // sprintf(buf, "\\tx%d\\li%d\\ri%d", indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2084 sprintf(buf
, "\\tx%d\\li%d", indentSize
, indentSize
);
2085 PushEnvironmentStyle(buf
);
2090 PopEnvironmentStyle();
2091 if (itemizeStack
.First())
2093 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2095 delete itemizeStack
.First();
2099 TexOutput("\\pard\n");
2100 WriteEnvironmentStyles();
2102 /* why do we need this? */
2103 if (itemizeStack
.Number() == 0)
2105 issuedNewParagraph
= 0;
2106 OnMacro(ltPAR
, 0, TRUE
);
2107 OnMacro(ltPAR
, 0, FALSE
);
2114 wxNode
*node
= itemizeStack
.First();
2117 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2120 struc
->currentItem
+= 1;
2123 int indentSize1
= struc
->labelIndentation
;
2124 int indentSize2
= struc
->indentation
;
2127 if (struc
->currentItem
> 1)
2129 if (currentItemSep
> 0)
2133 // WriteEnvironmentStyles();
2136 sprintf(buf
, "\\tx%d\\tx%d\\li%d\\fi-%d\n", indentSize1
, indentSize2
,
2137 indentSize2
, 20*itemIndentTab
);
2140 switch (struc
->listType
)
2142 case LATEX_ENUMERATE
:
2144 if (descriptionItemArg
)
2146 TexOutput("\\tab{ ");
2147 TraverseChildrenFromChunk(descriptionItemArg
);
2148 TexOutput("}\\tab");
2149 descriptionItemArg
= NULL
;
2153 sprintf(indentBuf
, "\\tab{\\b %d.}\\tab", struc
->currentItem
);
2154 TexOutput(indentBuf
);
2160 if (descriptionItemArg
)
2162 TexOutput("\\tab{ ");
2163 TraverseChildrenFromChunk(descriptionItemArg
);
2164 TexOutput("}\\tab");
2165 descriptionItemArg
= NULL
;
2169 if (bulletFile
&& winHelp
)
2171 if (winHelpVersion
> 3) // Transparent bitmap
2172 sprintf(indentBuf
, "\\tab\\{bmct %s\\}\\tab", bulletFile
);
2174 sprintf(indentBuf
, "\\tab\\{bmc %s\\}\\tab", bulletFile
);
2177 sprintf(indentBuf
, "\\tab{\\b o}\\tab");
2179 sprintf(indentBuf
, "\\tab{\\f1\\'b7}\\tab");
2180 TexOutput(indentBuf
);
2185 case LATEX_DESCRIPTION
:
2187 if (descriptionItemArg
)
2189 TexOutput("\\tab{\\b ");
2190 TraverseChildrenFromChunk(descriptionItemArg
);
2192 descriptionItemArg
= NULL
;
2202 case ltTWOCOLITEMRULED
:
2204 wxNode
*node
= itemizeStack
.First();
2207 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2210 struc
->currentItem
+= 1;
2213 wxNode
*node2
= NULL
;
2214 if (itemizeStack
.Number() > 1) // TODO: do I actually mean Nth(0) here??
2215 node2
= itemizeStack
.Nth(1);
2217 oldIndent
= ((ItemizeStruc
*)node2
->Data())->indentation
;
2220 if (struc
->currentItem
> 1)
2222 if (currentItemSep
> 0)
2225 // WriteEnvironmentStyles();
2228 // sprintf(buf, "\\tx%d\\li%d\\fi-%d\\ri%d\n", TwoColWidthA,
2229 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2231 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA,
2232 TwoColWidthA, TwoColWidthA);
2234 sprintf(buf
, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA
+ oldIndent
,
2235 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2246 if (macroId
== ltVERBATIM
)
2248 if (!issuedNewParagraph
)
2250 TexOutput("\\par\\pard");
2251 WriteEnvironmentStyles();
2252 issuedNewParagraph
= 1;
2254 else issuedNewParagraph
= 0;
2256 sprintf(buf
, "{\\f3\\fs20 ");
2262 if (macroId
== ltVERBATIM
)
2264 TexOutput("\\pard\n");
2265 // issuedNewParagraph = 1;
2266 WriteEnvironmentStyles();
2276 TexOutput("\\fi0\\qc ");
2278 PushEnvironmentStyle("\\qc");
2282 TexOutput("\\par\\pard\n");
2283 issuedNewParagraph
= 1;
2285 PopEnvironmentStyle();
2286 WriteEnvironmentStyles();
2294 TexOutput("\\fi0\\ql ");
2296 PushEnvironmentStyle("\\ql");
2300 TexOutput("\\par\\pard\n");
2301 issuedNewParagraph
= 1;
2303 PopEnvironmentStyle();
2304 WriteEnvironmentStyles();
2312 TexOutput("\\fi0\\qr ");
2314 PushEnvironmentStyle("\\qr");
2318 TexOutput("\\par\\pard\n");
2319 issuedNewParagraph
= 1;
2321 PopEnvironmentStyle();
2322 WriteEnvironmentStyles();
2327 case ltFOOTNOTESIZE
:
2331 sprintf(buf
, "{\\fs%d\n", smallFont
*2);
2334 else TexOutput("}\n");
2342 sprintf(buf
, "{\\fs%d\n", tinyFont
*2);
2345 else TexOutput("}\n");
2352 sprintf(buf
, "{\\fs%d\n", normalFont
*2);
2355 else TexOutput("}\n");
2362 sprintf(buf
, "{\\fs%d\n", largeFont1
*2);
2365 else TexOutput("}\n");
2372 sprintf(buf
, "{\\fs%d\n", LargeFont2
*2);
2375 else TexOutput("}\n");
2382 sprintf(buf
, "{\\fs%d\n", LARGEFont3
*2);
2385 else TexOutput("}\n");
2392 sprintf(buf
, "{\\fs%d\n", hugeFont1
*2);
2395 else TexOutput("}\n");
2402 sprintf(buf
, "{\\fs%d\n", HugeFont2
*2);
2405 else TexOutput("}\n");
2412 sprintf(buf
, "{\\fs%d\n", HUGEFont3
*2);
2415 else TexOutput("}\n");
2426 else TexOutput("}");
2433 TexOutput("{\\ul ");
2435 else TexOutput("}");
2448 else TexOutput("}");
2451 // Roman font: do nothing. Should really switch between
2460 TexOutput("{\\plain ");
2462 else TexOutput("}");
2466 // Medium-weight font. Unbolden...
2471 TexOutput("{\\b0 ");
2473 else TexOutput("}");
2476 // Upright (un-italic or slant)
2481 TexOutput("{\\i0 ");
2483 else TexOutput("}");
2492 TexOutput("{\\scaps ");
2494 else TexOutput("}");
2503 TexOutput("{\\f3 ");
2505 else TexOutput("}");
2530 if ( issuedNewParagraph
== 0 )
2532 TexOutput("\\par\\pard");
2533 issuedNewParagraph
++;
2535 // Extra par if parskip is more than zero (usually looks best.)
2536 if (!inTabular
&& (ParSkip
> 0))
2539 issuedNewParagraph
++;
2541 WriteEnvironmentStyles();
2543 // 1 is a whole paragraph if ParSkip == 0,
2544 // half a paragraph if ParSkip > 0
2545 else if ( issuedNewParagraph
== 1 )
2547 // Don't need a par at all if we've already had one,
2548 // and ParSkip == 0.
2550 // Extra par if parskip is more than zero (usually looks best.)
2551 if (!inTabular
&& (ParSkip
> 0))
2554 issuedNewParagraph
++;
2556 WriteEnvironmentStyles();
2559 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2561 TexOutput("\\par\\pard");
2563 // Extra par if parskip is more than zero (usually looks best.)
2564 if (!inTabular && (ParSkip > 0))
2566 WriteEnvironmentStyles();
2576 // In Windows Help, no newpages until we've started some chapters or sections
2577 if (!(winHelp
&& !startedSections
))
2579 TexOutput("\\page\n");
2584 if (start
&& DocumentTitle
)
2586 TexOutput("\\par\\pard");
2589 sprintf(buf
, "\\qc{\\fs%d\\b ", titleFont
*2);
2591 TraverseChildrenFromChunk(DocumentTitle
);
2592 TexOutput("}\\par\\pard\n");
2598 sprintf(buf
, "\\par\\qc{\\fs%d ", authorFont
*2);
2600 TraverseChildrenFromChunk(DocumentAuthor
);
2602 TexOutput("\\par\\pard\n");
2607 sprintf(buf
, "\\qc{\\fs%d ", authorFont
*2);
2609 TraverseChildrenFromChunk(DocumentDate
);
2610 TexOutput("}\\par\\pard\n");
2612 // If linear RTF, we want this titlepage to be in a separate
2613 // section with its own (blank) header and footer
2614 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2616 TexOutput("{\\header }{\\footer }\n");
2617 // Not sure about this: we get too many sections.
2618 // TexOutput("\\sect");
2623 case ltADDCONTENTSLINE
:
2627 if (contentsLineSection
&& contentsLineValue
)
2629 if (strcmp(contentsLineSection
, "chapter") == 0)
2631 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2633 else if (strcmp(contentsLineSection
, "section") == 0)
2635 if (DocumentStyle
!= LATEX_ARTICLE
)
2636 fprintf(Contents
, "\n\\tab%s\\par\n", contentsLineValue
);
2638 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2648 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2649 issuedNewParagraph
= 1;
2650 WriteEnvironmentStyles();
2658 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2659 issuedNewParagraph
= 1;
2660 WriteEnvironmentStyles();
2670 case ltNUMBEREDBIBITEM
:
2673 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
2675 TexOutput("\\par\\pard\\par\n\n");
2682 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2690 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2691 sprintf(buf
, "%d", chapterNo
);
2700 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2701 sprintf(buf
, "%d", sectionNo
);
2708 if (!start
&& !winHelp
)
2710 TexOutput("\\cols2\n");
2716 if (!start
&& !winHelp
)
2718 TexOutput("\\cols1\n");
2724 if (start
&& useWord
&& !winHelp
)
2726 FakeCurrentSection("Index");
2727 OnMacro(ltPAR
, 0, TRUE
);
2728 OnMacro(ltPAR
, 0, FALSE
);
2729 TexOutput("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n");
2733 case ltLISTOFFIGURES
:
2735 if (start
&& useWord
&& !winHelp
)
2737 FakeCurrentSection(FiguresNameString
, FALSE
);
2738 OnMacro(ltPAR
, 0, TRUE
);
2739 OnMacro(ltPAR
, 0, FALSE
);
2740 OnMacro(ltPAR
, 0, TRUE
);
2741 OnMacro(ltPAR
, 0, FALSE
);
2743 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n",
2749 case ltLISTOFTABLES
:
2751 if (start
&& useWord
&& !winHelp
)
2753 FakeCurrentSection(TablesNameString
, FALSE
);
2754 OnMacro(ltPAR
, 0, TRUE
);
2755 OnMacro(ltPAR
, 0, FALSE
);
2756 OnMacro(ltPAR
, 0, TRUE
);
2757 OnMacro(ltPAR
, 0, FALSE
);
2759 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n",
2767 if (start
) TexOutput("{\\f1\\'61}");
2770 if (start
) TexOutput("{\\f1\\'62}");
2773 if (start
) TexOutput("{\\f1\\'63}");
2776 if (start
) TexOutput("{\\f1\\'64}");
2780 if (start
) TexOutput("{\\f1\\'65}");
2783 if (start
) TexOutput("{\\f1\\'7A}");
2786 if (start
) TexOutput("{\\f1\\'68}");
2790 if (start
) TexOutput("{\\f1\\'71}");
2793 if (start
) TexOutput("{\\f1\\'69}");
2796 if (start
) TexOutput("{\\f1\\'6B}");
2799 if (start
) TexOutput("{\\f1\\'6C}");
2802 if (start
) TexOutput("{\\f1\\'6D}");
2805 if (start
) TexOutput("{\\f1\\'6E}");
2808 if (start
) TexOutput("{\\f1\\'78}");
2811 if (start
) TexOutput("{\\f1\\'70}");
2814 if (start
) TexOutput("{\\f1\\'76}");
2818 if (start
) TexOutput("{\\f1\\'72}");
2821 if (start
) TexOutput("{\\f1\\'73}");
2824 if (start
) TexOutput("{\\f1\\'56}");
2827 if (start
) TexOutput("{\\f1\\'74}");
2830 if (start
) TexOutput("{\\f1\\'75}");
2834 if (start
) TexOutput("{\\f1\\'66}");
2837 if (start
) TexOutput("{\\f1\\'63}");
2840 if (start
) TexOutput("{\\f1\\'79}");
2843 if (start
) TexOutput("{\\f1\\'77}");
2846 if (start
) TexOutput("{\\f1\\'47}");
2849 if (start
) TexOutput("{\\f1\\'44}");
2852 if (start
) TexOutput("{\\f1\\'51}");
2855 if (start
) TexOutput("{\\f1\\'4C}");
2858 if (start
) TexOutput("{\\f1\\'58}");
2861 if (start
) TexOutput("{\\f1\\'50}");
2864 if (start
) TexOutput("{\\f1\\'53}");
2867 if (start
) TexOutput("{\\f1\\'54}");
2870 if (start
) TexOutput("{\\f1\\'46}");
2873 if (start
) TexOutput("{\\f1\\'59}");
2876 if (start
) TexOutput("{\\f1\\'57}");
2878 // Binary operation symbols
2881 if (start
) TexOutput("{\\f1\\'A3}");
2884 if (start
) TexOutput("<<");
2887 if (start
) TexOutput("{\\f1\\'CC}");
2890 if (start
) TexOutput("{\\f1\\'CD}");
2893 if (start
) TexOutput("{\\f1\\'CE}");
2897 if (start
) TexOutput("{\\f1\\'B3}");
2900 if (start
) TexOutput(">>");
2903 if (start
) TexOutput("{\\f1\\'C9}");
2906 if (start
) TexOutput("{\\f1\\'CD}");
2909 if (start
) TexOutput("{\\f1\\'27}");
2912 if (start
) TexOutput("{\\f1\\'5E}");
2915 if (start
) TexOutput("{\\f1\\'B9}");
2918 if (start
) TexOutput("{\\f1\\'BB}");
2921 if (start
) TexOutput("{\\f1\\'40}");
2924 if (start
) TexOutput("{\\f1\\'BA}");
2927 if (start
) TexOutput("{\\f1\\'B5}");
2930 if (start
) TexOutput("{\\f1\\'7E}");
2933 if (start
) TexOutput("{\\f4\\'4A}");
2936 if (start
) TexOutput("{\\f4\\'4C}");
2939 if (start
) TexOutput("|");
2942 // Negated relation symbols
2944 if (start
) TexOutput("{\\f1\\'B9}");
2947 if (start
) TexOutput("{\\f1\\'CF}");
2950 if (start
) TexOutput("{\\f1\\'CB}");
2955 if (start
) TexOutput("{\\f1\\'AC}");
2958 if (start
) TexOutput("{\\f1\\'DC}");
2961 if (start
) TexOutput("{\\f1\\'AE}");
2964 if (start
) TexOutput("{\\f1\\'DE}");
2966 case ltLEFTRIGHTARROW
:
2967 if (start
) TexOutput("{\\f1\\'AB}");
2969 case ltLEFTRIGHTARROW2
:
2970 if (start
) TexOutput("{\\f1\\'DB}");
2973 if (start
) TexOutput("{\\f1\\'AD}");
2976 if (start
) TexOutput("{\\f1\\'DD}");
2979 if (start
) TexOutput("{\\f1\\'AF}");
2982 if (start
) TexOutput("{\\f1\\'DF}");
2985 // Miscellaneous symbols
2987 if (start
) TexOutput("{\\f1\\'CO}");
2990 if (start
) TexOutput("{\\f1\\'C3}");
2993 if (start
) TexOutput("{\\f1\\'C2}");
2996 if (start
) TexOutput("{\\f1\\'C1}");
2999 if (start
) TexOutput("{\\f1\\'C6}");
3002 if (start
) TexOutput("{\\f1\\'D1}");
3005 if (start
) TexOutput("{\\f1\\'D6}");
3008 if (start
) TexOutput("{\\f1\\'B6}");
3011 if (start
) TexOutput("{\\f1\\'5E}");
3014 if (start
) TexOutput("{\\f1\\'22}");
3017 if (start
) TexOutput("{\\f1\\'24}");
3020 if (start
) TexOutput("{\\f1\\'D8}");
3023 if (start
) TexOutput("{\\f1\\'23}");
3026 if (start
) TexOutput("{\\f1\\'D0}");
3029 if (start
) TexOutput("{\\f5\\'73}");
3032 if (start
) TexOutput("{\\f5\\'A8}");
3035 if (start
) TexOutput("{\\f5\\'A9}");
3038 if (start
) TexOutput("{\\f5\\'AA}");
3041 if (start
) TexOutput("{\\f5\\'AB}");
3044 if (start
) TexOutput("{\\f1\\'A5}");
3047 if (start
) TexOutput("{\\f0\\'A9}");
3050 if (start
) TexOutput("{\\f0\\'AE}");
3053 if (start
) TexOutput("{\\f1\\'B1}");
3056 if (start
) TexOutput("{\\f1\\'B1}");
3059 if (start
) TexOutput("{\\f1\\'B4}");
3062 if (start
) TexOutput("{\\f1\\'B8}");
3065 if (start
) TexOutput("{\\f1\\'D7}");
3068 if (start
) TexOutput("{\\f1\\'2A}");
3071 if (start
) TexOutput("{\\f5\\'AB}");
3074 if (start
) TexOutput("{\\f1\\'C7}");
3077 if (start
) TexOutput("{\\f1\\'C8}");
3080 if (start
) TexOutput("{\\f1\\'DA}");
3083 if (start
) TexOutput("{\\f1\\'D9}");
3086 if (start
) TexOutput("{\\f1\\'B0}");
3089 if (start
) TexOutput("{\\f1\\'B7}");
3092 if (start
) TexOutput("{\\f1\\'E0}");
3095 if (start
) TexOutput("{\\f1\\'C6}");
3098 if (start
) TexOutput("{\\f1\\'E0}");
3100 case ltBIGTRIANGLEDOWN
:
3101 if (start
) TexOutput("{\\f1\\'D1}");
3104 if (start
) TexOutput("{\\f1\\'C5}");
3107 if (start
) TexOutput("{\\f1\\'C4}");
3110 if (start
) TexOutput("{\\'DF}");
3114 if (start
) inFigure
= TRUE
;
3115 else inFigure
= FALSE
;
3120 if (start
) inTable
= TRUE
;
3121 else inTable
= FALSE
;
3126 DefaultOnMacro(macroId
, no_args
, start
);
3132 // Called on start/end of argument examination
3133 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3140 case ltCHAPTERHEADING
:
3143 case ltSECTIONHEADING
:
3145 case ltSUBSECTIONSTAR
:
3146 case ltSUBSUBSECTION
:
3147 case ltSUBSUBSECTIONSTAR
:
3149 case ltMEMBERSECTION
:
3150 case ltFUNCTIONSECTION
:
3154 if (!start
&& (arg_no
== 1))
3155 currentSection
= GetArgChunk();
3161 if (start
&& (arg_no
== 1))
3162 TexOutput("\\pard\\li600\\fi-600{\\b ");
3164 if (!start
&& (arg_no
== 1))
3167 if (start
&& (arg_no
== 2))
3169 if (!suppressNameDecoration
) TexOutput("{\\b ");
3170 currentMember
= GetArgChunk();
3172 if (!start
&& (arg_no
== 2))
3174 if (!suppressNameDecoration
) TexOutput("}");
3177 if (start
&& (arg_no
== 3))
3179 if (!start
&& (arg_no
== 3))
3181 // TexOutput(")\\li0\\fi0");
3182 // TexOutput(")\\par\\pard\\li0\\fi0");
3183 // issuedNewParagraph = 1;
3185 WriteEnvironmentStyles();
3191 if (start
&& (arg_no
== 1))
3192 TexOutput("\\pard\\li260\\fi-260{\\b ");
3193 if (!start
&& (arg_no
== 1))
3196 if (start
&& (arg_no
== 2))
3198 if (!suppressNameDecoration
) TexOutput("({\\b ");
3199 currentMember
= GetArgChunk();
3201 if (!start
&& (arg_no
== 2))
3203 if (!suppressNameDecoration
) TexOutput("}");
3206 if (!start
&& (arg_no
== 3))
3208 TexOutput(")\\li0\\fi0");
3209 WriteEnvironmentStyles();
3215 if (start
&& (arg_no
== 1))
3216 TexOutput("\\pard\\li260\\fi-260");
3218 if (!start
&& (arg_no
== 1))
3221 if (start
&& (arg_no
== 2))
3223 if (!start
&& (arg_no
== 2))
3226 if (start
&& (arg_no
== 2))
3227 currentMember
= GetArgChunk();
3229 if (start
&& (arg_no
== 3))
3231 if (!start
&& (arg_no
== 3))
3233 TexOutput(")\\li0\\fi0");
3234 WriteEnvironmentStyles();
3240 if (start
&& (arg_no
== 1))
3242 if (!start
&& (arg_no
== 1))
3244 if (start
&& (arg_no
== 2))
3248 if (!start
&& (arg_no
== 2))
3256 if (start
&& (arg_no
== 1))
3258 if (!start
&& (arg_no
== 1))
3259 TexOutput("} "); // This is the difference from param - one space!
3260 if (start
&& (arg_no
== 2))
3264 if (!start
&& (arg_no
== 2))
3272 if (!start
&& (arg_no
== 1))
3275 if (start
&& (arg_no
== 2))
3276 currentMember
= GetArgChunk();
3284 char *secName
= NULL
;
3286 char *refName
= GetArgData();
3287 if (winHelp
|| !useWord
)
3291 TexRef
*texRef
= FindReference(refName
);
3294 sec
= texRef
->sectionNumber
;
3295 secName
= texRef
->sectionName
;
3305 fprintf(Chapters
, "{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
3317 if ((GetNoArgs() - arg_no
) == 1)
3320 TexOutput("{\\uldb ");
3324 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3330 // Remove green colour/underlining if specified
3331 if (!hotSpotUnderline
&& !hotSpotColour
)
3333 else if (!hotSpotColour
)
3336 else TexOutput("}");
3339 else // If a linear document, must resolve the references ourselves
3341 if ((GetNoArgs() - arg_no
) == 1)
3343 // In a linear document we display the anchor text in italic plus
3351 helpRefText
= GetArgChunk();
3355 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3357 if (macroId
!= ltHELPREFN
)
3359 char *refName
= GetArgData();
3360 TexRef
*texRef
= NULL
;
3362 texRef
= FindReference(refName
);
3365 if (texRef
|| !ignoreBadRefs
)
3369 if (texRef
|| !ignoreBadRefs
)
3373 char *s
= GetArgData();
3375 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3377 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3381 // Only print section name if we're not in Word mode,
3382 // so can't do page references
3385 TexOutput(texRef
->sectionName
) ; TexOutput(" "); TexOutput(texRef
->sectionNumber
);
3391 sprintf(buf
, "Warning: unresolved reference '%s'", refName
);
3397 else TexOutput("??");
3401 if (texRef
|| !ignoreBadRefs
)
3416 else if (arg_no
== 2)
3421 TexOutput(" ({\\f3 ");
3436 if ((GetNoArgs() - arg_no
) == 1)
3439 TexOutput("{\\ul ");
3443 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3449 // Remove green colour/underlining if specified
3450 if (!hotSpotUnderline
&& !hotSpotColour
)
3452 else if (!hotSpotColour
)
3455 else TexOutput("}");
3458 else // A linear document...
3460 if ((GetNoArgs() - arg_no
) == 1)
3462 // In a linear document we just display the anchor text in italic
3473 case ltADDCONTENTSLINE
:
3475 if (start
&& !winHelp
)
3478 contentsLineSection
= copystring(GetArgData());
3479 else if (arg_no
== 3)
3480 contentsLineValue
= copystring(GetArgData());
3495 static int imageWidth
= 0;
3496 static int imageHeight
= 0;
3498 if (start
&& (arg_no
== 1))
3500 char *imageDimensions
= copystring(GetArgData());
3502 strcpy(buf1
, imageDimensions
);
3503 char *tok1
= strtok(buf1
, ";:");
3504 char *tok2
= strtok(NULL
, ";:");
3505 // Convert points to TWIPS (1 twip = 1/20th of point)
3506 imageWidth
= (int)(20*(tok1
? ParseUnitArgument(tok1
) : 0));
3507 imageHeight
= (int)(20*(tok2
? ParseUnitArgument(tok2
) : 0));
3508 if (imageDimensions
) // glt
3509 delete [] imageDimensions
;
3512 else if (start
&& (arg_no
== 2 ))
3514 char *filename
= copystring(GetArgData());
3516 if ((winHelp
|| (strcmp(bitmapMethod
, "includepicture") == 0) || (strcmp(bitmapMethod
, "import") == 0)) && useWord
)
3518 if (f
== "") // Try for a .shg (segmented hypergraphics file)
3520 strcpy(buf
, filename
);
3521 StripExtension(buf
);
3522 strcat(buf
, ".shg");
3523 f
= TexPathList
.FindValidPath(buf
);
3525 if (f
== "") // Try for a .bmp
3527 strcpy(buf
, filename
);
3528 StripExtension(buf
);
3529 strcat(buf
, ".bmp");
3530 f
= TexPathList
.FindValidPath(buf
);
3532 if (f
== "") // Try for a metafile instead
3534 strcpy(buf
, filename
);
3535 StripExtension(buf
);
3536 strcat(buf
, ".wmf");
3537 f
= TexPathList
.FindValidPath(buf
);
3543 if (bitmapTransparency
&& (winHelpVersion
> 3))
3544 TexOutput("\\{bmct ");
3546 TexOutput("\\{bmc ");
3547 wxString str
= wxFileNameFromPath(f
);
3548 TexOutput((char*) (const char*) str
);
3553 // Microsoft Word method
3554 if (strcmp(bitmapMethod
, "import") == 0)
3555 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3557 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3559 // Full path appears not to be valid!
3560 wxString str
= wxFileNameFromPath(f
);
3561 TexOutput((char*)(const char*) str
);
3563 int len = strlen(f);
3564 char smallBuf[2]; smallBuf[1] = 0;
3565 for (int i = 0; i < len; i++)
3568 TexOutput(smallBuf);
3569 if (smallBuf[0] == '\\')
3570 TexOutput(smallBuf);
3573 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3578 TexOutput("[No BMP or WMF for image file ");
3579 TexOutput(filename
);
3581 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3584 if (filename
) // glt
3589 if (f
== "") // Try for a .bmp
3591 strcpy(buf
, filename
);
3592 StripExtension(buf
);
3593 strcat(buf
, ".bmp");
3594 f
= TexPathList
.FindValidPath(buf
);
3598 FILE *fd
= fopen(f
, "rb");
3599 if (OutputBitmapHeader(fd
, winHelp
))
3600 OutputBitmapData(fd
);
3603 sprintf(buf
, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f
);
3608 else // Try for a metafile instead
3611 strcpy(buf
, filename
);
3612 StripExtension(buf
);
3613 strcat(buf
, ".wmf");
3614 f
= TexPathList
.FindValidPath(buf
);
3617 // HFILE handle = _lopen(f, READ);
3618 FILE *fd
= fopen(f
, "rb");
3619 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3621 OutputMetafileData(fd
);
3625 sprintf(buf
, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f
);
3633 TexOutput("[No BMP or WMF for image file ");
3634 TexOutput(filename
);
3636 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3650 case ltSUPERTABULAR
:
3656 currentRowNumber
= 0;
3659 tableVerticalLineLeft
= FALSE
;
3660 tableVerticalLineRight
= FALSE
;
3661 int currentWidth
= 0;
3663 char *alignString
= copystring(GetArgData());
3664 ParseTableArgument(alignString
);
3666 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3667 TexOutput("\\trowd\\trgaph108");
3669 // Write the first row formatting for compatibility
3670 // with standard Latex
3671 if (compatibilityMode
)
3673 for (int i
= 0; i
< noColumns
; i
++)
3675 currentWidth
+= TableData
[i
].width
;
3676 sprintf(buf
, "\\cellx%d", currentWidth
);
3679 TexOutput("\\pard\\intbl\n");
3681 delete[] alignString
;
3686 else if (arg_no
== 2 && !start
)
3688 TexOutput("\\pard\n");
3689 WriteEnvironmentStyles();
3700 TexOutput("\\li360\n");
3702 PushEnvironmentStyle("\\li360");
3707 PopEnvironmentStyle();
3708 OnMacro(ltPAR
, 0, TRUE
);
3709 OnMacro(ltPAR
, 0, FALSE
);
3717 TexOutput("\\li360\n");
3718 PushEnvironmentStyle("\\li360");
3722 PopEnvironmentStyle();
3723 OnMacro(ltPAR
, 0, TRUE
);
3724 OnMacro(ltPAR
, 0, FALSE
);
3736 sprintf(buf
, "\\box\\trgaph108%s\n", ((macroId
== ltNORMALBOXD
) ? "\\brdrdb" : "\\brdrs"));
3738 PushEnvironmentStyle(buf
);
3742 PopEnvironmentStyle();
3743 OnMacro(ltPAR
, 0, TRUE
);
3744 OnMacro(ltPAR
, 0, FALSE
);
3748 case ltHELPFONTSIZE
:
3752 char *data
= GetArgData();
3753 if (strcmp(data
, "10") == 0)
3755 else if (strcmp(data
, "11") == 0)
3757 else if (strcmp(data
, "12") == 0)
3759 sprintf(buf
, "\\fs%d\n", normalFont
*2);
3766 case ltHELPFONTFAMILY
:
3770 char *data
= GetArgData();
3771 if (strcmp(data
, "Swiss") == 0)
3772 TexOutput("\\f2\n");
3773 else if (strcmp(data
, "Symbol") == 0)
3774 TexOutput("\\f1\n");
3775 else if (strcmp(data
, "Times") == 0)
3776 TexOutput("\\f0\n");
3784 if (start
&& arg_no
== 1)
3786 char *data
= GetArgData();
3787 ParIndent
= ParseUnitArgument(data
);
3788 if (ParIndent
== 0 || forbidParindent
== 0)
3790 sprintf(buf
, "\\fi%d\n", ParIndent
*20);
3799 if (start
&& IsArgOptional())
3801 descriptionItemArg
= GetArgChunk();
3807 case ltTWOCOLITEMRULED
:
3814 TexOutput("\\tab ");
3821 if (macroId
== ltTWOCOLITEMRULED
)
3822 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3823 TexOutput("\\par\\pard\n");
3824 issuedNewParagraph
= 1;
3825 WriteEnvironmentStyles();
3837 case ltACCENT_GRAVE
:
3841 char *val
= GetArgData();
3884 case ltACCENT_ACUTE
:
3888 char *val
= GetArgData();
3937 case ltACCENT_CARET
:
3941 char *val
= GetArgData();
3984 case ltACCENT_TILDE
:
3988 char *val
= GetArgData();
4022 case ltACCENT_UMLAUT
:
4026 char *val
= GetArgData();
4082 char *val
= GetArgData();
4101 case ltACCENT_CADILLA
:
4105 char *val
= GetArgData();
4126 static char *helpTopic
= NULL
;
4127 static FILE *savedOutput
= NULL
;
4134 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4137 sprintf(footBuf
, "(%d)", footnoteCount
);
4139 TexOutput(" {\\ul ");
4142 helpTopic
= FindTopicName(NULL
);
4145 // Remove green colour/underlining if specified
4146 if (!hotSpotUnderline
&& !hotSpotColour
)
4148 else if (!hotSpotColour
)
4151 TexOutput(helpTopic
);
4154 fprintf(Popups
, "\\page\n");
4155 // fprintf(Popups, "\n${\\footnote }"); // No title
4156 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4157 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4158 savedOutput
= CurrentOutput1
;
4159 SetCurrentOutput(Popups
);
4163 SetCurrentOutput(savedOutput
);
4173 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4177 TexOutput("}}", TRUE
);
4183 case ltFOOTNOTEPOPUP
:
4185 static char *helpTopic
= NULL
;
4186 static FILE *savedOutput
= NULL
;
4193 TexOutput("{\\ul ");
4195 else TexOutput("}");
4198 else if (arg_no
== 2)
4202 helpTopic
= FindTopicName(NULL
);
4205 // Remove green colour/underlining if specified
4206 if (!hotSpotUnderline
&& !hotSpotColour
)
4208 else if (!hotSpotColour
)
4211 TexOutput(helpTopic
);
4214 fprintf(Popups
, "\\page\n");
4215 // fprintf(Popups, "\n${\\footnote }"); // No title
4216 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4217 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4218 savedOutput
= CurrentOutput1
;
4219 SetCurrentOutput(Popups
);
4223 SetCurrentOutput(savedOutput
);
4234 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4238 TexOutput("}}", TRUE
);
4246 if (start
&& (arg_no
== 1))
4259 if (winHelp
) return FALSE
;
4265 LeftHeaderEven
= GetArgChunk();
4266 if (strlen(GetArgData(LeftHeaderEven
)) == 0)
4267 LeftHeaderEven
= NULL
;
4270 CentreHeaderEven
= GetArgChunk();
4271 if (strlen(GetArgData(CentreHeaderEven
)) == 0)
4272 CentreHeaderEven
= NULL
;
4275 RightHeaderEven
= GetArgChunk();
4276 if (strlen(GetArgData(RightHeaderEven
)) == 0)
4277 RightHeaderEven
= NULL
;
4280 LeftHeaderOdd
= GetArgChunk();
4281 if (strlen(GetArgData(LeftHeaderOdd
)) == 0)
4282 LeftHeaderOdd
= NULL
;
4285 CentreHeaderOdd
= GetArgChunk();
4286 if (strlen(GetArgData(CentreHeaderOdd
)) == 0)
4287 CentreHeaderOdd
= NULL
;
4290 RightHeaderOdd
= GetArgChunk();
4291 if (strlen(GetArgData(RightHeaderOdd
)) == 0)
4292 RightHeaderOdd
= NULL
;
4293 OutputRTFHeaderCommands();
4309 if (winHelp
) return FALSE
;
4315 LeftFooterEven
= GetArgChunk();
4316 if (strlen(GetArgData(LeftFooterEven
)) == 0)
4317 LeftFooterEven
= NULL
;
4320 CentreFooterEven
= GetArgChunk();
4321 if (strlen(GetArgData(CentreFooterEven
)) == 0)
4322 CentreFooterEven
= NULL
;
4325 RightFooterEven
= GetArgChunk();
4326 if (strlen(GetArgData(RightFooterEven
)) == 0)
4327 RightFooterEven
= NULL
;
4330 LeftFooterOdd
= GetArgChunk();
4331 if (strlen(GetArgData(LeftFooterOdd
)) == 0)
4332 LeftFooterOdd
= NULL
;
4335 CentreFooterOdd
= GetArgChunk();
4336 if (strlen(GetArgData(CentreFooterOdd
)) == 0)
4337 CentreFooterOdd
= NULL
;
4340 RightFooterOdd
= GetArgChunk();
4341 if (strlen(GetArgData(RightFooterOdd
)) == 0)
4342 RightFooterOdd
= NULL
;
4343 OutputRTFFooterCommands();
4354 if (winHelp
) return FALSE
;
4355 // Fake a SetHeader command
4358 LeftHeaderOdd
= NULL
;
4359 CentreHeaderOdd
= NULL
;
4360 RightHeaderOdd
= NULL
;
4361 LeftHeaderEven
= NULL
;
4362 CentreHeaderEven
= NULL
;
4363 RightHeaderEven
= NULL
;
4364 OnInform("Consider using setheader/setfooter rather than markright.");
4366 RTFOnArgument(ltSETHEADER
, 4, start
);
4368 OutputRTFHeaderCommands();
4374 if (winHelp
) return FALSE
;
4375 // Fake a SetHeader command
4382 LeftHeaderOdd
= NULL
;
4383 CentreHeaderOdd
= NULL
;
4384 RightHeaderOdd
= NULL
;
4385 LeftHeaderEven
= NULL
;
4386 CentreHeaderEven
= NULL
;
4387 RightHeaderEven
= NULL
;
4388 OnInform("Consider using setheader/setfooter rather than markboth.");
4390 return RTFOnArgument(ltSETHEADER
, 1, start
);
4395 RTFOnArgument(ltSETHEADER
, 4, start
);
4397 OutputRTFHeaderCommands();
4404 case ltPAGENUMBERING
:
4411 if (winHelp
) return FALSE
;
4414 TexOutput("\\pgnrestart");
4415 char *data
= GetArgData();
4416 if (currentNumberStyle
) delete[] currentNumberStyle
;
4417 currentNumberStyle
= copystring(data
);
4418 OutputNumberStyle(currentNumberStyle
);
4427 if (winHelp
) return FALSE
;
4436 char *val
= GetArgData();
4437 currentItemSep
= ParseUnitArgument(val
);
4442 case ltEVENSIDEMARGIN
:
4447 case ltODDSIDEMARGIN
:
4451 char *val
= GetArgData();
4452 int twips
= (int)(20*ParseUnitArgument(val
));
4453 // Add an inch since in LaTeX it's specified minus an inch
4455 CurrentLeftMarginOdd
= twips
;
4456 sprintf(buf
, "\\margl%d\n", twips
);
4459 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4463 case ltMARGINPARWIDTH
:
4467 char *val
= GetArgData();
4468 int twips
= (int)(20*ParseUnitArgument(val
));
4469 CurrentMarginParWidth
= twips
;
4473 case ltMARGINPARSEP
:
4477 char *val
= GetArgData();
4478 int twips
= (int)(20*ParseUnitArgument(val
));
4479 CurrentMarginParSep
= twips
;
4480 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4488 char *val
= GetArgData();
4489 int twips
= (int)(20*ParseUnitArgument(val
));
4490 CurrentTextWidth
= twips
;
4492 // Need to set an implicit right margin
4493 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4494 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4495 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4496 sprintf(buf
, "\\margr%d\n", CurrentRightMarginOdd
);
4502 case ltMARGINPARODD
:
4508 TexOutput("\\box\n");
4509 PushEnvironmentStyle("\\box");
4513 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4522 TexOutput("\\par\\pard\n");
4523 PopEnvironmentStyle();
4524 WriteEnvironmentStyles();
4527 TexOutput("\\par\\pard\n");
4528 issuedNewParagraph
= 1;
4532 case ltMARGINPAREVEN
:
4538 TexOutput("\\box\n");
4539 PushEnvironmentStyle("\\box");
4545 // Have to calculate what the margins are changed to in WfW margin
4546 // mirror mode, on an even (left-hand) page.
4547 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4548 - CurrentTextWidth
+ GutterWidth
;
4549 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", x
, CurrentMarginParWidth
);
4554 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4564 TexOutput("\\par\\pard\n");
4565 PopEnvironmentStyle();
4566 WriteEnvironmentStyles();
4569 issuedNewParagraph
= 1;
4570 TexOutput("\\par\\pard\n");
4574 case ltTWOCOLWIDTHA
:
4578 char *val
= GetArgData();
4579 int twips
= (int)(20*ParseUnitArgument(val
));
4580 TwoColWidthA
= twips
;
4585 case ltTWOCOLWIDTHB
:
4589 char *val
= GetArgData();
4590 int twips
= (int)(20*ParseUnitArgument(val
));
4591 TwoColWidthB
= twips
;
4601 int currentWidth
= 0;
4603 if (!compatibilityMode
|| (currentRowNumber
> 0))
4605 TexOutput("\\pard\\intbl");
4607 if (macroId
== ltRULEDROW
)
4609 for (int i
= 0; i
< noColumns
; i
++)
4611 currentWidth
+= TableData
[i
].width
;
4614 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4616 else if (ruleTop
> 1)
4618 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4620 if (ruleBottom
== 1)
4622 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4624 else if (ruleBottom
> 1)
4626 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4629 if (TableData
[i
].rightBorder
)
4630 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4632 if (TableData
[i
].leftBorder
)
4633 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4635 sprintf(buf
, "\\cellx%d", currentWidth
);
4638 TexOutput("\\pard\\intbl\n");
4642 currentRowNumber
++;
4647 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4648 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4654 static int noMultiColumns
= 0;
4661 noMultiColumns
= atoi(GetArgData());
4679 for (int i
= 1; i
< noMultiColumns
; i
++)
4680 TexOutput("\\cell");
4687 if (start
&& (arg_no
== 1))
4690 // TexOutput("\\fi0\n");
4692 wxNode
*node
= itemizeStack
.First();
4694 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
4696 int indentValue
= 20*ParseUnitArgument(GetArgData());
4697 int indentSize
= indentValue
+ oldIndent
;
4699 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4700 itemizeStack
.Insert(struc
);
4702 sprintf(buf
, "\\tx%d\\li%d ", indentSize
, indentSize
);
4703 PushEnvironmentStyle(buf
);
4707 if (!start
&& (arg_no
== 2))
4709 PopEnvironmentStyle();
4710 if (itemizeStack
.First())
4712 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
4714 delete itemizeStack
.First();
4716 if (itemizeStack
.Number() == 0)
4718 TexOutput("\\par\\pard\n");
4719 issuedNewParagraph
= 1;
4720 WriteEnvironmentStyles();
4730 if (start && (arg_no == 1))
4733 wxNode *node = itemizeStack.First();
4735 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4737 int boxWidth = 20*ParseUnitArgument(GetArgData());
4739 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4740 int indentSize = indentValue + oldIndent;
4741 int indentSizeRight = indentSize + boxWidth;
4743 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4744 itemizeStack.Insert(struc);
4746 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4747 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4748 PushEnvironmentStyle(buf);
4752 if (!start && (arg_no == 2))
4754 PopEnvironmentStyle();
4755 if (itemizeStack.First())
4757 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4759 delete itemizeStack.First();
4761 if (itemizeStack.Number() == 0)
4763 TexOutput("\\par\\pard\n");
4764 issuedNewParagraph = 1;
4765 WriteEnvironmentStyles();
4772 case ltDOCUMENTSTYLE
:
4774 DefaultOnArgument(macroId
, arg_no
, start
);
4775 if (!start
&& !IsArgOptional())
4777 if (MinorDocumentStyleString
)
4779 if (StringMatch("twoside", MinorDocumentStyleString
))
4780 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4781 TexOutput("\\margmirror\\facingp\\sbkodd");
4782 if (StringMatch("twocolumn", MinorDocumentStyleString
))
4783 TexOutput("\\cols2");
4789 case ltSETHOTSPOTCOLOUR
:
4790 case ltSETHOTSPOTCOLOR
:
4794 char *text
= GetArgData();
4795 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4796 hotSpotColour
= TRUE
;
4798 hotSpotColour
= FALSE
;
4802 case ltSETTRANSPARENCY
:
4806 char *text
= GetArgData();
4807 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4808 bitmapTransparency
= TRUE
;
4810 bitmapTransparency
= FALSE
;
4814 case ltSETHOTSPOTUNDERLINE
:
4818 char *text
= GetArgData();
4819 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4820 hotSpotUnderline
= TRUE
;
4822 hotSpotUnderline
= FALSE
;
4828 if (arg_no
== 1 && start
)
4830 char *citeKey
= GetArgData();
4831 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4834 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4835 sprintf(buf
, "[%d]", citeCount
);
4836 ref
->sectionNumber
= copystring(buf
);
4839 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4840 sprintf(buf
, "{\\b [%d]} ", citeCount
);
4845 if (arg_no
== 2 && !start
)
4846 TexOutput("\\par\\pard\\par\n\n");
4850 case ltTHEBIBLIOGRAPHY
:
4852 if (start
&& (arg_no
== 1))
4856 SetCurrentOutputs(Contents
, Chapters
);
4860 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
4862 // If a non-custom page style, we generate the header now.
4863 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
4864 strcmp(PageStyle
, "empty") == 0 ||
4865 strcmp(PageStyle
, "headings") == 0))
4867 OutputRTFHeaderCommands();
4868 OutputRTFFooterCommands();
4871 // Need to reset the current numbering style, or RTF forgets it.
4872 OutputNumberStyle(currentNumberStyle
);
4873 SetCurrentOutput(Contents
);
4876 fprintf(Chapters
, "\\page\n");
4879 fprintf(Contents
, "\n{\\uldb %s}", ReferencesNameString
);
4881 fprintf(Contents
, "\\par\n\\pard{\\b %s}", ReferencesNameString
);
4883 startedSections
= TRUE
;
4886 fprintf(Chapters
, "\n${\\footnote %s}", ReferencesNameString
);
4888 char *topicName
= "bibliography";
4891 fprintf(Contents
, "{\\v %s}\\par\\pard\n", topicName
);
4893 fprintf(Contents
, "\\par\\par\\pard\n");
4897 fprintf(Chapters
, "\n#{\\footnote %s}\n", topicName
);
4898 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
4899 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ReferencesNameString
);
4900 GenerateKeywordsForTopic(topicName
);
4903 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4904 wxFileNameFromPath(FileRoot
), "Contents");
4908 SetCurrentOutput(Chapters
);
4909 char *styleCommand
= "";
4910 if (!winHelp
&& useHeadingStyles
)
4911 styleCommand
= "\\s1";
4912 fprintf(Chapters
, "\\pard{%s", (winHelp
? "\\keepn\\sa140\\sb140" : styleCommand
));
4913 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " References\\par\\pard}\n");
4923 * In Windows help, all keywords should be at the start of the
4924 * topic, but Latex \index commands can be anywhere in the text.
4925 * So we're going to have to build up lists of keywords for a topic,
4926 * and insert them on the second pass.
4928 * In linear RTF, we can embed the index entry now.
4933 // char *entry = GetArgData();
4935 OutputChunkToString(GetArgChunk(), buf
);
4940 AddKeyWordForTopic(CurrentTopic
, buf
);
4943 else GenerateIndexEntry(buf
);
4957 char *name
= GetArgData();
4958 int pos
= FindColourPosition(name
);
4961 sprintf(buf
, "{%s%d ", ((macroId
== ltFCOL
) ? "\\cf" : "\\cb"), pos
);
4966 sprintf(buf
, "Could not find colour name %s", name
);
4982 if (arg_no
== 2) TexOutput("}");
4989 if (start
&& !winHelp
&& useWord
)
4991 char *s
= GetArgData();
4992 // Only insert a bookmark here if it's not just been inserted
4993 // in a section heading.
4994 if ( !CurrentTopic
|| !(strcmp(CurrentTopic
, s
) == 0) )
4996 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4997 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4998 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
5002 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", s
,s
);
5010 if (start
&& useWord
&& !winHelp
)
5012 char *s
= GetArgData();
5013 fprintf(Chapters
, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
5022 inPopRefSection
= TRUE
;
5024 inPopRefSection
= FALSE
;
5027 case ltINSERTATLEVEL
:
5029 // This macro allows you to insert text at a different level
5030 // from the current level, e.g. into the Sections from within a subsubsection.
5031 if (!winHelp
& useWord
)
5033 static int currentLevelNo
= 1;
5034 static FILE* oldLevelFile
= Chapters
;
5041 oldLevelFile
= CurrentOutput1
;
5043 char *str
= GetArgData();
5044 currentLevelNo
= atoi(str
);
5046 // TODO: cope with article style (no chapters)
5047 switch (currentLevelNo
)
5051 outputFile
= Chapters
;
5056 outputFile
= Sections
;
5061 outputFile
= Subsections
;
5066 outputFile
= Subsubsections
;
5076 CurrentOutput1
= outputFile
;
5094 CurrentOutput1
= oldLevelFile
;
5102 return DefaultOnArgument(macroId
, arg_no
, start
);
5116 forbidParindent
= 0;
5117 contentsLineSection
= NULL
;
5118 contentsLineValue
= NULL
;
5119 descriptionItemArg
= NULL
;
5124 tableVerticalLineLeft
= FALSE
;
5125 tableVerticalLineRight
= FALSE
;
5127 startedSections
= FALSE
;
5131 if (InputFile
&& OutputFile
)
5133 // Do some RTF-specific transformations on all the strings,
5135 Text2RTF(GetTopLevelChunk());
5137 Contents
= fopen(TmpContentsName
, "w");
5138 Chapters
= fopen("chapters.rtf", "w");
5141 Sections
= fopen("sections.rtf", "w");
5142 Subsections
= fopen("subsections.rtf", "w");
5143 Subsubsections
= fopen("subsubsections.rtf", "w");
5144 Popups
= fopen("popups.rtf", "w");
5145 if (winHelpContents
)
5147 WinHelpContentsFile
= fopen(WinHelpContentsFileName
, "w");
5148 if (WinHelpContentsFile
)
5149 fprintf(WinHelpContentsFile
, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot
));
5152 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5154 OnError("Ouch! Could not open temporary file(s) for writing.");
5158 if (!Contents
|| !Chapters
)
5160 OnError("Ouch! Could not open temporary file(s) for writing.");
5166 fprintf(Chapters
, "\n#{\\footnote Contents}\n");
5167 fprintf(Chapters
, "${\\footnote Contents}\n");
5168 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
5169 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ContentsNameString
);
5170 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
5174 fprintf(Chapters
, "\\titlepg\n");
5175 fprintf(Contents
, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5178 // In WinHelp, Contents title takes font of title.
5179 // In linear RTF, same as chapter headings.
5180 fprintf(Contents
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5181 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5183 // By default, Swiss, 10 point.
5184 fprintf(Chapters
, "\\f2\\fs20\n");
5186 SetCurrentOutput(Chapters
);
5191 OnInform("Converting...");
5195 FILE *Header
= fopen("header.rtf", "w");
5198 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5201 WriteRTFHeader(Header
);
5202 fclose(Header
); Header
= NULL
;
5207 // fprintf(Contents, "\\page\n");
5208 fprintf(Chapters
, "\\page\n");
5209 fprintf(Sections
, "\\page\n");
5210 fprintf(Subsections
, "\\page\n");
5211 fprintf(Subsubsections
, "\\page\n\n");
5212 fprintf(Popups
, "\\page\n}\n");
5215 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5218 fclose(Contents
); Contents
= NULL
;
5219 fclose(Chapters
); Chapters
= NULL
;
5222 fclose(Sections
); Sections
= NULL
;
5223 fclose(Subsections
); Subsections
= NULL
;
5224 fclose(Subsubsections
); Subsubsections
= NULL
;
5225 fclose(Popups
); Popups
= NULL
;
5226 if (winHelpContents
)
5228 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5234 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5236 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5238 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5240 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5242 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile
);
5245 wxRemoveFile("tmp1.rtf");
5246 wxRemoveFile("tmp2.rtf");
5247 wxRemoveFile("tmp3.rtf");
5248 wxRemoveFile("tmp4.rtf");
5252 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5254 if (wxFileExists(OutputFile
))
5255 wxRemoveFile(OutputFile
);
5258 cwdStr
= wxGetWorkingDirectory();
5260 wxString outputDirStr
;
5261 outputDirStr
= wxPathOnly(OutputFile
);
5263 // Determine if the temp file and the output file are in the same directory,
5264 // and if they are, then just rename the temp file rather than copying
5265 // it, as this is much faster when working with large (multi-megabyte files)
5266 if ((wxStrcmp(outputDirStr
.c_str(),"") == 0) || // no path specified on output file
5267 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5269 wxRenameFile("tmp1.rtf", OutputFile
);
5273 wxCopyFile("tmp1.rtf", OutputFile
);
5277 wxRemoveFile("tmp1.rtf");
5280 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5282 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5284 wxCopyFile(TmpContentsName
, ContentsName
);
5285 wxRemoveFile(TmpContentsName
);
5288 wxRemoveFile("chapters.rtf");
5289 wxRemoveFile("header.rtf");
5293 wxRemoveFile("sections.rtf");
5294 wxRemoveFile("subsections.rtf");
5295 wxRemoveFile("subsubsections.rtf");
5296 wxRemoveFile("popups.rtf");
5298 if (winHelp
&& generateHPJ
)
5299 WriteHPJ(OutputFile
);