From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- graphics/mf2tex/README | 1 + graphics/mf2tex/example/runtest.tex | 10 ++ graphics/mf2tex/example/test1.log | 23 ++++ graphics/mf2tex/example/test1.mf | 36 ++++++ graphics/mf2tex/example/test1.tex | 14 +++ graphics/mf2tex/log2tex.c | 61 ++++++++++ graphics/mf2tex/log2tex.pas | 53 +++++++++ graphics/mf2tex/mf2tex.mf | 67 +++++++++++ graphics/mf2tex/mf2tex.tex | 53 +++++++++ graphics/mf2tex/mf2tex.txt | 218 ++++++++++++++++++++++++++++++++++++ 10 files changed, 536 insertions(+) create mode 120000 graphics/mf2tex/README create mode 100644 graphics/mf2tex/example/runtest.tex create mode 100644 graphics/mf2tex/example/test1.log create mode 100644 graphics/mf2tex/example/test1.mf create mode 100644 graphics/mf2tex/example/test1.tex create mode 100644 graphics/mf2tex/log2tex.c create mode 100644 graphics/mf2tex/log2tex.pas create mode 100644 graphics/mf2tex/mf2tex.mf create mode 100644 graphics/mf2tex/mf2tex.tex create mode 100644 graphics/mf2tex/mf2tex.txt (limited to 'graphics/mf2tex') diff --git a/graphics/mf2tex/README b/graphics/mf2tex/README new file mode 120000 index 0000000000..7f86df3608 --- /dev/null +++ b/graphics/mf2tex/README @@ -0,0 +1 @@ +mf2tex.txt \ No newline at end of file diff --git a/graphics/mf2tex/example/runtest.tex b/graphics/mf2tex/example/runtest.tex new file mode 100644 index 0000000000..c46b98649c --- /dev/null +++ b/graphics/mf2tex/example/runtest.tex @@ -0,0 +1,10 @@ +\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 diff --git a/graphics/mf2tex/example/test1.log b/graphics/mf2tex/example/test1.log new file mode 100644 index 0000000000..81d7c88c7a --- /dev/null +++ b/graphics/mf2tex/example/test1.log @@ -0,0 +1,23 @@ +This is METAFONT, Version 2.71(c)sb13 (preloaded base=plain 96.5.2) +14 MAR 1997 10:14 +** &plain \mode=hplaser; mag=1.0; input test1 +(test1.mf (c:\pas\m_m\makra\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). diff --git a/graphics/mf2tex/example/test1.mf b/graphics/mf2tex/example/test1.mf new file mode 100644 index 0000000000..0e0195b1a5 --- /dev/null +++ b/graphics/mf2tex/example/test1.mf @@ -0,0 +1,36 @@ +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; diff --git a/graphics/mf2tex/example/test1.tex b/graphics/mf2tex/example/test1.tex new file mode 100644 index 0000000000..4e50afa486 --- /dev/null +++ b/graphics/mf2tex/example/test1.tex @@ -0,0 +1,14 @@ +\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}} + diff --git a/graphics/mf2tex/log2tex.c b/graphics/mf2tex/log2tex.c new file mode 100644 index 0000000000..1d936a7c50 --- /dev/null +++ b/graphics/mf2tex/log2tex.c @@ -0,0 +1,61 @@ +/* convertor from generated LOG files to the corresponding TeX sources + + this program is for unix-systems */ + +#include +#include + +void error(char *txt){ + puts(txt); + exit(1); +} + +void main(int argc,char** argv){ + FILE *fi,*fo; + char line[200]; + + if(argc>=2) + strcpy(line,argv[1]); + else{ + printf("input: "); + scanf("%s",line); + } + strcat(line,".log"); + fi=fopen(line,"r"); + if(!fi) + error("can not open input file"); + while(!feof(fi)){ + fscanf(fi,"%s",line); + if(line[0]=='$' + && line[1]=='#' + && line[2]=='@' + && line[3]=='!'){ + int i=4; + do{ + line[i-4]=line[i]; + i++; + }while(line[i-1]); + strcat(line,".tex"); + fo=fopen(line,"w"); + if(!fo) + error("can not open output file"); + break; + } + } + while(!feof(fi)){ + fgets(line,200,fi); + if(line[0]=='!' + && line[1]=='@' + && line[2]=='#' + && line[3]=='$'){ + int i=4; + do{ + line[i-4]=line[i]; + i++; + }while(line[i-1]); + fputs(line,fo); + } + } + fclose(fo); + fclose(fi); +} diff --git a/graphics/mf2tex/log2tex.pas b/graphics/mf2tex/log2tex.pas new file mode 100644 index 0000000000..5cdcbcbf38 --- /dev/null +++ b/graphics/mf2tex/log2tex.pas @@ -0,0 +1,53 @@ +{convertor from generated LOG files to the corresponding TeX sources + + this program is for dos-systems} + +program log2tex; +uses + dos; +var + fi,fo:text; + line:string; + d:dirstr; + n:namestr; + e:extstr; + +procedure + error(txt:string); +begin + writeln(txt); + halt(1); +end; + +begin + if paramcount>=1 then begin + line:=paramstr(1); + end else begin + write('input: '); + readln(line); + end; + fsplit(line,d,n,e); + if e='' then line:=line+'.log'; + assign(fi,line); + {$i-} reset(fi); {$i+} + if ioresult<>0 then + error('can not open input file'); + while not eof(fi) do begin + readln(fi,line); + if copy(line,1,4)='$#@!' then begin + line:=copy(line,5,255); + assign(fo,line+'.tex'); + {$i-} rewrite(fo); {$i+} + if ioresult<>0 then + error('can not open output file'); + break; + end; + end; + while not eof(fi) do begin + readln(fi,line); + if copy(line,1,4)='!@#$' then + writeln(fo,copy(line,5,255)); + end; + close(fo); + close(fi); +end. diff --git a/graphics/mf2tex/mf2tex.mf b/graphics/mf2tex/mf2tex.mf new file mode 100644 index 0000000000..b93fd83cf1 --- /dev/null +++ b/graphics/mf2tex/mf2tex.mf @@ -0,0 +1,67 @@ +string fontname; + +def labelheader(expr name) = +fontname=name; +message "$#@!" & jobname; % for recognizing the file name +message "!@#$\font\font" & fontname & "=" & jobname; +message ""; % defining the fontname +enddef; + +def labelfoot = +message "!@#$"; +message ""; +enddef; + +def beginlabeledchar(expr a,b,c,d,name) = +beginchar(a,b,c,d); +message "!@#$"; +message "!@#$\def\" & fontname & name & "{\labels{%"; +enddef; % start of the character macro + +def endlabeledchar = +message "!@#$}{\font" & fontname & " \char" & decimal charcode & "}}"; +message ""; % end of the character macro +endchar; +enddef; + +def label(expr x,y,hor,vert,co) = +message "!@#$\move" & hor & vert & "(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; % insert this text in these coordinates justified by parameters + +% abbreviations for all justifications +def labelLU(expr x,y,co) = +message "!@#$\moveLU(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelRU(expr x,y,co) = +message "!@#$\moveRU(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelMU(expr x,y,co) = +message "!@#$\moveMU(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelLD(expr x,y,co) = +message "!@#$\moveLD(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelRD(expr x,y,co) = +message "!@#$\moveRD(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelMD(expr x,y,co) = +message "!@#$\moveMD(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelLM(expr x,y,co) = +message "!@#$\moveLM(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelRM(expr x,y,co) = +message "!@#$\moveRM(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelMM(expr x,y,co) = +message "!@#$\moveMM(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelLB(expr x,y,co) = +message "!@#$\moveLB(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelRB(expr x,y,co) = +message "!@#$\moveRB(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; +def labelMB(expr x,y,co) = +message "!@#$\moveMB(" & decimal (x/cm) & "cm," & decimal (y/cm) & "cm,{" & co & "})%"; +enddef; diff --git a/graphics/mf2tex/mf2tex.tex b/graphics/mf2tex/mf2tex.tex new file mode 100644 index 0000000000..45dce3df24 --- /dev/null +++ b/graphics/mf2tex/mf2tex.tex @@ -0,0 +1,53 @@ +% these macros are for moving the starting point and setting the +% vertical justification +% the text will be inserted, but TeX will not move its pointer to the +% space +\def\vertD#1#2#3{% justify the bottom + \vbox to 0pt{\vskip -#2\vss% + \hbox to 0pt{\hskip #1% + #3% + \hskip -#1}% + \vskip #2}} +\def\vertU#1#2#3{% justify the top + \vbox to 0pt{\vskip -#2% + \hbox to 0pt{\hskip #1% + #3% + \hskip -#1}% + \vss\vskip #2}} +\def\vertB#1#2#3{% justify the baseline + \vbox to 0pt{\vskip -#2% + \smash{\hbox to 0pt{\hskip #1% + #3% + \hskip -#1}}% + \vskip #2}} +\def\vertM#1#2#3{% justify the middle + \vbox to 0pt{\vskip -#2\vss% + \hbox to 0pt{\hskip #1% + #3% + \hskip -#1}% + \vss\vskip #2}} + +% these macros are for horizontal justification +\def\horL#1{#1\hss} %justify the left +\def\horR#1{\hss#1} % right +\def\horM#1{\hss#1\hss} % middle + +% abbreciations for all justifications +% they get the coordinates and the inserted text +\def\moveLU(#1,#2,#3){\vertU{#1}{#2}{\horL{#3}}} +\def\moveRU(#1,#2,#3){\vertU{#1}{#2}{\horR{#3}}} +\def\moveMU(#1,#2,#3){\vertU{#1}{#2}{\horM{#3}}} +\def\moveLD(#1,#2,#3){\vertD{#1}{#2}{\horL{#3}}} +\def\moveRD(#1,#2,#3){\vertD{#1}{#2}{\horR{#3}}} +\def\moveMD(#1,#2,#3){\vertD{#1}{#2}{\horM{#3}}} +\def\moveLM(#1,#2,#3){\vertM{#1}{#2}{\horL{#3}}} +\def\moveRM(#1,#2,#3){\vertM{#1}{#2}{\horR{#3}}} +\def\moveMM(#1,#2,#3){\vertM{#1}{#2}{\horM{#3}}} +\def\moveLB(#1,#2,#3){\vertB{#1}{#2}{\horL{#3}}} +\def\moveRB(#1,#2,#3){\vertB{#1}{#2}{\horR{#3}}} +\def\moveMB(#1,#2,#3){\vertB{#1}{#2}{\horM{#3}}} + +% macro with 2 parameters: labels and the picture +% it creates the hbox and inserts it correctly to the text +\def\labels#1#2{% + \noindent\hbox{#1#2}} diff --git a/graphics/mf2tex/mf2tex.txt b/graphics/mf2tex/mf2tex.txt new file mode 100644 index 0000000000..4832cf358e --- /dev/null +++ b/graphics/mf2tex/mf2tex.txt @@ -0,0 +1,218 @@ + --- 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 -- cgit v1.2.3