[NLUUG]   Welcome to ftp.nluug.nl
Current directory: /ibiblio/distributions/CTAN/graphics/mf2tex/
 
Current bandwidth utilization 1682.56 Mbit/s
Bandwidth utilization bar
Contents of README:
			  --- MF2TEX ---
	  Inserting the TeX labels into METAFONT sources

	  Robert Spalek, robert@atrey.karlin.mff.cuni.cz

   These macros are copyleft and may be freely distributed under the
		  General Public License (GPL)


	If  you  use  the  METAFONT  not  only	for  drawing fonts, but for
pictures too, you ofted need to insert labels into it (graphs, contructions
etc.)  METAFONT  can  draw dots, curves..., but not the text. Of course you
can  write  macros  in	TeX, which insert the given text in right place and
than insert the picture as a char. This solution has 2 problems:
- you must write  2  sources  (METAFONT  with  picture and TeX with labels)
- you must compute  the  right	coordinates, remember them, insert into the
  TeX source and  actualise them after EVERY change in METAFONT source

	It  would  be  nice,  if  we  could describe the labels in METAFONT
source	and METAFONT with TeX would together typeset picture with labels in
right places.

	METAFONT usually reads the source, draws the picture (and writes it
into TFM and GF files). If we make him to compute the coordinates and write
them  into  a  text  file,  another  program can read them and generate the
corresponding  TeX  source.  In our text we must only include generated TeX
source	and  insert  predefined  command  in  the  place, where we want the
picture to be.

	I implemented it in this way: METAFONT can't write into files, only
into  its  LOG	file. My macros write complete TeX source into the LOG file
in  a special format. A program LOG2TEX reads the LOG file and extracts the
source	into  the  TeX file. The TeX file uses special macros for inserting
the text in the right place, which are included too.

	Informations about using these macros are following:

METAFONT

1) at first you include my macros by `input mf2tex'

2) then you define the mode, measures...

   after the initialisation you write `labelheader("test");',
   where `test' is the name of the font, which do you want to use in
   the TeX source (the font will have the name `fonttest' and all
   characters will have the `test' prefix in their names).

3) instead `beginchar(char,width,height,depth);' you write
   `beginlabeledchar(char,width,height,depth,"one");',
   where `one' is the name of the defined character (used in the TeX
   macros). In my example the generated TeX macro will have name `testone'
   (it couldl be inserted into text by writing `\testone').

4) instead `endchar;' you write `endlabeledchar;'

5) at the end the METAFONT source you write `labelfoot;', which will
   finalise the output file

!) when you want to insert a label into a character, you write
   `labelXY(posx,posy,"text")', where X and Y mean justification. They
   must be one of the following letters:
   X:	      L (left), R (right), M (middle)
   Y:	      U (up), D (down), B (baseline), M (middle),

   posx and posy are the coordinates (it need not be the number, it can
   be the variable or dot too (x1, 1/2[x3,x7]...))

   and text is the inserted text. You should switch into the right font
   at the beginning, because you don't know, which font will be active
   in the moment of the picture insertion. You MUST NOT insert characters
   with ASCII code >127, because METAFONT will ignore them. If you need at
   example the letters with interpuction, you should use the TeX accents.
 Note: of course you could use all the TeX features (math mode, tables...)

Conversion

     Simply run the program `log2tex test1', where test1 is the name of the
METAFONT LOG file without extension.

TeX

1) at the beginning of the document write `\input mf2tex' (once and only
   once for the whole document)

2) then include all the generated sources (one for every METAFONT source):
   `\input test1'

3) when you want to insert the picture, write `\testone', where `test' is
   the name of the font and `one' is the name of the character in the font.
   This should work in all modes (horisontal, vertical, math...).
   Allocated space will be computed from the size of the picture (not
   including the labels!)

How do the TeX macros work

	I  wrote the macros \vertY, where Y is in {U,D,B,M}, which move the
pointer  into  the  given coordinate and insert the text with that vertical
justification.	You  MUST  NOT	insert	the text directly, but use the next
macro  \horX,  where  X  is in {L,R,M}, which will set the right horisontal
justification.

	You  don't  need  to  use  these  ugly macros, because I predefined
abbreviations  \moveXY(xpos,ypos,text}).  They	call these macros. You must
pay  attention in the text parameter, because it must not contain the right
paranthese  `)'.  If you need it, you must enclose the text parameter by {}
parantheses and it will be all right.

	For  inserting	the  picture  in  the  right  (horisontal)  mode is
predefined  the \labels macro with 2 parameters: the list of the labels and
the inserted char. User will call this macro.

	But you don't need to know these macros, METAFONT will generate the
source and you only use it.

	The program LOG2TEX reads the name of the generated TeX source file
