1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to Word RTF/WinHelp RTF
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
36 #if !WXWIN_COMPATIBILITY_2_4
37 static inline wxChar
* copystring(const wxChar
* s
)
38 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
42 static int indentLevel
= 0;
43 static int forbidParindent
= 0; // if > 0, no parindent (e.g. in center environment)
44 int forbidResetPar
= 0; // If > 0, don't reset memory of having output a new par
46 static wxChar
*contentsLineSection
= NULL
;
47 static wxChar
*contentsLineValue
= NULL
;
48 static TexChunk
*descriptionItemArg
= NULL
;
49 static wxStringList environmentStack
; // Stack of paragraph styles we need to remember
50 static int footnoteCount
= 0;
51 static int citeCount
= 1;
53 extern bool startedSections
;
54 extern FILE *Contents
;
55 extern FILE *Chapters
;
57 extern FILE *WinHelpContentsFile
;
58 extern wxChar
*RTFCharset
;
59 // This is defined in the Tex2Any library and isn't in use after parsing
60 extern wxChar
*BigBuffer
;
62 extern wxHashTable TexReferences
;
64 // Are we in verbatim mode? If so, format differently.
65 static bool inVerbatim
= false;
67 // We're in a series of PopRef topics, so don't output section headings
68 bool inPopRefSection
= false;
71 static bool hotSpotColour
= true;
72 static bool hotSpotUnderline
= true;
74 // Transparency (WHITE = transparent)
75 static bool bitmapTransparency
= true;
77 // Linear RTF requires us to set the style per section.
78 static wxChar
*currentNumberStyle
= NULL
;
79 static int currentItemSep
= 8;
80 static int CurrentTextWidth
= 8640; // Say, six inches
81 static int CurrentLeftMarginOdd
= 400;
82 static int CurrentLeftMarginEven
= 1440;
83 static int CurrentRightMarginOdd
= 1440;
84 static int CurrentRightMarginEven
= 400;
85 static int CurrentMarginParWidth
= 2000;
86 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
87 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
88 static int GutterWidth
= 2300;
90 // Two-column table dimensions, in twips
91 static int TwoColWidthA
= 1500;
92 static int TwoColWidthB
= 3000;
94 const int PageWidth
= 12242; // 8.25 inches wide for A4
96 // Remember the anchor in a helpref
97 static TexChunk
*helpRefText
= NULL
;
100 * Flag to say we've just issued a \par\pard command, so don't
101 * repeat this unnecessarily.
105 int issuedNewParagraph
= 0;
107 // Need to know whether we're in a table or figure for benefit
108 // of listoffigures/listoftables
109 static bool inFigure
= false;
110 static bool inTable
= false;
116 static wxChar
*CurrentChapterName
= NULL
;
117 static wxChar
*CurrentSectionName
= NULL
;
118 static wxChar
*CurrentSubsectionName
= NULL
;
119 static wxChar
*CurrentTopic
= NULL
;
121 static bool InPopups()
123 if (CurrentChapterName
&& (wxStrcmp(CurrentChapterName
, _T("popups")) == 0))
125 if (CurrentSectionName
&& (wxStrcmp(CurrentSectionName
, _T("popups")) == 0))
130 static void SetCurrentTopic(wxChar
*s
)
132 if (CurrentTopic
) delete[] CurrentTopic
;
133 CurrentTopic
= copystring(s
);
136 void SetCurrentChapterName(wxChar
*s
)
138 if (CurrentChapterName
) delete[] CurrentChapterName
;
139 CurrentChapterName
= copystring(s
);
142 void SetCurrentSectionName(wxChar
*s
)
144 if (CurrentSectionName
) delete[] CurrentSectionName
;
145 CurrentSectionName
= copystring(s
);
148 void SetCurrentSubsectionName(wxChar
*s
)
150 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
151 CurrentSubsectionName
= copystring(s
);
155 // Indicate that a parent topic at level 'level' has children.
156 // Level 1 is a chapter, 2 is a section, etc.
157 void NotifyParentHasChildren(int parentLevel
)
159 wxChar
*parentTopic
= NULL
;
164 parentTopic
= CurrentChapterName
;
169 parentTopic
= CurrentSectionName
;
174 parentTopic
= CurrentSubsectionName
;
184 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
187 texTopic
= new TexTopic
;
188 TopicTable
.Put(parentTopic
, texTopic
);
190 texTopic
->hasChildren
= true;
194 // Have to keep a count of what levels are books, what are pages,
195 // in order to correct for a Win95 bug which means that if you
196 // have a book at level n, and then a page at level n, the page
197 // ends up on level n + 1.
199 bool ContentsLevels
[5];
201 // Reset below this level (starts from 1)
202 void ResetContentsLevels(int l
)
205 for (i
= l
; i
< 5; i
++)
206 ContentsLevels
[i
] = false;
208 // There are always books on the top level
209 ContentsLevels
[0] = true;
212 // Output a WinHelp section as a keyword, substituting
214 void OutputSectionKeyword(FILE *fd
)
216 OutputCurrentSectionToString(wxTex2RTFBuffer
);
219 for (i
= 0; i
< wxStrlen(wxTex2RTFBuffer
); i
++)
220 if (wxTex2RTFBuffer
[i
] == ':')
221 wxTex2RTFBuffer
[i
] = ' ';
222 // Don't write to index if there's some RTF in the string
223 else if ( wxTex2RTFBuffer
[i
] == '{' )
226 wxFprintf(fd
, _T("K{\\footnote {K} "));
227 wxFprintf(fd
, _T("%s"), wxTex2RTFBuffer
);
229 wxFprintf(fd
, _T("}\n"));
232 // Write a line for the .cnt file, if we're doing this.
233 void WriteWinHelpContentsFileLine(wxChar
*topicName
, wxChar
*xitle
, int level
)
235 // First, convert any RTF characters to ASCII
239 // assuming iso-8859-1 here even in Unicode build (FIXME?)
240 while ( (xitle
[s
]!=0)&&(d
<255) )
242 wxChar ch
=wxChar(xitle
[s
]&0xff);
244 wxChar ch1
=wxChar(xitle
[s
+1]&0xff);
245 wxChar ch2
=wxChar(xitle
[s
+2]&0xff);
246 wxChar ch3
=wxChar(xitle
[s
+3]&0xff);
247 s
+=4; // next character
248 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]=wxChar('ö'); }
249 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]=wxChar('ä'); }
250 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]=wxChar('ü'); }
251 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]=wxChar('Ö'); }
252 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]=wxChar('Ä'); }
253 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]=wxChar('Ü'); }
261 // Section (2) becomes level 1 if it's an article.
262 if (DocumentStyle
== LATEX_ARTICLE
)
265 if (level
== 0) // Means we had a Chapter in an article, oops.
268 ResetContentsLevels(level
);
270 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
272 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
275 // If a previous section at this level was a book, we *have* to have a
276 // book not a page, because of a bug in WHC (or WinHelp 4).
277 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
279 // At this level, we have a pointer to a further hierarchy.
280 // So we need a 'book' consisting of (say) Chapter 1.
281 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
283 // Then we have a 'page' consisting of the text for this chapter
284 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
286 // Then we'll be writing out further pages or books at level + 1...
288 // Remember that at this level, we had a book and *must* for the
289 // remainder of sections at this level.
290 ContentsLevels
[level
-1] = true;
294 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
299 if (level
== 1 || ContentsLevels
[level
-1])
301 // Always have a book at level 1
302 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
303 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
304 ContentsLevels
[level
-1] = true;
307 // Probably doesn't have children if it hasn't been added to the topic table
308 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
313 void SplitIndexEntry(wxChar
*entry
, wxChar
*buf1
, wxChar
*buf2
)
315 int len
= wxStrlen(entry
); int i
= 0;
316 while ((i
< len
) && entry
[i
] != '!')
317 { buf1
[i
] = entry
[i
]; i
++; }
318 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
323 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
329 * Output topic index entries in WinHelp RTF
332 void GenerateKeywordsForTopic(wxChar
*topic
)
334 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
338 wxStringList
*list
= texTopic
->keywords
;
341 wxStringListNode
*node
= list
->GetFirst();
344 wxChar
*s
= (wxChar
*)node
->GetData();
346 // Must separate out main entry form subentry (only 1 subentry allowed)
347 wxChar buf1
[100]; wxChar buf2
[100];
348 SplitIndexEntry(s
, buf1
, buf2
);
350 // Check for ':' which messes up index
352 for (i
= 0; i
< wxStrlen(buf1
) ; i
++)
355 for (i
= 0; i
< wxStrlen(buf2
) ; i
++)
359 // {K} is a strange fix to prevent words beginning with K not
360 // being indexed properly
361 TexOutput(_T("K{\\footnote {K} "));
363 if (wxStrlen(buf2
) > 0)
369 TexOutput(_T("}\n"));
370 node
= node
->GetNext();
376 * Output index entry in linear RTF
380 void GenerateIndexEntry(wxChar
*entry
)
384 wxChar buf1
[100]; wxChar buf2
[100];
385 SplitIndexEntry(entry
, buf1
, buf2
);
387 TexOutput(_T("{\\xe\\v {"));
389 if (wxStrlen(buf2
) > 0)
391 TexOutput(_T("\\:"));
399 * Write a suitable RTF header.
403 void WriteColourTable(FILE *fd
)
405 wxFprintf(fd
, _T("{\\colortbl"));
406 wxNode
*node
= ColourTable
.GetFirst();
409 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->GetData();
410 wxFprintf(fd
, _T("\\red%d\\green%d\\blue%d;\n"), entry
->red
, entry
->green
, entry
->blue
);
411 node
= node
->GetNext();
413 wxFprintf(fd
, _T("}"));
417 * Write heading style
421 void WriteHeadingStyle(FILE *fd
, int heading
)
427 wxFprintf(fd
, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont
*2);
432 wxFprintf(fd
, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont
*2);
437 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
442 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
450 void WriteRTFHeader(FILE *fd
)
452 wxFprintf(fd
, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset
);
453 wxFprintf(fd
, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
454 wxFprintf(fd
, _T("{\\f3\\fmodern Courier New;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
458 wxFprintf(fd
, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n"));
460 wxFprintf(fd
, _T("{\\s1 ")); WriteHeadingStyle(fd
, 1); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 1;}\n"));
461 wxFprintf(fd
, _T("{\\s2 ")); WriteHeadingStyle(fd
, 2); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 2;}\n"));
462 wxFprintf(fd
, _T("{\\s3 ")); WriteHeadingStyle(fd
, 3); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 3;}\n"));
463 wxFprintf(fd
, _T("{\\s4 ")); WriteHeadingStyle(fd
, 4); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 4;}\n"));
466 wxFprintf(fd
, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\
467 \\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n"));
469 // Table of contents styles
470 wxFprintf(fd
, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
472 wxFprintf(fd
, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n"));
473 wxFprintf(fd
, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n"));
474 wxFprintf(fd
, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n"));
477 wxFprintf(fd
, _T("{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n"));
478 wxFprintf(fd
, _T("{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n"));
479 wxFprintf(fd
, _T("{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n"));
480 wxFprintf(fd
, _T("{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n"));
481 wxFprintf(fd
, _T("{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n"));
482 wxFprintf(fd
, _T("}\n"));
484 WriteColourTable(fd
);
485 wxFprintf(fd
, _T("\n\\ftnbj\\ftnrestart")); // Latex default is footnotes at bottom of page, not section.
486 wxFprintf(fd
, _T("\n"));
489 void OutputNumberStyle(wxChar
*numberStyle
)
493 if (wxStrcmp(numberStyle
, _T("arabic")) == 0)
495 TexOutput(_T("\\pgndec"));
497 else if (wxStrcmp(numberStyle
, _T("roman")) == 0)
499 TexOutput(_T("\\pgnlcrm"));
501 else if (wxStrcmp(numberStyle
, _T("Roman")) == 0)
503 TexOutput(_T("\\pgnucrm"));
505 else if (wxStrcmp(numberStyle
, _T("alph")) == 0)
507 TexOutput(_T("\\pgnlcltr"));
509 else if (wxStrcmp(numberStyle
, _T("Alph")) == 0)
511 TexOutput(_T("\\pgnucltr"));
517 * Write a Windows help project file
520 bool WriteHPJ(const wxString
& filename
)
522 wxChar hpjFilename
[256];
525 wxStrcpy(hpjFilename
, filename
);
526 StripExtension(hpjFilename
);
527 wxStrcat(hpjFilename
, _T(".hpj"));
529 wxStrcpy(helpFile
, wxFileNameFromPath(filename
));
530 StripExtension(helpFile
);
531 wxStrcpy(rtfFile
, helpFile
);
532 wxStrcat(helpFile
, _T(".hlp"));
533 wxStrcat(rtfFile
, _T(".rtf"));
535 FILE *fd
= wxFopen(hpjFilename
, _T("w"));
539 wxChar
*helpTitle
= winHelpTitle
;
541 helpTitle
= _T("Untitled");
543 wxString thePath
= wxPathOnly(InputFile
);
546 wxFprintf(fd
, _T("[OPTIONS]\n"));
547 wxFprintf(fd
, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath
.c_str());
548 wxFprintf(fd
, _T("TITLE=%s\n"), helpTitle
);
549 wxFprintf(fd
, _T("CONTENTS=Contents\n"));
551 if (winHelpVersion
> 3)
553 wxFprintf(fd
, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
554 wxFprintf(fd
, _T("COMPRESS=8 Zeck\n"));
555 wxFprintf(fd
, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
556 wxFprintf(fd
, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot
));
560 wxFprintf(fd
, _T("COMPRESS=HIGH\n"));
562 wxFprintf(fd
, _T("\n"));
564 if (winHelpVersion
> 3)
566 wxFprintf(fd
, _T("[WINDOWS]\n"));
567 wxFprintf(fd
, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
568 wxFprintf(fd
, _T("\n"));
571 wxFprintf(fd
, _T("[FILES]\n%s\n\n"), rtfFile
);
572 wxFprintf(fd
, _T("[CONFIG]\n"));
574 wxFprintf(fd
, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile
);
575 wxFprintf(fd
, _T("BrowseButtons()\n\n"));
576 wxFprintf(fd
, _T("[MAP]\n\n[BITMAPS]\n\n"));
583 * Given a TexChunk with a string value, scans through the string
584 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
585 * and inserting spaces at the start of lines since in Latex, a newline
586 * implies a space, but not in RTF.
590 void ProcessText2RTF(TexChunk
*chunk
)
592 bool changed
= false;
596 int len
= wxStrlen(chunk
->value
);
599 ch
= chunk
->value
[i
];
605 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("\\par\n")); ptr
+= 5;
606 // BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par{\\v this was verbatim}\n")); ptr += 5;
612 // If the first character of the next line is ASCII,
613 // put a space in. Implicit in Latex, not in RTF.
615 The reason this is difficult is that you don't really know
616 where a space would be appropriate. If you always put in a space
617 when you find a newline, unwanted spaces appear in the text.
619 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
620 !isspace(chunk
->value
[i
+1])) ||
621 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
622 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
623 !isspace(chunk
->value
[i
+2]))))
626 // DOS files have a 13 after the 10
630 if (chunk
->value
[i
] == 13)
637 BigBuffer
[ptr
] = ' ';
640 // Note that the actual ASCII character seen is dealt with in the next
651 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
653 BigBuffer
[ptr
] = '"'; ptr
++;
657 else if (!inVerbatim
&& ch
== '`') // Change ` to '
659 BigBuffer
[ptr
] = 39; ptr
++;
663 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
665 BigBuffer
[ptr
] = '\\'; ptr
++;
666 BigBuffer
[ptr
] = '\\'; ptr
++;
670 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curly bracket
672 BigBuffer
[ptr
] = '\\'; ptr
++;
673 BigBuffer
[ptr
] = ch
; ptr
++;
688 delete[] chunk
->value
;
689 chunk
->value
= copystring(BigBuffer
);
694 * Scan through all chunks starting from the given one,
695 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
696 * This should be called after Tex2Any has parsed the file,
697 * and before TraverseDocument is called.
701 void Text2RTF(TexChunk
*chunk
)
704 if (stopRunning
) return;
708 case CHUNK_TYPE_MACRO
:
710 TexMacroDef
*def
= chunk
->def
;
711 if (def
&& def
->ignore
)
714 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
717 wxNode
*node
= chunk
->children
.GetFirst();
720 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
721 Text2RTF(child_chunk
);
722 node
= node
->GetNext();
725 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
732 wxNode
*node
= chunk
->children
.GetFirst();
735 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
736 Text2RTF(child_chunk
);
737 node
= node
->GetNext();
742 case CHUNK_TYPE_STRING
:
745 ProcessText2RTF(chunk
);
756 wxChar browseBuf
[10];
757 static long browseId
= 0;
758 wxChar
*GetBrowseString(void)
762 wxSnprintf(buf
, sizeof(buf
), _T("%ld"), browseId
);
763 int noZeroes
= 5-wxStrlen(buf
);
764 wxStrcpy(browseBuf
, _T("browse"));
765 for (int i
= 0; i
< noZeroes
; i
++)
766 wxStrcat(browseBuf
, _T("0"));
767 wxStrcat(browseBuf
, buf
);
772 * Keeping track of environments to restore the styles after \pard.
773 * Push strings like "\qc" onto stack.
777 void PushEnvironmentStyle(wxChar
*style
)
779 environmentStack
.Add(style
);
782 void PopEnvironmentStyle(void)
784 wxStringListNode
*node
= environmentStack
.GetLast();
787 wxChar
*val
= (wxChar
*)node
->GetData();
793 // Write out the styles, most recent first.
794 void WriteEnvironmentStyles(void)
796 wxStringListNode
*node
= environmentStack
.GetLast();
799 wxChar
*val
= (wxChar
*)node
->GetData();
801 node
= node
->GetNext();
803 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
806 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d"), ParIndent
*20); // Convert points to TWIPS
809 if (environmentStack
.GetCount() > 0 || (ParIndent
> 0))
819 void OutputRTFHeaderCommands(void)
822 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
824 TexOutput(_T("{\\headerl }{\\headerr }"));
826 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
828 TexOutput(_T("{\\headerl }{\\headerr }"));
830 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
833 TexOutput(_T("{\\headerl\\fi0 "));
836 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
838 TexOutput(_T("{\\i \\qr "));
839 if (DocumentStyle
== LATEX_ARTICLE
)
841 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
846 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d: "), chapterNo
);
849 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
850 TexOutput(_T("}\\par\\pard}"));
853 TexOutput(_T("{\\headerr\\fi0 "));
856 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
858 TexOutput(_T("{\\i \\qc "));
859 if (DocumentStyle
== LATEX_ARTICLE
)
861 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
866 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d"), chapterNo
);
869 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
870 TexOutput(_T("}\\par\\pard}"));
874 int oldForbidResetPar
= forbidResetPar
;
877 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
879 TexOutput(_T("{\\headerl\\fi0 "));
882 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
886 if (!CentreHeaderEven
&& !RightHeaderEven
)
887 TexOutput(_T("\\ql "));
888 TraverseChildrenFromChunk(LeftHeaderEven
);
890 if (CentreHeaderEven
)
892 if (!LeftHeaderEven
&& !RightHeaderEven
)
893 TexOutput(_T("\\qc "));
895 TexOutput(_T("\\tab\\tab\\tab "));
896 TraverseChildrenFromChunk(CentreHeaderEven
);
900 if (!LeftHeaderEven
&& !CentreHeaderEven
)
901 TexOutput(_T("\\qr "));
903 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
904 TraverseChildrenFromChunk(RightHeaderEven
);
906 TexOutput(_T("\\par\\pard}"));
909 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
911 TexOutput(_T("{\\headerr\\fi0 "));
914 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
918 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
919 TexOutput(_T("\\ql "));
920 TraverseChildrenFromChunk(LeftHeaderOdd
);
924 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
925 TexOutput(_T("\\qc "));
927 TexOutput(_T("\\tab\\tab\\tab "));
928 TraverseChildrenFromChunk(CentreHeaderOdd
);
932 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
933 TexOutput(_T("\\qr "));
935 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
936 TraverseChildrenFromChunk(RightHeaderOdd
);
938 TexOutput(_T("\\par\\pard}"));
940 // As an approximation, don't put a header on the first page of a section.
941 // This may not always be desired, but it's a reasonable guess.
942 TexOutput(_T("{\\headerf }"));
944 forbidResetPar
= oldForbidResetPar
;
948 void OutputRTFFooterCommands(void)
950 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
952 TexOutput(_T("{\\footerl\\fi0 "));
954 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
955 TexOutput(_T("{\\qc "));
956 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
957 TexOutput(_T("}\\par\\pard}"));
959 TexOutput(_T("{\\footerr\\fi0 "));
961 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
962 TexOutput(_T("{\\qc "));
963 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
964 TexOutput(_T("}\\par\\pard}"));
966 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
968 TexOutput(_T("{\\footerl }{\\footerr }"));
970 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
972 TexOutput(_T("{\\footerl }{\\footerr }"));
976 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
978 TexOutput(_T("{\\footerl\\fi0 "));
980 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
983 if (!CentreFooterEven
&& !RightFooterEven
)
984 TexOutput(_T("\\ql "));
985 TraverseChildrenFromChunk(LeftFooterEven
);
987 if (CentreFooterEven
)
989 if (!LeftFooterEven
&& !RightFooterEven
)
990 TexOutput(_T("\\qc "));
992 TexOutput(_T("\\tab\\tab\\tab "));
993 TraverseChildrenFromChunk(CentreFooterEven
);
997 if (!LeftFooterEven
&& !CentreFooterEven
)
998 TexOutput(_T("\\qr "));
1000 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1001 TraverseChildrenFromChunk(RightFooterEven
);
1003 TexOutput(_T("\\par\\pard}"));
1006 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1008 TexOutput(_T("{\\footerr\\fi0 "));
1010 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
1013 if (!CentreFooterOdd
&& !RightFooterOdd
)
1014 TexOutput(_T("\\ql "));
1015 TraverseChildrenFromChunk(LeftFooterOdd
);
1017 if (CentreFooterOdd
)
1019 if (!LeftFooterOdd
&& !RightFooterOdd
)
1020 TexOutput(_T("\\qc "));
1022 TexOutput(_T("\\tab\\tab\\tab "));
1023 TraverseChildrenFromChunk(CentreFooterOdd
);
1027 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1028 TexOutput(_T("\\qr "));
1030 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1031 TraverseChildrenFromChunk(RightFooterOdd
);
1033 TexOutput(_T("\\par\\pard}"));
1036 // As an approximation, put a footer on the first page of a section.
1037 // This may not always be desired, but it's a reasonable guess.
1038 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1040 TexOutput(_T("{\\footerf\\fi0 "));
1043 if (!CentreFooterOdd
&& !RightFooterOdd
)
1044 TexOutput(_T("\\ql "));
1045 TraverseChildrenFromChunk(LeftFooterOdd
);
1047 if (CentreFooterOdd
)
1049 if (!LeftFooterOdd
&& !RightFooterOdd
)
1050 TexOutput(_T("\\qc "));
1052 TexOutput(_T("\\tab\\tab\\tab "));
1053 TraverseChildrenFromChunk(CentreFooterOdd
);
1057 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1058 TexOutput(_T("\\qr "));
1060 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1061 TraverseChildrenFromChunk(RightFooterOdd
);
1063 TexOutput(_T("\\par\\pard}"));
1068 // Called on start/end of macro examination
1069 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1073 wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start);
1074 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1075 OutputDebugString("\n"); wxYield();
1078 // ltLABEL is included here because after a section but BEFORE
1079 // the label is seen, a new paragraph is issued. Don't upset this by
1080 // immediately forgetting we've done it.
1081 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1082 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1083 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1084 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1085 macroId
!= ltPAGENUMBERING
&&
1086 (forbidResetPar
== 0)))
1088 issuedNewParagraph
= 0;
1096 case ltCHAPTERHEADING
:
1097 case ltCHAPTERHEADINGSTAR
:
1105 subsubsectionNo
= 0;
1108 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1111 wxChar
*topicName
= FindTopicName(GetNextChunk());
1112 SetCurrentChapterName(topicName
);
1114 if (winHelpContents
&& winHelp
&& !InPopups())
1116 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1117 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1119 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1124 wxFprintf(Contents
, _T("\n{\\uldb "));
1125 wxFprintf(Chapters
, _T("\\page"));
1126 wxFprintf(Chapters
, _T("\n${\\footnote "));
1128 SetCurrentOutputs(Contents
, Chapters
);
1130 SetCurrentOutput(Chapters
);
1134 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
1136 // If a non-custom page style, we generate the header now.
1137 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1138 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1139 wxStrcmp(PageStyle
, _T("headings")) == 0))
1141 OutputRTFHeaderCommands();
1142 OutputRTFFooterCommands();
1145 // Need to reset the current numbering style, or RTF forgets it.
1146 SetCurrentOutput(Chapters
);
1147 OutputNumberStyle(currentNumberStyle
);
1149 SetCurrentOutput(Contents
);
1153 if (macroId
== ltCHAPTER
)
1156 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo
);
1158 else if (macroId
== ltCHAPTERHEADING
)
1160 wxFprintf(Contents
, _T("\\par\n\\pard{\\b "));
1162 else SetCurrentOutput(NULL
); // No entry in table of contents
1166 startedSections
= true;
1168 // Output heading to contents page
1171 OutputCurrentSection();
1175 wxFprintf(Contents
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1176 //WriteEnvironmentStyles();
1178 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1179 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1181 // From here, just output to chapter
1182 SetCurrentOutput(Chapters
);
1187 wxFprintf(Chapters
, _T("}\n#{\\footnote %s}\n"), topicName
);
1188 wxFprintf(Chapters
, _T("+{\\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 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
1200 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1201 wxFileNameFromPath(FileRoot
), _T("Contents"));
1207 wxChar
*styleCommand
= _T("");
1208 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1209 styleCommand
= _T("\\s1");
1210 wxFprintf(Chapters
, _T("\\pard{%s"), ((winHelp
&& !InPopups()) ? _T("\\keepn\\sa140\\sb140") : styleCommand
));
1211 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" "));
1214 if (macroId
== ltCHAPTER
)
1217 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1218 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1220 wxFprintf(Chapters
, _T("%d. "), chapterNo
);
1224 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1227 OutputCurrentSection();
1228 TexOutput(_T("\\par\\pard}\n"));
1230 issuedNewParagraph
= 1;
1231 WriteEnvironmentStyles();
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 wxChar
*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 wxFprintf(Sections
, _T("\\page\n"));
1276 wxFprintf(jumpFrom
, _T("\n{\\uldb "));
1280 if (DocumentStyle
== LATEX_ARTICLE
)
1282 TexOutput(_T("\\sect\\pgncont\n"));
1283 // If a non-custom page style, we generate the header now.
1284 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1285 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1286 wxStrcmp(PageStyle
, _T("headings")) == 0))
1288 OutputRTFHeaderCommands();
1289 OutputRTFFooterCommands();
1292 SetCurrentOutput(Contents
);
1294 if (macroId
== ltSECTION
)
1298 if (DocumentStyle
== LATEX_REPORT
)
1299 wxFprintf(Contents
, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo
, sectionNo
);
1301 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo
);
1304 else if (macroId
== ltSECTIONHEADING
)
1308 if (DocumentStyle
== LATEX_REPORT
)
1309 wxFprintf(Contents
, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
1311 wxFprintf(Contents
, _T("\\par\n\\pard{\\b ")); //, sectionNo);
1314 else SetCurrentOutput(NULL
);
1317 if (startedSections
)
1320 wxFprintf(Sections
, _T("\\page\n"));
1322 startedSections
= true;
1325 wxFprintf(Sections
, _T("\n${\\footnote "));
1327 // Output heading to contents page
1329 OutputCurrentSection();
1335 wxFprintf(jumpFrom
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1336 //WriteEnvironmentStyles();
1339 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1341 if (DocumentStyle
== LATEX_REPORT
)
1342 wxFprintf(Contents
, _T("}\\par\\pard\n"));
1344 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1347 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1351 wxFprintf(Sections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1352 wxFprintf(Sections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1353 OutputSectionKeyword(Sections
);
1354 GenerateKeywordsForTopic(topicName
);
1357 if (DocumentStyle
== LATEX_ARTICLE
)
1359 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1360 wxFileNameFromPath(FileRoot
), _T("Contents"));
1362 else if (CurrentChapterName
)
1364 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1365 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1372 wxChar
*styleCommand
= _T("");
1373 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1375 if (DocumentStyle
== LATEX_ARTICLE
)
1376 styleCommand
= _T("\\s1");
1378 styleCommand
= _T("\\s2");
1380 wxChar
*keep
= _T("");
1381 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1382 keep
= _T("\\keepn\\sa140\\sb140");
1384 wxFprintf(winHelp
? Sections
: Chapters
, _T("\\pard{%s%s"),
1385 keep
, styleCommand
);
1387 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1388 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1389 wxFprintf(winHelp
? Sections
: Chapters
, _T(" "));
1393 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1395 if (DocumentStyle
== LATEX_REPORT
)
1398 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
1399 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1402 wxFprintf(Chapters
, _T("%d.%d. "), chapterNo
, sectionNo
);
1407 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1408 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1411 wxFprintf(Chapters
, _T("%d. "), sectionNo
);
1416 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1419 OutputCurrentSection();
1420 TexOutput(_T("\\par\\pard}\n"));
1421 // TexOutput(_T("\\par\\pard}\\par\n"));
1423 issuedNewParagraph
= 1;
1424 WriteEnvironmentStyles();
1425 // issuedNewParagraph = 2;
1430 case ltSUBSECTIONSTAR
:
1431 case ltMEMBERSECTION
:
1432 case ltFUNCTIONSECTION
:
1436 if (winHelp
&& !Sections
)
1438 OnError(_T("You cannot have a subsection before a section!"));
1442 subsubsectionNo
= 0;
1444 if (macroId
!= ltSUBSECTIONSTAR
)
1447 wxChar
*topicName
= FindTopicName(GetNextChunk());
1448 SetCurrentSubsectionName(topicName
);
1449 NotifyParentHasChildren(2);
1450 if (winHelpContents
&& winHelp
&& !InPopups())
1452 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1453 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1455 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1459 SetCurrentOutputs(Sections
, Subsections
);
1460 SetCurrentOutputs(Sections
, Subsections
);
1462 wxFprintf(Sections
, _T("\n{\\uldb "));
1466 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1467 (macroId
!= ltFUNCTIONSECTION
))
1469 SetCurrentOutput(Contents
);
1470 if (DocumentStyle
== LATEX_REPORT
)
1471 wxFprintf(Contents
, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo
, sectionNo
, subsectionNo
);
1473 wxFprintf(Contents
, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo
, subsectionNo
);
1474 } else SetCurrentOutput(NULL
);
1476 if (startedSections
)
1481 wxFprintf(Subsections
, _T("\\page\n"));
1483 // Experimental JACS 2004-02-21
1486 wxFprintf(Chapters
, _T("\\par\n"));
1489 startedSections
= true;
1492 wxFprintf(Subsections
, _T("\n${\\footnote "));
1494 // Output to contents page
1496 OutputCurrentSection();
1502 wxFprintf(Sections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1503 //WriteEnvironmentStyles();
1506 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1507 (macroId
!= ltFUNCTIONSECTION
))
1508 wxFprintf(Contents
, _T("\\par\\pard\n"));
1510 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1513 wxFprintf(Subsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1514 wxFprintf(Subsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1515 OutputSectionKeyword(Subsections
);
1516 GenerateKeywordsForTopic(topicName
);
1517 if (useUpButton
&& CurrentSectionName
)
1519 wxFprintf(Subsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1520 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1523 if (!winHelp
&& indexSubsections
&& useWord
)
1525 // Insert index entry for this subsection
1526 TexOutput(_T("{\\xe\\v {"));
1527 OutputCurrentSection();
1528 TexOutput(_T("}}"));
1533 wxChar
*styleCommand
= _T("");
1534 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1536 if (DocumentStyle
== LATEX_ARTICLE
)
1537 styleCommand
= _T("\\s2");
1539 styleCommand
= _T("\\s3");
1541 wxChar
*keep
= _T("");
1542 if (winHelp
&& !InPopups())
1543 keep
= _T("\\keepn\\sa140\\sb140");
1545 wxFprintf(winHelp
? Subsections
: Chapters
, _T("\\pard{%s%s"),
1546 keep
, styleCommand
);
1548 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1549 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1550 wxFprintf(winHelp
? Subsections
: Chapters
, _T(" "));
1554 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1555 (macroId
!= ltFUNCTIONSECTION
))
1557 if (DocumentStyle
== LATEX_REPORT
)
1560 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
1561 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1564 wxFprintf(Chapters
, _T("%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
);
1569 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
1570 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1573 wxFprintf(Chapters
, _T("%d.%d. "), sectionNo
, subsectionNo
);
1578 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1581 OutputCurrentSection(); // Repeat section header
1583 // Experimental JACS
1584 TexOutput(_T("\\par\\pard}\n"));
1585 // TexOutput(_T("\\par\\pard}\\par\n"));
1587 issuedNewParagraph
= 1;
1588 WriteEnvironmentStyles();
1593 case ltSUBSUBSECTION
:
1594 case ltSUBSUBSECTIONSTAR
:
1598 if (winHelp
&& !Subsections
)
1600 OnError(_T("You cannot have a subsubsection before a subsection!"));
1604 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1607 wxChar
*topicName
= FindTopicName(GetNextChunk());
1608 SetCurrentTopic(topicName
);
1609 NotifyParentHasChildren(3);
1610 if (winHelpContents
&& winHelp
)
1612 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1613 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1615 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1619 SetCurrentOutputs(Subsections
, Subsubsections
);
1620 wxFprintf(Subsections
, _T("\n{\\uldb "));
1624 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1626 if (DocumentStyle
== LATEX_ARTICLE
)
1628 SetCurrentOutput(Contents
);
1629 wxFprintf(Contents
, _T("\n\\tab\\tab %d.%d.%d\\tab "),
1630 sectionNo
, subsectionNo
, subsubsectionNo
);
1633 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1636 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1639 if (startedSections
)
1642 wxFprintf(Subsubsections
, _T("\\page\n"));
1643 // Experimental JACS 2004-02-21
1646 wxFprintf(Chapters
, _T("\\par\n"));
1650 startedSections
= true;
1653 wxFprintf(Subsubsections
, _T("\n${\\footnote "));
1655 // Output header to contents page
1656 OutputCurrentSection();
1660 wxFprintf(Subsections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1661 //WriteEnvironmentStyles();
1663 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1664 wxFprintf(Contents
, _T("\\par\\pard\n"));
1666 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1669 wxFprintf(Subsubsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1670 wxFprintf(Subsubsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1671 OutputSectionKeyword(Subsubsections
);
1672 GenerateKeywordsForTopic(topicName
);
1673 if (useUpButton
&& CurrentSubsectionName
)
1675 wxFprintf(Subsubsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1676 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1679 if (!winHelp
&& indexSubsections
&& useWord
)
1681 // Insert index entry for this subsubsection
1682 TexOutput(_T("{\\xe\\v {"));
1683 OutputCurrentSection();
1684 TexOutput(_T("}}"));
1687 wxChar
*styleCommand
= _T("");
1688 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1690 if (DocumentStyle
== LATEX_ARTICLE
)
1691 styleCommand
= _T("\\s3");
1693 styleCommand
= _T("\\s4");
1695 wxChar
*keep
= _T("");
1697 keep
= _T("\\keepn\\sa140\\sb140");
1699 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T("\\pard{%s%s"),
1700 keep
, styleCommand
);
1702 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1703 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1704 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T(" "));
1708 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1710 if (DocumentStyle
== LATEX_ARTICLE
)
1713 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
1714 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1717 wxFprintf(Chapters
, _T("%d.%d.%d. "), sectionNo
, subsectionNo
, subsubsectionNo
);
1722 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1723 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1726 wxFprintf(Chapters
, _T("%d.%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1731 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1734 OutputCurrentSection(); // Repeat section header
1735 TexOutput(_T("\\par\\pard}\n"));
1736 issuedNewParagraph
= 1;
1737 WriteEnvironmentStyles();
1738 // TexOutput(_T("\\par\\pard}\\par\n"));
1739 // issuedNewParagraph = 2;
1749 wxChar
*topicName
= FindTopicName(GetNextChunk());
1750 SetCurrentTopic(topicName
);
1752 TexOutput(_T("\\pard\\par"));
1759 if (winHelp
|| !useWord
)
1761 if (DocumentStyle
!= LATEX_ARTICLE
)
1762 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1764 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1768 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1769 FigureNameString
, topicName
, topicName
);
1776 if (winHelp
|| !useWord
)
1778 if (DocumentStyle
!= LATEX_ARTICLE
)
1779 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1781 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1785 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1786 TableNameString
, topicName
, topicName
);
1790 int n
= (inTable
? tableNo
: figureNo
);
1791 AddTexRef(topicName
, NULL
, NULL
,
1792 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1793 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1796 TexOutput(_T("\\qc{\\b "));
1798 TexOutput(_T("\\ql{\\b "));
1801 OutputCurrentSection();
1803 TexOutput(_T("}\\par\\pard\n"));
1804 WriteEnvironmentStyles();
1811 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1818 TexOutput(_T("}\n"));
1821 TexOutput(_T("K{\\footnote {K} "));
1822 suppressNameDecoration
= true;
1823 TraverseChildrenFromChunk(currentMember
);
1824 suppressNameDecoration
= false;
1825 TexOutput(_T("}\n"));
1827 if (!winHelp
&& useWord
)
1829 // Insert index entry for this function
1830 TexOutput(_T("{\\xe\\v {"));
1831 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1832 TraverseChildrenFromChunk(currentMember
);
1833 suppressNameDecoration
= false;
1834 TexOutput(_T("}}"));
1841 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1848 TexOutput(_T("}\n"));
1851 TexOutput(_T("K{\\footnote {K} "));
1852 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1853 TraverseChildrenFromChunk(currentMember
);
1854 suppressNameDecoration
= false;
1855 TexOutput(_T("}\n"));
1857 if (!winHelp
&& useWord
)
1859 // Insert index entry for this function
1860 TexOutput(_T("{\\xe\\v {"));
1861 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1862 TraverseChildrenFromChunk(currentMember
);
1863 suppressNameDecoration
= false;
1864 TexOutput(_T("}}"));
1871 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1874 TexOutput(_T("{\\b "));
1878 TexOutput(_T("}\n"));
1881 TexOutput(_T("K{\\footnote {K} "));
1882 TraverseChildrenFromChunk(currentMember
);
1883 TexOutput(_T("}\n"));
1885 if (!winHelp
&& useWord
)
1887 // Insert index entry for this function
1888 TexOutput(_T("{\\xe\\v {"));
1889 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1890 TraverseChildrenFromChunk(currentMember
);
1891 suppressNameDecoration
= false;
1892 TexOutput(_T("}}"));
1900 SetCurrentOutput(Chapters
);
1903 case ltTABLEOFCONTENTS
:
1907 if (!winHelp
&& useWord
)
1909 // Insert Word for Windows table of contents
1910 TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
1912 // In linear RTF, same as chapter headings.
1913 wxSnprintf(buf
, sizeof(buf
), _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont
*2, ContentsNameString
);
1916 wxSnprintf(buf
, sizeof(buf
), _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth
);
1918 // TexOutput(_T("\\sect\\sectd"));
1922 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1928 wxPutc(ch
, Chapters
);
1935 TexOutput(_T("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n"));
1936 OnInform(_T("Run Tex2RTF again to include contents page."));
1945 // TexOutput(_T("{\\b void}"));
1951 TexOutput(_T("{\\scaps HARDY}"));
1957 TexOutput(_T("wxCLIPS"));
1960 case ltSPECIALAMPERSAND
:
1965 TexOutput(_T("\\cell "));
1971 case ltSPECIALTILDE
:
1975 #if 1 // if(inVerbatim)
1983 case ltBACKSLASHCHAR
:
1989 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
1990 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
1991 int currentWidth
= 0;
1992 for (int i
= 0; i
< noColumns
; i
++)
1994 currentWidth
+= TableData
[i
].width
;
1995 if (TableData
[i
].rightBorder
)
1996 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
1998 if (TableData
[i
].leftBorder
)
1999 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
2001 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
2004 TexOutput(_T("\\pard\\intbl\n"));
2007 TexOutput(_T("\\line\n"));
2014 TexOutput(_T("\tab "));
2017 case ltRTFSP
: // Explicit space, RTF only
2029 if (indentLevel
> 0)
2031 // Experimental JACS 2004-02-21
2032 TexOutput(_T("\\par\n"));
2033 issuedNewParagraph
= 1;
2034 // TexOutput(_T("\\par\\par\n"));
2035 // issuedNewParagraph = 2;
2039 // Top-level list: issue a new paragraph if we haven't
2041 if (!issuedNewParagraph
)
2043 TexOutput(_T("\\par\\pard"));
2044 WriteEnvironmentStyles();
2045 issuedNewParagraph
= 1;
2047 else issuedNewParagraph
= 0;
2050 TexOutput(_T("\\fi0\n"));
2052 if (macroId
== ltENUMERATE
)
2053 listType
= LATEX_ENUMERATE
;
2054 else if (macroId
== ltITEMIZE
)
2055 listType
= LATEX_ITEMIZE
;
2057 listType
= LATEX_DESCRIPTION
;
2060 wxNode
*node
= itemizeStack
.GetFirst();
2062 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2064 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2065 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2067 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2068 itemizeStack
.Insert(struc
);
2070 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1
, indentSize2
, indentSize2
);
2071 PushEnvironmentStyle(buf
);
2075 currentItemSep
= 8; // Reset to the default
2077 PopEnvironmentStyle();
2079 if (itemizeStack
.GetFirst())
2081 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2083 delete itemizeStack
.GetFirst();
2085 /* Change 18/7/97 - don't know why we wish to do this
2086 if (itemizeStack.Number() == 0)
2088 OnMacro(ltPAR, 0, true);
2089 OnMacro(ltPAR, 0, false);
2090 issuedNewParagraph = 2;
2102 wxNode
*node
= itemizeStack
.GetFirst();
2104 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2106 int indentSize
= oldIndent
+ TwoColWidthA
;
2108 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2109 itemizeStack
.Insert(struc
);
2111 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2112 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200"), indentSize
, indentSize
);
2113 PushEnvironmentStyle(buf
);
2118 PopEnvironmentStyle();
2119 if (itemizeStack
.GetFirst())
2121 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2123 delete itemizeStack
.GetFirst();
2127 TexOutput(_T("\\pard\n"));
2128 WriteEnvironmentStyles();
2130 /* why do we need this? */
2132 TexOutput(_T("\\pard\n"));
2134 if (itemizeStack
.GetCount() == 0)
2136 issuedNewParagraph
= 0;
2137 OnMacro(ltPAR
, 0, true);
2138 OnMacro(ltPAR
, 0, false);
2146 wxNode
*node
= itemizeStack
.GetFirst();
2149 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2152 struc
->currentItem
+= 1;
2153 wxChar indentBuf
[60];
2155 int indentSize1
= struc
->labelIndentation
;
2156 int indentSize2
= struc
->indentation
;
2158 TexOutput(_T("\n"));
2159 if (struc
->currentItem
> 1 && issuedNewParagraph
== 0)
2162 // if (currentItemSep > 0)
2163 // TexOutput(_T("\\par"));
2165 TexOutput(_T("\\par"));
2166 issuedNewParagraph
= 1;
2167 // WriteEnvironmentStyles();
2170 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1
, indentSize2
,
2171 indentSize2
, 20*itemIndentTab
);
2174 switch (struc
->listType
)
2176 case LATEX_ENUMERATE
:
2178 if (descriptionItemArg
)
2180 TexOutput(_T("\\tab{ "));
2181 TraverseChildrenFromChunk(descriptionItemArg
);
2182 TexOutput(_T("}\\tab"));
2183 descriptionItemArg
= NULL
;
2187 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b %d.}\\tab"), struc
->currentItem
);
2188 TexOutput(indentBuf
);
2194 if (descriptionItemArg
)
2196 TexOutput(_T("\\tab{ "));
2197 TraverseChildrenFromChunk(descriptionItemArg
);
2198 TexOutput(_T("}\\tab"));
2199 descriptionItemArg
= NULL
;
2203 if (bulletFile
&& winHelp
)
2205 if (winHelpVersion
> 3) // Transparent bitmap
2206 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmct %s\\}\\tab"), bulletFile
);
2208 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmc %s\\}\\tab"), bulletFile
);
2211 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b o}\\tab"));
2213 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\f1\\'b7}\\tab"));
2214 TexOutput(indentBuf
);
2219 case LATEX_DESCRIPTION
:
2221 if (descriptionItemArg
)
2223 TexOutput(_T("\\tab{\\b "));
2224 TraverseChildrenFromChunk(descriptionItemArg
);
2225 TexOutput(_T("} "));
2226 descriptionItemArg
= NULL
;
2236 case ltTWOCOLITEMRULED
:
2238 wxNode
*node
= itemizeStack
.GetFirst();
2241 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2244 struc
->currentItem
+= 1;
2247 wxNode
*node2
= NULL
;
2248 if (itemizeStack
.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
2249 node2
= itemizeStack
.Item(1);
2251 oldIndent
= ((ItemizeStruc
*)node2
->GetData())->indentation
;
2253 TexOutput(_T("\n"));
2256 if (struc
->currentItem
> 1)
2258 if (currentItemSep
> 0)
2259 TexOutput(_T("\\par"));
2261 // WriteEnvironmentStyles();
2265 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA,
2266 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2268 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA,
2269 TwoColWidthA, TwoColWidthA);
2271 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA
+ oldIndent
,
2272 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2285 if (macroId
== ltVERBATIM
)
2287 if (!issuedNewParagraph
)
2289 TexOutput(_T("\\par\\pard"));
2290 WriteEnvironmentStyles();
2291 issuedNewParagraph
= 1;
2293 else issuedNewParagraph
= 0;
2297 if (macroId
== ltVERBATIM
)
2298 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\s10\\fs20\\li720\\sa0 "));
2300 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\fs20 "));
2306 if (macroId
== ltVERBATIM
)
2308 TexOutput(_T("\\pard\n"));
2309 WriteEnvironmentStyles();
2312 TexOutput(_T("\\par\n"));
2313 issuedNewParagraph
= 1;
2324 TexOutput(_T("\\qc "));
2326 PushEnvironmentStyle(_T("\\qc\\sa200"));
2330 TexOutput(_T("\\par\\pard\n"));
2331 issuedNewParagraph
= 1;
2333 PopEnvironmentStyle();
2334 WriteEnvironmentStyles();
2342 TexOutput(_T("\\ql\\sa200 "));
2344 PushEnvironmentStyle(_T("\\ql"));
2348 TexOutput(_T("\\par\\pard\n"));
2349 issuedNewParagraph
= 1;
2351 PopEnvironmentStyle();
2352 WriteEnvironmentStyles();
2360 TexOutput(_T("\\qr\\sa200 "));
2362 PushEnvironmentStyle(_T("\\qr"));
2366 TexOutput(_T("\\par\\pard\n"));
2367 issuedNewParagraph
= 1;
2369 PopEnvironmentStyle();
2370 WriteEnvironmentStyles();
2375 case ltFOOTNOTESIZE
:
2379 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), smallFont
*2);
2382 else TexOutput(_T("}\n"));
2390 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), tinyFont
*2);
2393 else TexOutput(_T("}\n"));
2400 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), normalFont
*2);
2403 else TexOutput(_T("}\n"));
2410 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), largeFont1
*2);
2413 else TexOutput(_T("}\n"));
2420 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LargeFont2
*2);
2423 else TexOutput(_T("}\n"));
2430 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LARGEFont3
*2);
2433 else TexOutput(_T("}\n"));
2440 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), hugeFont1
*2);
2443 else TexOutput(_T("}\n"));
2450 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HugeFont2
*2);
2453 else TexOutput(_T("}\n"));
2460 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HUGEFont3
*2);
2463 else TexOutput(_T("}\n"));
2472 TexOutput(_T("{\\b "));
2474 else TexOutput(_T("}"));
2481 TexOutput(_T("{\\ul "));
2483 else TexOutput(_T("}"));
2494 TexOutput(_T("{\\i "));
2496 else TexOutput(_T("}"));
2499 // Roman font: do nothing. Should really switch between
2508 TexOutput(_T("{\\plain "));
2510 else TexOutput(_T("}"));
2514 // Medium-weight font. Unbolden...
2519 TexOutput(_T("{\\b0 "));
2521 else TexOutput(_T("}"));
2524 // Upright (un-italic or slant)
2529 TexOutput(_T("{\\i0 "));
2531 else TexOutput(_T("}"));
2540 TexOutput(_T("{\\scaps "));
2542 else TexOutput(_T("}"));
2551 TexOutput(_T("{\\f3 "));
2553 else TexOutput(_T("}"));
2559 TexOutput(_T("\\{"));
2565 TexOutput(_T("\\}"));
2571 TexOutput(_T("\\\\"));
2578 if ( issuedNewParagraph
== 0 )
2580 TexOutput(_T("\\par\\pard"));
2581 issuedNewParagraph
++;
2583 // Extra par if parskip is more than zero (usually looks best.)
2584 // N.B. JACS 2004-02-21: shouldn't need this for linear RTF if
2585 // we have a suitable set of styles.
2587 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2589 TexOutput(_T("\\par"));
2590 issuedNewParagraph
++;
2593 WriteEnvironmentStyles();
2595 // 1 is a whole paragraph if ParSkip == 0,
2596 // half a paragraph if ParSkip > 0
2597 else if ( issuedNewParagraph
== 1 )
2599 // Don't need a par at all if we've already had one,
2600 // and ParSkip == 0.
2602 // Extra par if parskip is more than zero (usually looks best.)
2603 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2605 TexOutput(_T("\\par"));
2606 issuedNewParagraph
++;
2609 WriteEnvironmentStyles();
2612 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2614 TexOutput(_T("\\par\\pard"));
2616 // Extra par if parskip is more than zero (usually looks best.)
2617 if (!inTabular && (ParSkip > 0))
2618 TexOutput(_T("\\par"));
2619 WriteEnvironmentStyles();
2623 TexOutput(_T("\n"));
2629 // In Windows Help, no newpages until we've started some chapters or sections
2630 if (!(winHelp
&& !startedSections
))
2632 TexOutput(_T("\\page\n"));
2637 if (start
&& DocumentTitle
)
2639 TexOutput(_T("\\par\\pard"));
2641 TexOutput(_T("\\par"));
2642 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d\\b "), titleFont
*2);
2644 TraverseChildrenFromChunk(DocumentTitle
);
2645 TexOutput(_T("}\\par\\pard\n"));
2650 TexOutput(_T("\\par"));
2651 wxSnprintf(buf
, sizeof(buf
), _T("\\par\\qc{\\fs%d "), authorFont
*2);
2653 TraverseChildrenFromChunk(DocumentAuthor
);
2655 TexOutput(_T("\\par\\pard\n"));
2659 TexOutput(_T("\\par"));
2660 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d "), authorFont
*2);
2662 TraverseChildrenFromChunk(DocumentDate
);
2663 TexOutput(_T("}\\par\\pard\n"));
2665 // If linear RTF, we want this titlepage to be in a separate
2666 // section with its own (blank) header and footer
2667 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2669 TexOutput(_T("{\\header }{\\footer }\n"));
2670 // Not sure about this: we get too many sections.
2671 // TexOutput(_T("\\sect"));
2676 case ltADDCONTENTSLINE
:
2680 if (contentsLineSection
&& contentsLineValue
)
2682 if (wxStrcmp(contentsLineSection
, _T("chapter")) == 0)
2684 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2686 else if (wxStrcmp(contentsLineSection
, _T("section")) == 0)
2688 if (DocumentStyle
!= LATEX_ARTICLE
)
2689 wxFprintf(Contents
, _T("\n\\tab%s\\par\n"), contentsLineValue
);
2691 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2701 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2702 issuedNewParagraph
= 1;
2703 WriteEnvironmentStyles();
2711 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2712 issuedNewParagraph
= 1;
2713 WriteEnvironmentStyles();
2723 case ltNUMBEREDBIBITEM
:
2726 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
2728 TexOutput(_T("\\par\\pard\\par\n\n"));
2735 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2743 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2744 wxSnprintf(buf
, sizeof(buf
), _T("%d"), chapterNo
);
2753 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2754 wxSnprintf(buf
, sizeof(buf
), _T("%d"), sectionNo
);
2761 if (!start
&& !winHelp
)
2763 TexOutput(_T("\\cols2\n"));
2769 if (!start
&& !winHelp
)
2771 TexOutput(_T("\\cols1\n"));
2777 if (start
&& useWord
&& !winHelp
)
2779 FakeCurrentSection(_T("Index"));
2780 OnMacro(ltPAR
, 0, true);
2781 OnMacro(ltPAR
, 0, false);
2782 TexOutput(_T("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n"));
2786 case ltLISTOFFIGURES
:
2788 if (start
&& useWord
&& !winHelp
)
2790 FakeCurrentSection(FiguresNameString
, false);
2791 OnMacro(ltPAR
, 0, true);
2792 OnMacro(ltPAR
, 0, false);
2793 OnMacro(ltPAR
, 0, true);
2794 OnMacro(ltPAR
, 0, false);
2796 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"),
2802 case ltLISTOFTABLES
:
2804 if (start
&& useWord
&& !winHelp
)
2806 FakeCurrentSection(TablesNameString
, false);
2807 OnMacro(ltPAR
, 0, true);
2808 OnMacro(ltPAR
, 0, false);
2809 OnMacro(ltPAR
, 0, true);
2810 OnMacro(ltPAR
, 0, false);
2812 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"),
2820 if (start
) TexOutput(_T("{\\f1\\'61}"));
2823 if (start
) TexOutput(_T("{\\f1\\'62}"));
2826 if (start
) TexOutput(_T("{\\f1\\'63}"));
2829 if (start
) TexOutput(_T("{\\f1\\'64}"));
2833 if (start
) TexOutput(_T("{\\f1\\'65}"));
2836 if (start
) TexOutput(_T("{\\f1\\'7A}"));
2839 if (start
) TexOutput(_T("{\\f1\\'68}"));
2843 if (start
) TexOutput(_T("{\\f1\\'71}"));
2846 if (start
) TexOutput(_T("{\\f1\\'69}"));
2849 if (start
) TexOutput(_T("{\\f1\\'6B}"));
2852 if (start
) TexOutput(_T("{\\f1\\'6C}"));
2855 if (start
) TexOutput(_T("{\\f1\\'6D}"));
2858 if (start
) TexOutput(_T("{\\f1\\'6E}"));
2861 if (start
) TexOutput(_T("{\\f1\\'78}"));
2864 if (start
) TexOutput(_T("{\\f1\\'70}"));
2867 if (start
) TexOutput(_T("{\\f1\\'76}"));
2871 if (start
) TexOutput(_T("{\\f1\\'72}"));
2874 if (start
) TexOutput(_T("{\\f1\\'73}"));
2877 if (start
) TexOutput(_T("{\\f1\\'56}"));
2880 if (start
) TexOutput(_T("{\\f1\\'74}"));
2883 if (start
) TexOutput(_T("{\\f1\\'75}"));
2887 if (start
) TexOutput(_T("{\\f1\\'66}"));
2890 if (start
) TexOutput(_T("{\\f1\\'63}"));
2893 if (start
) TexOutput(_T("{\\f1\\'79}"));
2896 if (start
) TexOutput(_T("{\\f1\\'77}"));
2899 if (start
) TexOutput(_T("{\\f1\\'47}"));
2902 if (start
) TexOutput(_T("{\\f1\\'44}"));
2905 if (start
) TexOutput(_T("{\\f1\\'51}"));
2908 if (start
) TexOutput(_T("{\\f1\\'4C}"));
2911 if (start
) TexOutput(_T("{\\f1\\'58}"));
2914 if (start
) TexOutput(_T("{\\f1\\'50}"));
2917 if (start
) TexOutput(_T("{\\f1\\'53}"));
2920 if (start
) TexOutput(_T("{\\f1\\'54}"));
2923 if (start
) TexOutput(_T("{\\f1\\'46}"));
2926 if (start
) TexOutput(_T("{\\f1\\'59}"));
2929 if (start
) TexOutput(_T("{\\f1\\'57}"));
2931 // Binary operation symbols
2934 if (start
) TexOutput(_T("{\\f1\\'A3}"));
2937 if (start
) TexOutput(_T("<<"));
2940 if (start
) TexOutput(_T("{\\f1\\'CC}"));
2943 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2946 if (start
) TexOutput(_T("{\\f1\\'CE}"));
2950 if (start
) TexOutput(_T("{\\f1\\'B3}"));
2953 if (start
) TexOutput(_T(">>"));
2956 if (start
) TexOutput(_T("{\\f1\\'C9}"));
2959 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2962 if (start
) TexOutput(_T("{\\f1\\'27}"));
2965 if (start
) TexOutput(_T("{\\f1\\'5E}"));
2968 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2971 if (start
) TexOutput(_T("{\\f1\\'BB}"));
2974 if (start
) TexOutput(_T("{\\f1\\'40}"));
2977 if (start
) TexOutput(_T("{\\f1\\'BA}"));
2980 if (start
) TexOutput(_T("{\\f1\\'B5}"));
2983 if (start
) TexOutput(_T("{\\f1\\'7E}"));
2986 if (start
) TexOutput(_T("{\\f4\\'4A}"));
2989 if (start
) TexOutput(_T("{\\f4\\'4C}"));
2992 if (start
) TexOutput(_T("|"));
2995 // Negated relation symbols
2997 if (start
) TexOutput(_T("{\\f1\\'B9}"));
3000 if (start
) TexOutput(_T("{\\f1\\'CF}"));
3003 if (start
) TexOutput(_T("{\\f1\\'CB}"));
3008 if (start
) TexOutput(_T("{\\f1\\'AC}"));
3011 if (start
) TexOutput(_T("{\\f1\\'DC}"));
3014 if (start
) TexOutput(_T("{\\f1\\'AE}"));
3017 if (start
) TexOutput(_T("{\\f1\\'DE}"));
3019 case ltLEFTRIGHTARROW
:
3020 if (start
) TexOutput(_T("{\\f1\\'AB}"));
3022 case ltLEFTRIGHTARROW2
:
3023 if (start
) TexOutput(_T("{\\f1\\'DB}"));
3026 if (start
) TexOutput(_T("{\\f1\\'AD}"));
3029 if (start
) TexOutput(_T("{\\f1\\'DD}"));
3032 if (start
) TexOutput(_T("{\\f1\\'AF}"));
3035 if (start
) TexOutput(_T("{\\f1\\'DF}"));
3038 // Miscellaneous symbols
3040 if (start
) TexOutput(_T("{\\f1\\'CO}"));
3043 if (start
) TexOutput(_T("{\\f1\\'C3}"));
3046 if (start
) TexOutput(_T("{\\f1\\'C2}"));
3049 if (start
) TexOutput(_T("{\\f1\\'C1}"));
3052 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3055 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3058 if (start
) TexOutput(_T("{\\f1\\'D6}"));
3061 if (start
) TexOutput(_T("{\\f1\\'B6}"));
3064 if (start
) TexOutput(_T("{\\f1\\'5E}"));
3067 if (start
) TexOutput(_T("{\\f1\\'22}"));
3070 if (start
) TexOutput(_T("{\\f1\\'24}"));
3073 if (start
) TexOutput(_T("{\\f1\\'D8}"));
3076 if (start
) TexOutput(_T("{\\f1\\'23}"));
3079 if (start
) TexOutput(_T("{\\f1\\'D0}"));
3082 if (start
) TexOutput(_T("{\\f5\\'73}"));
3085 if (start
) TexOutput(_T("{\\f5\\'A8}"));
3088 if (start
) TexOutput(_T("{\\f5\\'A9}"));
3091 if (start
) TexOutput(_T("{\\f5\\'AA}"));
3094 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3097 if (start
) TexOutput(_T("{\\f1\\'A5}"));
3100 if (start
) TexOutput(_T("{\\f0\\'A9}"));
3103 if (start
) TexOutput(_T("{\\f0\\'AE}"));
3106 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3109 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3112 if (start
) TexOutput(_T("{\\f1\\'B4}"));
3115 if (start
) TexOutput(_T("{\\f1\\'B8}"));
3118 if (start
) TexOutput(_T("{\\f1\\'D7}"));
3121 if (start
) TexOutput(_T("{\\f1\\'2A}"));
3124 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3127 if (start
) TexOutput(_T("{\\f1\\'C7}"));
3130 if (start
) TexOutput(_T("{\\f1\\'C8}"));
3133 if (start
) TexOutput(_T("{\\f1\\'DA}"));
3136 if (start
) TexOutput(_T("{\\f1\\'D9}"));
3139 if (start
) TexOutput(_T("{\\f1\\'B0}"));
3142 if (start
) TexOutput(_T("{\\f1\\'B7}"));
3145 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3148 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3151 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3153 case ltBIGTRIANGLEDOWN
:
3154 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3157 if (start
) TexOutput(_T("{\\f1\\'C5}"));
3160 if (start
) TexOutput(_T("{\\f1\\'C4}"));
3163 if (start
) TexOutput(_T("{\\'DF}"));
3167 if (start
) inFigure
= true;
3168 else inFigure
= false;
3173 if (start
) inTable
= true;
3174 else inTable
= false;
3179 DefaultOnMacro(macroId
, no_args
, start
);
3185 // Called on start/end of argument examination
3186 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3193 case ltCHAPTERHEADING
:
3196 case ltSECTIONHEADING
:
3198 case ltSUBSECTIONSTAR
:
3199 case ltSUBSUBSECTION
:
3200 case ltSUBSUBSECTIONSTAR
:
3202 case ltMEMBERSECTION
:
3203 case ltFUNCTIONSECTION
:
3207 if (!start
&& (arg_no
== 1))
3208 currentSection
= GetArgChunk();
3213 if (start
&& (arg_no
== 1))
3214 TexOutput(_T("\\pard\\li600\\fi-600{\\b "));
3216 if (!start
&& (arg_no
== 1))
3217 TexOutput(_T("} "));
3219 if (start
&& (arg_no
== 2))
3221 if (!suppressNameDecoration
) TexOutput(_T("{\\b "));
3222 currentMember
= GetArgChunk();
3224 if (!start
&& (arg_no
== 2))
3226 if (!suppressNameDecoration
) TexOutput(_T("}"));
3229 if (start
&& (arg_no
== 3))
3231 if (!start
&& (arg_no
== 3))
3233 // TexOutput(_T(")\\li0\\fi0"));
3234 // TexOutput(_T(")\\par\\pard\\li0\\fi0"));
3235 // issuedNewParagraph = 1;
3237 WriteEnvironmentStyles();
3243 if (start
&& (arg_no
== 1))
3244 TexOutput(_T("\\pard\\li260\\fi-260{\\b "));
3245 if (!start
&& (arg_no
== 1))
3246 TexOutput(_T("} "));
3248 if (start
&& (arg_no
== 2))
3250 if (!suppressNameDecoration
) TexOutput(_T("({\\b "));
3251 currentMember
= GetArgChunk();
3253 if (!start
&& (arg_no
== 2))
3255 if (!suppressNameDecoration
) TexOutput(_T("}"));
3258 if (!start
&& (arg_no
== 3))
3260 TexOutput(_T(")\\li0\\fi0"));
3261 WriteEnvironmentStyles();
3267 if (start
&& (arg_no
== 1))
3268 TexOutput(_T("\\pard\\li260\\fi-260"));
3270 if (!start
&& (arg_no
== 1))
3273 if (start
&& (arg_no
== 2))
3274 TexOutput(_T("(*"));
3275 if (!start
&& (arg_no
== 2))
3278 if (start
&& (arg_no
== 2))
3279 currentMember
= GetArgChunk();
3281 if (start
&& (arg_no
== 3))
3283 if (!start
&& (arg_no
== 3))
3285 TexOutput(_T(")\\li0\\fi0"));
3286 WriteEnvironmentStyles();
3292 if (start
&& (arg_no
== 1))
3293 TexOutput(_T("{\\b "));
3294 if (!start
&& (arg_no
== 1))
3296 if (start
&& (arg_no
== 2))
3298 TexOutput(_T("{\\i "));
3300 if (!start
&& (arg_no
== 2))
3308 if (start
&& (arg_no
== 1))
3309 TexOutput(_T("{\\b "));
3310 if (!start
&& (arg_no
== 1))
3311 TexOutput(_T("} ")); // This is the difference from param - one space!
3312 if (start
&& (arg_no
== 2))
3314 TexOutput(_T("{\\i "));
3316 if (!start
&& (arg_no
== 2))
3324 if (!start
&& (arg_no
== 1))
3327 if (start
&& (arg_no
== 2))
3328 currentMember
= GetArgChunk();
3337 wxChar
*refName
= GetArgData();
3338 if (winHelp
|| !useWord
)
3342 TexRef
*texRef
= FindReference(refName
);
3345 sec
= texRef
->sectionNumber
;
3355 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
3367 if ((GetNoArgs() - arg_no
) == 1)
3370 TexOutput(_T("{\\uldb "));
3374 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3378 TexOutput(_T("{\\v "));
3380 // Remove green colour/underlining if specified
3381 if (!hotSpotUnderline
&& !hotSpotColour
)
3383 else if (!hotSpotColour
)
3386 else TexOutput(_T("}"));
3389 else // If a linear document, must resolve the references ourselves
3391 if ((GetNoArgs() - arg_no
) == 1)
3393 // In a linear document we display the anchor text in italic plus
3396 TexOutput(_T("{\\i "));
3401 helpRefText
= GetArgChunk();
3405 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3407 if (macroId
!= ltHELPREFN
)
3409 wxChar
*refName
= GetArgData();
3410 TexRef
*texRef
= NULL
;
3412 texRef
= FindReference(refName
);
3415 if (texRef
|| !ignoreBadRefs
)
3416 TexOutput(_T(" ("));
3419 if (texRef
|| !ignoreBadRefs
)
3423 TexOutput(_T("p. "));
3424 TexOutput(_T("{\\field{\\*\\fldinst PAGEREF "));
3426 TexOutput(_T(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"));
3430 // Only print section name if we're not in Word mode,
3431 // so can't do page references
3434 TexOutput(texRef
->sectionName
);
3436 TexOutput(texRef
->sectionNumber
);
3441 TexOutput(_T("??"));
3442 wxSnprintf(buf
, sizeof(buf
), _T("Warning: unresolved reference '%s'"), refName
);
3448 else TexOutput(_T("??"));
3452 if (texRef
|| !ignoreBadRefs
)
3467 else if (arg_no
== 2)
3472 TexOutput(_T(" ({\\f3 "));
3476 TexOutput(_T("})"));
3487 if ((GetNoArgs() - arg_no
) == 1)
3490 TexOutput(_T("{\\ul "));
3494 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3498 TexOutput(_T("{\\v "));
3500 // Remove green colour/underlining if specified
3501 if (!hotSpotUnderline
&& !hotSpotColour
)
3503 else if (!hotSpotColour
)
3506 else TexOutput(_T("}"));
3509 else // A linear document...
3511 if ((GetNoArgs() - arg_no
) == 1)
3513 // In a linear document we just display the anchor text in italic
3515 TexOutput(_T("{\\i "));
3524 case ltADDCONTENTSLINE
:
3526 if (start
&& !winHelp
)
3529 contentsLineSection
= copystring(GetArgData());
3530 else if (arg_no
== 3)
3531 contentsLineValue
= copystring(GetArgData());
3545 static int imageWidth
= 0;
3546 static int imageHeight
= 0;
3548 if (start
&& (arg_no
== 1))
3550 wxChar
*imageDimensions
= copystring(GetArgData());
3552 // imageWidth - Convert points to TWIPS (1 twip = 1/20th of point)
3553 wxStringTokenizer
tok(imageDimensions
, _T(";:"), wxTOKEN_STRTOK
);
3554 if(tok
.HasMoreTokens())
3556 wxString token
= tok
.GetNextToken();
3557 imageWidth
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3564 // imageHeight - Convert points to TWIPS (1 twip = 1/20th of point)
3565 if(tok
.HasMoreTokens())
3567 wxString token
= tok
.GetNextToken();
3568 imageHeight
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3575 if (imageDimensions
) // glt
3576 delete [] imageDimensions
;
3579 else if (start
&& (arg_no
== 2 ))
3581 wxChar
*filename
= copystring(GetArgData());
3582 wxString f
= _T("");
3583 if ((winHelp
|| (wxStrcmp(bitmapMethod
, _T("includepicture")) == 0) || (wxStrcmp(bitmapMethod
, _T("import")) == 0)) && useWord
)
3585 if (f
== _T("")) // Try for a .shg (segmented hypergraphics file)
3587 wxStrcpy(buf
, filename
);
3588 StripExtension(buf
);
3589 wxStrcat(buf
, _T(".shg"));
3590 f
= TexPathList
.FindValidPath(buf
);
3592 if (f
== _T("")) // Try for a .bmp
3594 wxStrcpy(buf
, filename
);
3595 StripExtension(buf
);
3596 wxStrcat(buf
, _T(".bmp"));
3597 f
= TexPathList
.FindValidPath(buf
);
3599 if (f
== _T("")) // Try for a metafile instead
3601 wxStrcpy(buf
, filename
);
3602 StripExtension(buf
);
3603 wxStrcat(buf
, _T(".wmf"));
3604 f
= TexPathList
.FindValidPath(buf
);
3610 if (bitmapTransparency
&& (winHelpVersion
> 3))
3611 TexOutput(_T("\\{bmct "));
3613 TexOutput(_T("\\{bmc "));
3614 wxString str
= wxFileNameFromPath(f
);
3615 TexOutput((wxChar
*) (const wxChar
*) str
);
3616 TexOutput(_T("\\}"));
3620 // Microsoft Word method
3621 if (wxStrcmp(bitmapMethod
, _T("import")) == 0)
3622 TexOutput(_T("{\\field{\\*\\fldinst IMPORT "));
3624 TexOutput(_T("{\\field{\\*\\fldinst INCLUDEPICTURE "));
3626 // Full path appears not to be valid!
3627 wxString str
= wxFileNameFromPath(f
);
3628 TexOutput((wxChar
*)(const wxChar
*) str
);
3630 int len = wxStrlen(f);
3631 wxChar smallBuf[2]; smallBuf[1] = 0;
3632 for (int i = 0; i < len; i++)
3635 TexOutput(smallBuf);
3636 if (smallBuf[0] == '\\')
3637 TexOutput(smallBuf);
3640 TexOutput(_T("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}"));
3645 TexOutput(_T("[No BMP or WMF for image file "));
3646 TexOutput(filename
);
3648 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3651 if (filename
) // glt
3656 if (f
== _T("")) // Try for a .bmp
3658 wxStrcpy(buf
, filename
);
3659 StripExtension(buf
);
3660 wxStrcat(buf
, _T(".bmp"));
3661 f
= TexPathList
.FindValidPath(buf
);
3665 FILE *fd
= wxFopen(f
, _T("rb"));
3666 if (OutputBitmapHeader(fd
, winHelp
))
3667 OutputBitmapData(fd
);
3670 wxSnprintf(buf
, sizeof(buf
), _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f
.c_str());
3675 else // Try for a metafile instead
3678 wxStrcpy(buf
, filename
);
3679 StripExtension(buf
);
3680 wxStrcat(buf
, _T(".wmf"));
3681 f
= TexPathList
.FindValidPath(buf
);
3684 // HFILE handle = _lopen(f, READ);
3685 FILE *fd
= wxFopen(f
, _T("rb"));
3686 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3688 OutputMetafileData(fd
);
3692 wxSnprintf(buf
, sizeof(buf
), _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f
.c_str());
3700 TexOutput(_T("[No BMP or WMF for image file "));
3701 TexOutput(filename
);
3703 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3716 case ltSUPERTABULAR
:
3722 currentRowNumber
= 0;
3725 tableVerticalLineLeft
= false;
3726 tableVerticalLineRight
= false;
3727 int currentWidth
= 0;
3729 wxChar
*alignString
= copystring(GetArgData());
3730 ParseTableArgument(alignString
);
3732 // TexOutput(_T("\\trowd\\trgaph108\\trleft-108"));
3733 TexOutput(_T("\\trowd\\trgaph108"));
3735 // Write the first row formatting for compatibility
3736 // with standard Latex
3737 if (compatibilityMode
)
3739 for (int i
= 0; i
< noColumns
; i
++)
3741 currentWidth
+= TableData
[i
].width
;
3742 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
3745 TexOutput(_T("\\pard\\intbl\n"));
3747 delete[] alignString
;
3752 else if (arg_no
== 2 && !start
)
3754 TexOutput(_T("\\pard\n"));
3755 WriteEnvironmentStyles();
3766 TexOutput(_T("\\li360\n"));
3768 PushEnvironmentStyle(_T("\\li360\\sa200"));
3773 PopEnvironmentStyle();
3774 OnMacro(ltPAR
, 0, true);
3775 OnMacro(ltPAR
, 0, false);
3783 TexOutput(_T("\\li360\n"));
3784 PushEnvironmentStyle(_T("\\li360\\sa200"));
3788 PopEnvironmentStyle();
3789 OnMacro(ltPAR
, 0, true);
3790 OnMacro(ltPAR
, 0, false);
3802 wxSnprintf(buf
, sizeof(buf
), _T("\\sa200\\box\\trgaph108%s\n"), ((macroId
== ltNORMALBOXD
) ? _T("\\brdrdb") : _T("\\brdrs")));
3804 PushEnvironmentStyle(buf
);
3808 PopEnvironmentStyle();
3809 OnMacro(ltPAR
, 0, true);
3810 OnMacro(ltPAR
, 0, false);
3814 case ltHELPFONTSIZE
:
3818 wxChar
*data
= GetArgData();
3819 if (wxStrcmp(data
, _T("10")) == 0)
3821 else if (wxStrcmp(data
, _T("11")) == 0)
3823 else if (wxStrcmp(data
, _T("12")) == 0)
3825 wxSnprintf(buf
, sizeof(buf
), _T("\\fs%d\n"), normalFont
*2);
3832 case ltHELPFONTFAMILY
:
3836 wxChar
*data
= GetArgData();
3837 if (wxStrcmp(data
, _T("Swiss")) == 0)
3838 TexOutput(_T("\\f2\n"));
3839 else if (wxStrcmp(data
, _T("Symbol")) == 0)
3840 TexOutput(_T("\\f1\n"));
3841 else if (wxStrcmp(data
, _T("Times")) == 0)
3842 TexOutput(_T("\\f0\n"));
3850 if (start
&& arg_no
== 1)
3852 wxChar
*data
= GetArgData();
3853 ParIndent
= ParseUnitArgument(data
);
3854 if (ParIndent
== 0 || forbidParindent
== 0)
3856 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d\n"), ParIndent
*20);
3865 if (start
&& IsArgOptional())
3867 descriptionItemArg
= GetArgChunk();
3873 case ltTWOCOLITEMRULED
:
3880 TexOutput(_T("\\tab "));
3887 if (macroId
== ltTWOCOLITEMRULED
)
3888 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
3889 TexOutput(_T("\\par\\pard\n"));
3890 issuedNewParagraph
= 1;
3891 WriteEnvironmentStyles();
3902 case ltACCENT_GRAVE
:
3906 wxChar
*val
= GetArgData();
3912 TexOutput(_T("\\'e0"));
3915 TexOutput(_T("\\'e8"));
3918 TexOutput(_T("\\'ec"));
3921 TexOutput(_T("\\'f2"));
3924 TexOutput(_T("\\'f9"));
3927 TexOutput(_T("\\'c0"));
3930 TexOutput(_T("\\'c8"));
3933 TexOutput(_T("\\'cc"));
3936 TexOutput(_T("\\'d2"));
3939 TexOutput(_T("\\'d9"));
3948 case ltACCENT_ACUTE
:
3952 wxChar
*val
= GetArgData();
3958 TexOutput(_T("\\'e1"));
3961 TexOutput(_T("\\'e9"));
3964 TexOutput(_T("\\'ed"));
3967 TexOutput(_T("\\'f3"));
3970 TexOutput(_T("\\'fa"));
3973 TexOutput(_T("\\'fd"));
3976 TexOutput(_T("\\'c1"));
3979 TexOutput(_T("\\'c9"));
3982 TexOutput(_T("\\'cd"));
3985 TexOutput(_T("\\'d3"));
3988 TexOutput(_T("\\'da"));
3991 TexOutput(_T("\\'dd"));
4000 case ltACCENT_CARET
:
4004 wxChar
*val
= GetArgData();
4010 TexOutput(_T("\\'e2"));
4013 TexOutput(_T("\\'ea"));
4016 TexOutput(_T("\\'ee"));
4019 TexOutput(_T("\\'f4"));
4022 TexOutput(_T("\\'fb"));
4025 TexOutput(_T("\\'c2"));
4028 TexOutput(_T("\\'ca"));
4031 TexOutput(_T("\\'ce"));
4034 TexOutput(_T("\\'d4"));
4037 TexOutput(_T("\\'db"));
4046 case ltACCENT_TILDE
:
4050 wxChar
*val
= GetArgData();
4056 TexOutput(_T("\\'e3"));
4062 TexOutput(_T("\\'f1"));
4065 TexOutput(_T("\\'f5"));
4068 TexOutput(_T("\\'c3"));
4071 TexOutput(_T("\\'d1"));
4074 TexOutput(_T("\\'d5"));
4083 case ltACCENT_UMLAUT
:
4087 wxChar
*val
= GetArgData();
4093 TexOutput(_T("\\'e4"));
4096 TexOutput(_T("\\'eb"));
4099 TexOutput(_T("\\'ef"));
4102 TexOutput(_T("\\'f6"));
4105 TexOutput(_T("\\'fc"));
4108 TexOutput(_T("\\'df"));
4111 TexOutput(_T("\\'ff"));
4114 TexOutput(_T("\\'c4"));
4117 TexOutput(_T("\\'cb"));
4120 TexOutput(_T("\\'cf"));
4123 TexOutput(_T("\\'d6"));
4126 TexOutput(_T("\\'dc"));
4129 TexOutput(_T("\\'df"));
4142 wxChar
*val
= GetArgData();
4148 TexOutput(_T("\\'e5"));
4151 TexOutput(_T("\\'c5"));
4160 case ltACCENT_CADILLA
:
4164 wxChar
*val
= GetArgData();
4170 TexOutput(_T("\\'e7"));
4173 TexOutput(_T("\\'c7"));
4184 static wxChar
*helpTopic
= NULL
;
4185 static FILE *savedOutput
= NULL
;
4192 OnInform(_T("Consider using \\footnotepopup instead of \\footnote."));
4195 wxSnprintf(footBuf
, sizeof(footBuf
), _T("(%d)"), footnoteCount
);
4197 TexOutput(_T(" {\\ul "));
4200 helpTopic
= FindTopicName(NULL
);
4201 TexOutput(_T("{\\v "));
4203 // Remove green colour/underlining if specified
4204 if (!hotSpotUnderline
&& !hotSpotColour
)
4206 else if (!hotSpotColour
)
4209 TexOutput(helpTopic
);
4212 wxFprintf(Popups
, _T("\\page\n"));
4213 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4214 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4215 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4216 savedOutput
= CurrentOutput1
;
4217 SetCurrentOutput(Popups
);
4221 SetCurrentOutput(savedOutput
);
4231 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4235 TexOutput(_T("}}"), true);
4240 case ltFOOTNOTEPOPUP
:
4242 static wxChar
*helpTopic
= NULL
;
4243 static FILE *savedOutput
= NULL
;
4250 TexOutput(_T("{\\ul "));
4258 else if (arg_no
== 2)
4262 helpTopic
= FindTopicName(NULL
);
4263 TexOutput(_T("{\\v "));
4265 // Remove green colour/underlining if specified
4266 if (!hotSpotUnderline
&& !hotSpotColour
)
4268 else if (!hotSpotColour
)
4271 TexOutput(helpTopic
);
4274 wxFprintf(Popups
, _T("\\page\n"));
4275 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4276 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4277 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4278 savedOutput
= CurrentOutput1
;
4279 SetCurrentOutput(Popups
);
4283 SetCurrentOutput(savedOutput
);
4294 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4298 TexOutput(_T("}}"), true);
4306 if (start
&& (arg_no
== 1))
4318 if (winHelp
) return false;
4324 LeftHeaderEven
= GetArgChunk();
4325 if (wxStrlen(GetArgData(LeftHeaderEven
)) == 0)
4326 LeftHeaderEven
= NULL
;
4329 CentreHeaderEven
= GetArgChunk();
4330 if (wxStrlen(GetArgData(CentreHeaderEven
)) == 0)
4331 CentreHeaderEven
= NULL
;
4334 RightHeaderEven
= GetArgChunk();
4335 if (wxStrlen(GetArgData(RightHeaderEven
)) == 0)
4336 RightHeaderEven
= NULL
;
4339 LeftHeaderOdd
= GetArgChunk();
4340 if (wxStrlen(GetArgData(LeftHeaderOdd
)) == 0)
4341 LeftHeaderOdd
= NULL
;
4344 CentreHeaderOdd
= GetArgChunk();
4345 if (wxStrlen(GetArgData(CentreHeaderOdd
)) == 0)
4346 CentreHeaderOdd
= NULL
;
4349 RightHeaderOdd
= GetArgChunk();
4350 if (wxStrlen(GetArgData(RightHeaderOdd
)) == 0)
4351 RightHeaderOdd
= NULL
;
4352 OutputRTFHeaderCommands();
4367 if (winHelp
) return false;
4373 LeftFooterEven
= GetArgChunk();
4374 if (wxStrlen(GetArgData(LeftFooterEven
)) == 0)
4375 LeftFooterEven
= NULL
;
4378 CentreFooterEven
= GetArgChunk();
4379 if (wxStrlen(GetArgData(CentreFooterEven
)) == 0)
4380 CentreFooterEven
= NULL
;
4383 RightFooterEven
= GetArgChunk();
4384 if (wxStrlen(GetArgData(RightFooterEven
)) == 0)
4385 RightFooterEven
= NULL
;
4388 LeftFooterOdd
= GetArgChunk();
4389 if (wxStrlen(GetArgData(LeftFooterOdd
)) == 0)
4390 LeftFooterOdd
= NULL
;
4393 CentreFooterOdd
= GetArgChunk();
4394 if (wxStrlen(GetArgData(CentreFooterOdd
)) == 0)
4395 CentreFooterOdd
= NULL
;
4398 RightFooterOdd
= GetArgChunk();
4399 if (wxStrlen(GetArgData(RightFooterOdd
)) == 0)
4400 RightFooterOdd
= NULL
;
4401 OutputRTFFooterCommands();
4411 if (winHelp
) return false;
4412 // Fake a SetHeader command
4415 LeftHeaderOdd
= NULL
;
4416 CentreHeaderOdd
= NULL
;
4417 RightHeaderOdd
= NULL
;
4418 LeftHeaderEven
= NULL
;
4419 CentreHeaderEven
= NULL
;
4420 RightHeaderEven
= NULL
;
4421 OnInform(_T("Consider using setheader/setfooter rather than markright."));
4423 RTFOnArgument(ltSETHEADER
, 4, start
);
4425 OutputRTFHeaderCommands();
4430 if (winHelp
) return false;
4431 // Fake a SetHeader command
4438 LeftHeaderOdd
= NULL
;
4439 CentreHeaderOdd
= NULL
;
4440 RightHeaderOdd
= NULL
;
4441 LeftHeaderEven
= NULL
;
4442 CentreHeaderEven
= NULL
;
4443 RightHeaderEven
= NULL
;
4444 OnInform(_T("Consider using setheader/setfooter rather than markboth."));
4446 return RTFOnArgument(ltSETHEADER
, 1, start
);
4450 RTFOnArgument(ltSETHEADER
, 4, start
);
4452 OutputRTFHeaderCommands();
4458 case ltPAGENUMBERING
:
4465 if (winHelp
) return false;
4468 TexOutput(_T("\\pgnrestart"));
4469 wxChar
*data
= GetArgData();
4470 if (currentNumberStyle
) delete[] currentNumberStyle
;
4471 currentNumberStyle
= copystring(data
);
4472 OutputNumberStyle(currentNumberStyle
);
4474 TexOutput(_T("\n"));
4480 if (winHelp
) return false;
4489 wxChar
*val
= GetArgData();
4490 currentItemSep
= ParseUnitArgument(val
);
4495 case ltEVENSIDEMARGIN
:
4499 case ltODDSIDEMARGIN
:
4503 wxChar
*val
= GetArgData();
4504 int twips
= (int)(20*ParseUnitArgument(val
));
4505 // Add an inch since in LaTeX it's specified minus an inch
4507 CurrentLeftMarginOdd
= twips
;
4508 wxSnprintf(buf
, sizeof(buf
), _T("\\margl%d\n"), twips
);
4511 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4515 case ltMARGINPARWIDTH
:
4519 wxChar
*val
= GetArgData();
4520 int twips
= (int)(20*ParseUnitArgument(val
));
4521 CurrentMarginParWidth
= twips
;
4525 case ltMARGINPARSEP
:
4529 wxChar
*val
= GetArgData();
4530 int twips
= (int)(20*ParseUnitArgument(val
));
4531 CurrentMarginParSep
= twips
;
4532 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4540 wxChar
*val
= GetArgData();
4541 int twips
= (int)(20*ParseUnitArgument(val
));
4542 CurrentTextWidth
= twips
;
4544 // Need to set an implicit right margin
4545 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4546 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4547 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4548 wxSnprintf(buf
, sizeof(buf
), _T("\\margr%d\n"), CurrentRightMarginOdd
);
4554 case ltMARGINPARODD
:
4560 TexOutput(_T("\\sa200\\box\n"));
4561 PushEnvironmentStyle(_T("\\sa200\\box"));
4565 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4574 TexOutput(_T("\\par\\pard\n"));
4575 PopEnvironmentStyle();
4576 WriteEnvironmentStyles();
4579 TexOutput(_T("\\par\\pard\n"));
4580 issuedNewParagraph
= 1;
4584 case ltMARGINPAREVEN
:
4590 TexOutput(_T("\\sa200\\box\n"));
4591 PushEnvironmentStyle(_T("\\sa200\\box"));
4597 // Have to calculate what the margins are changed to in WfW margin
4598 // mirror mode, on an even (left-hand) page.
4599 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4600 - CurrentTextWidth
+ GutterWidth
;
4601 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), x
, CurrentMarginParWidth
);
4606 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4616 TexOutput(_T("\\par\\pard\n"));
4617 PopEnvironmentStyle();
4618 WriteEnvironmentStyles();
4621 issuedNewParagraph
= 1;
4622 TexOutput(_T("\\par\\pard\n"));
4626 case ltTWOCOLWIDTHA
:
4630 wxChar
*val
= GetArgData();
4631 int twips
= (int)(20*ParseUnitArgument(val
));
4632 TwoColWidthA
= twips
;
4636 case ltTWOCOLWIDTHB
:
4640 wxChar
*val
= GetArgData();
4641 int twips
= (int)(20*ParseUnitArgument(val
));
4642 TwoColWidthB
= twips
;
4651 int currentWidth
= 0;
4653 if (!compatibilityMode
|| (currentRowNumber
> 0))
4655 TexOutput(_T("\\pard\\intbl"));
4657 if (macroId
== ltRULEDROW
)
4659 for (int i
= 0; i
< noColumns
; i
++)
4661 currentWidth
+= TableData
[i
].width
;
4664 TexOutput(_T("\\clbrdrt\\brdrs\\brdrw15"));
4666 else if (ruleTop
> 1)
4668 TexOutput(_T("\\clbrdrt\\brdrdb\\brdrw15"));
4670 if (ruleBottom
== 1)
4672 TexOutput(_T("\\clbrdrb\\brdrs\\brdrw15"));
4674 else if (ruleBottom
> 1)
4676 TexOutput(_T("\\clbrdrb\\brdrdb\\brdrw15"));
4679 if (TableData
[i
].rightBorder
)
4680 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
4682 if (TableData
[i
].leftBorder
)
4683 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
4685 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
4688 TexOutput(_T("\\pard\\intbl\n"));
4692 currentRowNumber
++;
4697 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
4698 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
4704 static int noMultiColumns
= 0;
4711 noMultiColumns
= wxAtoi(GetArgData());
4728 for (int i
= 1; i
< noMultiColumns
; i
++)
4729 TexOutput(_T("\\cell"));
4736 if (start
&& (arg_no
== 1))
4739 // TexOutput(_T("\\fi0\n"));
4741 wxNode
*node
= itemizeStack
.GetFirst();
4743 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
4745 int indentValue
= 20*ParseUnitArgument(GetArgData());
4746 int indentSize
= indentValue
+ oldIndent
;
4748 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4749 itemizeStack
.Insert(struc
);
4751 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200 "), indentSize
, indentSize
);
4752 PushEnvironmentStyle(buf
);
4756 if (!start
&& (arg_no
== 2))
4758 PopEnvironmentStyle();
4759 if (itemizeStack
.GetFirst())
4761 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
4763 delete itemizeStack
.GetFirst();
4765 if (itemizeStack
.GetCount() == 0)
4767 TexOutput(_T("\\par\\pard\n"));
4768 issuedNewParagraph
= 1;
4769 WriteEnvironmentStyles();
4778 if (start && (arg_no == 1))
4781 wxNode *node = itemizeStack.GetFirst();
4783 oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
4785 int boxWidth = 20*ParseUnitArgument(GetArgData());
4787 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4788 int indentSize = indentValue + oldIndent;
4789 int indentSizeRight = indentSize + boxWidth;
4791 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4792 itemizeStack.Insert(struc);
4794 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\lr%d\\sa200\\box%s "), indentSize, indentSize, indentSizeRight,
4795 ((macroId == ltCENTEREDBOX) ? _T("\\brdrs") : _T("\\brdrdb")));
4796 PushEnvironmentStyle(buf);
4800 if (!start && (arg_no == 2))
4802 PopEnvironmentStyle();
4803 if (itemizeStack.GetFirst())
4805 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
4807 delete itemizeStack.GetFirst();
4809 if (itemizeStack.Number() == 0)
4811 TexOutput(_T("\\par\\pard\n"));
4812 issuedNewParagraph = 1;
4813 WriteEnvironmentStyles();
4820 case ltDOCUMENTSTYLE
:
4822 DefaultOnArgument(macroId
, arg_no
, start
);
4823 if (!start
&& !IsArgOptional())
4825 if (MinorDocumentStyleString
)
4827 if (StringMatch(_T("twoside"), MinorDocumentStyleString
))
4828 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4829 TexOutput(_T("\\margmirror\\facingp\\sbkodd"));
4830 if (StringMatch(_T("twocolumn"), MinorDocumentStyleString
))
4831 TexOutput(_T("\\cols2"));
4833 TexOutput(_T("\n"));
4837 case ltSETHOTSPOTCOLOUR
:
4838 case ltSETHOTSPOTCOLOR
:
4842 wxChar
*text
= GetArgData();
4843 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4844 hotSpotColour
= true;
4846 hotSpotColour
= false;
4850 case ltSETTRANSPARENCY
:
4854 wxChar
*text
= GetArgData();
4855 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4856 bitmapTransparency
= true;
4858 bitmapTransparency
= false;
4862 case ltSETHOTSPOTUNDERLINE
:
4866 wxChar
*text
= GetArgData();
4867 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4868 hotSpotUnderline
= true;
4870 hotSpotUnderline
= false;
4876 if (arg_no
== 1 && start
)
4878 wxChar
*citeKey
= GetArgData();
4879 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4882 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4883 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
4884 ref
->sectionNumber
= copystring(buf
);
4887 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
4888 wxSnprintf(buf
, sizeof(buf
), _T("{\\b [%d]} "), citeCount
);
4893 if (arg_no
== 2 && !start
)
4894 TexOutput(_T("\\par\\pard\\par\n\n"));
4897 case ltTHEBIBLIOGRAPHY
:
4899 if (start
&& (arg_no
== 1))
4903 SetCurrentOutputs(Contents
, Chapters
);
4907 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
4909 // If a non-custom page style, we generate the header now.
4910 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
4911 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
4912 wxStrcmp(PageStyle
, _T("headings")) == 0))
4914 OutputRTFHeaderCommands();
4915 OutputRTFFooterCommands();
4918 // Need to reset the current numbering style, or RTF forgets it.
4919 OutputNumberStyle(currentNumberStyle
);
4920 SetCurrentOutput(Contents
);
4923 wxFprintf(Chapters
, _T("\\page\n"));
4926 wxFprintf(Contents
, _T("\n{\\uldb %s}"), ReferencesNameString
);
4928 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString
);
4930 startedSections
= true;
4933 wxFprintf(Chapters
, _T("\n${\\footnote %s}"), ReferencesNameString
);
4935 wxChar
*topicName
= _T("bibliography");
4939 wxFprintf(Contents
, _T("{\\v %s}\\par\\pard\n"), topicName
);
4940 WriteEnvironmentStyles();
4943 wxFprintf(Contents
, _T("\\par\\par\\pard\n"));
4947 wxFprintf(Chapters
, _T("\n#{\\footnote %s}\n"), topicName
);
4948 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
4949 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ReferencesNameString
);
4950 GenerateKeywordsForTopic(topicName
);
4953 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
4954 wxFileNameFromPath(FileRoot
), "Contents");
4958 SetCurrentOutput(Chapters
);
4959 wxChar
*styleCommand
= _T("");
4960 if (!winHelp
&& useHeadingStyles
)
4961 styleCommand
= _T("\\s1");
4962 wxFprintf(Chapters
, _T("\\pard{%s"), (winHelp
? _T("\\keepn\\sa140\\sb140") : styleCommand
));
4963 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" References\\par\\pard}\n"));
4972 * In Windows help, all keywords should be at the start of the
4973 * topic, but Latex \index commands can be anywhere in the text.
4974 * So we're going to have to build up lists of keywords for a topic,
4975 * and insert them on the second pass.
4977 * In linear RTF, we can embed the index entry now.
4982 // wxChar *entry = GetArgData();
4984 OutputChunkToString(GetArgChunk(), buf
);
4989 AddKeyWordForTopic(CurrentTopic
, buf
);
4992 else GenerateIndexEntry(buf
);
5005 wxChar
*name
= GetArgData();
5006 int pos
= FindColourPosition(name
);
5009 wxSnprintf(buf
, sizeof(buf
), _T("{%s%d "), ((macroId
== ltFCOL
) ? _T("\\cf") : _T("\\cb")), pos
);
5014 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
5029 if (arg_no
== 2) TexOutput(_T("}"));
5035 if (start
&& !winHelp
&& useWord
)
5037 wxChar
*s
= GetArgData();
5038 // Only insert a bookmark here if it's not just been inserted
5039 // in a section heading.
5040 if ( !CurrentTopic
|| !(wxStrcmp(CurrentTopic
, s
) == 0) )
5042 if ( (!CurrentChapterName || !(CurrentChapterName && (wxStrcmp(CurrentChapterName, s) == 0))) &&
5043 (!CurrentSectionName || !(CurrentSectionName && (wxStrcmp(CurrentSectionName, s) == 0))) &&
5044 (!CurrentSubsectionName || !(CurrentSubsectionName && (wxStrcmp(CurrentSubsectionName, s) == 0)))
5048 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s
,s
);
5055 if (start
&& useWord
&& !winHelp
)
5057 wxChar
*s
= GetArgData();
5058 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
5066 inPopRefSection
= true;
5068 inPopRefSection
= false;
5071 case ltINSERTATLEVEL
:
5073 // This macro allows you to insert text at a different level
5074 // from the current level, e.g. into the Sections from within a subsubsection.
5075 if (!winHelp
& useWord
)
5077 static int currentLevelNo
= 1;
5078 static FILE* oldLevelFile
= Chapters
;
5085 oldLevelFile
= CurrentOutput1
;
5087 wxChar
*str
= GetArgData();
5088 currentLevelNo
= wxAtoi(str
);
5090 // TODO: cope with article style (no chapters)
5091 switch (currentLevelNo
)
5095 outputFile
= Chapters
;
5100 outputFile
= Sections
;
5105 outputFile
= Subsections
;
5110 outputFile
= Subsubsections
;
5120 CurrentOutput1
= outputFile
;
5136 CurrentOutput1
= oldLevelFile
;
5142 return DefaultOnArgument(macroId
, arg_no
, start
);
5154 forbidParindent
= 0;
5155 contentsLineSection
= NULL
;
5156 contentsLineValue
= NULL
;
5157 descriptionItemArg
= NULL
;
5162 tableVerticalLineLeft
= false;
5163 tableVerticalLineRight
= false;
5165 startedSections
= false;
5169 if (!InputFile
.empty() && !OutputFile
.empty())
5171 // Do some RTF-specific transformations on all the strings,
5173 Text2RTF(GetTopLevelChunk());
5175 Contents
= wxFopen(TmpContentsName
, _T("w"));
5176 Chapters
= wxFopen(_T("chapters.rtf"), _T("w"));
5179 Sections
= wxFopen(_T("sections.rtf"), _T("w"));
5180 Subsections
= wxFopen(_T("subsections.rtf"), _T("w"));
5181 Subsubsections
= wxFopen(_T("subsubsections.rtf"), _T("w"));
5182 Popups
= wxFopen(_T("popups.rtf"), _T("w"));
5183 if (winHelpContents
)
5185 WinHelpContentsFile
= wxFopen(WinHelpContentsFileName
, _T("w"));
5186 if (WinHelpContentsFile
)
5187 wxFprintf(WinHelpContentsFile
, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot
));
5190 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5192 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5196 if (!Contents
|| !Chapters
)
5198 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5204 wxFprintf(Chapters
, _T("\n#{\\footnote Contents}\n"));
5205 wxFprintf(Chapters
, _T("${\\footnote Contents}\n"));
5206 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
5207 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ContentsNameString
);
5208 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
5212 wxFprintf(Chapters
, _T("\\titlepg\n"));
5213 wxFprintf(Contents
, _T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
5216 // In WinHelp, Contents title takes font of title.
5217 // In linear RTF, same as chapter headings.
5218 wxFprintf(Contents
, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"),
5219 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5221 // By default, Swiss, 11 point.
5222 wxFprintf(Chapters
, _T("\\f2\\fs22\n"));
5224 PushEnvironmentStyle(_T("\\f2\\fs22\\sa200"));
5226 SetCurrentOutput(Chapters
);
5231 OnInform(_T("Converting..."));
5235 FILE *Header
= wxFopen(_T("header.rtf"), _T("w"));
5238 OnError(_T("Ouch! Could not open temporary file header.rtf for writing."));
5241 WriteRTFHeader(Header
);
5244 PopEnvironmentStyle();
5249 // wxFprintf(Contents, _T("\\page\n"));
5250 wxFprintf(Chapters
, _T("\\page\n"));
5251 wxFprintf(Sections
, _T("\\page\n"));
5252 wxFprintf(Subsections
, _T("\\page\n"));
5253 wxFprintf(Subsubsections
, _T("\\page\n\n"));
5254 wxFprintf(Popups
, _T("\\page\n}\n"));
5257 // TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
5259 TexOutput(_T("}\n"));
5260 fclose(Contents
); Contents
= NULL
;
5261 fclose(Chapters
); Chapters
= NULL
;
5264 fclose(Sections
); Sections
= NULL
;
5265 fclose(Subsections
); Subsections
= NULL
;
5266 fclose(Subsubsections
); Subsubsections
= NULL
;
5267 fclose(Popups
); Popups
= NULL
;
5268 if (winHelpContents
)
5270 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5276 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5278 wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
5280 wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
5282 wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
5284 wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile
);
5287 wxRemoveFile(_T("tmp1.rtf"));
5288 wxRemoveFile(_T("tmp2.rtf"));
5289 wxRemoveFile(_T("tmp3.rtf"));
5290 wxRemoveFile(_T("tmp4.rtf"));
5294 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5296 if (wxFileExists(OutputFile
))
5297 wxRemoveFile(OutputFile
);
5300 cwdStr
= wxGetWorkingDirectory();
5302 wxString outputDirStr
;
5303 outputDirStr
= wxPathOnly(OutputFile
);
5305 // Determine if the temp file and the output file are in the same directory,
5306 // and if they are, then just rename the temp file rather than copying
5307 // it, as this is much faster when working with large (multi-megabyte files)
5308 if ((wxStrcmp(outputDirStr
.c_str(),_T("")) == 0) || // no path specified on output file
5309 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5311 wxRenameFile(_T("tmp1.rtf"), OutputFile
);
5315 wxCopyFile(_T("tmp1.rtf"), OutputFile
);
5319 wxRemoveFile(_T("tmp1.rtf"));
5322 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5324 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5326 wxCopyFile(TmpContentsName
, ContentsName
);
5327 wxRemoveFile(TmpContentsName
);
5330 wxRemoveFile(_T("chapters.rtf"));
5331 wxRemoveFile(_T("header.rtf"));
5335 wxRemoveFile(_T("sections.rtf"));
5336 wxRemoveFile(_T("subsections.rtf"));
5337 wxRemoveFile(_T("subsubsections.rtf"));
5338 wxRemoveFile(_T("popups.rtf"));
5340 if (winHelp
&& generateHPJ
)
5341 WriteHPJ(OutputFile
);