In order to make your own fonts for jsMath, you need to download the following archive:Making Your Own jsMath Fonts
It contains the scripts you need in order to create the files used by jsMath for extra fonts.make-jsMath-font-1.2.zip(24KB)
Overview:
In order for jsMath to handle an extra font, it needs to have several things: first, it needs a subdirectory in thejsMath/fontsdirectory named for the new font, and in that directory should be adef.jsfile that tells jsMath about the font and the characters in it. Second, in order to handle the image fallback mode for the font, this directory should contain two sub-directories called "alpha" and "plain", which store the images of the characters in the font at the various sizes that jsMath needs.The
make-jsMath-fontcommand will make all these files for you. If you want the extra font to work in unicode fallback mode, you will need to hand edit the file to include the unicode code points for the characters in the font. This is tedious, but will make your font work in all viewing modes, and your users will be thankful for it. On the other hand, image mode works very well in most situations, so you can get by without unicode tables in most cases.
Configuration:
Themake-jsMath-fontscript uses several programs to help it create the necessary files. These includelatex,dvipng(1.6 or later),mftrace,fontforge, and (optionally) ImageMagick'sconvertcommand. You will need to have these programs installed on your machine before you can generate jsMath fonts.You also need to tell
make-jsMath-fontwhere these programs are located on your system. This is done by editing thebin/config.plfile. It contains the paths to the various commands thatmake-jsMath-fontwill require. You should not need to edit other files. If you don't have the convert command, set$CONVERTto an empty string; it is only used to reduce the size of the alpha-channel images, and is not strictly necessary.
Making a Font:
To create a new jsMath font,cdto the directory containing themake-jsMath-fontscript and type./make-jsMath-font fontnamewhere "fontname" is the name of the TeX font to be created. For example,./make-jsMath-font cmbsy10would create the files jsMath needs to handle the Computer Modern bold symbol font. It takes several minutes to generate all the images, but the script will give you updates on its progress.You can specify a value for Metafont's "blacker" parameter to make a version of the TTF file that is heavier than the default.
./make-jsMath-font 25 cmsy10The CM fonts are designed to be rather thing, and on the PC in particular, these do not render well on screen, so a heavier version is helpful. Values between 10 and 35 seem to work well for most fonts. Note, however, that some fonts, or some characters within a font, may not honor the "blacker" value, and so this setting may not always help. A reasonable value for the PC is 25 and for the Mac is 10.When the script completes, you should have several new files in this directory. First, there is a
fontsdirectory containing a subdirectory for your font. In the example above, you would getfonts/cmbsy10. Thecmbsy10directory needs to be placed in yourjsMath/fontsdirectory on your web server in order to make this new font available to your web pages.You will also see a
.ttffile (in this example,cmbsy10.ttf), which is the TrueType font file that your users should install on their computers in order to take full advantage of the font. (Note that the name includes "jsMath", since the encoding for the font is not one that will be useful in other applications. This also prevents the font from conflicting with the ones used by Firefox or the MathPlayer plugin for MSIE on the PC.) You probably should make the.ttffile available on your website for them to download. If they don't install the font, they may get a font warning message, and jsMath will use the image fallback method for these fonts. That will work fine, except that you can not use the\colorcommand to change the math displayed in this font to another color, and it will not print at as high a resolution as the rest of the text.[If you want to make additional
.ttffiles without rebuilding all the images, use, for example,./bin/mkttf.pl 10 cmsy10to make just the.ttffile for cmsy10 with blacker set to 10. You may want to make darker versions for the PC and ligher for the Mac, and make both available on your website.]Finally, you should also find an
.htmlfile (for example,cmbsy10.html) that contains an HTML font table (like the ones appearing on the jsMath website) that should display the contents of the new font. Note, however, that this is not a complete HTML file, just the table itself; you will need to insert this into an HTML file that loadsjsMath.jsfrom the proper location on your server and then callsjsMath.Process()before you can actually view the font table.Before you can use the font with
jsMath.js, however, you will have to do one bit of editing by hand, which is described in the next section.
Adjusting the Test Character:
When your browser loads a page that includes an extra jsMath font, jsMath will try to determine if you have the.ttffile for that font installed on your computer. It does this by trying to access a character within the new font, and compares that to what it would have gotten in the browser's default serif font. If the new font is not available, the browser will take the character from the serif font, so jsMath can compare the size of the character it got to the size of the character it would normally get from the serif font. If they differ, then jsMath assumes the.ttffile is present, and if they are the same, jsMath assumes the font is unavailable.To make this work correctly, jsMath needs to test a character that will have a noticeably different size in the new font from what it would normally have in the serif font. But jsMath can usually only distinguish the WIDTHs of the characters (since all characters in the same font return the same character height to the browser). That means that in order for jsMath to test the font, you need to specify a character for it to use, and that character should be significantly different in its width from the usual character in that font position. You specify the character using the position within the TeX font (a number from 0 to 127, or 0x00 to 0x7F in hex), but you should stick to the characters between 33 and 126 (0x21 and 0x7E), since the other ones are mapped to unusual locations by the font encoding. Some usual candidates are thin characters like "|" (0x7C), ":" (0x3A), ";" (0x3B), "." (0x2E), "," (0x2C), and "!" (0x21), when the corresponding positions contain wide characters in the new font. Alternatively, you can look for thin characters in the new font that correspond to wide ones in the standard font, though there are usually fewer of those.
The
make-jsMath-fontscript will make an educated guess about what the best character and multiplication factor should be for your font. It uses a table of "typical" widths for the serif font to do this, and since these widths might not match your browser's fonts exactly, the test it picks might not be the best one. In particular, if the scaling factor is less than 2, you might need to adjust the character or the factor by hand.To help you find an appropriate character, you can use the
font-table.texfile located in this directory. If youtexthis file, you will be prompted for the name of a font (e.g., cmbsy10) and the magnification (5 is a good value for most fonts). The result will be a table that shows all the characters in the font (with small numbers indicating the position of each character within the font, in both hex and decimal). If you make a table for your new font and for cmtt10 (which has the normal ASCII characters in positions 33 through 126), so you can compare these to see which characters differ in width the most.When you have selected a suitable character, edit the
def.jsfile in the fonts subdirectory for your new font (e.g.,fonts/cmbsy10/def.jsin our example above). Near the bottom of the file is a section where the font is registered with jsMath. Look for thetestCharspecification and set the value that follows to be the position of the character you selected (either in decimal or hex). ThetestFactorsays how much larger the character in the new font has to be in order to count as indicating the presence of the font. Try to pick a character where the factor can be at least 2. This is not always possible, however, so you can reduce that factor if necessary. Remember that some people may have a different default font setting than yours, so leave a little leeway in your factor. Also, test your setting using both large and small font sizes (zoom the test page in or out and reload it) to make sure that the factor is suitable in a variety of sizes. Finally test your choice with more than one browser if you can. If you are testing a character that is thinner in the new font than in the serif font, change thetestvalue fromjsMath.Font.Test1tojsMath.Font.Test2.Once you have a working test character, the new font should work well in jsMath's TeX-font mode and in the two image-font modes. The user may still select the unicode fallback method, however, and make-jsMath-font does not create a unicode fallback table for the font. That is because it does not know what the characters in the font look like, so can't tell what unicode code points to map them to; you'll have to do that yourself. This is described in the next section.
Setting up a Unicode Fallback Table:
If you want your new font to work in unicode fallback mode, you will need to tell jsMath what unicode code points to use for each character when the the TeX font is not installed on the user's computer. Unfortunately, this needs to be done by hand, in most cases. You might find the character charts athttp://www.unicode.org/charts/to be of benefit in this; it includes an alphabetical list of code points by name in addition to the charts. For Mac OS X users, the Edit menu contains a Special Characters item which can be used to locate unicode characters (select "Code Tables" or "All Characters" from the View menu at the top of the dialog for the most complete listings).There are several methods for entering the code tables into the
def.jsfile. One of them is given in a comment at the bottom of the file (in the fallback item of the Register command). This method allows you to replace individual items in the main list at the top of the page; if the font contains the usual alphabetic and numeric characters, for example, you would not need to replace them, so this might be the most convenient method. Another method allows you to replace all the character fields for all the characters in the font at once; see themsam10/def.jsfile for an example of how this is done.Determining the unicode code points for all the characters in the font can be a tedious job. The
find-unicodecommand in this directory can help. It requires a.pfafile that contains the correct encoding for the font, and uses the character names from that encoding to look up the corresponding unicode code points. Many TeX installations include properly encoded.pfbfiles (look intexmf/fonts/type1); if yours doesn't, you can find them onhttp://www.ctan.org/by searching for the filename you are interested in. If you have a.pfbfile, you can convert it to a.pfafile using thepfbtopfacommand.If you don't have a
.pfaor.pfbfile, you may be able to create one usingmftace, but only if it is able to determine the correct encoding file. If it usestex256.enc, you are probably out of luck, because that is unlikely to be the correct encoding. You may be able to find the right one in thetexmf/dvipshierarchy (look for.encfiles), or on CTAN.Once you have a usable
.pfafile, use the command./find-unicode filewherefileis the name of the.pfafile. This will look through the.pfafile for named character positions, and useFontForgeto look those names up. Unfortunately, not all.pfafiles use names thatFontForgewill recognize, but it can sometimes be a help. The output offind-unicodewill be the table that you need to past into thedef.jsfile in fallback function. WhenFontForgedoesn't know the character,find-unicodewill use '??' for the character value; you will need to look through the unicode tables by hand to find appropriate code points. Only those code points that are not already properly set in the main table will be printed (e.g., for fonts that have the alphabetic characters in their usual places).Note that you will need to remove the comma following the last entry in the list when you paste the table into the
def.jsfile. Although Mozilla will process the list when there is an extra comma, other browsers won't so you need to be careful about that.Sometimes
FontForgedoes know the proper code point, but only if the name were capitalized differently. For example, thewasy10.pfafile lists one of its entries as "aries", butFontForgewill only recognize "Aries". You might use the commandstrings `which fontforge` | grep -i namewherenameis the name of the character you are interested in. It might show you names thatFontForgewould recognize. You can edit the.pfafile to use these names instead and runfind-unicodeagain.
Using Your New Font in Your Web Pages:
To use your new font in your own web page, first loadjsMath.jsin the usual way, then include<SCRIPT>jsMath.Font.Load("fontname")</SCRIPT>wherefontnameis the name of the new font. For example,<SCRIPT>jsMath.Font.Load("cmbsy10")</SCRIPT>for the example above. To access characters in the font, you can use the\char{fontname}{charnum}command. For example,\char{cmbsy10}{0x3A}would produce the character at position 3A in the cmbsy10 font. If there are certain characters you will be using frequently, you can create macros for them:<SCRIPT>jsMath.Macro("bfnot","\\char{cmbsy10}{0x3A}")</SCRIPT>so that\bfnotwill now produce the bold version of the logical-not sign at location 3A in the cmbsy10 font. (See the section on defining macros for more information.)In addition to this approach, the new font can also be accessed by a macro that switches the current font family (much like
\bfdoes). When a font is loaded into jsMath, a new macro is created automatically for just this purpose. For example, when eufm10 is loaded, a macro\eufmis created that sets the current font family to eufm10. If you use{\eufm A}in a math formula, you will get the Fractur German A. Note, however, that this approach has all the limitations that\bfdoes in math mode; it only affects the characters that would normally be typeset in the math italic font.If there are macros that you want to have defined every time a font is loaded (e.g.,
\mathcalwhen you load eusm10), they can be included by adding amacrositem to the Registration call in the font'sdef.jsfile. See thefonts/eusm10/def.jsfile for an example. Thedef.jsfiles can include additional JavaScript code that can be tied to these macros, if more complex processing is needed for the font.
dpvc@union.edu