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 s
+=4; // next character
252 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]='ö'; a
=1; }
253 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]='ä'; a
=1; }
254 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]='ü'; a
=1; }
255 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]='Ö'; a
=1; }
256 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]='Ä'; a
=1; }
257 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]='Ü'; a
=1; }
259 // printf("!!!!! %04X %04X %04X %04X! \n",ch1,ch2,ch3,ch4);
267 // Section (2) becomes level 1 if it's an article.
268 if (DocumentStyle
== LATEX_ARTICLE
)
271 if (level
== 0) // Means we had a Chapter in an article, oops.
274 ResetContentsLevels(level
);
279 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
281 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
284 // If a previous section at this level was a book, we *have* to have a
285 // book not a page, because of a bug in WHC (or WinHelp 4).
286 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
288 // At this level, we have a pointer to a further hierarchy.
289 // So we need a 'book' consisting of (say) Chapter 1.
290 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
292 // Then we have a 'page' consisting of the text for this chapter
293 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
295 // Then we'll be writing out further pages or books at level + 1...
297 // Remember that at this level, we had a book and *must* for the
298 // remainder of sections at this level.
299 ContentsLevels
[level
-1] = TRUE
;
303 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
308 if (level
== 1 || ContentsLevels
[level
-1])
310 // Always have a book at level 1
311 fprintf(WinHelpContentsFile
, "%d %s\n", level
, title
);
312 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
+1, title
, topicName
);
313 ContentsLevels
[level
-1] = TRUE
;
316 // Probably doesn't have children if it hasn't been added to the topic table
317 fprintf(WinHelpContentsFile
, "%d %s=%s\n", level
, title
, topicName
);
322 void SplitIndexEntry(char *entry
, char *buf1
, char *buf2
)
324 int len
= strlen(entry
); int i
= 0;
325 while ((i
< len
) && entry
[i
] != '!')
326 { buf1
[i
] = entry
[i
]; i
++; }
327 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
332 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
338 * Output topic index entries in WinHelp RTF
341 void GenerateKeywordsForTopic(char *topic
)
343 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
347 wxStringList
*list
= texTopic
->keywords
;
350 wxNode
*node
= list
->First();
353 char *s
= (char *)node
->Data();
355 // Must separate out main entry form subentry (only 1 subentry allowed)
356 char buf1
[100]; char buf2
[100];
357 SplitIndexEntry(s
, buf1
, buf2
);
359 // Check for ':' which messes up index
361 for (i
= 0; i
< strlen(buf1
) ; i
++)
364 for (i
= 0; i
< strlen(buf2
) ; i
++)
368 // {K} is a strange fix to prevent words beginning with K not
369 // being indexed properly
370 TexOutput("K{\\footnote {K} ");
372 if (strlen(buf2
) > 0)
385 * Output index entry in linear RTF
389 void GenerateIndexEntry(char *entry
)
393 char buf1
[100]; char buf2
[100];
394 SplitIndexEntry(entry
, buf1
, buf2
);
396 TexOutput("{\\xe\\v {");
398 if (strlen(buf2
) > 0)
408 * Write a suitable RTF header.
412 void WriteColourTable(FILE *fd
)
414 fprintf(fd
, "{\\colortbl");
415 wxNode
*node
= ColourTable
.First();
418 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->Data();
419 fprintf(fd
, "\\red%d\\green%d\\blue%d;\n", entry
->red
, entry
->green
, entry
->blue
);
426 * Write heading style
430 void WriteHeadingStyle(FILE *fd
, int heading
)
436 fprintf(fd
, "\\b\\fs%d", chapterFont
*2);
441 fprintf(fd
, "\\b\\fs%d", sectionFont
*2);
446 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
451 fprintf(fd
, "\\b\\fs%d", subsectionFont
*2);
459 void WriteRTFHeader(FILE *fd
)
461 fprintf(fd
, "{\\rtf1\\%s \\deff0\n", RTFCharset
);
462 fprintf(fd
, "{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n");
463 fprintf(fd
, "{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}");
467 fprintf(fd
, "{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n");
469 fprintf(fd
, "{\\s1 "); WriteHeadingStyle(fd
, 1); fprintf(fd
, "\\sbasedon0\\snext0 heading 1;}\n");
470 fprintf(fd
, "{\\s2 "); WriteHeadingStyle(fd
, 2); fprintf(fd
, "\\sbasedon0\\snext0 heading 2;}\n");
471 fprintf(fd
, "{\\s3 "); WriteHeadingStyle(fd
, 3); fprintf(fd
, "\\sbasedon0\\snext0 heading 3;}\n");
472 fprintf(fd
, "{\\s4 "); WriteHeadingStyle(fd
, 4); fprintf(fd
, "\\sbasedon0\\snext0 heading 4;}\n");
473 // Table of contents styles
474 fprintf(fd
, "{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n");
476 fprintf(fd
, "{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n");
477 fprintf(fd
, "{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n");
478 fprintf(fd
, "{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n");
481 fprintf(fd
, "{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n");
482 fprintf(fd
, "{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n");
483 fprintf(fd
, "{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n");
484 fprintf(fd
, "{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n");
485 fprintf(fd
, "{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n");
488 WriteColourTable(fd
);
489 fprintf(fd
, "\n\\ftnbj\\ftnrestart"); // Latex default is footnotes at bottom of page, not section.
493 void OutputNumberStyle(char *numberStyle
)
497 if (strcmp(numberStyle
, "arabic") == 0)
499 TexOutput("\\pgndec");
501 else if (strcmp(numberStyle
, "roman") == 0)
503 TexOutput("\\pgnlcrm");
505 else if (strcmp(numberStyle
, "Roman") == 0)
507 TexOutput("\\pgnucrm");
509 else if (strcmp(numberStyle
, "alph") == 0)
511 TexOutput("\\pgnlcltr");
513 else if (strcmp(numberStyle
, "Alph") == 0)
515 TexOutput("\\pgnucltr");
521 * Write a Windows help project file
524 bool WriteHPJ(char *filename
)
526 char hpjFilename
[256];
529 strcpy(hpjFilename
, filename
);
530 StripExtension(hpjFilename
);
531 strcat(hpjFilename
, ".hpj");
533 strcpy(helpFile
, wxFileNameFromPath(filename
));
534 StripExtension(helpFile
);
535 strcpy(rtfFile
, helpFile
);
536 strcat(helpFile
, ".hlp");
537 strcat(rtfFile
, ".rtf");
539 FILE *fd
= fopen(hpjFilename
, "w");
543 char *helpTitle
= winHelpTitle
;
545 helpTitle
= "Untitled";
547 wxString thePath
= wxPathOnly(InputFile
);
548 if (thePath
.IsEmpty())
550 fprintf(fd
, "[OPTIONS]\n");
551 fprintf(fd
, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath
.c_str());
552 fprintf(fd
, "TITLE=%s\n", helpTitle
);
553 fprintf(fd
, "CONTENTS=Contents\n");
555 if (winHelpVersion
> 3)
557 fprintf(fd
, "; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n");
558 fprintf(fd
, "COMPRESS=8 Zeck\n");
559 fprintf(fd
, "LCID=0x809 0x0 0x0 ;English (British)\n");
560 fprintf(fd
, "HLP=.\\%s.hlp\n", wxFileNameFromPath(FileRoot
));
564 fprintf(fd
, "COMPRESS=HIGH\n");
568 if (winHelpVersion
> 3)
570 fprintf(fd
, "[WINDOWS]\n");
571 fprintf(fd
, "Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n");
575 fprintf(fd
, "[FILES]\n%s\n\n", rtfFile
);
576 fprintf(fd
, "[CONFIG]\n");
578 fprintf(fd
, "CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n", helpFile
);
579 fprintf(fd
, "BrowseButtons()\n\n");
580 fprintf(fd
, "[MAP]\n\n[BITMAPS]\n\n");
587 * Given a TexChunk with a string value, scans through the string
588 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
589 * and inserting spaces at the start of lines since in Latex, a newline
590 * implies a space, but not in RTF.
594 void ProcessText2RTF(TexChunk
*chunk
)
596 bool changed
= FALSE
;
600 int len
= strlen(chunk
->value
);
603 ch
= chunk
->value
[i
];
609 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "\\par\n"); ptr
+= 5;
615 // If the first character of the next line is ASCII,
616 // put a space in. Implicit in Latex, not in RTF.
618 The reason this is difficult is that you don't really know
619 where a space would be appropriate. If you always put in a space
620 when you find a newline, unwanted spaces appear in the text.
622 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
623 !isspace(chunk
->value
[i
+1])) ||
624 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
625 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
626 !isspace(chunk
->value
[i
+2]))))
629 // DOS files have a 13 after the 10
633 if (chunk
->value
[i
] == 13)
640 BigBuffer
[ptr
] = ' ';
643 // Note that the actual ASCII character seen is dealt with in the next
654 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
656 BigBuffer
[ptr
] = '"'; ptr
++;
660 else if (!inVerbatim
&& ch
== '`') // Change ` to '
662 BigBuffer
[ptr
] = 39; ptr
++;
666 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
668 BigBuffer
[ptr
] = '\\'; ptr
++;
669 BigBuffer
[ptr
] = '\\'; ptr
++;
673 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curley bracket
675 BigBuffer
[ptr
] = '\\'; ptr
++;
676 BigBuffer
[ptr
] = ch
; ptr
++;
691 delete[] chunk
->value
;
692 chunk
->value
= copystring(BigBuffer
);
697 * Scan through all chunks starting from the given one,
698 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
699 * This should be called after Tex2Any has parsed the file,
700 * and before TraverseDocument is called.
704 void Text2RTF(TexChunk
*chunk
)
707 if (stopRunning
) return;
711 case CHUNK_TYPE_MACRO
:
713 TexMacroDef
*def
= chunk
->def
;
714 if (def
&& def
->ignore
)
717 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
720 wxNode
*node
= chunk
->children
.First();
723 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
724 Text2RTF(child_chunk
);
728 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
735 wxNode
*node
= chunk
->children
.First();
738 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
739 Text2RTF(child_chunk
);
745 case CHUNK_TYPE_STRING
:
748 ProcessText2RTF(chunk
);
760 static long browseId
= 0;
761 char *GetBrowseString(void)
765 sprintf(buf
, "%ld", browseId
);
766 int noZeroes
= 5-strlen(buf
);
767 strcpy(browseBuf
, "browse");
768 for (int i
= 0; i
< noZeroes
; i
++)
769 strcat(browseBuf
, "0");
770 strcat(browseBuf
, buf
);
775 * Keeping track of environments to restore the styles after \pard.
776 * Push strings like "\qc" onto stack.
780 void PushEnvironmentStyle(char *style
)
782 environmentStack
.Add(style
);
785 void PopEnvironmentStyle(void)
787 wxNode
*node
= environmentStack
.Last();
790 char *val
= (char *)node
->Data();
796 // Write out the styles, most recent first.
797 void WriteEnvironmentStyles(void)
799 wxNode
*node
= environmentStack
.Last();
802 char *val
= (char *)node
->Data();
806 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
809 sprintf(buf
, "\\fi%d", ParIndent
*20); // Convert points to TWIPS
812 if (environmentStack
.Number() > 0 || (ParIndent
> 0))
822 void OutputRTFHeaderCommands(void)
825 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
827 TexOutput("{\\headerl }{\\headerr }");
829 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
831 TexOutput("{\\headerl }{\\headerr }");
833 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
836 TexOutput("{\\headerl\\fi0 ");
839 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
841 TexOutput("{\\i \\qr ");
842 if (DocumentStyle
== LATEX_ARTICLE
)
844 sprintf(buf
, "SECTION %d", sectionNo
);
849 sprintf(buf
, "CHAPTER %d: ", chapterNo
);
852 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
853 TexOutput("}\\par\\pard}");
856 TexOutput("{\\headerr\\fi0 ");
859 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
861 TexOutput("{\\i \\qc ");
862 if (DocumentStyle
== LATEX_ARTICLE
)
864 sprintf(buf
, "SECTION %d", sectionNo
);
869 sprintf(buf
, "CHAPTER %d", chapterNo
);
872 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
873 TexOutput("}\\par\\pard}");
877 int oldForbidResetPar
= forbidResetPar
;
880 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
882 TexOutput("{\\headerl\\fi0 ");
885 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
889 if (!CentreHeaderEven
&& !RightHeaderEven
)
891 TraverseChildrenFromChunk(LeftHeaderEven
);
893 if (CentreHeaderEven
)
895 if (!LeftHeaderEven
&& !RightHeaderEven
)
898 TexOutput("\\tab\\tab\\tab ");
899 TraverseChildrenFromChunk(CentreHeaderEven
);
903 if (!LeftHeaderEven
&& !CentreHeaderEven
)
906 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
907 TraverseChildrenFromChunk(RightHeaderEven
);
909 TexOutput("\\par\\pard}");
912 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
914 TexOutput("{\\headerr\\fi0 ");
917 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
921 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
923 TraverseChildrenFromChunk(LeftHeaderOdd
);
927 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
930 TexOutput("\\tab\\tab\\tab ");
931 TraverseChildrenFromChunk(CentreHeaderOdd
);
935 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
938 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
939 TraverseChildrenFromChunk(RightHeaderOdd
);
941 TexOutput("\\par\\pard}");
943 // As an approximation, don't put a header on the first page of a section.
944 // This may not always be desired, but it's a reasonable guess.
945 TexOutput("{\\headerf }");
947 forbidResetPar
= oldForbidResetPar
;
951 void OutputRTFFooterCommands(void)
953 if (PageStyle
&& strcmp(PageStyle
, "plain") == 0)
955 TexOutput("{\\footerl\\fi0 ");
957 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
959 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
960 TexOutput("}\\par\\pard}");
962 TexOutput("{\\footerr\\fi0 ");
964 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
966 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
967 TexOutput("}\\par\\pard}");
969 else if (PageStyle
&& strcmp(PageStyle
, "empty") == 0)
971 TexOutput("{\\footerl }{\\footerr }");
973 else if (PageStyle
&& strcmp(PageStyle
, "headings") == 0)
975 TexOutput("{\\footerl }{\\footerr }");
979 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
981 TexOutput("{\\footerl\\fi0 ");
983 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
986 if (!CentreFooterEven
&& !RightFooterEven
)
988 TraverseChildrenFromChunk(LeftFooterEven
);
990 if (CentreFooterEven
)
992 if (!LeftFooterEven
&& !RightFooterEven
)
995 TexOutput("\\tab\\tab\\tab ");
996 TraverseChildrenFromChunk(CentreFooterEven
);
1000 if (!LeftFooterEven
&& !CentreFooterEven
)
1003 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1004 TraverseChildrenFromChunk(RightFooterEven
);
1006 TexOutput("\\par\\pard}");
1009 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1011 TexOutput("{\\footerr\\fi0 ");
1013 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
1016 if (!CentreFooterOdd
&& !RightFooterOdd
)
1018 TraverseChildrenFromChunk(LeftFooterOdd
);
1020 if (CentreFooterOdd
)
1022 if (!LeftFooterOdd
&& !RightFooterOdd
)
1025 TexOutput("\\tab\\tab\\tab ");
1026 TraverseChildrenFromChunk(CentreFooterOdd
);
1030 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1033 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1034 TraverseChildrenFromChunk(RightFooterOdd
);
1036 TexOutput("\\par\\pard}");
1039 // As an approximation, put a footer on the first page of a section.
1040 // This may not always be desired, but it's a reasonable guess.
1041 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1043 TexOutput("{\\footerf\\fi0 ");
1046 if (!CentreFooterOdd
&& !RightFooterOdd
)
1048 TraverseChildrenFromChunk(LeftFooterOdd
);
1050 if (CentreFooterOdd
)
1052 if (!LeftFooterOdd
&& !RightFooterOdd
)
1055 TexOutput("\\tab\\tab\\tab ");
1056 TraverseChildrenFromChunk(CentreFooterOdd
);
1060 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1063 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1064 TraverseChildrenFromChunk(RightFooterOdd
);
1066 TexOutput("\\par\\pard}");
1071 // Called on start/end of macro examination
1072 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1076 sprintf(tmpBuf, "%d (%d)", macroId, (int)start);
1077 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1078 OutputDebugString("\n"); wxYield();
1081 // ltLABEL is included here because after a section but BEFORE
1082 // the label is seen, a new paragraph is issued. Don't upset this by
1083 // immediately forgetting we've done it.
1084 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1085 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1086 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1087 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1088 macroId
!= ltPAGENUMBERING
&&
1089 (forbidResetPar
== 0)))
1091 issuedNewParagraph
= 0;
1099 case ltCHAPTERHEADING
:
1100 case ltCHAPTERHEADINGSTAR
:
1108 subsubsectionNo
= 0;
1111 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1114 char *topicName
= FindTopicName(GetNextChunk());
1115 SetCurrentChapterName(topicName
);
1117 if (winHelpContents
&& winHelp
&& !InPopups())
1119 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1120 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1122 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1127 fprintf(Contents
, "\n{\\uldb ");
1128 fprintf(Chapters
, "\\page");
1129 fprintf(Chapters
, "\n${\\footnote ");
1131 SetCurrentOutputs(Contents
, Chapters
);
1133 SetCurrentOutput(Chapters
);
1137 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
1139 // If a non-custom page style, we generate the header now.
1140 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1141 strcmp(PageStyle
, "empty") == 0 ||
1142 strcmp(PageStyle
, "headings") == 0))
1144 OutputRTFHeaderCommands();
1145 OutputRTFFooterCommands();
1148 // Need to reset the current numbering style, or RTF forgets it.
1149 SetCurrentOutput(Chapters
);
1150 OutputNumberStyle(currentNumberStyle
);
1152 SetCurrentOutput(Contents
);
1156 if (macroId
== ltCHAPTER
)
1159 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", chapterNo
);
1161 else if (macroId
== ltCHAPTERHEADING
)
1163 fprintf(Contents
, "\\par\n\\pard{\\b ");
1165 else SetCurrentOutput(NULL
); // No entry in table of contents
1169 startedSections
= TRUE
;
1171 // Output heading to contents page
1174 OutputCurrentSection();
1177 fprintf(Contents
, "}{\\v %s}\\par\\pard\n", topicName
);
1178 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1179 fprintf(Contents
, "}\\par\\par\\pard\n");
1181 // From here, just output to chapter
1182 SetCurrentOutput(Chapters
);
1187 fprintf(Chapters
, "}\n#{\\footnote %s}\n", topicName
);
1188 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
1190 OutputSectionKeyword(Chapters
);
1192 GenerateKeywordsForTopic(topicName
);
1195 // If we're generating a .cnt file, we don't want to be able
1196 // jump up to the old-style contents page, so disable it.
1197 if (winHelpContents
)
1198 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
1200 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1201 wxFileNameFromPath(FileRoot
), "Contents");
1207 char *styleCommand
= "";
1208 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1209 styleCommand
= "\\s1";
1210 fprintf(Chapters
, "\\pard{%s", ((winHelp
&& !InPopups()) ? "\\keepn\\sa140\\sb140" : styleCommand
));
1211 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " ");
1214 if (macroId
== ltCHAPTER
)
1217 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1218 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1220 fprintf(Chapters
, "%d. ", chapterNo
);
1224 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1227 OutputCurrentSection();
1228 TexOutput("\\par\\pard}\\par\n");
1230 issuedNewParagraph
= 2;
1236 case ltSECTIONHEADING
:
1237 case ltSECTIONHEADINGSTAR
:
1241 if (DocumentStyle
== LATEX_ARTICLE
)
1242 jumpFrom
= Contents
;
1244 jumpFrom
= Chapters
;
1249 subsubsectionNo
= 0;
1250 if (DocumentStyle
== LATEX_ARTICLE
)
1253 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1256 char *topicName
= FindTopicName(GetNextChunk());
1257 SetCurrentSectionName(topicName
);
1258 NotifyParentHasChildren(1);
1259 if (winHelpContents
&& winHelp
&& !InPopups())
1261 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1262 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1264 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1268 SetCurrentOutputs(jumpFrom
, Sections
);
1269 // Newline for a new section if this is an article
1270 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1271 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1272 fprintf(Sections
, "\\page\n");
1275 fprintf(jumpFrom
, "\n{\\uldb ");
1279 if (DocumentStyle
== LATEX_ARTICLE
)
1281 TexOutput("\\sect\\pgncont\n");
1282 // If a non-custom page style, we generate the header now.
1283 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
1284 strcmp(PageStyle
, "empty") == 0 ||
1285 strcmp(PageStyle
, "headings") == 0))
1287 OutputRTFHeaderCommands();
1288 OutputRTFFooterCommands();
1291 SetCurrentOutput(Contents
);
1293 if (macroId
== ltSECTION
)
1297 if (DocumentStyle
== LATEX_REPORT
)
1298 fprintf(Contents
, "\n\\pard{\\tab %d.%d\\tab ", chapterNo
, sectionNo
);
1300 fprintf(Contents
, "\\par\n\\pard{\\b %d\\tab ", sectionNo
);
1303 else if (macroId
== ltSECTIONHEADING
)
1307 if (DocumentStyle
== LATEX_REPORT
)
1308 fprintf(Contents
, "\n\\pard{\\tab "); //, chapterNo, sectionNo);
1310 fprintf(Contents
, "\\par\n\\pard{\\b "); //, sectionNo);
1313 else SetCurrentOutput(NULL
);
1316 if (startedSections
)
1319 fprintf(Sections
, "\\page\n");
1321 startedSections
= TRUE
;
1324 fprintf(Sections
, "\n${\\footnote ");
1326 // Output heading to contents page
1328 OutputCurrentSection();
1333 fprintf(jumpFrom
, "}{\\v %s}\\par\\pard\n", topicName
);
1335 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1337 if (DocumentStyle
== LATEX_REPORT
)
1338 fprintf(Contents
, "}\\par\\pard\n");
1340 fprintf(Contents
, "}\\par\\par\\pard\n");
1343 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1347 fprintf(Sections
, "}\n#{\\footnote %s}\n", topicName
);
1348 fprintf(Sections
, "+{\\footnote %s}\n", GetBrowseString());
1349 OutputSectionKeyword(Sections
);
1350 GenerateKeywordsForTopic(topicName
);
1353 if (DocumentStyle
== LATEX_ARTICLE
)
1355 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1356 wxFileNameFromPath(FileRoot
), "Contents");
1358 else if (CurrentChapterName
)
1360 fprintf(Sections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1361 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1368 char *styleCommand
= "";
1369 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1371 if (DocumentStyle
== LATEX_ARTICLE
)
1372 styleCommand
= "\\s1";
1374 styleCommand
= "\\s2";
1377 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1378 keep
= "\\keepn\\sa140\\sb140";
1380 fprintf(winHelp
? Sections
: Chapters
, "\\pard{%s%s",
1381 keep
, styleCommand
);
1383 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1384 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1385 fprintf(winHelp
? Sections
: Chapters
, " ");
1389 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1391 if (DocumentStyle
== LATEX_REPORT
)
1394 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo,
1395 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1398 fprintf(Chapters
, "%d.%d. ", chapterNo
, sectionNo
);
1403 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1404 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1407 fprintf(Chapters
, "%d. ", sectionNo
);
1412 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1415 OutputCurrentSection();
1416 TexOutput("\\par\\pard}\\par\n");
1418 issuedNewParagraph
= 2;
1423 case ltSUBSECTIONSTAR
:
1424 case ltMEMBERSECTION
:
1425 case ltFUNCTIONSECTION
:
1429 if (winHelp
&& !Sections
)
1431 OnError("You cannot have a subsection before a section!");
1435 subsubsectionNo
= 0;
1437 if (macroId
!= ltSUBSECTIONSTAR
)
1440 char *topicName
= FindTopicName(GetNextChunk());
1441 SetCurrentSubsectionName(topicName
);
1442 NotifyParentHasChildren(2);
1443 if (winHelpContents
&& winHelp
&& !InPopups())
1445 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1446 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1448 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1452 SetCurrentOutputs(Sections
, Subsections
);
1453 SetCurrentOutputs(Sections
, Subsections
);
1455 fprintf(Sections
, "\n{\\uldb ");
1459 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1460 (macroId
!= ltFUNCTIONSECTION
))
1462 SetCurrentOutput(Contents
);
1463 if (DocumentStyle
== LATEX_REPORT
)
1464 fprintf(Contents
, "\n\\pard\\tab\\tab %d.%d.%d\\tab ", chapterNo
, sectionNo
, subsectionNo
);
1466 fprintf(Contents
, "\n\\pard\\tab %d.%d\\tab ", sectionNo
, subsectionNo
);
1467 } else SetCurrentOutput(NULL
);
1469 if (startedSections
)
1474 fprintf(Subsections
, "\\page\n");
1477 fprintf(Chapters
, "\\par\n");
1479 startedSections
= TRUE
;
1482 fprintf(Subsections
, "\n${\\footnote ");
1484 // Output to contents page
1486 OutputCurrentSection();
1491 fprintf(Sections
, "}{\\v %s}\\par\\pard\n", topicName
);
1493 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1494 (macroId
!= ltFUNCTIONSECTION
))
1495 fprintf(Contents
, "\\par\\pard\n");
1497 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1500 fprintf(Subsections
, "}\n#{\\footnote %s}\n", topicName
);
1501 fprintf(Subsections
, "+{\\footnote %s}\n", GetBrowseString());
1502 OutputSectionKeyword(Subsections
);
1503 GenerateKeywordsForTopic(topicName
);
1504 if (useUpButton
&& CurrentSectionName
)
1506 fprintf(Subsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1507 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1510 if (!winHelp
&& indexSubsections
&& useWord
)
1512 // Insert index entry for this subsection
1513 TexOutput("{\\xe\\v {");
1514 OutputCurrentSection();
1520 char *styleCommand
= "";
1521 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1523 if (DocumentStyle
== LATEX_ARTICLE
)
1524 styleCommand
= "\\s2";
1526 styleCommand
= "\\s3";
1529 if (winHelp
&& !InPopups())
1530 keep
= "\\keepn\\sa140\\sb140";
1532 fprintf(winHelp
? Subsections
: Chapters
, "\\pard{%s%s",
1533 keep
, styleCommand
);
1535 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1536 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1537 fprintf(winHelp
? Subsections
: Chapters
, " ");
1541 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1542 (macroId
!= ltFUNCTIONSECTION
))
1544 if (DocumentStyle
== LATEX_REPORT
)
1547 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo,
1548 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1551 fprintf(Chapters
, "%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
);
1556 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo,
1557 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1560 fprintf(Chapters
, "%d.%d. ", sectionNo
, subsectionNo
);
1565 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1568 OutputCurrentSection(); // Repeat section header
1569 TexOutput("\\par\\pard}\\par\n");
1571 issuedNewParagraph
= 2;
1576 case ltSUBSUBSECTION
:
1577 case ltSUBSUBSECTIONSTAR
:
1581 if (winHelp
&& !Subsections
)
1583 OnError("You cannot have a subsubsection before a subsection!");
1587 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1590 char *topicName
= FindTopicName(GetNextChunk());
1591 SetCurrentTopic(topicName
);
1592 NotifyParentHasChildren(3);
1593 if (winHelpContents
&& winHelp
)
1595 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1596 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1598 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1602 SetCurrentOutputs(Subsections
, Subsubsections
);
1603 fprintf(Subsections
, "\n{\\uldb ");
1607 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1609 if (DocumentStyle
== LATEX_ARTICLE
)
1611 SetCurrentOutput(Contents
);
1612 fprintf(Contents
, "\n\\tab\\tab %d.%d.%d\\tab ",
1613 sectionNo
, subsectionNo
, subsubsectionNo
);
1616 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1619 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1622 if (startedSections
)
1625 fprintf(Subsubsections
, "\\page\n");
1627 fprintf(Chapters
, "\\par\n");
1630 startedSections
= TRUE
;
1633 fprintf(Subsubsections
, "\n${\\footnote ");
1635 // Output header to contents page
1636 OutputCurrentSection();
1639 fprintf(Subsections
, "}{\\v %s}\\par\\pard\n", topicName
);
1640 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1641 fprintf(Contents
, "\\par\\pard\n");
1643 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1646 fprintf(Subsubsections
, "}\n#{\\footnote %s}\n", topicName
);
1647 fprintf(Subsubsections
, "+{\\footnote %s}\n", GetBrowseString());
1648 OutputSectionKeyword(Subsubsections
);
1649 GenerateKeywordsForTopic(topicName
);
1650 if (useUpButton
&& CurrentSubsectionName
)
1652 fprintf(Subsubsections
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1653 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1656 if (!winHelp
&& indexSubsections
&& useWord
)
1658 // Insert index entry for this subsubsection
1659 TexOutput("{\\xe\\v {");
1660 OutputCurrentSection();
1664 char *styleCommand
= "";
1665 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1667 if (DocumentStyle
== LATEX_ARTICLE
)
1668 styleCommand
= "\\s3";
1670 styleCommand
= "\\s4";
1674 keep
= "\\keepn\\sa140\\sb140";
1676 fprintf(winHelp
? Subsubsections
: Chapters
, "\\pard{%s%s",
1677 keep
, styleCommand
);
1679 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1680 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1681 fprintf(winHelp
? Subsubsections
: Chapters
, " ");
1685 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1687 if (DocumentStyle
== LATEX_ARTICLE
)
1690 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo, subsubsectionNo,
1691 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1694 fprintf(Chapters
, "%d.%d.%d. ", sectionNo
, subsectionNo
, subsubsectionNo
);
1699 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1700 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
,
1703 fprintf(Chapters
, "%d.%d.%d.%d. ", chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1708 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", topicName
, topicName
);
1711 OutputCurrentSection(); // Repeat section header
1712 TexOutput("\\par\\pard}\\par\n");
1713 issuedNewParagraph
= 2;
1714 // if (winHelp) TexOutput("\\pard");
1724 char *topicName
= FindTopicName(GetNextChunk());
1725 SetCurrentTopic(topicName
);
1727 TexOutput("\\pard\\par");
1734 if (winHelp
|| !useWord
)
1736 if (DocumentStyle
!= LATEX_ARTICLE
)
1737 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1739 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1743 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1744 FigureNameString
, topicName
, topicName
);
1751 if (winHelp
|| !useWord
)
1753 if (DocumentStyle
!= LATEX_ARTICLE
)
1754 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1756 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1760 sprintf(figBuf
, "%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1761 TableNameString
, topicName
, topicName
);
1765 int n
= (inTable
? tableNo
: figureNo
);
1766 AddTexRef(topicName
, NULL
, NULL
,
1767 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1768 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1771 TexOutput("\\qc{\\b ");
1773 TexOutput("\\ql{\\b ");
1776 OutputCurrentSection();
1778 TexOutput("}\\par\\pard\n");
1779 WriteEnvironmentStyles();
1786 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1796 TexOutput("K{\\footnote {K} ");
1797 suppressNameDecoration
= TRUE
;
1798 TraverseChildrenFromChunk(currentMember
);
1799 suppressNameDecoration
= FALSE
;
1802 if (!winHelp
&& useWord
)
1804 // Insert index entry for this function
1805 TexOutput("{\\xe\\v {");
1806 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1807 TraverseChildrenFromChunk(currentMember
);
1808 suppressNameDecoration
= FALSE
;
1816 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1826 TexOutput("K{\\footnote {K} ");
1827 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1828 TraverseChildrenFromChunk(currentMember
);
1829 suppressNameDecoration
= FALSE
;
1832 if (!winHelp
&& useWord
)
1834 // Insert index entry for this function
1835 TexOutput("{\\xe\\v {");
1836 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1837 TraverseChildrenFromChunk(currentMember
);
1838 suppressNameDecoration
= FALSE
;
1846 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1856 TexOutput("K{\\footnote {K} ");
1857 TraverseChildrenFromChunk(currentMember
);
1860 if (!winHelp
&& useWord
)
1862 // Insert index entry for this function
1863 TexOutput("{\\xe\\v {");
1864 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1865 TraverseChildrenFromChunk(currentMember
);
1866 suppressNameDecoration
= FALSE
;
1875 SetCurrentOutput(Chapters
);
1878 case ltTABLEOFCONTENTS
:
1882 if (!winHelp
&& useWord
)
1884 // Insert Word for Windows table of contents
1885 TexOutput("\\par\\pard\\pgnrestart\\sect\\titlepg");
1887 // In linear RTF, same as chapter headings.
1888 sprintf(buf
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n", chapterFont
*2, ContentsNameString
);
1891 sprintf(buf
, "{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n", contentsDepth
);
1893 // TexOutput("\\sect\\sectd");
1897 FILE *fd
= fopen(ContentsName
, "r");
1910 TexOutput("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n");
1911 OnInform("Run Tex2RTF again to include contents page.");
1920 // TexOutput("{\\b void}");
1926 TexOutput("{\\scaps HARDY}");
1932 TexOutput("wxCLIPS");
1935 case ltSPECIALAMPERSAND
:
1940 TexOutput("\\cell ");
1946 case ltSPECIALTILDE
:
1957 case ltBACKSLASHCHAR
:
1963 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
1964 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
1965 int currentWidth
= 0;
1966 for (int i
= 0; i
< noColumns
; i
++)
1968 currentWidth
+= TableData
[i
].width
;
1969 if (TableData
[i
].rightBorder
)
1970 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
1972 if (TableData
[i
].leftBorder
)
1973 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
1975 sprintf(buf
, "\\cellx%d", currentWidth
);
1978 TexOutput("\\pard\\intbl\n");
1981 TexOutput("\\line\n");
1991 case ltRTFSP
: // Explicit space, RTF only
2003 if (indentLevel
> 0)
2005 TexOutput("\\par\\par\n");
2006 issuedNewParagraph
= 2;
2010 // Top-level list: issue a new paragraph if we haven't
2012 if (!issuedNewParagraph
)
2014 TexOutput("\\par\\pard");
2015 WriteEnvironmentStyles();
2016 issuedNewParagraph
= 1;
2018 else issuedNewParagraph
= 0;
2021 TexOutput("\\fi0\n");
2023 if (macroId
== ltENUMERATE
)
2024 listType
= LATEX_ENUMERATE
;
2025 else if (macroId
== ltITEMIZE
)
2026 listType
= LATEX_ITEMIZE
;
2028 listType
= LATEX_DESCRIPTION
;
2031 wxNode
*node
= itemizeStack
.First();
2033 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2035 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2036 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2038 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2039 itemizeStack
.Insert(struc
);
2041 sprintf(buf
, "\\tx%d\\tx%d\\li%d", indentSize1
, indentSize2
, indentSize2
);
2042 PushEnvironmentStyle(buf
);
2046 currentItemSep
= 8; // Reset to the default
2048 PopEnvironmentStyle();
2050 if (itemizeStack
.First())
2052 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2054 delete itemizeStack
.First();
2056 /* Change 18/7/97 - don't know why we wish to do this
2057 if (itemizeStack.Number() == 0)
2059 OnMacro(ltPAR, 0, TRUE);
2060 OnMacro(ltPAR, 0, FALSE);
2061 issuedNewParagraph = 2;
2073 wxNode
*node
= itemizeStack
.First();
2075 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
2077 int indentSize
= oldIndent
+ TwoColWidthA
;
2079 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2080 itemizeStack
.Insert(struc
);
2082 // sprintf(buf, "\\tx%d\\li%d\\ri%d", indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2083 sprintf(buf
, "\\tx%d\\li%d", indentSize
, indentSize
);
2084 PushEnvironmentStyle(buf
);
2089 PopEnvironmentStyle();
2090 if (itemizeStack
.First())
2092 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
2094 delete itemizeStack
.First();
2098 TexOutput("\\pard\n");
2099 WriteEnvironmentStyles();
2101 /* why do we need this? */
2102 if (itemizeStack
.Number() == 0)
2104 issuedNewParagraph
= 0;
2105 OnMacro(ltPAR
, 0, TRUE
);
2106 OnMacro(ltPAR
, 0, FALSE
);
2113 wxNode
*node
= itemizeStack
.First();
2116 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2119 struc
->currentItem
+= 1;
2122 int indentSize1
= struc
->labelIndentation
;
2123 int indentSize2
= struc
->indentation
;
2126 if (struc
->currentItem
> 1)
2128 if (currentItemSep
> 0)
2132 // WriteEnvironmentStyles();
2135 sprintf(buf
, "\\tx%d\\tx%d\\li%d\\fi-%d\n", indentSize1
, indentSize2
,
2136 indentSize2
, 20*itemIndentTab
);
2139 switch (struc
->listType
)
2141 case LATEX_ENUMERATE
:
2143 if (descriptionItemArg
)
2145 TexOutput("\\tab{ ");
2146 TraverseChildrenFromChunk(descriptionItemArg
);
2147 TexOutput("}\\tab");
2148 descriptionItemArg
= NULL
;
2152 sprintf(indentBuf
, "\\tab{\\b %d.}\\tab", struc
->currentItem
);
2153 TexOutput(indentBuf
);
2159 if (descriptionItemArg
)
2161 TexOutput("\\tab{ ");
2162 TraverseChildrenFromChunk(descriptionItemArg
);
2163 TexOutput("}\\tab");
2164 descriptionItemArg
= NULL
;
2168 if (bulletFile
&& winHelp
)
2170 if (winHelpVersion
> 3) // Transparent bitmap
2171 sprintf(indentBuf
, "\\tab\\{bmct %s\\}\\tab", bulletFile
);
2173 sprintf(indentBuf
, "\\tab\\{bmc %s\\}\\tab", bulletFile
);
2176 sprintf(indentBuf
, "\\tab{\\b o}\\tab");
2178 sprintf(indentBuf
, "\\tab{\\f1\\'b7}\\tab");
2179 TexOutput(indentBuf
);
2184 case LATEX_DESCRIPTION
:
2186 if (descriptionItemArg
)
2188 TexOutput("\\tab{\\b ");
2189 TraverseChildrenFromChunk(descriptionItemArg
);
2191 descriptionItemArg
= NULL
;
2201 case ltTWOCOLITEMRULED
:
2203 wxNode
*node
= itemizeStack
.First();
2206 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
2209 struc
->currentItem
+= 1;
2212 wxNode
*node2
= NULL
;
2213 if (itemizeStack
.Number() > 1) // TODO: do I actually mean Nth(0) here??
2214 node2
= itemizeStack
.Nth(1);
2216 oldIndent
= ((ItemizeStruc
*)node2
->Data())->indentation
;
2219 if (struc
->currentItem
> 1)
2221 if (currentItemSep
> 0)
2224 // WriteEnvironmentStyles();
2227 // sprintf(buf, "\\tx%d\\li%d\\fi-%d\\ri%d\n", TwoColWidthA,
2228 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2230 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA,
2231 TwoColWidthA, TwoColWidthA);
2233 sprintf(buf
, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA
+ oldIndent
,
2234 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2245 if (macroId
== ltVERBATIM
)
2247 if (!issuedNewParagraph
)
2249 TexOutput("\\par\\pard");
2250 WriteEnvironmentStyles();
2251 issuedNewParagraph
= 1;
2253 else issuedNewParagraph
= 0;
2255 sprintf(buf
, "{\\f3\\fs20 ");
2261 if (macroId
== ltVERBATIM
)
2263 TexOutput("\\pard\n");
2264 // issuedNewParagraph = 1;
2265 WriteEnvironmentStyles();
2275 TexOutput("\\fi0\\qc ");
2277 PushEnvironmentStyle("\\qc");
2281 TexOutput("\\par\\pard\n");
2282 issuedNewParagraph
= 1;
2284 PopEnvironmentStyle();
2285 WriteEnvironmentStyles();
2293 TexOutput("\\fi0\\ql ");
2295 PushEnvironmentStyle("\\ql");
2299 TexOutput("\\par\\pard\n");
2300 issuedNewParagraph
= 1;
2302 PopEnvironmentStyle();
2303 WriteEnvironmentStyles();
2311 TexOutput("\\fi0\\qr ");
2313 PushEnvironmentStyle("\\qr");
2317 TexOutput("\\par\\pard\n");
2318 issuedNewParagraph
= 1;
2320 PopEnvironmentStyle();
2321 WriteEnvironmentStyles();
2326 case ltFOOTNOTESIZE
:
2330 sprintf(buf
, "{\\fs%d\n", smallFont
*2);
2333 else TexOutput("}\n");
2341 sprintf(buf
, "{\\fs%d\n", tinyFont
*2);
2344 else TexOutput("}\n");
2351 sprintf(buf
, "{\\fs%d\n", normalFont
*2);
2354 else TexOutput("}\n");
2361 sprintf(buf
, "{\\fs%d\n", largeFont1
*2);
2364 else TexOutput("}\n");
2371 sprintf(buf
, "{\\fs%d\n", LargeFont2
*2);
2374 else TexOutput("}\n");
2381 sprintf(buf
, "{\\fs%d\n", LARGEFont3
*2);
2384 else TexOutput("}\n");
2391 sprintf(buf
, "{\\fs%d\n", hugeFont1
*2);
2394 else TexOutput("}\n");
2401 sprintf(buf
, "{\\fs%d\n", HugeFont2
*2);
2404 else TexOutput("}\n");
2411 sprintf(buf
, "{\\fs%d\n", HUGEFont3
*2);
2414 else TexOutput("}\n");
2425 else TexOutput("}");
2432 TexOutput("{\\ul ");
2434 else TexOutput("}");
2447 else TexOutput("}");
2450 // Roman font: do nothing. Should really switch between
2459 TexOutput("{\\plain ");
2461 else TexOutput("}");
2465 // Medium-weight font. Unbolden...
2470 TexOutput("{\\b0 ");
2472 else TexOutput("}");
2475 // Upright (un-italic or slant)
2480 TexOutput("{\\i0 ");
2482 else TexOutput("}");
2491 TexOutput("{\\scaps ");
2493 else TexOutput("}");
2502 TexOutput("{\\f3 ");
2504 else TexOutput("}");
2529 if ( issuedNewParagraph
== 0 )
2531 TexOutput("\\par\\pard");
2532 issuedNewParagraph
++;
2534 // Extra par if parskip is more than zero (usually looks best.)
2535 if (!inTabular
&& (ParSkip
> 0))
2538 issuedNewParagraph
++;
2540 WriteEnvironmentStyles();
2542 // 1 is a whole paragraph if ParSkip == 0,
2543 // half a paragraph if ParSkip > 0
2544 else if ( issuedNewParagraph
== 1 )
2546 // Don't need a par at all if we've already had one,
2547 // and ParSkip == 0.
2549 // Extra par if parskip is more than zero (usually looks best.)
2550 if (!inTabular
&& (ParSkip
> 0))
2553 issuedNewParagraph
++;
2555 WriteEnvironmentStyles();
2558 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2560 TexOutput("\\par\\pard");
2562 // Extra par if parskip is more than zero (usually looks best.)
2563 if (!inTabular && (ParSkip > 0))
2565 WriteEnvironmentStyles();
2575 // In Windows Help, no newpages until we've started some chapters or sections
2576 if (!(winHelp
&& !startedSections
))
2578 TexOutput("\\page\n");
2583 if (start
&& DocumentTitle
)
2585 TexOutput("\\par\\pard");
2588 sprintf(buf
, "\\qc{\\fs%d\\b ", titleFont
*2);
2590 TraverseChildrenFromChunk(DocumentTitle
);
2591 TexOutput("}\\par\\pard\n");
2597 sprintf(buf
, "\\par\\qc{\\fs%d ", authorFont
*2);
2599 TraverseChildrenFromChunk(DocumentAuthor
);
2601 TexOutput("\\par\\pard\n");
2606 sprintf(buf
, "\\qc{\\fs%d ", authorFont
*2);
2608 TraverseChildrenFromChunk(DocumentDate
);
2609 TexOutput("}\\par\\pard\n");
2611 // If linear RTF, we want this titlepage to be in a separate
2612 // section with its own (blank) header and footer
2613 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2615 TexOutput("{\\header }{\\footer }\n");
2616 // Not sure about this: we get too many sections.
2617 // TexOutput("\\sect");
2622 case ltADDCONTENTSLINE
:
2626 if (contentsLineSection
&& contentsLineValue
)
2628 if (strcmp(contentsLineSection
, "chapter") == 0)
2630 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2632 else if (strcmp(contentsLineSection
, "section") == 0)
2634 if (DocumentStyle
!= LATEX_ARTICLE
)
2635 fprintf(Contents
, "\n\\tab%s\\par\n", contentsLineValue
);
2637 fprintf(Contents
, "\\par\n{\\b %s}\\par\n", contentsLineValue
);
2647 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2648 issuedNewParagraph
= 1;
2649 WriteEnvironmentStyles();
2657 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2658 issuedNewParagraph
= 1;
2659 WriteEnvironmentStyles();
2669 case ltNUMBEREDBIBITEM
:
2672 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
2674 TexOutput("\\par\\pard\\par\n\n");
2681 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2689 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2690 sprintf(buf
, "%d", chapterNo
);
2699 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2700 sprintf(buf
, "%d", sectionNo
);
2707 if (!start
&& !winHelp
)
2709 TexOutput("\\cols2\n");
2715 if (!start
&& !winHelp
)
2717 TexOutput("\\cols1\n");
2723 if (start
&& useWord
&& !winHelp
)
2725 FakeCurrentSection("Index");
2726 OnMacro(ltPAR
, 0, TRUE
);
2727 OnMacro(ltPAR
, 0, FALSE
);
2728 TexOutput("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n");
2732 case ltLISTOFFIGURES
:
2734 if (start
&& useWord
&& !winHelp
)
2736 FakeCurrentSection(FiguresNameString
, FALSE
);
2737 OnMacro(ltPAR
, 0, TRUE
);
2738 OnMacro(ltPAR
, 0, FALSE
);
2739 OnMacro(ltPAR
, 0, TRUE
);
2740 OnMacro(ltPAR
, 0, FALSE
);
2742 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n",
2748 case ltLISTOFTABLES
:
2750 if (start
&& useWord
&& !winHelp
)
2752 FakeCurrentSection(TablesNameString
, FALSE
);
2753 OnMacro(ltPAR
, 0, TRUE
);
2754 OnMacro(ltPAR
, 0, FALSE
);
2755 OnMacro(ltPAR
, 0, TRUE
);
2756 OnMacro(ltPAR
, 0, FALSE
);
2758 sprintf(buf
, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n",
2766 if (start
) TexOutput("{\\f1\\'61}");
2769 if (start
) TexOutput("{\\f1\\'62}");
2772 if (start
) TexOutput("{\\f1\\'63}");
2775 if (start
) TexOutput("{\\f1\\'64}");
2779 if (start
) TexOutput("{\\f1\\'65}");
2782 if (start
) TexOutput("{\\f1\\'7A}");
2785 if (start
) TexOutput("{\\f1\\'68}");
2789 if (start
) TexOutput("{\\f1\\'71}");
2792 if (start
) TexOutput("{\\f1\\'69}");
2795 if (start
) TexOutput("{\\f1\\'6B}");
2798 if (start
) TexOutput("{\\f1\\'6C}");
2801 if (start
) TexOutput("{\\f1\\'6D}");
2804 if (start
) TexOutput("{\\f1\\'6E}");
2807 if (start
) TexOutput("{\\f1\\'78}");
2810 if (start
) TexOutput("{\\f1\\'70}");
2813 if (start
) TexOutput("{\\f1\\'76}");
2817 if (start
) TexOutput("{\\f1\\'72}");
2820 if (start
) TexOutput("{\\f1\\'73}");
2823 if (start
) TexOutput("{\\f1\\'56}");
2826 if (start
) TexOutput("{\\f1\\'74}");
2829 if (start
) TexOutput("{\\f1\\'75}");
2833 if (start
) TexOutput("{\\f1\\'66}");
2836 if (start
) TexOutput("{\\f1\\'63}");
2839 if (start
) TexOutput("{\\f1\\'79}");
2842 if (start
) TexOutput("{\\f1\\'77}");
2845 if (start
) TexOutput("{\\f1\\'47}");
2848 if (start
) TexOutput("{\\f1\\'44}");
2851 if (start
) TexOutput("{\\f1\\'51}");
2854 if (start
) TexOutput("{\\f1\\'4C}");
2857 if (start
) TexOutput("{\\f1\\'58}");
2860 if (start
) TexOutput("{\\f1\\'50}");
2863 if (start
) TexOutput("{\\f1\\'53}");
2866 if (start
) TexOutput("{\\f1\\'54}");
2869 if (start
) TexOutput("{\\f1\\'46}");
2872 if (start
) TexOutput("{\\f1\\'59}");
2875 if (start
) TexOutput("{\\f1\\'57}");
2877 // Binary operation symbols
2880 if (start
) TexOutput("{\\f1\\'A3}");
2883 if (start
) TexOutput("<<");
2886 if (start
) TexOutput("{\\f1\\'CC}");
2889 if (start
) TexOutput("{\\f1\\'CD}");
2892 if (start
) TexOutput("{\\f1\\'CE}");
2896 if (start
) TexOutput("{\\f1\\'B3}");
2899 if (start
) TexOutput(">>");
2902 if (start
) TexOutput("{\\f1\\'C9}");
2905 if (start
) TexOutput("{\\f1\\'CD}");
2908 if (start
) TexOutput("{\\f1\\'27}");
2911 if (start
) TexOutput("{\\f1\\'5E}");
2914 if (start
) TexOutput("{\\f1\\'B9}");
2917 if (start
) TexOutput("{\\f1\\'BB}");
2920 if (start
) TexOutput("{\\f1\\'40}");
2923 if (start
) TexOutput("{\\f1\\'BA}");
2926 if (start
) TexOutput("{\\f1\\'B5}");
2929 if (start
) TexOutput("{\\f1\\'7E}");
2932 if (start
) TexOutput("{\\f4\\'4A}");
2935 if (start
) TexOutput("{\\f4\\'4C}");
2938 if (start
) TexOutput("|");
2941 // Negated relation symbols
2943 if (start
) TexOutput("{\\f1\\'B9}");
2946 if (start
) TexOutput("{\\f1\\'CF}");
2949 if (start
) TexOutput("{\\f1\\'CB}");
2954 if (start
) TexOutput("{\\f1\\'AC}");
2957 if (start
) TexOutput("{\\f1\\'DC}");
2960 if (start
) TexOutput("{\\f1\\'AE}");
2963 if (start
) TexOutput("{\\f1\\'DE}");
2965 case ltLEFTRIGHTARROW
:
2966 if (start
) TexOutput("{\\f1\\'AB}");
2968 case ltLEFTRIGHTARROW2
:
2969 if (start
) TexOutput("{\\f1\\'DB}");
2972 if (start
) TexOutput("{\\f1\\'AD}");
2975 if (start
) TexOutput("{\\f1\\'DD}");
2978 if (start
) TexOutput("{\\f1\\'AF}");
2981 if (start
) TexOutput("{\\f1\\'DF}");
2984 // Miscellaneous symbols
2986 if (start
) TexOutput("{\\f1\\'CO}");
2989 if (start
) TexOutput("{\\f1\\'C3}");
2992 if (start
) TexOutput("{\\f1\\'C2}");
2995 if (start
) TexOutput("{\\f1\\'C1}");
2998 if (start
) TexOutput("{\\f1\\'C6}");
3001 if (start
) TexOutput("{\\f1\\'D1}");
3004 if (start
) TexOutput("{\\f1\\'D6}");
3007 if (start
) TexOutput("{\\f1\\'B6}");
3010 if (start
) TexOutput("{\\f1\\'5E}");
3013 if (start
) TexOutput("{\\f1\\'22}");
3016 if (start
) TexOutput("{\\f1\\'24}");
3019 if (start
) TexOutput("{\\f1\\'D8}");
3022 if (start
) TexOutput("{\\f1\\'23}");
3025 if (start
) TexOutput("{\\f1\\'D0}");
3028 if (start
) TexOutput("{\\f5\\'73}");
3031 if (start
) TexOutput("{\\f5\\'A8}");
3034 if (start
) TexOutput("{\\f5\\'A9}");
3037 if (start
) TexOutput("{\\f5\\'AA}");
3040 if (start
) TexOutput("{\\f5\\'AB}");
3043 if (start
) TexOutput("{\\f1\\'A5}");
3046 if (start
) TexOutput("{\\f0\\'A9}");
3049 if (start
) TexOutput("{\\f0\\'AE}");
3052 if (start
) TexOutput("{\\f1\\'B1}");
3055 if (start
) TexOutput("{\\f1\\'B1}");
3058 if (start
) TexOutput("{\\f1\\'B4}");
3061 if (start
) TexOutput("{\\f1\\'B8}");
3064 if (start
) TexOutput("{\\f1\\'D7}");
3067 if (start
) TexOutput("{\\f1\\'2A}");
3070 if (start
) TexOutput("{\\f5\\'AB}");
3073 if (start
) TexOutput("{\\f1\\'C7}");
3076 if (start
) TexOutput("{\\f1\\'C8}");
3079 if (start
) TexOutput("{\\f1\\'DA}");
3082 if (start
) TexOutput("{\\f1\\'D9}");
3085 if (start
) TexOutput("{\\f1\\'B0}");
3088 if (start
) TexOutput("{\\f1\\'B7}");
3091 if (start
) TexOutput("{\\f1\\'E0}");
3094 if (start
) TexOutput("{\\f1\\'C6}");
3097 if (start
) TexOutput("{\\f1\\'E0}");
3099 case ltBIGTRIANGLEDOWN
:
3100 if (start
) TexOutput("{\\f1\\'D1}");
3103 if (start
) TexOutput("{\\f1\\'C5}");
3106 if (start
) TexOutput("{\\f1\\'C4}");
3109 if (start
) TexOutput("{\\'DF}");
3113 if (start
) inFigure
= TRUE
;
3114 else inFigure
= FALSE
;
3119 if (start
) inTable
= TRUE
;
3120 else inTable
= FALSE
;
3125 DefaultOnMacro(macroId
, no_args
, start
);
3131 // Called on start/end of argument examination
3132 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3139 case ltCHAPTERHEADING
:
3142 case ltSECTIONHEADING
:
3144 case ltSUBSECTIONSTAR
:
3145 case ltSUBSUBSECTION
:
3146 case ltSUBSUBSECTIONSTAR
:
3148 case ltMEMBERSECTION
:
3149 case ltFUNCTIONSECTION
:
3153 if (!start
&& (arg_no
== 1))
3154 currentSection
= GetArgChunk();
3160 if (start
&& (arg_no
== 1))
3161 TexOutput("\\pard\\li600\\fi-600{\\b ");
3163 if (!start
&& (arg_no
== 1))
3166 if (start
&& (arg_no
== 2))
3168 if (!suppressNameDecoration
) TexOutput("{\\b ");
3169 currentMember
= GetArgChunk();
3171 if (!start
&& (arg_no
== 2))
3173 if (!suppressNameDecoration
) TexOutput("}");
3176 if (start
&& (arg_no
== 3))
3178 if (!start
&& (arg_no
== 3))
3180 // TexOutput(")\\li0\\fi0");
3181 // TexOutput(")\\par\\pard\\li0\\fi0");
3182 // issuedNewParagraph = 1;
3184 WriteEnvironmentStyles();
3190 if (start
&& (arg_no
== 1))
3191 TexOutput("\\pard\\li260\\fi-260{\\b ");
3192 if (!start
&& (arg_no
== 1))
3195 if (start
&& (arg_no
== 2))
3197 if (!suppressNameDecoration
) TexOutput("({\\b ");
3198 currentMember
= GetArgChunk();
3200 if (!start
&& (arg_no
== 2))
3202 if (!suppressNameDecoration
) TexOutput("}");
3205 if (!start
&& (arg_no
== 3))
3207 TexOutput(")\\li0\\fi0");
3208 WriteEnvironmentStyles();
3214 if (start
&& (arg_no
== 1))
3215 TexOutput("\\pard\\li260\\fi-260");
3217 if (!start
&& (arg_no
== 1))
3220 if (start
&& (arg_no
== 2))
3222 if (!start
&& (arg_no
== 2))
3225 if (start
&& (arg_no
== 2))
3226 currentMember
= GetArgChunk();
3228 if (start
&& (arg_no
== 3))
3230 if (!start
&& (arg_no
== 3))
3232 TexOutput(")\\li0\\fi0");
3233 WriteEnvironmentStyles();
3239 if (start
&& (arg_no
== 1))
3241 if (!start
&& (arg_no
== 1))
3243 if (start
&& (arg_no
== 2))
3247 if (!start
&& (arg_no
== 2))
3255 if (start
&& (arg_no
== 1))
3257 if (!start
&& (arg_no
== 1))
3258 TexOutput("} "); // This is the difference from param - one space!
3259 if (start
&& (arg_no
== 2))
3263 if (!start
&& (arg_no
== 2))
3271 if (!start
&& (arg_no
== 1))
3274 if (start
&& (arg_no
== 2))
3275 currentMember
= GetArgChunk();
3283 char *secName
= NULL
;
3285 char *refName
= GetArgData();
3286 if (winHelp
|| !useWord
)
3290 TexRef
*texRef
= FindReference(refName
);
3293 sec
= texRef
->sectionNumber
;
3294 secName
= texRef
->sectionName
;
3304 fprintf(Chapters
, "{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
3316 if ((GetNoArgs() - arg_no
) == 1)
3319 TexOutput("{\\uldb ");
3323 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3329 // Remove green colour/underlining if specified
3330 if (!hotSpotUnderline
&& !hotSpotColour
)
3332 else if (!hotSpotColour
)
3335 else TexOutput("}");
3338 else // If a linear document, must resolve the references ourselves
3340 if ((GetNoArgs() - arg_no
) == 1)
3342 // In a linear document we display the anchor text in italic plus
3350 helpRefText
= GetArgChunk();
3354 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3356 if (macroId
!= ltHELPREFN
)
3358 char *refName
= GetArgData();
3359 TexRef
*texRef
= NULL
;
3361 texRef
= FindReference(refName
);
3364 if (texRef
|| !ignoreBadRefs
)
3368 if (texRef
|| !ignoreBadRefs
)
3373 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3375 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3379 // Only print section name if we're not in Word mode,
3380 // so can't do page references
3383 TexOutput(texRef
->sectionName
) ; TexOutput(" "); TexOutput(texRef
->sectionNumber
);
3389 sprintf(buf
, "Warning: unresolved reference '%s'", refName
);
3395 else TexOutput("??");
3399 if (texRef
|| !ignoreBadRefs
)
3414 else if (arg_no
== 2)
3419 TexOutput(" ({\\f3 ");
3434 if ((GetNoArgs() - arg_no
) == 1)
3437 TexOutput("{\\ul ");
3441 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3447 // Remove green colour/underlining if specified
3448 if (!hotSpotUnderline
&& !hotSpotColour
)
3450 else if (!hotSpotColour
)
3453 else TexOutput("}");
3456 else // A linear document...
3458 if ((GetNoArgs() - arg_no
) == 1)
3460 // In a linear document we just display the anchor text in italic
3471 case ltADDCONTENTSLINE
:
3473 if (start
&& !winHelp
)
3476 contentsLineSection
= copystring(GetArgData());
3477 else if (arg_no
== 3)
3478 contentsLineValue
= copystring(GetArgData());
3493 static int imageWidth
= 0;
3494 static int imageHeight
= 0;
3496 if (start
&& (arg_no
== 1))
3498 char *imageDimensions
= copystring(GetArgData());
3500 strcpy(buf1
, imageDimensions
);
3501 char *tok1
= strtok(buf1
, ";:");
3502 char *tok2
= strtok(NULL
, ";:");
3503 // Convert points to TWIPS (1 twip = 1/20th of point)
3504 imageWidth
= (int)(20*(tok1
? ParseUnitArgument(tok1
) : 0));
3505 imageHeight
= (int)(20*(tok2
? ParseUnitArgument(tok2
) : 0));
3506 if (imageDimensions
) // glt
3507 delete [] imageDimensions
;
3510 else if (start
&& (arg_no
== 2 ))
3512 char *filename
= copystring(GetArgData());
3514 if ((winHelp
|| (strcmp(bitmapMethod
, "includepicture") == 0) || (strcmp(bitmapMethod
, "import") == 0)) && useWord
)
3516 if (f
== "") // Try for a .shg (segmented hypergraphics file)
3518 strcpy(buf
, filename
);
3519 StripExtension(buf
);
3520 strcat(buf
, ".shg");
3521 f
= TexPathList
.FindValidPath(buf
);
3523 if (f
== "") // Try for a .bmp
3525 strcpy(buf
, filename
);
3526 StripExtension(buf
);
3527 strcat(buf
, ".bmp");
3528 f
= TexPathList
.FindValidPath(buf
);
3530 if (f
== "") // Try for a metafile instead
3532 strcpy(buf
, filename
);
3533 StripExtension(buf
);
3534 strcat(buf
, ".wmf");
3535 f
= TexPathList
.FindValidPath(buf
);
3541 if (bitmapTransparency
&& (winHelpVersion
> 3))
3542 TexOutput("\\{bmct ");
3544 TexOutput("\\{bmc ");
3545 wxString str
= wxFileNameFromPath(f
);
3546 TexOutput((char*) (const char*) str
);
3551 // Microsoft Word method
3552 if (strcmp(bitmapMethod
, "import") == 0)
3553 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3555 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3557 // Full path appears not to be valid!
3558 wxString str
= wxFileNameFromPath(f
);
3559 TexOutput((char*)(const char*) str
);
3561 int len = strlen(f);
3562 char smallBuf[2]; smallBuf[1] = 0;
3563 for (int i = 0; i < len; i++)
3566 TexOutput(smallBuf);
3567 if (smallBuf[0] == '\\')
3568 TexOutput(smallBuf);
3571 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3576 TexOutput("[No BMP or WMF for image file ");
3577 TexOutput(filename
);
3579 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3582 if (filename
) // glt
3587 if (f
== "") // Try for a .bmp
3589 strcpy(buf
, filename
);
3590 StripExtension(buf
);
3591 strcat(buf
, ".bmp");
3592 f
= TexPathList
.FindValidPath(buf
);
3596 FILE *fd
= fopen(f
, "rb");
3597 if (OutputBitmapHeader(fd
, winHelp
))
3598 OutputBitmapData(fd
);
3601 sprintf(buf
, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f
);
3606 else // Try for a metafile instead
3609 strcpy(buf
, filename
);
3610 StripExtension(buf
);
3611 strcat(buf
, ".wmf");
3612 f
= TexPathList
.FindValidPath(buf
);
3615 // HFILE handle = _lopen(f, READ);
3616 FILE *fd
= fopen(f
, "rb");
3617 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3619 OutputMetafileData(fd
);
3623 sprintf(buf
, "Could not read metafile %s. Perhaps it's not a placeable metafile?", (const char*)f
);
3631 TexOutput("[No BMP or WMF for image file ");
3632 TexOutput(filename
);
3634 sprintf(buf
, "Warning: could not find a BMP or WMF equivalent for %s.", filename
);
3648 case ltSUPERTABULAR
:
3654 currentRowNumber
= 0;
3657 tableVerticalLineLeft
= FALSE
;
3658 tableVerticalLineRight
= FALSE
;
3659 int currentWidth
= 0;
3661 char *alignString
= copystring(GetArgData());
3662 ParseTableArgument(alignString
);
3664 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3665 TexOutput("\\trowd\\trgaph108");
3667 // Write the first row formatting for compatibility
3668 // with standard Latex
3669 if (compatibilityMode
)
3671 for (int i
= 0; i
< noColumns
; i
++)
3673 currentWidth
+= TableData
[i
].width
;
3674 sprintf(buf
, "\\cellx%d", currentWidth
);
3677 TexOutput("\\pard\\intbl\n");
3679 delete[] alignString
;
3684 else if (arg_no
== 2 && !start
)
3686 TexOutput("\\pard\n");
3687 WriteEnvironmentStyles();
3698 TexOutput("\\li360\n");
3700 PushEnvironmentStyle("\\li360");
3705 PopEnvironmentStyle();
3706 OnMacro(ltPAR
, 0, TRUE
);
3707 OnMacro(ltPAR
, 0, FALSE
);
3715 TexOutput("\\li360\n");
3716 PushEnvironmentStyle("\\li360");
3720 PopEnvironmentStyle();
3721 OnMacro(ltPAR
, 0, TRUE
);
3722 OnMacro(ltPAR
, 0, FALSE
);
3734 sprintf(buf
, "\\box\\trgaph108%s\n", ((macroId
== ltNORMALBOXD
) ? "\\brdrdb" : "\\brdrs"));
3736 PushEnvironmentStyle(buf
);
3740 PopEnvironmentStyle();
3741 OnMacro(ltPAR
, 0, TRUE
);
3742 OnMacro(ltPAR
, 0, FALSE
);
3746 case ltHELPFONTSIZE
:
3750 char *data
= GetArgData();
3751 if (strcmp(data
, "10") == 0)
3753 else if (strcmp(data
, "11") == 0)
3755 else if (strcmp(data
, "12") == 0)
3757 sprintf(buf
, "\\fs%d\n", normalFont
*2);
3764 case ltHELPFONTFAMILY
:
3768 char *data
= GetArgData();
3769 if (strcmp(data
, "Swiss") == 0)
3770 TexOutput("\\f2\n");
3771 else if (strcmp(data
, "Symbol") == 0)
3772 TexOutput("\\f1\n");
3773 else if (strcmp(data
, "Times") == 0)
3774 TexOutput("\\f0\n");
3782 if (start
&& arg_no
== 1)
3784 char *data
= GetArgData();
3785 ParIndent
= ParseUnitArgument(data
);
3786 if (ParIndent
== 0 || forbidParindent
== 0)
3788 sprintf(buf
, "\\fi%d\n", ParIndent
*20);
3797 if (start
&& IsArgOptional())
3799 descriptionItemArg
= GetArgChunk();
3805 case ltTWOCOLITEMRULED
:
3812 TexOutput("\\tab ");
3819 if (macroId
== ltTWOCOLITEMRULED
)
3820 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3821 TexOutput("\\par\\pard\n");
3822 issuedNewParagraph
= 1;
3823 WriteEnvironmentStyles();
3835 case ltACCENT_GRAVE
:
3839 char *val
= GetArgData();
3882 case ltACCENT_ACUTE
:
3886 char *val
= GetArgData();
3935 case ltACCENT_CARET
:
3939 char *val
= GetArgData();
3982 case ltACCENT_TILDE
:
3986 char *val
= GetArgData();
4020 case ltACCENT_UMLAUT
:
4024 char *val
= GetArgData();
4080 char *val
= GetArgData();
4099 case ltACCENT_CADILLA
:
4103 char *val
= GetArgData();
4124 static char *helpTopic
= NULL
;
4125 static FILE *savedOutput
= NULL
;
4132 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4135 sprintf(footBuf
, "(%d)", footnoteCount
);
4137 TexOutput(" {\\ul ");
4140 helpTopic
= FindTopicName(NULL
);
4143 // Remove green colour/underlining if specified
4144 if (!hotSpotUnderline
&& !hotSpotColour
)
4146 else if (!hotSpotColour
)
4149 TexOutput(helpTopic
);
4152 fprintf(Popups
, "\\page\n");
4153 // fprintf(Popups, "\n${\\footnote }"); // No title
4154 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4155 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4156 savedOutput
= CurrentOutput1
;
4157 SetCurrentOutput(Popups
);
4161 SetCurrentOutput(savedOutput
);
4171 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4175 TexOutput("}}", TRUE
);
4181 case ltFOOTNOTEPOPUP
:
4183 static char *helpTopic
= NULL
;
4184 static FILE *savedOutput
= NULL
;
4191 TexOutput("{\\ul ");
4193 else TexOutput("}");
4196 else if (arg_no
== 2)
4200 helpTopic
= FindTopicName(NULL
);
4203 // Remove green colour/underlining if specified
4204 if (!hotSpotUnderline
&& !hotSpotColour
)
4206 else if (!hotSpotColour
)
4209 TexOutput(helpTopic
);
4212 fprintf(Popups
, "\\page\n");
4213 // fprintf(Popups, "\n${\\footnote }"); // No title
4214 fprintf(Popups
, "\n#{\\footnote %s}\n", helpTopic
);
4215 fprintf(Popups
, "+{\\footnote %s}\n", GetBrowseString());
4216 savedOutput
= CurrentOutput1
;
4217 SetCurrentOutput(Popups
);
4221 SetCurrentOutput(savedOutput
);
4232 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE
);
4236 TexOutput("}}", TRUE
);
4244 if (start
&& (arg_no
== 1))
4257 if (winHelp
) return FALSE
;
4263 LeftHeaderEven
= GetArgChunk();
4264 if (strlen(GetArgData(LeftHeaderEven
)) == 0)
4265 LeftHeaderEven
= NULL
;
4268 CentreHeaderEven
= GetArgChunk();
4269 if (strlen(GetArgData(CentreHeaderEven
)) == 0)
4270 CentreHeaderEven
= NULL
;
4273 RightHeaderEven
= GetArgChunk();
4274 if (strlen(GetArgData(RightHeaderEven
)) == 0)
4275 RightHeaderEven
= NULL
;
4278 LeftHeaderOdd
= GetArgChunk();
4279 if (strlen(GetArgData(LeftHeaderOdd
)) == 0)
4280 LeftHeaderOdd
= NULL
;
4283 CentreHeaderOdd
= GetArgChunk();
4284 if (strlen(GetArgData(CentreHeaderOdd
)) == 0)
4285 CentreHeaderOdd
= NULL
;
4288 RightHeaderOdd
= GetArgChunk();
4289 if (strlen(GetArgData(RightHeaderOdd
)) == 0)
4290 RightHeaderOdd
= NULL
;
4291 OutputRTFHeaderCommands();
4307 if (winHelp
) return FALSE
;
4313 LeftFooterEven
= GetArgChunk();
4314 if (strlen(GetArgData(LeftFooterEven
)) == 0)
4315 LeftFooterEven
= NULL
;
4318 CentreFooterEven
= GetArgChunk();
4319 if (strlen(GetArgData(CentreFooterEven
)) == 0)
4320 CentreFooterEven
= NULL
;
4323 RightFooterEven
= GetArgChunk();
4324 if (strlen(GetArgData(RightFooterEven
)) == 0)
4325 RightFooterEven
= NULL
;
4328 LeftFooterOdd
= GetArgChunk();
4329 if (strlen(GetArgData(LeftFooterOdd
)) == 0)
4330 LeftFooterOdd
= NULL
;
4333 CentreFooterOdd
= GetArgChunk();
4334 if (strlen(GetArgData(CentreFooterOdd
)) == 0)
4335 CentreFooterOdd
= NULL
;
4338 RightFooterOdd
= GetArgChunk();
4339 if (strlen(GetArgData(RightFooterOdd
)) == 0)
4340 RightFooterOdd
= NULL
;
4341 OutputRTFFooterCommands();
4352 if (winHelp
) return FALSE
;
4353 // Fake a SetHeader command
4356 LeftHeaderOdd
= NULL
;
4357 CentreHeaderOdd
= NULL
;
4358 RightHeaderOdd
= NULL
;
4359 LeftHeaderEven
= NULL
;
4360 CentreHeaderEven
= NULL
;
4361 RightHeaderEven
= NULL
;
4362 OnInform("Consider using setheader/setfooter rather than markright.");
4364 RTFOnArgument(ltSETHEADER
, 4, start
);
4366 OutputRTFHeaderCommands();
4372 if (winHelp
) return FALSE
;
4373 // Fake a SetHeader command
4380 LeftHeaderOdd
= NULL
;
4381 CentreHeaderOdd
= NULL
;
4382 RightHeaderOdd
= NULL
;
4383 LeftHeaderEven
= NULL
;
4384 CentreHeaderEven
= NULL
;
4385 RightHeaderEven
= NULL
;
4386 OnInform("Consider using setheader/setfooter rather than markboth.");
4388 return RTFOnArgument(ltSETHEADER
, 1, start
);
4393 RTFOnArgument(ltSETHEADER
, 4, start
);
4395 OutputRTFHeaderCommands();
4402 case ltPAGENUMBERING
:
4409 if (winHelp
) return FALSE
;
4412 TexOutput("\\pgnrestart");
4413 char *data
= GetArgData();
4414 if (currentNumberStyle
) delete[] currentNumberStyle
;
4415 currentNumberStyle
= copystring(data
);
4416 OutputNumberStyle(currentNumberStyle
);
4425 if (winHelp
) return FALSE
;
4434 char *val
= GetArgData();
4435 currentItemSep
= ParseUnitArgument(val
);
4440 case ltEVENSIDEMARGIN
:
4445 case ltODDSIDEMARGIN
:
4449 char *val
= GetArgData();
4450 int twips
= (int)(20*ParseUnitArgument(val
));
4451 // Add an inch since in LaTeX it's specified minus an inch
4453 CurrentLeftMarginOdd
= twips
;
4454 sprintf(buf
, "\\margl%d\n", twips
);
4457 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4461 case ltMARGINPARWIDTH
:
4465 char *val
= GetArgData();
4466 int twips
= (int)(20*ParseUnitArgument(val
));
4467 CurrentMarginParWidth
= twips
;
4471 case ltMARGINPARSEP
:
4475 char *val
= GetArgData();
4476 int twips
= (int)(20*ParseUnitArgument(val
));
4477 CurrentMarginParSep
= twips
;
4478 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4486 char *val
= GetArgData();
4487 int twips
= (int)(20*ParseUnitArgument(val
));
4488 CurrentTextWidth
= twips
;
4490 // Need to set an implicit right margin
4491 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4492 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4493 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4494 sprintf(buf
, "\\margr%d\n", CurrentRightMarginOdd
);
4500 case ltMARGINPARODD
:
4506 TexOutput("\\box\n");
4507 PushEnvironmentStyle("\\box");
4511 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4520 TexOutput("\\par\\pard\n");
4521 PopEnvironmentStyle();
4522 WriteEnvironmentStyles();
4525 TexOutput("\\par\\pard\n");
4526 issuedNewParagraph
= 1;
4530 case ltMARGINPAREVEN
:
4536 TexOutput("\\box\n");
4537 PushEnvironmentStyle("\\box");
4543 // Have to calculate what the margins are changed to in WfW margin
4544 // mirror mode, on an even (left-hand) page.
4545 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4546 - CurrentTextWidth
+ GutterWidth
;
4547 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", x
, CurrentMarginParWidth
);
4552 sprintf(buf
, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX
, CurrentMarginParWidth
);
4562 TexOutput("\\par\\pard\n");
4563 PopEnvironmentStyle();
4564 WriteEnvironmentStyles();
4567 issuedNewParagraph
= 1;
4568 TexOutput("\\par\\pard\n");
4572 case ltTWOCOLWIDTHA
:
4576 char *val
= GetArgData();
4577 int twips
= (int)(20*ParseUnitArgument(val
));
4578 TwoColWidthA
= twips
;
4583 case ltTWOCOLWIDTHB
:
4587 char *val
= GetArgData();
4588 int twips
= (int)(20*ParseUnitArgument(val
));
4589 TwoColWidthB
= twips
;
4599 int currentWidth
= 0;
4601 if (!compatibilityMode
|| (currentRowNumber
> 0))
4603 TexOutput("\\pard\\intbl");
4605 if (macroId
== ltRULEDROW
)
4607 for (int i
= 0; i
< noColumns
; i
++)
4609 currentWidth
+= TableData
[i
].width
;
4612 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4614 else if (ruleTop
> 1)
4616 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4618 if (ruleBottom
== 1)
4620 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4622 else if (ruleBottom
> 1)
4624 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4627 if (TableData
[i
].rightBorder
)
4628 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4630 if (TableData
[i
].leftBorder
)
4631 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4633 sprintf(buf
, "\\cellx%d", currentWidth
);
4636 TexOutput("\\pard\\intbl\n");
4640 currentRowNumber
++;
4645 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4646 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4652 static int noMultiColumns
= 0;
4659 noMultiColumns
= atoi(GetArgData());
4677 for (int i
= 1; i
< noMultiColumns
; i
++)
4678 TexOutput("\\cell");
4685 if (start
&& (arg_no
== 1))
4688 // TexOutput("\\fi0\n");
4690 wxNode
*node
= itemizeStack
.First();
4692 oldIndent
= ((ItemizeStruc
*)node
->Data())->indentation
;
4694 int indentValue
= 20*ParseUnitArgument(GetArgData());
4695 int indentSize
= indentValue
+ oldIndent
;
4697 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4698 itemizeStack
.Insert(struc
);
4700 sprintf(buf
, "\\tx%d\\li%d ", indentSize
, indentSize
);
4701 PushEnvironmentStyle(buf
);
4705 if (!start
&& (arg_no
== 2))
4707 PopEnvironmentStyle();
4708 if (itemizeStack
.First())
4710 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
4712 delete itemizeStack
.First();
4714 if (itemizeStack
.Number() == 0)
4716 TexOutput("\\par\\pard\n");
4717 issuedNewParagraph
= 1;
4718 WriteEnvironmentStyles();
4728 if (start && (arg_no == 1))
4731 wxNode *node = itemizeStack.First();
4733 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4735 int boxWidth = 20*ParseUnitArgument(GetArgData());
4737 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4738 int indentSize = indentValue + oldIndent;
4739 int indentSizeRight = indentSize + boxWidth;
4741 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4742 itemizeStack.Insert(struc);
4744 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4745 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4746 PushEnvironmentStyle(buf);
4750 if (!start && (arg_no == 2))
4752 PopEnvironmentStyle();
4753 if (itemizeStack.First())
4755 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4757 delete itemizeStack.First();
4759 if (itemizeStack.Number() == 0)
4761 TexOutput("\\par\\pard\n");
4762 issuedNewParagraph = 1;
4763 WriteEnvironmentStyles();
4770 case ltDOCUMENTSTYLE
:
4772 DefaultOnArgument(macroId
, arg_no
, start
);
4773 if (!start
&& !IsArgOptional())
4775 if (MinorDocumentStyleString
)
4777 if (StringMatch("twoside", MinorDocumentStyleString
))
4778 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4779 TexOutput("\\margmirror\\facingp\\sbkodd");
4780 if (StringMatch("twocolumn", MinorDocumentStyleString
))
4781 TexOutput("\\cols2");
4787 case ltSETHOTSPOTCOLOUR
:
4788 case ltSETHOTSPOTCOLOR
:
4792 char *text
= GetArgData();
4793 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4794 hotSpotColour
= TRUE
;
4796 hotSpotColour
= FALSE
;
4800 case ltSETTRANSPARENCY
:
4804 char *text
= GetArgData();
4805 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4806 bitmapTransparency
= TRUE
;
4808 bitmapTransparency
= FALSE
;
4812 case ltSETHOTSPOTUNDERLINE
:
4816 char *text
= GetArgData();
4817 if (strcmp(text
, "yes") == 0 || strcmp(text
, "on") == 0 || strcmp(text
, "ok") == 0)
4818 hotSpotUnderline
= TRUE
;
4820 hotSpotUnderline
= FALSE
;
4826 if (arg_no
== 1 && start
)
4828 char *citeKey
= GetArgData();
4829 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4832 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4833 sprintf(buf
, "[%d]", citeCount
);
4834 ref
->sectionNumber
= copystring(buf
);
4837 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4838 sprintf(buf
, "{\\b [%d]} ", citeCount
);
4843 if (arg_no
== 2 && !start
)
4844 TexOutput("\\par\\pard\\par\n\n");
4848 case ltTHEBIBLIOGRAPHY
:
4850 if (start
&& (arg_no
== 1))
4854 SetCurrentOutputs(Contents
, Chapters
);
4858 fprintf(Chapters
, "\\sect\\pgncont\\titlepg\n");
4860 // If a non-custom page style, we generate the header now.
4861 if (PageStyle
&& (strcmp(PageStyle
, "plain") == 0 ||
4862 strcmp(PageStyle
, "empty") == 0 ||
4863 strcmp(PageStyle
, "headings") == 0))
4865 OutputRTFHeaderCommands();
4866 OutputRTFFooterCommands();
4869 // Need to reset the current numbering style, or RTF forgets it.
4870 OutputNumberStyle(currentNumberStyle
);
4871 SetCurrentOutput(Contents
);
4874 fprintf(Chapters
, "\\page\n");
4877 fprintf(Contents
, "\n{\\uldb %s}", ReferencesNameString
);
4879 fprintf(Contents
, "\\par\n\\pard{\\b %s}", ReferencesNameString
);
4881 startedSections
= TRUE
;
4884 fprintf(Chapters
, "\n${\\footnote %s}", ReferencesNameString
);
4886 char *topicName
= "bibliography";
4889 fprintf(Contents
, "{\\v %s}\\par\\pard\n", topicName
);
4891 fprintf(Contents
, "\\par\\par\\pard\n");
4895 fprintf(Chapters
, "\n#{\\footnote %s}\n", topicName
);
4896 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
4897 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ReferencesNameString
);
4898 GenerateKeywordsForTopic(topicName
);
4901 fprintf(Chapters
, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4902 wxFileNameFromPath(FileRoot
), "Contents");
4906 SetCurrentOutput(Chapters
);
4907 char *styleCommand
= "";
4908 if (!winHelp
&& useHeadingStyles
)
4909 styleCommand
= "\\s1";
4910 fprintf(Chapters
, "\\pard{%s", (winHelp
? "\\keepn\\sa140\\sb140" : styleCommand
));
4911 WriteHeadingStyle(Chapters
, 1); fprintf(Chapters
, " References\\par\\pard}\n");
4921 * In Windows help, all keywords should be at the start of the
4922 * topic, but Latex \index commands can be anywhere in the text.
4923 * So we're going to have to build up lists of keywords for a topic,
4924 * and insert them on the second pass.
4926 * In linear RTF, we can embed the index entry now.
4931 // char *entry = GetArgData();
4933 OutputChunkToString(GetArgChunk(), buf
);
4938 AddKeyWordForTopic(CurrentTopic
, buf
);
4941 else GenerateIndexEntry(buf
);
4955 char *name
= GetArgData();
4956 int pos
= FindColourPosition(name
);
4959 sprintf(buf
, "{%s%d ", ((macroId
== ltFCOL
) ? "\\cf" : "\\cb"), pos
);
4964 sprintf(buf
, "Could not find colour name %s", name
);
4980 if (arg_no
== 2) TexOutput("}");
4987 if (start
&& !winHelp
&& useWord
)
4989 char *s
= GetArgData();
4990 // Only insert a bookmark here if it's not just been inserted
4991 // in a section heading.
4992 if ( !CurrentTopic
|| !(strcmp(CurrentTopic
, s
) == 0) )
4994 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4995 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4996 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
5000 fprintf(Chapters
, "{\\bkmkstart %s}{\\bkmkend %s}", s
,s
);
5008 if (start
&& useWord
&& !winHelp
)
5010 char *s
= GetArgData();
5011 fprintf(Chapters
, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
5020 inPopRefSection
= TRUE
;
5022 inPopRefSection
= FALSE
;
5025 case ltINSERTATLEVEL
:
5027 // This macro allows you to insert text at a different level
5028 // from the current level, e.g. into the Sections from within a subsubsection.
5029 if (!winHelp
& useWord
)
5031 static int currentLevelNo
= 1;
5032 static FILE* oldLevelFile
= Chapters
;
5039 oldLevelFile
= CurrentOutput1
;
5041 char *str
= GetArgData();
5042 currentLevelNo
= atoi(str
);
5044 // TODO: cope with article style (no chapters)
5045 switch (currentLevelNo
)
5049 outputFile
= Chapters
;
5054 outputFile
= Sections
;
5059 outputFile
= Subsections
;
5064 outputFile
= Subsubsections
;
5074 CurrentOutput1
= outputFile
;
5092 CurrentOutput1
= oldLevelFile
;
5100 return DefaultOnArgument(macroId
, arg_no
, start
);
5114 forbidParindent
= 0;
5115 contentsLineSection
= NULL
;
5116 contentsLineValue
= NULL
;
5117 descriptionItemArg
= NULL
;
5122 tableVerticalLineLeft
= FALSE
;
5123 tableVerticalLineRight
= FALSE
;
5125 startedSections
= FALSE
;
5129 if (InputFile
&& OutputFile
)
5131 // Do some RTF-specific transformations on all the strings,
5133 Text2RTF(GetTopLevelChunk());
5135 Contents
= fopen(TmpContentsName
, "w");
5136 Chapters
= fopen("chapters.rtf", "w");
5139 Sections
= fopen("sections.rtf", "w");
5140 Subsections
= fopen("subsections.rtf", "w");
5141 Subsubsections
= fopen("subsubsections.rtf", "w");
5142 Popups
= fopen("popups.rtf", "w");
5143 if (winHelpContents
)
5145 WinHelpContentsFile
= fopen(WinHelpContentsFileName
, "w");
5146 if (WinHelpContentsFile
)
5147 fprintf(WinHelpContentsFile
, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot
));
5150 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5152 OnError("Ouch! Could not open temporary file(s) for writing.");
5156 if (!Contents
|| !Chapters
)
5158 OnError("Ouch! Could not open temporary file(s) for writing.");
5164 fprintf(Chapters
, "\n#{\\footnote Contents}\n");
5165 fprintf(Chapters
, "${\\footnote Contents}\n");
5166 fprintf(Chapters
, "+{\\footnote %s}\n", GetBrowseString());
5167 fprintf(Chapters
, "K{\\footnote {K} %s}\n", ContentsNameString
);
5168 fprintf(Chapters
, "!{\\footnote DisableButton(\"Up\")}\n");
5172 fprintf(Chapters
, "\\titlepg\n");
5173 fprintf(Contents
, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5176 // In WinHelp, Contents title takes font of title.
5177 // In linear RTF, same as chapter headings.
5178 fprintf(Contents
, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5179 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5181 // By default, Swiss, 10 point.
5182 fprintf(Chapters
, "\\f2\\fs20\n");
5184 SetCurrentOutput(Chapters
);
5189 OnInform("Converting...");
5193 FILE *Header
= fopen("header.rtf", "w");
5196 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5199 WriteRTFHeader(Header
);
5200 fclose(Header
); Header
= NULL
;
5205 // fprintf(Contents, "\\page\n");
5206 fprintf(Chapters
, "\\page\n");
5207 fprintf(Sections
, "\\page\n");
5208 fprintf(Subsections
, "\\page\n");
5209 fprintf(Subsubsections
, "\\page\n\n");
5210 fprintf(Popups
, "\\page\n}\n");
5213 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5216 fclose(Contents
); Contents
= NULL
;
5217 fclose(Chapters
); Chapters
= NULL
;
5220 fclose(Sections
); Sections
= NULL
;
5221 fclose(Subsections
); Subsections
= NULL
;
5222 fclose(Subsubsections
); Subsubsections
= NULL
;
5223 fclose(Popups
); Popups
= NULL
;
5224 if (winHelpContents
)
5226 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5232 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5234 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5236 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5238 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5240 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile
);
5243 wxRemoveFile("tmp1.rtf");
5244 wxRemoveFile("tmp2.rtf");
5245 wxRemoveFile("tmp3.rtf");
5246 wxRemoveFile("tmp4.rtf");
5250 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5252 if (wxFileExists(OutputFile
))
5253 wxRemoveFile(OutputFile
);
5256 cwdStr
= wxGetWorkingDirectory();
5258 wxString outputDirStr
;
5259 outputDirStr
= wxPathOnly(OutputFile
);
5261 // Determine if the temp file and the output file are in the same directory,
5262 // and if they are, then just rename the temp file rather than copying
5263 // it, as this is much faster when working with large (multi-megabyte files)
5264 if ((wxStrcmp(outputDirStr
.c_str(),"") == 0) || // no path specified on output file
5265 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5267 wxRenameFile("tmp1.rtf", OutputFile
);
5271 wxCopyFile("tmp1.rtf", OutputFile
);
5275 wxRemoveFile("tmp1.rtf");
5278 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5280 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5282 wxCopyFile(TmpContentsName
, ContentsName
);
5283 wxRemoveFile(TmpContentsName
);
5286 wxRemoveFile("chapters.rtf");
5287 wxRemoveFile("header.rtf");
5291 wxRemoveFile("sections.rtf");
5292 wxRemoveFile("subsections.rtf");
5293 wxRemoveFile("subsubsections.rtf");
5294 wxRemoveFile("popups.rtf");
5296 if (winHelp
&& generateHPJ
)
5297 WriteHPJ(OutputFile
);