# About web2c, c code conversion

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.

-
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 2:04
With regards to your edit, as you say you're interested in Windows, how about 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 2:16
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. –  Khaled Hosny Nov 24 '12 at 4:04
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. –  Khaled Hosny Nov 24 '12 at 12:49
To get your way around WEB, you should start with webman (I can’t find a PDF file, but just tex it). –  Khaled Hosny Nov 24 '12 at 12:51

## 2 Answers

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 8:32

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

-