Esempio n. 1
0
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;
		}
}
Esempio n. 2
0
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++;	
	}
	
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
void 
TranslateCommand()
/****************************************************************************
purpose: The function is called on a backslash in input file and
	 tries to call the command-function for the following command.
returns: success or not
globals: fTex, fRtf, command-functions have side effects or recursive calls;
         global flags for convert
 ****************************************************************************/
{
	char            cCommand[MAXCOMMANDLEN];
	int             i,mode;
	int             cThis;


	cThis = getTexChar();
	mode = GetTexMode();
	
	diagnostics(5, "Beginning TranslateCommand() \\%c", cThis);

	switch (cThis) {
	case '}':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("\\}");
		return;
	case '{':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("\\{");
		return;
	case '#':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("#");
		return;
	case '$':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("$");
		return;
	case '&':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("&");
		return;
	case '%':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("%%");
		return;
	case '_':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("_");
		return;
		
	case '\\':		/* \\[1mm] or \\*[1mm] possible */
		CmdSlashSlash(0);
		return;
		
	case ' ':
	case '\n':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF(" ");	/* ordinary interword space */
		skipSpaces();
		return;

/* \= \> \< \+ \- \' \` all have different meanings in a tabbing environment */

	case '-':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		} else
			fprintRTF("\\-");
		return;

	case '+':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		}
		return;
		
	case '<':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		}
		return;

	case '>':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			CmdTabjump();
			PushBrace();
		} else 
			CmdSpace(0.50);  /* medium space */
		return;
		
	case '`':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		} else
			CmdLApostrophChar(0);
		return;
		
	case '\'':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
			return;
		} else
			CmdRApostrophChar(0);	/* char ' =?= \' */
		return;

	case '=':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			CmdTabset();
			PushBrace();
		}
		else
			CmdMacronChar(0);
		return;
		
	case '~':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdTildeChar(0);
		return;
	case '^':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdHatChar(0);
		return;
	case '.':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdDotChar(0);
		return;
	case '\"':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdUmlauteChar(0);
		return;
	case '(':
		CmdEquation(EQN_RND_OPEN | ON);
		/*PushBrace();*/
		return;
	case '[':
		CmdEquation(EQN_BRACKET_OPEN | ON);
		/*PushBrace();*/
		return;
	case ')':
		CmdEquation(EQN_RND_CLOSE | OFF);
		/*ret = RecursionLevel - PopBrace();*/
		return;
	case ']':
		CmdEquation(EQN_BRACKET_CLOSE | OFF);
		/*ret = RecursionLevel - PopBrace();*/
		return;
	case '/':
		CmdIgnore(0);		/* italic correction */
		return;
	case '!':
		CmdIgnore(0);		/* \! negative thin space */
		return;
	case ',':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdSpace(0.33);	/* \, produces a small space */
		return;
	case ';':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdSpace(0.75);	/* \; produces a thick space */
		return;
	case '@':
		CmdIgnore(0);	/* \@ produces an "end of sentence" space */
		return;
	case '3':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("{\\'df}");	/* german symbol 'á' */
		return;
	}


	/* LEG180498 Commands consist of letters and can have an optional * at the end */
	for (i = 0; i < MAXCOMMANDLEN; i++) {
		if (!isalpha((int)cThis) && (cThis != '*')) {
			bool            found_nl = FALSE;

			if (cThis == '%'){			/* put the % back and get the next char */
				ungetTexChar('%');
				cThis=getTexChar();
			}

			/* all spaces after commands are ignored, a single \n may occur */
			while (cThis == ' ' || (cThis == '\n' && !found_nl)) {
				if (cThis == '\n')
					found_nl = TRUE;
				cThis = getTexChar();
			}

			ungetTexChar(cThis);	/* put back first non-space char after command */
			break;					/* done skipping spaces */
		} else
			cCommand[i] = cThis;

		cThis = getRawTexChar();	/* Necessary because % ends a command */
	}

	cCommand[i] = '\0';	/* mark end of string with zero */
	diagnostics(5, "TranslateCommand() <%s>", cCommand);

	if (i == 0)
		return;
		
	if (strcmp(cCommand,"begin")==0){
		fprintRTF("{");
		PushBrace();
	}
		
	if (CallCommandFunc(cCommand)){	/* call handling function for command */
		if (strcmp(cCommand,"end")==0) {
			ret = RecursionLevel - PopBrace();
			fprintRTF("}");
		}
		return;
	}
	
	if (TryDirectConvert(cCommand)) return;
	
	if (TryVariableIgnore(cCommand)) return;
		
	diagnostics(WARNING, "Command \\%s not found - ignored", cCommand);
}
Esempio n. 5
0
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);
}