3.1 Using hTeX

Using hTeX is really easy. It extends standard Hollywood text commands like SetFont() and TextOut() to support rendering text that is formatted using the LaTeX markup language. To draw LaTeX-formatted text using hTeX, just make sure you open the font using hTeX by passing the Loader tag to SetFont(). To use hTeX's inbuilt LaTeX font, just pass "latex" as the font name. Once you have opened a font through hTeX, all Hollywood commands that draw text will automatically do so through hTeX, e.g.:

 
@REQUIRE "hTeX"

SetFont("latex", 72, {Loader = "hTeX"})
SetFontStyle(#ANTIALIAS)

text$ = "\\int_{now}^{+\\infty} \\text{Keep trying}"

TextOut(#CENTER, #CENTER, text$)

hTeX will draw all text as real vector graphics so you can scale, rotate, and transform all text drawn by hTeX as you please. It will always be perfectly crisp because hTeX handles all text as true vector graphics.

As described above, if you pass "latex" as the font name to SetFont(), hTeX will use its inbuilt font which is Latin Modern Math. If you want to use a different font, you must pass a path to its TTF/OTF file, e.g.

 
SetFont("fonts/myfont.otf", {Loader = "hTeX"})

Note that if you pass a path to an OTF file you must also provide a CLM file for the font because that is needed by MicroTeX. The CLM file must be located in the same path as the OTF file and it must use the same name as the font filename except that the extension must be .clm. So if you pass the font myfont.otf to SetFont(), there must also be a CLM file named myfont.clm in the same directory. CLM files can be generated using the otf2clm script which is part of the MicroTeX distribution.

Note that currently it is not possible to use multiple fonts with hTeX. You can only use a single font with hTeX. The font that you specify in the first call to SetFont() is the only font you will be able to use with hTeX. If you try to use a different font with hTeX later, SetFont() will fail.

In the code above we explicitly tell SetFont() to use hTeX to open the font by passing "hTeX" in the Loader tag. Alternatively, you can also globally enable hTeX for all Hollywood commands dealing with fonts by simply installing hTeX's font adapter. This can be done by setting the InstallAdapter tag to True when @REQUIREing hTeX, e.g. like this:

 
@REQUIRE "hTeX", {InstallAdapter = True}

If you globally enable hTeX, you don't have to use the Loader tag with SetFont() or other Hollywood commands that deal with fonts any longer because if hTeX is globally enabled, commands like SetFont() will automatically ask hTeX for every font that is to be opened whether or not the plugin would like to handle this font.

When using hTeX you can also pass some additional arguments to SetFont(), OpenFont() or the @FONT preprocessor by using Hollywood's user tags. The following additional arguments are recognized by hTeX:

Monochrome
Set this tag to True if you want hTeX to operate in monochrome mode. This will reduce memory consumption by 75% because hTeX only needs to allocate one pixel channel instead of four but you will only be able to use single-colored text in monochrome mode so things like colored tables or boxes won't be drawn correctly. Defaults to False.

Here's how you can pass user tags to hTeX:

 
@REQUIRE "hTeX"
SetFont("latex", 72, {Loader = "hTeX", UserTags = {Monochrome = True}})
SetFontStyle(#ANTIALIAS)
text$ = "\\int_{now}^{+\\infty} \\text{Keep trying}"
TextOut(#CENTER, #CENTER, text$)

By default, hTeX will draw the LaTeX-formatted text to the current output device, e.g. a Hollywood display or a brush. Alternatively, it is possible to make hTeX export the text as a PDF document, SVG image, or a PNG image. To do that, you have to use the function htex.SetOutputMode().


Show TOC