/wxwindows/utils/tex2rtf/src/rtfutils.cpp
C++ | 5342 lines | 4905 code | 172 blank | 265 comment | 773 complexity | d2fbe2b97888e587a358270a6f2a915a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-3.0
Large files files are truncated, but you can click here to view the full file
- /////////////////////////////////////////////////////////////////////////////
- // Name: rtfutils.cpp
- // Purpose: Converts Latex to Word RTF/WinHelp RTF
- // Author: Julian Smart
- // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
- // Ron Lee
- // Created: 7.9.93
- // RCS-ID: $Id: rtfutils.cpp 36101 2005-11-07 13:27:09Z ABX $
- // Copyright: (c) Julian Smart
- // Licence: wxWindows licence
- /////////////////////////////////////////////////////////////////////////////
- // For compilers that support precompilation, includes "wx.h".
- #include "wx/wxprec.h"
- #ifdef __BORLANDC__
- #pragma hdrstop
- #endif
- #ifndef WX_PRECOMP
- #endif
- #include "tex2any.h"
- #include "tex2rtf.h"
- #include <ctype.h>
- #include <stdlib.h>
- #include <stdio.h>
- #ifdef __WIN32__
- #include <windows.h>
- #endif
- #include "bmputils.h"
- #include "table.h"
- #if !WXWIN_COMPATIBILITY_2_4
- static inline wxChar* copystring(const wxChar* s)
- { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
- #endif
- wxList itemizeStack;
- static int indentLevel = 0;
- static int forbidParindent = 0; // if > 0, no parindent (e.g. in center environment)
- int forbidResetPar = 0; // If > 0, don't reset memory of having output a new par
- static wxChar *contentsLineSection = NULL;
- static wxChar *contentsLineValue = NULL;
- static TexChunk *descriptionItemArg = NULL;
- static wxStringList environmentStack; // Stack of paragraph styles we need to remember
- static int footnoteCount = 0;
- static int citeCount = 1;
- extern bool winHelp;
- extern bool startedSections;
- extern FILE *Contents;
- extern FILE *Chapters;
- extern FILE *Popups;
- extern FILE *WinHelpContentsFile;
- extern wxChar *RTFCharset;
- // This is defined in the Tex2Any library and isn't in use after parsing
- extern wxChar *BigBuffer;
- extern wxHashTable TexReferences;
- // Are we in verbatim mode? If so, format differently.
- static bool inVerbatim = false;
- // We're in a series of PopRef topics, so don't output section headings
- bool inPopRefSection = false;
- // Green colour?
- static bool hotSpotColour = true;
- static bool hotSpotUnderline = true;
- // Transparency (WHITE = transparent)
- static bool bitmapTransparency = true;
- // Linear RTF requires us to set the style per section.
- static wxChar *currentNumberStyle = NULL;
- static int currentItemSep = 8;
- static int CurrentTextWidth = 8640; // Say, six inches
- static int CurrentLeftMarginOdd = 400;
- static int CurrentLeftMarginEven = 1440;
- static int CurrentRightMarginOdd = 1440;
- static int CurrentRightMarginEven = 400;
- static int CurrentMarginParWidth = 2000;
- static int CurrentMarginParSep = 400; // Gap between marginpar and text
- static int CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
- static int GutterWidth = 2300;
- // Two-column table dimensions, in twips
- static int TwoColWidthA = 1500;
- static int TwoColWidthB = 3000;
- const int PageWidth = 12242; // 8.25 inches wide for A4
- // Remember the anchor in a helpref
- static TexChunk *helpRefText = NULL;
- /*
- * Flag to say we've just issued a \par\pard command, so don't
- * repeat this unnecessarily.
- *
- */
- int issuedNewParagraph = 0;
- // Need to know whether we're in a table or figure for benefit
- // of listoffigures/listoftables
- static bool inFigure = false;
- static bool inTable = false;
- /*
- * Current topics
- *
- */
- static wxChar *CurrentChapterName = NULL;
- static wxChar *CurrentSectionName = NULL;
- static wxChar *CurrentSubsectionName = NULL;
- static wxChar *CurrentTopic = NULL;
- static bool InPopups()
- {
- if (CurrentChapterName && (wxStrcmp(CurrentChapterName, _T("popups")) == 0))
- return true;
- if (CurrentSectionName && (wxStrcmp(CurrentSectionName, _T("popups")) == 0))
- return true;
- return false;
- }
- static void SetCurrentTopic(wxChar *s)
- {
- if (CurrentTopic) delete[] CurrentTopic;
- CurrentTopic = copystring(s);
- }
- void SetCurrentChapterName(wxChar *s)
- {
- if (CurrentChapterName) delete[] CurrentChapterName;
- CurrentChapterName = copystring(s);
- SetCurrentTopic(s);
- }
- void SetCurrentSectionName(wxChar *s)
- {
- if (CurrentSectionName) delete[] CurrentSectionName;
- CurrentSectionName = copystring(s);
- SetCurrentTopic(s);
- }
- void SetCurrentSubsectionName(wxChar *s)
- {
- if (CurrentSubsectionName) delete[] CurrentSubsectionName;
- CurrentSubsectionName = copystring(s);
- SetCurrentTopic(s);
- }
- // Indicate that a parent topic at level 'level' has children.
- // Level 1 is a chapter, 2 is a section, etc.
- void NotifyParentHasChildren(int parentLevel)
- {
- wxChar *parentTopic = NULL;
- switch (parentLevel)
- {
- case 1:
- {
- parentTopic = CurrentChapterName;
- break;
- }
- case 2:
- {
- parentTopic = CurrentSectionName;
- break;
- }
- case 3:
- {
- parentTopic = CurrentSubsectionName;
- break;
- }
- default:
- {
- break;
- }
- }
- if (parentTopic)
- {
- TexTopic *texTopic = (TexTopic *)TopicTable.Get(parentTopic);
- if (!texTopic)
- {
- texTopic = new TexTopic;
- TopicTable.Put(parentTopic, texTopic);
- }
- texTopic->hasChildren = true;
- }
- }
- // Have to keep a count of what levels are books, what are pages,
- // in order to correct for a Win95 bug which means that if you
- // have a book at level n, and then a page at level n, the page
- // ends up on level n + 1.
- bool ContentsLevels[5];
- // Reset below this level (starts from 1)
- void ResetContentsLevels(int l)
- {
- int i;
- for (i = l; i < 5; i++)
- ContentsLevels[i] = false;
- // There are always books on the top level
- ContentsLevels[0] = true;
- }
- // Output a WinHelp section as a keyword, substituting
- // : for space.
- void OutputSectionKeyword(FILE *fd)
- {
- OutputCurrentSectionToString(wxTex2RTFBuffer);
- unsigned int i;
- for (i = 0; i < wxStrlen(wxTex2RTFBuffer); i++)
- if (wxTex2RTFBuffer[i] == ':')
- wxTex2RTFBuffer[i] = ' ';
- // Don't write to index if there's some RTF in the string
- else if ( wxTex2RTFBuffer[i] == '{' )
- return;
- wxFprintf(fd, _T("K{\\footnote {K} "));
- wxFprintf(fd, _T("%s"), wxTex2RTFBuffer);
- wxFprintf(fd, _T("}\n"));
- }
- // Write a line for the .cnt file, if we're doing this.
- void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level)
- {
- // First, convert any RTF characters to ASCII
- wxChar title[255];
- int s=0;
- int d=0;
- // assuming iso-8859-1 here even in Unicode build (FIXME?)
- while ( (xitle[s]!=0)&&(d<255) )
- {
- wxChar ch=wxChar(xitle[s]&0xff);
- if (ch==0x5c) {
- wxChar ch1=wxChar(xitle[s+1]&0xff);
- wxChar ch2=wxChar(xitle[s+2]&0xff);
- wxChar ch3=wxChar(xitle[s+3]&0xff);
- s+=4; // next character
- if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]=wxChar('ö'); }
- if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]=wxChar('ä'); }
- if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]=wxChar('ü'); }
- if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]=wxChar('Ö'); }
- if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]=wxChar('Ä'); }
- if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]=wxChar('Ü'); }
- } else {
- title[d++]=ch;
- s++;
- }
- }
- title[d]=0;
- // Section (2) becomes level 1 if it's an article.
- if (DocumentStyle == LATEX_ARTICLE)
- level --;
- if (level == 0) // Means we had a Chapter in an article, oops.
- return;
- ResetContentsLevels(level);
- if (winHelp && winHelpContents && WinHelpContentsFile)
- {
- TexTopic *texTopic = (TexTopic *)TopicTable.Get(topicName);
- if (texTopic)
- {
- // If a previous section at this level was a book, we *have* to have a
- // book not a page, because of a bug in WHC (or WinHelp 4).
- if (texTopic->hasChildren || level == 1 || ContentsLevels[level-1])
- {
- // At this level, we have a pointer to a further hierarchy.
- // So we need a 'book' consisting of (say) Chapter 1.
- wxFprintf(WinHelpContentsFile, _T("%d %s\n"), level, title);
- // Then we have a 'page' consisting of the text for this chapter
- wxFprintf(WinHelpContentsFile, _T("%d %s=%s\n"), level+1, title, topicName);
- // Then we'll be writing out further pages or books at level + 1...
- // Remember that at this level, we had a book and *must* for the
- // remainder of sections at this level.
- ContentsLevels[level-1] = true;
- }
- else
- {
- wxFprintf(WinHelpContentsFile, _T("%d %s=%s\n"), level, title, topicName);
- }
- }
- else
- {
- if (level == 1 || ContentsLevels[level-1])
- {
- // Always have a book at level 1
- wxFprintf(WinHelpContentsFile, _T("%d %s\n"), level, title);
- wxFprintf(WinHelpContentsFile, _T("%d %s=%s\n"), level+1, title, topicName);
- ContentsLevels[level-1] = true;
- }
- else
- // Probably doesn't have children if it hasn't been added to the topic table
- wxFprintf(WinHelpContentsFile, _T("%d %s=%s\n"), level, title, topicName);
- }
- }
- }
- void SplitIndexEntry(wxChar *entry, wxChar *buf1, wxChar *buf2)
- {
- int len = wxStrlen(entry); int i = 0;
- while ((i < len) && entry[i] != '!')
- { buf1[i] = entry[i]; i ++; }
- buf1[i] = 0; buf2[0] = 0; int j = 0;
- if (entry[i] == '!')
- {
- i ++;
- while (i < len) { buf2[j] = entry[i]; i ++; j++; }
- buf2[j] = 0;
- }
- }
- /*
- * Output topic index entries in WinHelp RTF
- *
- */
- void GenerateKeywordsForTopic(wxChar *topic)
- {
- TexTopic *texTopic = (TexTopic *)TopicTable.Get(topic);
- if (!texTopic)
- return;
- wxStringList *list = texTopic->keywords;
- if (list)
- {
- wxStringListNode *node = list->GetFirst();
- while (node)
- {
- wxChar *s = (wxChar *)node->GetData();
- // Must separate out main entry form subentry (only 1 subentry allowed)
- wxChar buf1[100]; wxChar buf2[100];
- SplitIndexEntry(s, buf1, buf2);
- // Check for ':' which messes up index
- unsigned int i;
- for (i = 0; i < wxStrlen(buf1) ; i++)
- if (buf1[i] == ':')
- buf1[i] = ' ';
- for (i = 0; i < wxStrlen(buf2) ; i++)
- if (buf2[i] == ':')
- buf2[i] = ' ';
- // {K} is a strange fix to prevent words beginning with K not
- // being indexed properly
- TexOutput(_T("K{\\footnote {K} "));
- TexOutput(buf1);
- if (wxStrlen(buf2) > 0)
- {
- // Output subentry
- TexOutput(_T(", "));
- TexOutput(buf2);
- }
- TexOutput(_T("}\n"));
- node = node->GetNext();
- }
- }
- }
- /*
- * Output index entry in linear RTF
- *
- */
- void GenerateIndexEntry(wxChar *entry)
- {
- if (useWord)
- {
- wxChar buf1[100]; wxChar buf2[100];
- SplitIndexEntry(entry, buf1, buf2);
- TexOutput(_T("{\\xe\\v {"));
- TexOutput(buf1);
- if (wxStrlen(buf2) > 0)
- {
- TexOutput(_T("\\:"));
- TexOutput(buf2);
- }
- TexOutput(_T("}}"));
- }
- }
- /*
- * Write a suitable RTF header.
- *
- */
- void WriteColourTable(FILE *fd)
- {
- wxFprintf(fd, _T("{\\colortbl"));
- wxNode *node = ColourTable.GetFirst();
- while (node)
- {
- ColourTableEntry *entry = (ColourTableEntry *)node->GetData();
- wxFprintf(fd, _T("\\red%d\\green%d\\blue%d;\n"), entry->red, entry->green, entry->blue);
- node = node->GetNext();
- }
- wxFprintf(fd, _T("}"));
- }
- /*
- * Write heading style
- *
- */
- void WriteHeadingStyle(FILE *fd, int heading)
- {
- switch (heading)
- {
- case 1:
- {
- wxFprintf(fd, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont*2);
- break;
- }
- case 2:
- {
- wxFprintf(fd, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont*2);
- break;
- }
- case 3:
- {
- wxFprintf(fd, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont*2);
- break;
- }
- case 4:
- {
- wxFprintf(fd, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont*2);
- break;
- }
- default:
- break;
- }
- }
- void WriteRTFHeader(FILE *fd)
- {
- wxFprintf(fd, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset);
- wxFprintf(fd, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
- wxFprintf(fd, _T("{\\f3\\fmodern Courier New;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
- /*
- * Style sheet
- */
- wxFprintf(fd, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n"));
- // Headings
- wxFprintf(fd, _T("{\\s1 ")); WriteHeadingStyle(fd, 1); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 1;}\n"));
- wxFprintf(fd, _T("{\\s2 ")); WriteHeadingStyle(fd, 2); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 2;}\n"));
- wxFprintf(fd, _T("{\\s3 ")); WriteHeadingStyle(fd, 3); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 3;}\n"));
- wxFprintf(fd, _T("{\\s4 ")); WriteHeadingStyle(fd, 4); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 4;}\n"));
- // Code style
- wxFprintf(fd, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\
- \\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n"));
- // Table of contents styles
- wxFprintf(fd, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
- wxFprintf(fd, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n"));
- wxFprintf(fd, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n"));
- wxFprintf(fd, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n"));
- // Index styles
- wxFprintf(fd, _T("{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n"));
- wxFprintf(fd, _T("{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n"));
- wxFprintf(fd, _T("{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n"));
- wxFprintf(fd, _T("{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n"));
- wxFprintf(fd, _T("{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n"));
- wxFprintf(fd, _T("}\n"));
- WriteColourTable(fd);
- wxFprintf(fd, _T("\n\\ftnbj\\ftnrestart")); // Latex default is footnotes at bottom of page, not section.
- wxFprintf(fd, _T("\n"));
- }
- void OutputNumberStyle(wxChar *numberStyle)
- {
- if (numberStyle)
- {
- if (wxStrcmp(numberStyle, _T("arabic")) == 0)
- {
- TexOutput(_T("\\pgndec"));
- }
- else if (wxStrcmp(numberStyle, _T("roman")) == 0)
- {
- TexOutput(_T("\\pgnlcrm"));
- }
- else if (wxStrcmp(numberStyle, _T("Roman")) == 0)
- {
- TexOutput(_T("\\pgnucrm"));
- }
- else if (wxStrcmp(numberStyle, _T("alph")) == 0)
- {
- TexOutput(_T("\\pgnlcltr"));
- }
- else if (wxStrcmp(numberStyle, _T("Alph")) == 0)
- {
- TexOutput(_T("\\pgnucltr"));
- }
- }
- }
- /*
- * Write a Windows help project file
- */
- bool WriteHPJ(const wxString& filename)
- {
- wxChar hpjFilename[256];
- wxChar helpFile[50];
- wxChar rtfFile[50];
- wxStrcpy(hpjFilename, filename);
- StripExtension(hpjFilename);
- wxStrcat(hpjFilename, _T(".hpj"));
- wxStrcpy(helpFile, wxFileNameFromPath(filename));
- StripExtension(helpFile);
- wxStrcpy(rtfFile, helpFile);
- wxStrcat(helpFile, _T(".hlp"));
- wxStrcat(rtfFile, _T(".rtf"));
- FILE *fd = wxFopen(hpjFilename, _T("w"));
- if (!fd)
- return false;
- wxChar *helpTitle = winHelpTitle;
- if (!helpTitle)
- helpTitle = _T("Untitled");
- wxString thePath = wxPathOnly(InputFile);
- if (thePath.empty())
- thePath = _T(".");
- wxFprintf(fd, _T("[OPTIONS]\n"));
- wxFprintf(fd, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath.c_str());
- wxFprintf(fd, _T("TITLE=%s\n"), helpTitle);
- wxFprintf(fd, _T("CONTENTS=Contents\n"));
- if (winHelpVersion > 3)
- {
- wxFprintf(fd, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
- wxFprintf(fd, _T("COMPRESS=8 Zeck\n"));
- wxFprintf(fd, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
- wxFprintf(fd, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot));
- }
- else
- {
- wxFprintf(fd, _T("COMPRESS=HIGH\n"));
- }
- wxFprintf(fd, _T("\n"));
- if (winHelpVersion > 3)
- {
- wxFprintf(fd, _T("[WINDOWS]\n"));
- wxFprintf(fd, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
- wxFprintf(fd, _T("\n"));
- }
- wxFprintf(fd, _T("[FILES]\n%s\n\n"), rtfFile);
- wxFprintf(fd, _T("[CONFIG]\n"));
- if (useUpButton)
- wxFprintf(fd, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile);
- wxFprintf(fd, _T("BrowseButtons()\n\n"));
- wxFprintf(fd, _T("[MAP]\n\n[BITMAPS]\n\n"));
- fclose(fd);
- return true;
- }
- /*
- * Given a TexChunk with a string value, scans through the string
- * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
- * and inserting spaces at the start of lines since in Latex, a newline
- * implies a space, but not in RTF.
- *
- */
- void ProcessText2RTF(TexChunk *chunk)
- {
- bool changed = false;
- int ptr = 0;
- int i = 0;
- wxChar ch = 1;
- int len = wxStrlen(chunk->value);
- while (ch != 0)
- {
- ch = chunk->value[i];
- if (ch == 10)
- {
- if (inVerbatim)
- {
- BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par\n")); ptr += 5;
- // BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par{\\v this was verbatim}\n")); ptr += 5;
- i ++;
- changed = true;
- }
- else
- {
- // If the first character of the next line is ASCII,
- // put a space in. Implicit in Latex, not in RTF.
- /*
- The reason this is difficult is that you don't really know
- where a space would be appropriate. If you always put in a space
- when you find a newline, unwanted spaces appear in the text.
- */
- if ((i > 0) && (len > i+1 && isascii(chunk->value[i+1]) &&
- !isspace(chunk->value[i+1])) ||
- ((len > i+1 && chunk->value[i+1] == 13) &&
- (len > i+2 && isascii(chunk->value[i+2]) &&
- !isspace(chunk->value[i+2]))))
- // if (true)
- {
- // DOS files have a 13 after the 10
- BigBuffer[ptr] = 10;
- ptr ++;
- i ++;
- if (chunk->value[i] == 13)
- {
- BigBuffer[ptr] = 13;
- ptr ++;
- i ++;
- }
- BigBuffer[ptr] = ' ';
- ptr ++;
- // Note that the actual ASCII character seen is dealt with in the next
- // iteration
- changed = true;
- }
- else
- {
- BigBuffer[ptr] = ch;
- i ++;
- }
- }
- }
- else if (!inVerbatim && ch == '`' && (len >= i+1 && chunk->value[i+1] == '`'))
- {
- BigBuffer[ptr] = '"'; ptr ++;
- i += 2;
- changed = true;
- }
- else if (!inVerbatim && ch == '`') // Change ` to '
- {
- BigBuffer[ptr] = 39; ptr ++;
- i += 1;
- changed = true;
- }
- else if (inVerbatim && ch == '\\') // Change backslash to two backslashes
- {
- BigBuffer[ptr] = '\\'; ptr ++;
- BigBuffer[ptr] = '\\'; ptr ++;
- i += 1;
- changed = true;
- }
- else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curly bracket
- {
- BigBuffer[ptr] = '\\'; ptr ++;
- BigBuffer[ptr] = ch; ptr ++;
- i += 1;
- changed = true;
- }
- else
- {
- BigBuffer[ptr] = ch;
- i ++;
- ptr ++;
- }
- }
- BigBuffer[ptr] = 0;
- if (changed)
- {
- delete[] chunk->value;
- chunk->value = copystring(BigBuffer);
- }
- }
- /*
- * Scan through all chunks starting from the given one,
- * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
- * This should be called after Tex2Any has parsed the file,
- * and before TraverseDocument is called.
- *
- */
- void Text2RTF(TexChunk *chunk)
- {
- Tex2RTFYield();
- if (stopRunning) return;
- switch (chunk->type)
- {
- case CHUNK_TYPE_MACRO:
- {
- TexMacroDef *def = chunk->def;
- if (def && def->ignore)
- return;
- if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB))
- inVerbatim = true;
- wxNode *node = chunk->children.GetFirst();
- while (node)
- {
- TexChunk *child_chunk = (TexChunk *)node->GetData();
- Text2RTF(child_chunk);
- node = node->GetNext();
- }
- if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB))
- inVerbatim = false;
- break;
- }
- case CHUNK_TYPE_ARG:
- {
- wxNode *node = chunk->children.GetFirst();
- while (node)
- {
- TexChunk *child_chunk = (TexChunk *)node->GetData();
- Text2RTF(child_chunk);
- node = node->GetNext();
- }
- break;
- }
- case CHUNK_TYPE_STRING:
- {
- if (chunk->value)
- ProcessText2RTF(chunk);
- break;
- }
- }
- }
- /*
- * Not used yet
- *
- */
- wxChar browseBuf[10];
- static long browseId = 0;
- wxChar *GetBrowseString(void)
- {
- wxChar buf[10];
- browseId ++;
- wxSnprintf(buf, sizeof(buf), _T("%ld"), browseId);
- int noZeroes = 5-wxStrlen(buf);
- wxStrcpy(browseBuf, _T("browse"));
- for (int i = 0; i < noZeroes; i++)
- wxStrcat(browseBuf, _T("0"));
- wxStrcat(browseBuf, buf);
- return browseBuf;
- }
- /*
- * Keeping track of environments to restore the styles after \pard.
- * Push strings like "\qc" onto stack.
- *
- */
- void PushEnvironmentStyle(wxChar *style)
- {
- environmentStack.Add(style);
- }
- void PopEnvironmentStyle(void)
- {
- wxStringListNode *node = environmentStack.GetLast();
- if (node)
- {
- wxChar *val = (wxChar *)node->GetData();
- delete[] val;
- delete node;
- }
- }
- // Write out the styles, most recent first.
- void WriteEnvironmentStyles(void)
- {
- wxStringListNode *node = environmentStack.GetLast();
- while (node)
- {
- wxChar *val = (wxChar *)node->GetData();
- TexOutput(val);
- node = node->GetNext();
- }
- if (!inTabular && (ParIndent > 0) && (forbidParindent == 0))
- {
- wxChar buf[15];
- wxSnprintf(buf, sizeof(buf), _T("\\fi%d"), ParIndent*20); // Convert points to TWIPS
- TexOutput(buf);
- }
- if (environmentStack.GetCount() > 0 || (ParIndent > 0))
- TexOutput(_T("\n"));
- }
- /*
- * Output a header
- *
- */
- void OutputRTFHeaderCommands(void)
- {
- wxChar buf[300];
- if (PageStyle && wxStrcmp(PageStyle, _T("plain")) == 0)
- {
- TexOutput(_T("{\\headerl }{\\headerr }"));
- }
- else if (PageStyle && wxStrcmp(PageStyle, _T("empty")) == 0)
- {
- TexOutput(_T("{\\headerl }{\\headerr }"));
- }
- else if (PageStyle && wxStrcmp(PageStyle, _T("headings")) == 0)
- {
- // Left header
- TexOutput(_T("{\\headerl\\fi0 "));
- if (headerRule)
- TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
- TexOutput(_T("{\\i \\qr "));
- if (DocumentStyle == LATEX_ARTICLE)
- {
- wxSnprintf(buf, sizeof(buf), _T("SECTION %d"), sectionNo);
- TexOutput(buf);
- }
- else
- {
- wxSnprintf(buf, sizeof(buf), _T("CHAPTER %d: "), chapterNo);
- TexOutput(buf);
- }
- TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
- TexOutput(_T("}\\par\\pard}"));
- // Right header
- TexOutput(_T("{\\headerr\\fi0 "));
- if (headerRule)
- TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
- TexOutput(_T("{\\i \\qc "));
- if (DocumentStyle == LATEX_ARTICLE)
- {
- wxSnprintf(buf, sizeof(buf), _T("SECTION %d"), sectionNo);
- TexOutput(buf);
- }
- else
- {
- wxSnprintf(buf, sizeof(buf), _T("CHAPTER %d"), chapterNo);
- TexOutput(buf);
- }
- TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
- TexOutput(_T("}\\par\\pard}"));
- }
- else
- {
- int oldForbidResetPar = forbidResetPar;
- forbidResetPar = 0;
- if (LeftHeaderEven || CentreHeaderEven || RightHeaderEven)
- {
- TexOutput(_T("{\\headerl\\fi0 "));
- if (headerRule)
- TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
- if (LeftHeaderEven)
- {
- if (!CentreHeaderEven && !RightHeaderEven)
- TexOutput(_T("\\ql "));
- TraverseChildrenFromChunk(LeftHeaderEven);
- }
- if (CentreHeaderEven)
- {
- if (!LeftHeaderEven && !RightHeaderEven)
- TexOutput(_T("\\qc "));
- else
- TexOutput(_T("\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(CentreHeaderEven);
- }
- if (RightHeaderEven)
- {
- if (!LeftHeaderEven && !CentreHeaderEven)
- TexOutput(_T("\\qr "));
- else
- TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(RightHeaderEven);
- }
- TexOutput(_T("\\par\\pard}"));
- }
- if (LeftHeaderOdd || CentreHeaderOdd || RightHeaderOdd)
- {
- TexOutput(_T("{\\headerr\\fi0 "));
- if (headerRule)
- TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
- if (LeftHeaderOdd)
- {
- if (!CentreHeaderOdd && !RightHeaderOdd)
- TexOutput(_T("\\ql "));
- TraverseChildrenFromChunk(LeftHeaderOdd);
- }
- if (CentreHeaderOdd)
- {
- if (!LeftHeaderOdd && !RightHeaderOdd)
- TexOutput(_T("\\qc "));
- else
- TexOutput(_T("\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(CentreHeaderOdd);
- }
- if (RightHeaderOdd)
- {
- if (!LeftHeaderOdd && !CentreHeaderOdd)
- TexOutput(_T("\\qr "));
- else
- TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(RightHeaderOdd);
- }
- TexOutput(_T("\\par\\pard}"));
- }
- // As an approximation, don't put a header on the first page of a section.
- // This may not always be desired, but it's a reasonable guess.
- TexOutput(_T("{\\headerf }"));
- forbidResetPar = oldForbidResetPar;
- }
- }
- void OutputRTFFooterCommands(void)
- {
- if (PageStyle && wxStrcmp(PageStyle, _T("plain")) == 0)
- {
- TexOutput(_T("{\\footerl\\fi0 "));
- if (footerRule)
- TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
- TexOutput(_T("{\\qc "));
- TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
- TexOutput(_T("}\\par\\pard}"));
- TexOutput(_T("{\\footerr\\fi0 "));
- if (footerRule)
- TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
- TexOutput(_T("{\\qc "));
- TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
- TexOutput(_T("}\\par\\pard}"));
- }
- else if (PageStyle && wxStrcmp(PageStyle, _T("empty")) == 0)
- {
- TexOutput(_T("{\\footerl }{\\footerr }"));
- }
- else if (PageStyle && wxStrcmp(PageStyle, _T("headings")) == 0)
- {
- TexOutput(_T("{\\footerl }{\\footerr }"));
- }
- else
- {
- if (LeftFooterEven || CentreFooterEven || RightFooterEven)
- {
- TexOutput(_T("{\\footerl\\fi0 "));
- if (footerRule)
- TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
- if (LeftFooterEven)
- {
- if (!CentreFooterEven && !RightFooterEven)
- TexOutput(_T("\\ql "));
- TraverseChildrenFromChunk(LeftFooterEven);
- }
- if (CentreFooterEven)
- {
- if (!LeftFooterEven && !RightFooterEven)
- TexOutput(_T("\\qc "));
- else
- TexOutput(_T("\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(CentreFooterEven);
- }
- if (RightFooterEven)
- {
- if (!LeftFooterEven && !CentreFooterEven)
- TexOutput(_T("\\qr "));
- else
- TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(RightFooterEven);
- }
- TexOutput(_T("\\par\\pard}"));
- }
- if (LeftFooterOdd || CentreFooterOdd || RightFooterOdd)
- {
- TexOutput(_T("{\\footerr\\fi0 "));
- if (footerRule)
- TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
- if (LeftFooterOdd)
- {
- if (!CentreFooterOdd && !RightFooterOdd)
- TexOutput(_T("\\ql "));
- TraverseChildrenFromChunk(LeftFooterOdd);
- }
- if (CentreFooterOdd)
- {
- if (!LeftFooterOdd && !RightFooterOdd)
- TexOutput(_T("\\qc "));
- else
- TexOutput(_T("\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(CentreFooterOdd);
- }
- if (RightFooterOdd)
- {
- if (!LeftFooterOdd && !CentreFooterOdd)
- TexOutput(_T("\\qr "));
- else
- TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(RightFooterOdd);
- }
- TexOutput(_T("\\par\\pard}"));
- }
- // As an approximation, put a footer on the first page of a section.
- // This may not always be desired, but it's a reasonable guess.
- if (LeftFooterOdd || CentreFooterOdd || RightFooterOdd)
- {
- TexOutput(_T("{\\footerf\\fi0 "));
- if (LeftFooterOdd)
- {
- if (!CentreFooterOdd && !RightFooterOdd)
- TexOutput(_T("\\ql "));
- TraverseChildrenFromChunk(LeftFooterOdd);
- }
- if (CentreFooterOdd)
- {
- if (!LeftFooterOdd && !RightFooterOdd)
- TexOutput(_T("\\qc "));
- else
- TexOutput(_T("\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(CentreFooterOdd);
- }
- if (RightFooterOdd)
- {
- if (!LeftFooterOdd && !CentreFooterOdd)
- TexOutput(_T("\\qr "));
- else
- TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
- TraverseChildrenFromChunk(RightFooterOdd);
- }
- TexOutput(_T("\\par\\pard}"));
- }
- }
- }
- // Called on start/end of macro examination
- void RTFOnMacro(int macroId, int no_args, bool start)
- {
- /*
- wxChar tmpBuf[40];
- wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start);
- OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
- OutputDebugString("\n"); wxYield();
- */
- // ltLABEL is included here because after a section but BEFORE
- // the label is seen, a new paragraph is issued. Don't upset this by
- // immediately forgetting we've done it.
- if (start && (macroId != ltPAR && macroId != ltITEMIZE &&
- macroId != ltENUMERATE && macroId != ltDESCRIPTION &&
- macroId != ltVERBATIM && macroId != ltLABEL &&
- macroId != ltSETHEADER && macroId != ltSETFOOTER &&
- macroId != ltPAGENUMBERING &&
- (forbidResetPar == 0)))
- {
- issuedNewParagraph = 0;
- }
- wxChar buf[300];
- switch (macroId)
- {
- case ltCHAPTER:
- case ltCHAPTERSTAR:
- case ltCHAPTERHEADING:
- case ltCHAPTERHEADINGSTAR:
- {
- if (!start)
- {
- sectionNo = 0;
- figureNo = 0;
- tableNo = 0;
- subsectionNo = 0;
- subsubsectionNo = 0;
- footnoteCount = 0;
- if (macroId != ltCHAPTERSTAR && macroId != ltCHAPTERHEADINGSTAR)
- chapterNo ++;
- wxChar *topicName = FindTopicName(GetNextChunk());
- SetCurrentChapterName(topicName);
- if (winHelpContents && winHelp && !InPopups())
- {
- OutputCurrentSectionToString(wxTex2RTFBuffer);
- WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 1);
- }
- AddTexRef(topicName, NULL, ChapterNameString, chapterNo);
- if (winHelp)
- {
- if (!InPopups())
- wxFprintf(Contents, _T("\n{\\uldb "));
- wxFprintf(Chapters, _T("\\page"));
- wxFprintf(Chapters, _T("\n${\\footnote "));
- if (!InPopups())
- SetCurrentOutputs(Contents, Chapters);
- else
- SetCurrentOutput(Chapters);
- }
- else
- {
- wxFprintf(Chapters, _T("\\sect\\pgncont\\titlepg\n"));
- // If a non-custom page style, we generate the header now.
- if (PageStyle && (wxStrcmp(PageStyle, _T("plain")) == 0 ||
- wxStrcmp(PageStyle, _T("empty")) == 0 ||
- wxStrcmp(PageStyle, _T("headings")) == 0))
- {
- OutputRTFHeaderCommands();
- OutputRTFFooterCommands();
- }
- // Need to reset the current numbering style, or RTF forgets it.
- SetCurrentOutput(Chapters);
- OutputNumberStyle(currentNumberStyle);
- SetCurrentOutput(Contents);
- if (!InPopups())
- {
- if (macroId == ltCHAPTER)
- {
- // Section
- wxFprintf(Contents, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo);
- }
- else if (macroId == ltCHAPTERHEADING)
- {
- wxFprintf(Contents, _T("\\par\n\\pard{\\b "));
- }
- else SetCurrentOutput(NULL); // No entry in table of contents
- }
- }
- startedSections = true;
- // Output heading to contents page
- if (!InPopups())
- {
- OutputCurrentSection();
- if (winHelp)
- {
- wxFprintf(Contents, _T("}{\\v %s}\\pard\\par\n"), topicName);
- //WriteEnvironmentStyles();
- }
- else if ((macroId == ltCHAPTER) || (macroId == ltCHAPTERHEADING))
- wxFprintf(Contents, _T("}\\par\\par\\pard\n"));
- // From here, just output to chapter
- SetCurrentOutput(Chapters);
- }
- if (winHelp)
- {
- wxFprintf(Chapters, _T("}\n#{\\footnote %s}\n"), topicName);
- wxFprintf(Chapters, _T("+{\\footnote %s}\n"), GetBrowseString());
- OutputSectionKeyword(Chapters);
- GenerateKeywordsForTopic(topicName);
- if (useUpButton)
- {
- // If we're generating a .cnt file, we don't want to be able
- // jump up to the old-style contents page, so disable it.
- if (winHelpContents)
- wxFprintf(Chapters, _T("!{\\footnote DisableButton(\"Up\")}\n"));
- else
- wxFprintf(Chapters, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
- wxFileNameFromPath(FileRoot), _T("Contents"));
- }
- }
- if (!InPopups())
- {
- wxChar *styleCommand = _T("");
- if (!winHelp && useHeadingStyles && (macroId == ltCHAPTER || macroId == ltCHAPTERHEADING || macroId == ltCHAPTERHEADINGSTAR))
- styleCommand = _T("\\s1");
- wxFprintf(Chapters, _T("\\pard{%s"), ((winHelp && !InPopups()) ? _T("\\keepn\\sa140\\sb140") : styleCommand));
- WriteHeadingStyle(Chapters, 1); wxFprintf(Chapters, _T(" "));
- if (!winHelp)
- {
- if (macroId == ltCHAPTER)
- {
- if (useWord)
- // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName, topicName);
- else
- wxFprintf(Chapters, _T("%d. "), chapterNo);
- }
- else if ( useWord )
- {
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName, topicName);
- }
- }
- OutputCurrentSection();
- TexOutput(_T("\\par\\pard}\n"));
- }
- issuedNewParagraph = 1;
- WriteEnvironmentStyles();
- }
- break;
- }
- case ltSECTION:
- case ltSECTIONSTAR:
- case ltSECTIONHEADING:
- case ltSECTIONHEADINGSTAR:
- case ltGLOSS:
- {
- FILE *jumpFrom;
- if (DocumentStyle == LATEX_ARTICLE)
- jumpFrom = Contents;
- else
- jumpFrom = Chapters;
- if (!start)
- {
- subsectionNo = 0;
- subsubsectionNo = 0;
- if (DocumentStyle == LATEX_ARTICLE)
- footnoteCount = 0;
- if (macroId != ltSECTIONSTAR && macroId != ltSECTIONHEADINGSTAR)
- sectionNo ++;
- wxChar *topicName = FindTopicName(GetNextChunk());
- SetCurrentSectionName(topicName);
- NotifyParentHasChildren(1);
- if (winHelpContents && winHelp && !InPopups())
- {
- OutputCurrentSectionToString(wxTex2RTFBuffer);
- WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 2);
- }
- AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo);
- if (winHelp)
- {
- SetCurrentOutputs(jumpFrom, Sections);
- // Newline for a new section if this is an article
- if ((DocumentStyle == LATEX_ARTICLE) &&
- ((macroId == ltSECTION) || (macroId == ltSECTIONSTAR) || (macroId == ltSECTIONHEADINGSTAR)))
- wxFprintf(Sections, _T("\\page\n"));
- if (!InPopups())
- wxFprintf(jumpFrom, _T("\n{\\uldb "));
- }
- else
- {
- if (DocumentStyle == LATEX_ARTICLE)
- {
- TexOutput(_T("\\sect\\pgncont\n"));
- // If a non-custom page style, we generate the header now.
- if (PageStyle && (wxStrcmp(PageStyle, _T("plain")) == 0 ||
- wxStrcmp(PageStyle, _T("empty")) == 0 ||
- wxStrcmp(PageStyle, _T("headings")) == 0))
- {
- OutputRTFHeaderCommands();
- OutputRTFFooterCommands();
- }
- }
- SetCurrentOutput(Contents);
- if (macroId == ltSECTION)
- {
- if (!InPopups())
- {
- if (DocumentStyle == LATEX_REPORT)
- wxFprintf(Contents, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo, sectionNo);
- else
- wxFprintf(Contents, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo);
- }
- }
- else if (macroId == ltSECTIONHEADING)
- {
- if (!InPopups())
- {
- if (DocumentStyle == LATEX_REPORT)
- wxFprintf(Contents, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
- else
- wxFprintf(Contents, _T("\\par\n\\pard{\\b ")); //, sectionNo);
- }
- }
- else SetCurrentOutput(NULL);
- }
- if (startedSections)
- {
- if (winHelp)
- wxFprintf(Sections, _T("\\page\n"));
- }
- startedSections = true;
- if (winHelp)
- wxFprintf(Sections, _T("\n${\\footnote "));
- // Output heading to contents page
- if (!InPopups())
- OutputCurrentSection();
- if (winHelp)
- {
- if (!InPopups())
- {
- wxFprintf(jumpFrom, _T("}{\\v %s}\\pard\\par\n"), topicName);
- //WriteEnvironmentStyles();
- }
- }
- else if ((macroId != ltSECTIONSTAR) && (macroId != ltGLOSS))
- {
- if (DocumentStyle == LATEX_REPORT)
- wxFprintf(Contents, _T("}\\par\\pard\n"));
- else
- wxFprintf(Contents, _T("}\\par\\par\\pard\n"));
- }
- SetCurrentOutput(winHelp ? Sections : Chapters);
- if (winHelp)
- {
- wxFprintf(Sections, _T("}\n#{\\footnote %s}\n"), topicName);
- wxFprintf(Sections, _T("+{\\footnote %s}\n"), GetBrowseString());
- OutputSectionKeyword(Sections);
- GenerateKeywordsForTopic(topicName);
- if (useUpButton)
- {
- if (DocumentStyle == LATEX_ARTICLE)
- {
- wxFprintf(Sections, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
- wxFileNameFromPath(FileRoot), _T("Contents"));
- }
- else if (CurrentChapterName)
- {
- wxFprintf(Sections, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
- wxFileNameFromPath(FileRoot), CurrentChapterName);
- }
- }
- }
- if (!InPopups())
- {
- wxChar *styleCommand = _T("");
- if (!winHelp && useHeadingStyles && (macroId != ltSECTIONSTAR))
- {
- if (DocumentStyle == LATEX_ARTICLE)
- styleCommand = _T("\\s1");
- else
- styleCommand = _T("\\s2");
- }
- wxChar *keep = _T("");
- if (winHelp && (macroId != ltGLOSS) && !InPopups())
- keep = _T("\\keepn\\sa140\\sb140");
- wxFprintf(winHelp ? Sections : Chapters, _T("\\pard{%s%s"),
- keep, styleCommand);
- WriteHeadingStyle((winHelp ? Sections : Chapters),
- (DocumentStyle == LATEX_ARTICLE ? 1 : 2));
- wxFprintf(winHelp ? Sections : Chapters, _T(" "));
- if (!winHelp)
- {
- if ((macroId != ltSECTIONSTAR) && (macroId != ltSECTIONHEADINGSTAR) && (macroId != ltGLOSS))
- {
- if (DocumentStyle == LATEX_REPORT)
- {
- if (useWord)
- // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName,
- topicName);
- else
- wxFprintf(Chapters, _T("%d.%d. "), chapterNo, sectionNo);
- }
- else
- {
- if (useWord)
- // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName,
- topicName);
- else
- wxFprintf(Chapters, _T("%d. "), sectionNo);
- }
- }
- else if ( useWord )
- {
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName, topicName);
- }
- }
- OutputCurrentSection();
- TexOutput(_T("\\par\\pard}\n"));
- // TexOutput(_T("\\par\\pard}\\par\n"));
- }
- issuedNewParagraph = 1;
- WriteEnvironmentStyles();
- // issuedNewParagraph = 2;
- }
- break;
- }
- case ltSUBSECTION:
- case ltSUBSECTIONSTAR:
- case ltMEMBERSECTION:
- case ltFUNCTIONSECTION:
- {
- if (!start)
- {
- if (winHelp && !Sections)
- {
- OnError(_T("You cannot have a subsection before a section!"));
- }
- else
- {
- subsubsectionNo = 0;
- if (macroId != ltSUBSECTIONSTAR)
- subsectionNo ++;
- wxChar *topicName = FindTopicName(GetNextChunk());
- SetCurrentSubsectionName(topicName);
- NotifyParentHasChildren(2);
- if (winHelpContents && winHelp && !InPopups())
- {
- OutputCurrentSectionToString(wxTex2RTFBuffer);
- WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 3);
- }
- AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo);
- if (winHelp)
- {
- SetCurrentOutputs(Sections, Subsections);
- SetCurrentOutputs(Sections, Subsections);
- if (!InPopups())
- wxFprintf(Sections, _T("\n{\\uldb "));
- }
- else
- {
- if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) &&
- (macroId != ltFUNCTIONSECTION))
- {
- SetCurrentOutput(Contents);
- if (DocumentStyle == LATEX_REPORT)
- wxFprintf(Contents, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo, sectionNo, subsectionNo);
- else
- wxFprintf(Contents, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo, subsectionNo);
- } else SetCurrentOutput(NULL);
- }
- if (startedSections)
- {
- if (winHelp)
- {
- if (!InPopups())
- wxFprintf(Subsections, _T("\\page\n"));
- }
- // Experimental JACS 2004-02-21
- #if 0
- else
- wxFprintf(Chapters, _T("\\par\n"));
- #endif
- }
- startedSections = true;
- if (winHelp)
- wxFprintf(Subsections, _T("\n${\\footnote "));
- // Output to contents page
- if (!InPopups())
- OutputCurrentSection();
- if (winHelp)
- {
- if (!InPopups())
- {
- wxFprintf(Sections, _T("}{\\v %s}\\pard\\par\n"), topicName);
- //WriteEnvironmentStyles();
- }
- }
- else if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) &&
- (macroId != ltFUNCTIONSECTION))
- wxFprintf(Contents, _T("\\par\\pard\n"));
- SetCurrentOutput(winHelp ? Subsections : Chapters);
- if (winHelp)
- {
- wxFprintf(Subsections, _T("}\n#{\\footnote %s}\n"), topicName);
- wxFprintf(Subsections, _T("+{\\footnote %s}\n"), GetBrowseString());
- OutputSectionKeyword(Subsections);
- GenerateKeywordsForTopic(topicName);
- if (useUpButton && CurrentSectionName)
- {
- wxFprintf(Subsections, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
- wxFileNameFromPath(FileRoot), CurrentSectionName);
- }
- }
- if (!winHelp && indexSubsections && useWord)
- {
- // Insert index entry for this subsection
- TexOutput(_T("{\\xe\\v {"));
- OutputCurrentSection();
- TexOutput(_T("}}"));
- }
- if (!InPopups())
- {
- wxChar *styleCommand = _T("");
- if (!winHelp && useHeadingStyles && (macroId != ltSUBSECTIONSTAR))
- {
- if (DocumentStyle == LATEX_ARTICLE)
- styleCommand = _T("\\s2");
- else
- styleCommand = _T("\\s3");
- }
- wxChar *keep = _T("");
- if (winHelp && !InPopups())
- keep = _T("\\keepn\\sa140\\sb140");
- wxFprintf(winHelp ? Subsections : Chapters, _T("\\pard{%s%s"),
- keep, styleCommand);
- WriteHeadingStyle((winHelp ? Subsections : Chapters),
- (DocumentStyle == LATEX_ARTICLE ? 2 : 3));
- wxFprintf(winHelp ? Subsections : Chapters, _T(" "));
- if (!winHelp)
- {
- if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) &&
- (macroId != ltFUNCTIONSECTION))
- {
- if (DocumentStyle == LATEX_REPORT)
- {
- if (useWord)
- // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName,
- topicName);
- else
- wxFprintf(Chapters, _T("%d.%d.%d. "), chapterNo, sectionNo, subsectionNo);
- }
- else
- {
- if (useWord)
- // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName,
- topicName);
- else
- wxFprintf(Chapters, _T("%d.%d. "), sectionNo, subsectionNo);
- }
- }
- else if ( useWord )
- {
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName, topicName);
- }
- }
- OutputCurrentSection(); // Repeat section header
- // Experimental JACS
- TexOutput(_T("\\par\\pard}\n"));
- // TexOutput(_T("\\par\\pard}\\par\n"));
- }
- issuedNewParagraph = 1;
- WriteEnvironmentStyles();
- }
- }
- break;
- }
- case ltSUBSUBSECTION:
- case ltSUBSUBSECTIONSTAR:
- {
- if (!start)
- {
- if (winHelp && !Subsections)
- {
- OnError(_T("You cannot have a subsubsection before a subsection!"));
- }
- else
- {
- if (macroId != ltSUBSUBSECTIONSTAR)
- subsubsectionNo ++;
- wxChar *topicName = FindTopicName(GetNextChunk());
- SetCurrentTopic(topicName);
- NotifyParentHasChildren(3);
- if (winHelpContents && winHelp)
- {
- OutputCurrentSectionToString(wxTex2RTFBuffer);
- WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 4);
- }
- AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo, subsubsectionNo);
- if (winHelp)
- {
- SetCurrentOutputs(Subsections, Subsubsections);
- wxFprintf(Subsections, _T("\n{\\uldb "));
- }
- else
- {
- if (macroId != ltSUBSUBSECTIONSTAR)
- {
- if (DocumentStyle == LATEX_ARTICLE)
- {
- SetCurrentOutput(Contents);
- wxFprintf(Contents, _T("\n\\tab\\tab %d.%d.%d\\tab "),
- sectionNo, subsectionNo, subsubsectionNo);
- }
- else
- SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else
- }
- else
- SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else
- }
- if (startedSections)
- {
- if (winHelp)
- wxFprintf(Subsubsections, _T("\\page\n"));
- // Experimental JACS 2004-02-21
- #if 0
- else
- wxFprintf(Chapters, _T("\\par\n"));
- #endif
- }
- startedSections = true;
- if (winHelp)
- wxFprintf(Subsubsections, _T("\n${\\footnote "));
- // Output header to contents page
- OutputCurrentSection();
- if (winHelp)
- {
- wxFprintf(Subsections, _T("}{\\v %s}\\pard\\par\n"), topicName);
- //WriteEnvironmentStyles();
- }
- else if ((DocumentStyle == LATEX_ARTICLE) && (macroId != ltSUBSUBSECTIONSTAR))
- wxFprintf(Contents, _T("\\par\\pard\n"));
- SetCurrentOutput(winHelp ? Subsubsections : Chapters);
- if (winHelp)
- {
- wxFprintf(Subsubsections, _T("}\n#{\\footnote %s}\n"), topicName);
- wxFprintf(Subsubsections, _T("+{\\footnote %s}\n"), GetBrowseString());
- OutputSectionKeyword(Subsubsections);
- GenerateKeywordsForTopic(topicName);
- if (useUpButton && CurrentSubsectionName)
- {
- wxFprintf(Subsubsections, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
- wxFileNameFromPath(FileRoot), CurrentSubsectionName);
- }
- }
- if (!winHelp && indexSubsections && useWord)
- {
- // Insert index entry for this subsubsection
- TexOutput(_T("{\\xe\\v {"));
- OutputCurrentSection();
- TexOutput(_T("}}"));
- }
- wxChar *styleCommand = _T("");
- if (!winHelp && useHeadingStyles && (macroId != ltSUBSUBSECTIONSTAR))
- {
- if (DocumentStyle == LATEX_ARTICLE)
- styleCommand = _T("\\s3");
- else
- styleCommand = _T("\\s4");
- }
- wxChar *keep = _T("");
- if (winHelp)
- keep = _T("\\keepn\\sa140\\sb140");
- wxFprintf(winHelp ? Subsubsections : Chapters, _T("\\pard{%s%s"),
- keep, styleCommand);
- WriteHeadingStyle((winHelp ? Subsubsections : Chapters),
- (DocumentStyle == LATEX_ARTICLE ? 3 : 4));
- wxFprintf(winHelp ? Subsubsections : Chapters, _T(" "));
- if (!winHelp)
- {
- if ((macroId != ltSUBSUBSECTIONSTAR))
- {
- if (DocumentStyle == LATEX_ARTICLE)
- {
- if (useWord)
- // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
- wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName,
- topicName);
- else
- wxFprintf(Chapters, _T("%d.%d.%d. "), sectionNo, …
Large files files are truncated, but you can click here to view the full file