void CmdThebibliography(int code) { int amount = 450; if (code & ON) { char * s = getBraceParam(); /*throw away widest_label */ free(s); CmdEndParagraph(0); CmdVspace(VSPACE_MEDIUM_SKIP); CmdStartParagraph(TITLE_PAR); fprintRTF("{\\plain\\b\\fs32 "); if (g_document_type == FORMAT_ARTICLE) ConvertBabelName("REFNAME"); else ConvertBabelName("BIBNAME"); fprintRTF("}"); CmdEndParagraph(0); CmdVspace(VSPACE_SMALL_SKIP); PushEnvironment(GENERIC_ENV); //setLength("parindent", -amount); //g_left_margin_indent += 2*amount; } else { CmdEndParagraph(0); CmdVspace(VSPACE_SMALL_SKIP); PopEnvironment(); g_processing_list_environment=FALSE; } }
void CmdMusic(int code) /****************************************************************************** purpose: Process \begin{music} ... \end{music} environment ******************************************************************************/ { char *contents; char endmusic[] = "\\end{music}"; if (!(code & ON)) { diagnostics(4, "exiting CmdMusic"); return; } diagnostics(4, "entering CmdMusic"); contents = getTexUntil(endmusic, TRUE); CmdEndParagraph(0); CmdVspace(VSPACE_SMALL_SKIP); CmdIndent(INDENT_NONE); CmdStartParagraph(FIRST_PAR); WriteLatexAsBitmap("\\begin{music}",contents,endmusic); ConvertString(endmusic); CmdEndParagraph(0); CmdVspace(VSPACE_SMALL_SKIP); CmdIndent(INDENT_INHIBIT); free(contents); }
void CmdPrintIndex(int code) { CmdEndParagraph(0); fprintRTF("\\page "); fprintRTF("{\\field{\\*\\fldinst{INDEX \\\\c 2}}{\\fldrslt{}}}"); }
void SetTexMode(int mode) { if (abs(mode) != g_TeX_mode) diagnostics(4, "TeX mode changing from [%s] -> [%s]", TexModeName[g_TeX_mode], TexModeName[abs(mode)]); if (mode < 0) { /* hack to allow CmdStartParagraph to set mode directly */ g_TeX_mode = -mode; return; } if (g_TeX_mode == MODE_VERTICAL && mode == MODE_HORIZONTAL) CmdStartParagraph(ANY_PAR); if (g_TeX_mode == MODE_HORIZONTAL && mode == MODE_VERTICAL) CmdEndParagraph(0); g_TeX_mode = mode; }
void CmdBibitem(int code) { char *label, *key, *signet, *s, c; g_processing_list_environment=TRUE; CmdEndParagraph(0); CmdStartParagraph(FIRST_PAR); label = getBracketParam(); key = getBraceParam(); signet = strdup_nobadchars(key); s=ScanAux("bibcite", key, 0); if (label && !s) { /* happens when file needs to be latex'ed again */ diagnostics(WARNING,"file needs to be latexed again for references"); fprintRTF("["); ConvertString(label); fprintRTF("]"); } else { diagnostics(4,"CmdBibitem <%s>",s); if (g_document_bibstyle == BIBSTYLE_STANDARD) { // fprintRTF("["); fprintRTF("{\\v\\*\\bkmkstart BIB_%s}",signet); ConvertString(s); fprintRTF("{\\*\\bkmkend BIB_%s}",signet); // fprintRTF("]"); fprintRTF("."); fprintRTF("\\tab "); } /* else emit nothing for APALIKE */ } if (s) free(s); if (label) free(label); free(signet); free(key); c=getNonBlank(); ungetTexChar(c); }
static void FinishRtfEquation(int code, int EQ_Needed) { if (EQ_Needed && g_processing_fields==1) { fprintRTF("}}{\\fldrslt }}"); g_processing_fields--; } switch (code) { case EQN_MATH: diagnostics(4,"FinishRtfEquation -- \\end{math}"); CmdIndent(INDENT_INHIBIT); SetTexMode(MODE_HORIZONTAL); break; case EQN_DOLLAR: diagnostics(4,"FinishRtfEquation -- $"); fprintRTF("}"); SetTexMode(MODE_HORIZONTAL); break; case EQN_RND_OPEN: diagnostics(4,"FinishRtfEquation -- \\)"); fprintRTF("}"); SetTexMode(MODE_HORIZONTAL); break; case EQN_DOLLAR_DOLLAR: diagnostics(4,"FinishRtfEquation -- $$"); CmdEndParagraph(0); CmdIndent(INDENT_INHIBIT); fprintRTF("}"); break; case EQN_BRACKET_OPEN: diagnostics(4,"FinishRtfEquation -- \\["); SetTexMode(MODE_VERTICAL); fprintRTF("\\par\\par\n}"); break; case EQN_DISPLAYMATH: diagnostics(4,"FinishRtfEquation -- displaymath"); CmdEndParagraph(0); CmdIndent(INDENT_INHIBIT); break; case EQN_EQUATION_STAR: diagnostics(4,"FinishRtfEquation -- equation*"); CmdEndParagraph(0); CmdIndent(INDENT_INHIBIT); break; case EQN_ARRAY_STAR: diagnostics(4,"FinishRtfEquation -- eqnarray* "); CmdEndParagraph(0); CmdIndent(INDENT_INHIBIT); g_processing_eqnarray = FALSE; g_processing_tabular = FALSE; break; case EQN_EQUATION: case EQN_ARRAY: diagnostics(4,"FinishRtfEquation --- equation or eqnarray"); if (g_show_equation_number && !g_suppress_equation_number) { char number[20]; incrementCounter("equation"); for (; g_equation_column < 3; g_equation_column++) fprintRTF("\\tab "); fprintRTF("\\tab{\\b0 ("); sprintf(number,"%d",getCounter("equation")); InsertBookmark(g_equation_label,number); if (g_equation_label) { free(g_equation_label); g_equation_label = NULL; } fprintRTF(")}"); } g_processing_eqnarray = FALSE; g_processing_tabular = FALSE; CmdEndParagraph(0); CmdIndent(INDENT_INHIBIT); break; default: diagnostics(ERROR, "calling FinishRtfEquation with OFF code"); break; } }
static void PrepareRtfEquation(int code, int EQ_Needed) { int width,a,b,c; width = getLength("textwidth"); a = 0.45 * width; b = 0.50 * width; c = 0.55 * width; switch (code) { case EQN_MATH: diagnostics(4, "PrepareRtfEquation ... \\begin{math}"); SetTexMode(MODE_MATH); break; case EQN_DOLLAR: diagnostics(4, "PrepareRtfEquation ... $"); fprintRTF("{"); SetTexMode(MODE_MATH); break; case EQN_RND_OPEN: diagnostics(4, "PrepareRtfEquation ... \\("); fprintRTF("{"); SetTexMode(MODE_MATH); break; case EQN_DOLLAR_DOLLAR: diagnostics(4,"PrepareRtfEquation -- $$"); CmdEndParagraph(0); SetTexMode(MODE_DISPLAYMATH); g_show_equation_number = FALSE; fprintRTF("{\\pard\\tqc\\tx%d\\tab ", b); break; case EQN_BRACKET_OPEN: diagnostics(4,"PrepareRtfEquation -- \\["); SetTexMode(MODE_DISPLAYMATH); g_show_equation_number = TRUE; fprintRTF("\\par\\par\n{\\pard\\tqc\\tx%d\\tqr\\tx%d\n\\tab ", b, width); break; case EQN_DISPLAYMATH: diagnostics(4,"PrepareRtfEquation -- displaymath"); g_show_equation_number = FALSE; fprintRTF("\\par\\par\n\\pard"); fprintRTF("\\tqc\\tx%d", b); fprintRTF("\\tab "); SetTexMode(MODE_DISPLAYMATH); break; case EQN_EQUATION_STAR: diagnostics(4,"PrepareRtfEquation -- equation*"); g_show_equation_number = FALSE; fprintRTF("\\par\\par\n\\pard"); fprintRTF("\\tqc\\tx%d", b); fprintRTF("\\tab "); SetTexMode(MODE_DISPLAYMATH); break; case EQN_EQUATION: diagnostics(4,"PrepareRtfEquation -- equation"); g_equation_column = 5; /* avoid adding \tabs when finishing */ g_show_equation_number = TRUE; fprintRTF("\\par\\par\n\\pard"); fprintRTF("\\tqc\\tx%d\\tqr\\tx%d", b, width); fprintRTF("\\tab "); SetTexMode(MODE_DISPLAYMATH); break; case EQN_ARRAY_STAR: diagnostics(4,"PrepareRtfEquation -- eqnarray* "); g_show_equation_number = FALSE; g_processing_eqnarray = TRUE; g_processing_tabular = TRUE; g_equation_column = 1; fprintRTF("\\par\\par\n\\pard"); fprintRTF("\\tqr\\tx%d\\tqc\\tx%d\\tql\\tx%d", a, b, c); fprintRTF("\\tab "); SetTexMode(MODE_DISPLAYMATH); break; case EQN_ARRAY: diagnostics(4,"PrepareRtfEquation --- eqnarray"); g_show_equation_number = TRUE; g_processing_eqnarray = TRUE; g_processing_tabular = TRUE; g_equation_column = 1; fprintRTF("\\par\\par\n\\pard"); fprintRTF("\\tqr\\tx%d\\tqc\\tx%d\\tql\\tx%d\\tqr\\tx%d", a, b, c, width); fprintRTF("\\tab "); SetTexMode(MODE_DISPLAYMATH); break; default: diagnostics(ERROR, "calling PrepareRtfEquation with OFF code"); break; } if (EQ_Needed && g_processing_fields==0) { fprintRTF("{\\field{\\*\\fldinst{ EQ "); g_processing_fields++; } }
void Convert() /**************************************************************************** purpose: converts inputfile and writes result to outputfile globals: fTex, fRtf and all global flags for convert (see above) ****************************************************************************/ { char cThis = '\n'; char cLast = '\0'; char cNext; int mode, count,pending_new_paragraph; diagnostics(3, "Entering Convert ret = %d", ret); RecursionLevel++; PushLevels(); while ((cThis = getTexChar()) && cThis != '\0') { if (cThis == '\n') diagnostics(5, "Current character is '\\n' mode = %d ret = %d level = %d", GetTexMode(), ret, RecursionLevel); else diagnostics(5, "Current character is '%c' mode = %d ret = %d level = %d", cThis, GetTexMode(), ret, RecursionLevel); mode = GetTexMode(); pending_new_paragraph--; switch (cThis) { case '\\': PushLevels(); TranslateCommand(); CleanStack(); if (ret > 0) { diagnostics(5, "Exiting Convert via TranslateCommand ret = %d level = %d", ret, RecursionLevel); ret--; RecursionLevel--; return; } break; case '{': if (mode==MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL); CleanStack(); PushBrace(); fprintRTF("{"); break; case '}': CleanStack(); ret = RecursionLevel - PopBrace(); fprintRTF("}"); if (ret > 0) { diagnostics(5, "Exiting Convert via '}' ret = %d level = %d", ret, RecursionLevel); ret--; RecursionLevel--; return; } break; case ' ': if (mode==MODE_VERTICAL || mode==MODE_MATH || mode==MODE_DISPLAYMATH) cThis = cLast; else if ( cLast != ' ' && cLast != '\n' ) { if (GetTexMode()==MODE_RESTRICTED_HORIZONTAL) fprintRTF("\\~"); else fprintRTF(" "); } break; case '\n': tabcounter = 0; if (mode==MODE_MATH || mode==MODE_DISPLAYMATH) { cNext = getNonBlank(); ungetTexChar(cNext); } else { cNext = getNonSpace(); if (cNext == '\n') { /* new paragraph ... skip all ' ' and '\n' */ pending_new_paragraph=2; CmdEndParagraph(0); cNext = getNonBlank(); ungetTexChar(cNext); } else { /* add a space if needed */ ungetTexChar(cNext); if (mode != MODE_VERTICAL && cLast != ' ') fprintRTF(" "); } } break; case '$': cNext = getTexChar(); diagnostics(5,"Processing $, next char <%c>",cNext); if (cNext == '$' && GetTexMode() != MODE_MATH) CmdEquation(EQN_DOLLAR_DOLLAR | ON); else { ungetTexChar(cNext); CmdEquation(EQN_DOLLAR | ON); } /* Formulas need to close all Convert() operations when they end This works for \begin{equation} but not $$ since the BraceLevel and environments don't get pushed properly. We do it explicitly here. */ /* if (GetTexMode() == MODE_MATH || GetTexMode() == MODE_DISPLAYMATH) PushBrace(); else { ret = RecursionLevel - PopBrace(); if (ret > 0) { ret--; RecursionLevel--; diagnostics(5, "Exiting Convert via Math ret = %d", ret); return; } } */ break; case '&': if (g_processing_arrays) { fprintRTF("%c",g_field_separator); break; } if (GetTexMode() == MODE_MATH || GetTexMode() == MODE_DISPLAYMATH) { /* in eqnarray */ fprintRTF("\\tab "); g_equation_column++; break; } if (g_processing_tabular) { /* in tabular */ actCol++; fprintRTF("\\cell\\pard\\intbl\\q%c ", colFmt[actCol]); break; } fprintRTF("&"); break; case '~': fprintRTF("\\~"); break; case '^': CmdSuperscript(0); break; case '_': CmdSubscript(0); break; case '-': if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) fprintRTF("-"); else { SetTexMode(MODE_HORIZONTAL); count = getSameChar('-')+1; if (count == 1) fprintRTF("-"); else if (count == 2) fprintRTF("\\endash "); else if (count == 3) fprintRTF("\\emdash "); else while (count--) fprintRTF("-"); } break; case '|': if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) fprintRTF("|"); else fprintRTF("\\emdash "); break; case '\'': if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) fprintRTF("'"); else { SetTexMode(MODE_HORIZONTAL); count = getSameChar('\'')+1; if (count == 2) fprintRTF("\\rdblquote "); else while (count--) fprintRTF("\\rquote "); } break; case '`': SetTexMode(MODE_HORIZONTAL); count = getSameChar('`')+1; if (count == 2) fprintRTF("\\ldblquote "); else while (count--) fprintRTF("\\lquote "); break; case '\"': SetTexMode(MODE_HORIZONTAL); if (GermanMode) TranslateGerman(); else fprintRTF("\""); break; case '<': if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL); if (GetTexMode() == MODE_HORIZONTAL){ cNext = getTexChar(); if (cNext == '<') { if (FrenchMode) { /* not quite right */ skipSpaces(); cNext = getTexChar(); if (cNext == '~') skipSpaces(); else ungetTexChar(cNext); fprintRTF("\\'ab\\~"); } else fprintRTF("\\'ab"); } else { ungetTexChar(cNext); fprintRTF("<"); } } else fprintRTF("<"); break; case '>': if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL); if (GetTexMode() == MODE_HORIZONTAL){ cNext = getTexChar(); if (cNext == '>') fprintRTF("\\'bb"); else { ungetTexChar(cNext); fprintRTF(">"); } } else fprintRTF(">"); break; case '!': if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) fprintRTF("!"); else { SetTexMode(MODE_HORIZONTAL); if ((cNext = getTexChar()) && cNext == '`') { fprintRTF("\\'a1 "); } else { fprintRTF("! "); ungetTexChar(cNext); } } break; case '?': SetTexMode(MODE_HORIZONTAL); if ((cNext = getTexChar()) && cNext == '`') { fprintRTF("\\'bf "); } else { fprintRTF("? "); ungetTexChar(cNext); } break; case ':': if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) fprintRTF(":"); else { SetTexMode(MODE_HORIZONTAL); if (FrenchMode) fprintRTF("\\~:"); else fprintRTF(":"); } break; case '.': if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) fprintRTF("."); else { SetTexMode(MODE_HORIZONTAL); fprintRTF("."); /* try to simulate double spaces after sentences */ cNext = getTexChar(); if (0 && cNext == ' ' && (isalpha((int)cLast) && !isupper((int) cLast))) fprintRTF(" "); ungetTexChar(cNext); } break; case '\t': diagnostics(WARNING, "This should not happen, ignoring \\t"); cThis = ' '; break; case '\r': diagnostics(WARNING, "This should not happen, ignoring \\r"); cThis = ' '; break; case '%': diagnostics(WARNING, "This should not happen, ignoring %%"); cThis = ' '; break; case '(': if (g_processing_fields&&g_escape_parent) fprintRTF("\\\\("); else fprintRTF("("); break; case ')': if (g_processing_fields&&g_escape_parent) fprintRTF("\\\\)"); else fprintRTF(")"); break; case ';': if (g_field_separator == ';' && g_processing_fields) fprintRTF("\\\\;"); else if (FrenchMode) fprintRTF("\\~;"); else fprintRTF(";"); break; case ',': if (g_field_separator == ',' && g_processing_fields) fprintRTF("\\\\,"); else fprintRTF(","); break; default: if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) { if (('a' <= cThis && cThis <= 'z') || ('A' <= cThis && cThis <= 'Z')) fprintRTF("{\\i %c}", cThis); else fprintRTF("%c", cThis); } else { SetTexMode(MODE_HORIZONTAL); fprintRTF("%c", cThis); } break; } tabcounter++; cLast = cThis; } RecursionLevel--; diagnostics(5, "Exiting Convert via exhaustion ret = %d", ret); }