from  the  line,  which  start by $#@!. Than it copies all the lines, which
begin bye !@#$ to that file. It does not do anything else, the complete TeX
source is generated by the METAFONT macros.

	I  include  the  2  sources  of  the  LOG2TEX program: Pascal and C
sources. I include a DOS executable program too.

Example of the METAFONT, LOG file, generated TeX file and TeX source:

test1.mf:

    input mf2tex

    mode_setup;
    labelheader("test");

    unit#=3cm#;
    mypen#=0.3mm#;
    define_pixels(unit,mypen);

    beginlabeledchar(1,unit#,0.9unit#,0,"one");
	    z1=(0,0);
	    z2=(w,0);
	    z3-z1=(z2-z1) rotated 60;
	    pickup pencircle scaled mypen;
	    draw z1--z2--z3--cycle;		    %big triangle

	    z4=1/3[z1,z2]; z5=2/3[z1,z2];
	    z6=1/3[z2,z3]; z7=2/3[z2,z3];
	    z8=1/3[z3,z1]; z9=2/3[z3,z1];
	    draw z4--z7--z8--z5--z6--z9--cycle;     %3 middle triangles

	    labelMM(x9,1/3[y4,y9],"A"); 	    %6 letters
	    labelMM(x3,1/3[y4,y9],"B");
	    labelMM(x6,1/3[y4,y9],"C");
	    labelMM(x4,1/3[y9,y8],"D");
	    labelMM(x5,1/3[y9,y8],"E");
	    labelMM(x3,1/3[y8,y3],"F");

	    labelMM(x4,2/3[y4,y9],"a"); 	    %next 3 letters
	    labelMM(x5,2/3[y4,y9],"b");
	    labelMM(x3,2/3[y9,y8],"c");
    endlabeledchar;

    labelfoot;

    end;

test1.log:

    This is METAFONT, Version 2.71(c)sb13 (preloaded base=plain 96.5.2)
    13 MAR 1997 18:17
    ** &plain \mode=hplaser; mag=1.0; input test1
    (test1.mf (mf2tex.mf)
    $#@!test1
    !@#$\font\fonttest=test1
    !@#$
    !@#$\def\testone{\labels{%
    !@#$\moveMM(0.49953cm,0.28839cm,{A})%
    !@#$\moveMM(1.4986cm,0.28839cm,{B})%
    !@#$\moveMM(2.49767cm,0.28839cm,{C})%
    !@#$\moveMM(0.99905cm,1.15361cm,{D})%
    !@#$\moveMM(1.99814cm,1.15361cm,{E})%
    !@#$\moveMM(1.4986cm,2.01884cm,{F})%
    !@#$\moveMM(0.99905cm,0.57681cm,{a})%
    !@#$\moveMM(1.99814cm,0.57681cm,{b})%
    !@#$\moveMM(1.4986cm,1.44203cm,{c})%
    !@#$}{\fonttest \char1}}
    [1]
    !@#$
     )
    Font metrics written on test1.tfm.
    Output written on test1.300 (1 character, 3072 bytes).

test1.tex:

    \font\fonttest=test1

    \def\testone{\labels{%
    \moveMM(0.49953cm,0.28839cm,{A})%
    \moveMM(1.4986cm,0.28839cm,{B})%
    \moveMM(2.49767cm,0.28839cm,{C})%
    \moveMM(0.99905cm,1.15361cm,{D})%
    \moveMM(1.99814cm,1.15361cm,{E})%
    \moveMM(1.4986cm,2.01884cm,{F})%
    \moveMM(0.99905cm,0.57681cm,{a})%
    \moveMM(1.99814cm,0.57681cm,{b})%
    \moveMM(1.4986cm,1.44203cm,{c})%
    }{\fonttest \char1}}

runtest.tex:

    \input mf2tex
    \input test1

    This is a text before the picture, because we want it to be inserted in
    the middle of the text. Now we are able to insert it: ``One, two,
    \testone, four.'' Is it displayed all right? Let's display it
    centered.
    $$\testone$$

    \bye

Icon  Name                                  Last modified      Size  
[DIR] Parent Directory - [DIR] example/ 20-Oct-1999 09:22 - [TXT] README 14-Mar-1997 01:00 7.7K [TXT] log2tex.c 14-Mar-1997 01:00 1.0K [   ] log2tex.exe 14-Mar-1997 01:00 3.8K [TXT] log2tex.pas 14-Mar-1997 01:00 933 [TXT] mf2tex.mf 14-Mar-1997 01:00 2.3K [   ] mf2tex.tex 14-Mar-1997 01:00 1.7K [TXT] mf2tex.txt 14-Mar-1997 01:00 7.7K

NLUUG - Open Systems. Open Standards
Become a member and get discounts on conferences and more, see the NLUUG website!