void CmdLabel(int code) /****************************************************************************** purpose: handles \label \ref \pageref \cite ******************************************************************************/ { char *text, *signet, *s; char *option = NULL; int mode=GetTexMode(); option = getBracketParam(); text = getBraceParam(); if (strlen(text)==0) { free(text); return; } switch (code) { case LABEL_LABEL: if (g_processing_figure || g_processing_table) break; if (mode == MODE_DISPLAYMATH) { g_equation_label = strdup_nobadchars(text); diagnostics(3,"equation label is <%s>",text); } else InsertBookmark(text,""); break; case LABEL_HYPERREF: case LABEL_REF: signet = strdup_nobadchars(text); s = ScanAux("newlabel", text, 1); if (g_fields_use_REF) { fprintRTF("{\\field{\\*\\fldinst{\\lang1024 REF BM%s \\\\* MERGEFORMAT }}",signet); fprintRTF("{\\fldrslt{"); } if (s) ConvertString(s); else fprintRTF("?"); if (g_fields_use_REF) fprintRTF("}}}"); free(signet); if (s) free(s); break; case LABEL_HYPERPAGEREF: case LABEL_PAGEREF: signet = strdup_nobadchars(text); if (g_fields_use_REF) { fprintRTF("{\\field{\\*\\fldinst{\\lang1024 PAGEREF BM%s \\\\* MERGEFORMAT }}",signet); fprintRTF("{\\fldrslt{"); } fprintRTF("%s",signet); if (g_fields_use_REF) fprintRTF("}}}"); free(signet); break; } free(text); if (option) free(option); }
void CmdArray(int code) /****************************************************************************** purpose : Handles \begin{array}[c]{ccc} ... \end{array} ******************************************************************************/ { char * v_align, * col_align, *s; int n=0; if (code & ON) { v_align = getBracketParam(); col_align = getBraceParam(); diagnostics(4, "CmdArray() ... \\begin{array}[%s]{%s}", v_align?v_align:"", col_align); if (v_align) free(v_align); s = col_align; while (*s) { if (*s == 'c' || *s == 'l' || *s == 'r' ) n++; s++; } free(col_align); fprintRTF(" \\\\a \\\\ac \\\\co%d (", n); g_processing_arrays++; } else { fprintRTF(")"); diagnostics(4, "CmdArray() ... \\end{array}"); g_processing_arrays--; } }
void CmdFootNote(int code) /****************************************************************************** purpose: converts footnotes from LaTeX to Rtf params : code specifies whether it is a footnote or a thanks-mark ******************************************************************************/ { char *number, *text; static int thankno = 1; int text_ref_upsize, foot_ref_upsize; int DefFont = DefaultFontFamily(); diagnostics(4,"Entering ConvertFootNote"); number = getBracketParam(); /* ignored by automatic footnumber generation */ text = getBraceParam(); if (number) free(number); text_ref_upsize = (int) (0.8 * CurrentFontSize()); foot_ref_upsize = (int) (0.8 * CurrentFontSize()); switch (code) { case FOOTNOTE_THANKS: thankno++; fprintRTF("{\\up%d %d}\n", text_ref_upsize, thankno); fprintRTF("{\\*\\footnote \\pard\\plain\\s246\\f%d",DefFont); fprintRTF("\\fs%d {\\up%d %d}", CurrentFontSize(), foot_ref_upsize, thankno); break; case FOOTNOTE: fprintRTF("{\\up%d\\chftn}\n", text_ref_upsize); fprintRTF("{\\*\\footnote \\pard\\plain\\s246\\f%d",DefFont); fprintRTF("\\fs%d {\\up%d\\chftn}", CurrentFontSize(), foot_ref_upsize); break; case FOOTNOTE_TEXT: fprintRTF("{\\*\\footnote \\pard\\plain\\s246\\f%d",DefFont); fprintRTF("\\fs%d ", CurrentFontSize()); break; } ConvertString(text); fprintRTF("}\n "); diagnostics(4,"Exiting CmdFootNote"); free(text); }
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); }
void CmdRoot(int code) /****************************************************************************** purpose: converts \sqrt{x} or \root[\alpha]{x+y} ******************************************************************************/ { char *root; char *power; power = getBracketParam(); root = getBraceParam(); fprintRTF(" \\\\R("); if (power && strlen(power)>0) ConvertString(power); fprintRTF("%c", g_field_separator); ConvertString(root); fprintRTF(")"); if (power) free(power); free(root); }
void CmdTikzPicture(int code) /****************************************************************************** purpose: handle \begin{tikzpicture} ... \end{tikzpicture} by converting to png image and inserting ******************************************************************************/ { char *pre, *post, *tikzcode, *param; param = getBracketParam(); if (code & ON) { pre = strdup("\\begin{tikzpicture}"); post = strdup("\\end{tikzpicture}"); tikzcode=getTexUntil(post,0); TikzToPng(tikzcode,param); ConvertString(post); /* to balance the \begin{picture} */ free(pre); free(post); free(tikzcode); free(param); } }
void CmdCite(int code) /****************************************************************************** purpose: handles \cite ******************************************************************************/ { char punct[4]="[],"; char *text, *str1; char *keys, *key, *next_keys; char *option = NULL; char *pretext = NULL; /* Setup punctuation and read options before citation */ g_current_cite_paren=TRUE; *g_last_author_cited='\0'; if (g_document_bibstyle == BIBSTYLE_STANDARD){ option = getBracketParam(); } if (g_document_bibstyle == BIBSTYLE_APALIKE){ strcpy(punct,"();"); option = getBracketParam(); } if (g_document_bibstyle == BIBSTYLE_AUTHORDATE){ strcpy(punct,"();"); option = getBracketParam(); } if (g_document_bibstyle == BIBSTYLE_NATBIB){ pretext = getBracketParam(); option = getBracketParam(); strcpy(punct,"();"); if (code!=CITE_P && code!=CITE_P_STAR && code!=CITE_ALP && code!=CITE_ALP_STAR && code!=CITE_YEAR_P) g_current_cite_paren=FALSE; } if (g_document_bibstyle == BIBSTYLE_APACITE){ pretext = getAngleParam(); option = getBracketParam(); strcpy(punct,"();"); if (code!=CITE_CITE && code!=CITE_FULL && code!=CITE_SHORT && code!=CITE_YEAR) g_current_cite_paren=FALSE; g_current_cite_type=code; } text = getBraceParam(); str1 = strdup_nocomments(text); free(text); text=str1; if (strlen(text)==0) { free(text); if (pretext) free(pretext); if (option) free(option); return; } /* output text before citation */ if (g_current_cite_paren) fprintRTF("\n%c", punct[0]); if (pretext && g_document_bibstyle == BIBSTYLE_APACITE ) { ConvertString(pretext); fprintRTF(" "); } /* now start processing keys */ keys = strdup_noblanks(text); free(text); key = keys; next_keys = popCommaName(key); g_current_cite_item=0; while (key) { char *s, *t; g_current_cite_item++; s = ScanAux("bibcite", key, 0); /* look up bibliographic reference */ if (g_document_bibstyle == BIBSTYLE_APALIKE) { /* can't use Word refs for APALIKE or APACITE*/ t = s ? s : key; ConvertString(t); } if (g_document_bibstyle == BIBSTYLE_AUTHORDATE) { t = s ? s : key; if (code==CITE_SHORT) g_suppress_name=TRUE; ConvertString(t); if (code==CITE_SHORT) g_suppress_name=FALSE; } if (g_document_bibstyle == BIBSTYLE_APACITE) { /* */ t = s ? s : key; g_current_cite_seen=citation_used(key); ConvertString(t); } if (g_document_bibstyle == BIBSTYLE_NATBIB) { diagnostics(2,"natbib key=[%s] <%s>",key, s); if (s) { g_current_cite_seen=citation_used(key); ConvertNatbib(s,code,pretext,option); } else ConvertString(key); } if (g_document_bibstyle == BIBSTYLE_STANDARD) { /* */ char *signet = strdup_nobadchars(key); t = s ? s : signet; /* if .aux is missing or incomplete use original citation */ if (g_fields_use_REF) { fprintRTF("{\\field{\\*\\fldinst{\\lang1024 REF BIB_%s \\\\* MERGEFORMAT }}",signet); fprintRTF("{\\fldrslt{"); } ConvertString(t); if (g_fields_use_REF) fprintRTF("}}}"); if (signet) free(signet); } if (next_keys) fprintRTF("%c ",punct[2]); /* punctuation between citations */ key=next_keys; next_keys=popCommaName(key); /* key modified to be a single key */ if (s) free(s); } /* final text after citation */ if (option && (g_document_bibstyle == BIBSTYLE_APACITE || g_document_bibstyle == BIBSTYLE_AUTHORDATE)) { fprintRTF(", "); ConvertString(option); } if (g_current_cite_paren) fprintRTF("\n%c", punct[1]); if (keys) free(keys); if (option) free(option); if (pretext) free(pretext); }
static char * expandmacro(char *macro, char *opt_param, int params) /************************************************************************** purpose: retrieves and expands a defined macro **************************************************************************/ { int i=0,param; char * args[9], *dmacro, *macro_piece, *next_piece, *expanded, buffer[1024], *cs; if (params<=0) return strdup(macro); if (opt_param) { args[i++] = getBracketParam(); if (!args[0]) args[0] = strdup(opt_param); } for (; i<params; i++) { args[i] = getBraceParam(); diagnostics(3, "argument #%d <%s>", i+1, args[i]); } *buffer='\0'; expanded = buffer; dmacro = strdup(macro); macro_piece = dmacro; /* convert "\csname" to "\" */ while ((cs=strstr(dmacro, "\\csname")) != NULL) strcpy(cs+1,cs+7); /* remove "\endcsname" */ while ((cs=strstr(dmacro, "\\endcsname")) != NULL) strcpy(cs,cs+10); /* do not use strtok because it may be used elsewhere */ while (macro_piece && *macro_piece) { next_piece = strchr(macro_piece, '#'); if (next_piece) { *next_piece = '\0'; next_piece++; if (*next_piece=='#') param = 101; /* just a flag for below */ else param = *next_piece - '1'; next_piece++; } else param = -1; diagnostics(3, "expandmacro piece =<%s>", macro_piece); strcpy(expanded,macro_piece); expanded += strlen(macro_piece); if (param > -1) { if (param==101) { diagnostics(3, "expandmacro ## = #"); strcpy(expanded,"#"); expanded ++; } else if (param<params) { diagnostics(3, "expandmacro arg =<%s>", args[param]); strcpy(expanded,args[param]); expanded += strlen(args[param]); } else diagnostics(WARNING,"confusing definition in macro=<%s>", macro); } macro_piece = next_piece; } /* ConvertString(buffer);*/ for (i=0; i< params; i++) if (args[i]) free(args[i]); if (dmacro) free(dmacro); diagnostics(3, "expandmacro expanded=<%s>", buffer); return strdup(buffer); }
void CmdGraphics(int code) /* \includegraphics[parameters]{filename} where parameters is a comma-separated list of any of the following: bb=llx lly urx ury (bounding box), width=h_length, height=v_length, angle=angle, scale=factor, clip=true/false, draft=true/false. code=0 => includegraphics code=1 => epsffile code=2 => epsfbox code=3 => \BoxedSPSF code=4 => psfig */ { char *options,*options2; char *filename,*fullpathname, *fullname; double scale=1.0; double baseline=0.0; double x; char *p; if (code==0) { /* could be \includegraphics*[0,0][5,5]{file.pict} */ options = getBracketParam(); options2 = getBracketParam(); if (options2) free(options2); if (options) { /* \includegraphics[scale=0.5]{file.png} */ p = strstr(options,"scale"); if (p) { p = strchr(p,'='); if (p && (sscanf(p+1,"%lf", &x) == 1)) scale = x; } free(options); } filename = getBraceParam(); diagnostics(1, "image scale = %g", scale); if (g_figs_extract && g_processing_figure) { struct stat st ={0}; if (stat(g_figsdir, &st) == -1) { mkdir(g_figsdir,0755); } g_fignum++; char *name = (char *)malloc(15*sizeof(char)); snprintf(name,15,"Ris%d.png",g_fignum); char *destname = strdup_together(g_figsdir,"/"); char *pngname = strdup_together(destname,name); int cmd_len = strlen("convert -alpha off -density 300x300 ") + strlen(destname) + strlen(filename)+32; char *cmd = (char *) malloc(cmd_len); snprintf(cmd,cmd_len,"convert -density 300x300 %s -alpha off %s ",filename,pngname); system(cmd); free(cmd); free(destname); free(pngname); free(name); } } if (code==1) { /* \epsffile{filename.eps} */ filename = getBraceParam(); } if (code==2) { /* \epsfbox[0 0 30 50]{filename.ps} */ options = getBracketParam(); if (options) free(options); filename = getBraceParam(); } if (code==3) { /* \BoxedEPSF{filename [scaled nnn]} */ char *s; filename = getBraceParam(); s= strchr(filename,' '); if (s) *s='\0'; } if (code==4) { /* \psfig{figure=filename,height=hhh,width=www} */ char *s, *t; filename = getBraceParam(); s = strstr(filename,"figure="); if (!s) return; s += strlen("figure="); t = strchr(s,','); if (t) *t='\0'; t = strdup(s); free(filename); filename = t; } SetTexMode(MODE_HORIZONTAL); fullname=strdup_absolute_path(filename); fullpathname=append_graphic_extension(fullname); free(fullname); if (has_extension(fullpathname, ".pict")) PutPictFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".png")) PutPngFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".gif")) PutGifFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".emf")) PutEmfFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".wmf")) PutWmfFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".eps")) PutEpsFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".pdf")) PutPdfFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".ps")) PutEpsFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".tiff")) PutTiffFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".tif")) PutTiffFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".jpg")) PutJpegFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".jpeg")) PutJpegFile(fullpathname, scale, baseline, TRUE); else diagnostics(WARNING, "Conversion of '%s' not supported", filename); free(filename); free(fullpathname); }