Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #672
| From | greenux <greenux@gmx.de> |
|---|---|
| Newsgroups | comp.graphics.apps.gnuplot |
| Subject | New strlen_tex() in gnuplot source code |
| Date | 2011-11-07 01:36 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <6993c3c9-ed3d-475d-9ae6-26250f63decd@ek5g2000vbb.googlegroups.com> (permalink) |
Hi gnuplot developers,
I had kind of trouble using latex commands in gnuplot with epslatex
terminal and build me a workaround by creating one file with the latex
command, another file only with placeholder create by latex with the
estimated size from latex and then combined them. This is kind of
stupid. Instead it would be much better to improve the gnuplot source
code.
I finally made a new strlen_tex() function in term.c (see below - I'm
not really good in C programming!!!) to estimate the length of the
latex code correctly by running latex. (I will change term->h_char to
1 to get more precise results).
Now I have the same problem for the height (especially for the key
box), but there is no strheight_tex() function, only a term->v_char.
The correct term->v_char should be a function depend on the heighest
key entry (the entries heights can differ e. g. if using subscript or
superscript!). Because of that I would like to propose to change the
gnuplot source in a way that each terminal provides a strheight()
function instead of t->v_char. Than for each element the height is
estimated by the strheight(char *entry) function. For constant height
the strheight() function returns term->v_char, but in other cases it
can also return the exact value.
The key box height can now be calculated by getting the highest value
of strheight() for each entry. The same holds for xtics, ytics, ...
Running latex doesn't take much time, but it improves the result very
much!
This change affects a lot of source code, but it improves the
possibilities for all terminals and the results!
I would be very thankful if someone who is much better in C
programming then me could make these changes!
Regards,
greenux
/*
* Run latex to estimate the correct strlen no matter what is the
text
*/
int
strlen_tex(const char *str)
{
const char *s = str;
char ch;
int len = 0;
int i = 0;
float a; //result array
//Write latex code to file
FILE *texfile = fopen("gnuplot_estimate_strlen_tex.tmp","w");
fprintf(texfile,"\\documentclass{article}\n"); //Maybe a minimal
class would increase speed
//Read packages from file
FILE *pkgfile = fopen("packages.tex","r"); //load all required
packages from file in same directory, later a terminal option could be
used
while ( 1 )
{
ch = fgetc ( pkgfile );
if ( ch == EOF )
break;
else
fputc ( ch, texfile );
}
fclose(pkgfile);
fprintf(texfile,"\\newwrite\\tempfile\n");
fprintf(texfile,"\\makeatletter\n");
fprintf(texfile,"\\newcommand*{\\printlength}[1]{\\strip@pt\
\dimexpr(#1)\\relax}\n");
fprintf(texfile,"\\makeatother\n\n");
fprintf(texfile,"\\begin{document}\n");
fprintf(texfile,"\\newlength{\\mytextwidth}\n \\newlength{\
\mytextheight}\n");
fprintf(texfile,"\\immediate\\openout\
\tempfile=gnuplot_estimate_strlen_tex_out.tmp\n");
fprintf(texfile,"\\renewcommand{\\myobject}{%s}\n",s); //Write the
text to latex file
fprintf(texfile,"\\settowidth{\\mytextwidth}{\\myobject}\n");
//fprintf(texfile,"\\settoheight{\\mytextheight}{\\hbox{\
\myobject}}\n"); //not used only to know what to do to get the correct
height
fprintf(texfile,"\\immediate\\write\\tempfile{\\printlength{\
\mytextwidth}}\n");
fprintf(texfile,"\\immediate\\closeout\\tempfile\n");
fprintf(texfile,"\\end{document}\n");
fclose(texfile); /*done!*/
//Run latex
int exitcode = system("pdflatex -draftmode -interaction=batchmode
\"gnuplot_estimate_strlen_tex.tmp\""); //todo: use macros instead of
filename here
FILE *ofile = fopen ("gnuplot_estimate_strlen_tex_out.tmp","r");
//todo: use macros instead of filename here, maybe tmp-directory
if (!ofile) {
/* can't open, stop processing */
}
a=0.0;
int returncodefscanf = fscanf(ofile,"%f",&a);
fclose(ofile);
len=a/5; //Depends on what latex returns, currently not exact!
fprintf(stderr,"Size from latex is %f - Estimate length is %d
\n",a,len); //debug information
return len;
}
Back to comp.graphics.apps.gnuplot | Previous | Next | Find similar
New strlen_tex() in gnuplot source code greenux <greenux@gmx.de> - 2011-11-07 01:36 -0800
csiph-web