10

I'd like to convert some Tex-and-friends code to C, so that I can play with modifying it. As I understand it, the process is:

(1) The tangle utility converts foo.web to a foo.p (Pascal) file, and then

(2) I use web2c to convert foo.p to foo.c

I have managed to make step #1 work, but I'm stuck on step #2. I found the "convert" function and it's components in .../texk/web2c/web2c (in the Live Tex distribution). I was hoping that I could just switch to that directory and type "make" to compile/build the web2c utility. But this directory does not contain a typical Makefile. It has Makefile.am and Makefile.in, but these don't seem to do any compilation, as far as I can see (though I know very little about make files).

So, the questions are:

(1) Is there somewhere I can get a pre-built web2c conversion tool (for Windows), or

(2) Can someone give me good instructions for building it myself.

Edit: Even better ...

(3) Is there somewhere I can get C code for TeX and Metafont. This code is produced as part of the TeX build process, but apparently it must get thrown away after compilation, since I can't seem to find it anywhere.

Edit: Regarding approach #3, I looked at Y&Y TeX, LuaTex, and CXTeX. They have C code, but, as far as I can see, none of them include Metafont, which is the subsystem that most interests me.

Results from typing "Build":

configure: WARNING: Sorry, neither Carbon framework nor fontconfig library: disabling xetex
configure: error: terminating.
=== configuring in web2c failed

And in config.log, I found:

configure:18449: checking for installed fontconfig headers and library
configure:18482: gcc -o conftest.exe -g -O2    conftest.c -lfontconfig  >&5
conftest.c:48:35: fatal error: fontconfig/fontconfig.h: No such file or directory
compilation terminated.
configure:18482: $? = 1
configure: failed program was:
| /* confdefs.h */

But, as Khaled pointed out, I could have avoided building these components, anyway, if I'd done a bit more research.

Avoiding the Above Error In case it helps any of my fellow neophytes and idiots ...

The error arises because fontconfig is missing. The "prerequisites" section of the build instructions tells you how to avoid this. You have to use

 --disable-xetex
 --disable-xdvipdfmx.
bubba
  • 2,462
  • Is there a configure script? Running this generates Makefile from Makefile.in. (If there's only a configure.in, you will need to run autoconf, but you may not already have that installed.) Can't help with the rest I'm afraid. – cyberSingularity Nov 24 '12 at 02:04
  • With regards to your edit, as you say you're interested in Windows, how about http://miktex.org/sources, which includes already C-translated versions of the code for both TeX and metafont in the Programs\TeXAndFriends\mf and Programs\TeXAndFriends\tex folders. – cyberSingularity Nov 24 '12 at 02:16
  • 1
    There is "configure" and "configure.ac". I'm looking at the TeX Live source, but switching to some source distro would be fine if it would make things easier. Thanks. – bubba Nov 24 '12 at 02:16
  • @cyberSinguarity: the MikTex source was the first place I looked, actually. In Programs\TexAndFriends\mf, all I see is mf.web. There is one small C++ program, screen.cpp, but that's just for screen display, I think. Do you see something different ?? – bubba Nov 24 '12 at 02:27
  • Actually, no, sorry! I looked only in the pdftex folder which does appear to have C code, and assumed the rest did too. But I guess it's worth mentioning in the question where you downloaded the web code from! – cyberSingularity Nov 24 '12 at 02:31
  • 4
    If you built TeX Live with the included Build script, the converted files should be under Work/texk/web2c/; there you will find tex0.c, mf0.c etc. but I don’t think hacking the generated C files is such a good idea. – خالد حسني Nov 24 '12 at 04:04
  • Thanks Khaled (and thanks for the XITS fonts, too). I was hoping I wouldn't have to build everything. I realize that the generated C code will be hard to work with, but, for me, I think it will easier than editing web/pascal. Is there some other alternative ? – bubba Nov 24 '12 at 08:31
  • I took Khaled's suggsetion, and just typed "Build". To my astonishment, everything seemed to be working for about 20 minutes. Then I got an error. Too hard to explain here, so I added it to the end of the question. – bubba Nov 24 '12 at 12:49
  • 3
    You can only build TeX and MetaFont, see README.config for build options (e.g. passing something like --disable-all-pkgs --enable-tex --enable-mf --without-mf-x-toolkit --without-x to configure would do the trick. I put the two files here tex0.c & mf0.c. But if I were you, I’d learn WEB and pascal, actually this exactly what I did to hack LuaTeX (before it was ported to C) and XeTeX. – خالد حسني Nov 24 '12 at 12:49
  • 2
    To get your way around WEB, you should start with webman (I can’t find a PDF file, but just tex it). – خالد حسني Nov 24 '12 at 12:51
  • 1
    Thanks a million, Khaled. You have saved me hours of grief. I wish I'd asked for help here yesterday, before wasting 14 hours of work. With all due respect to DEK (and to you), I can't see learning WEB/pascal in this day and age. I'm a geometry guy, and I think there are some interesting ideas buried within Metafont that I'd like to re-use elsewhere. I'm not a professional programmer, so I need all the help I can get from a modern IDE and modern languages. – bubba Nov 24 '12 at 13:09
  • @Khaled -- if you copy/paste some of what you wrote into an answer, I will happily accept it. – bubba Nov 24 '12 at 13:22

2 Answers2

10

If you built TeX Live with the included Build script, the converted files should be under Work/texk/web2c/; there you will find tex0.c, mf0.c etc. To build only TeX and MetaFont, you can pass something like --disable-all-pkgs --enable-tex --enable-mf --without-mf-x-toolkit --without-x to configure (see README.config for general build option documentation)

All in all, I don’t think hacking the generated C files is such a good idea, it is stripped from all documentations and macros which makes it very hard to read.

There is “a hand-converted C version of TeX” (looks like PDFTeX actually) by Taco Hoekwater here, but no MetaFont. MetaPost has been converted to C for a while now, and so is LuaTeX (both mainly maintained by Taco as well).

  • I couldn't find the "--enable-tex" option, but I was able to build most of tex-live and get the files I wanted. Thanks again. – bubba Nov 26 '12 at 08:32
6

I recently created a (Windows) build of Web2c.exe using Microsoft's Visual Studio and posted some notes describing the process on my blog. To date, I've built tangle and weave from their .web and .ch files: next step TeX! Those notes don't cover every step, but they might help if you want to have a go yourself, whether you are using Windows or Linux. You can find the post here: http://www.readytext.co.uk/?p=2529