8

It is suggested in TeXbook (p. 46) that in adapting TeX to type Norwegian,

You can arrange the font metric file so that TeX will interpret ae, o/, aa, AE, O/, and AA as ligatures that produce \ae, \o, \aa, \AE, \O and \AA, respectively; and you could put the characters \aa and \AA into positions 128 and 129 of the font.

I would like to figure out how to do this in an isolated test document. Here's how I can make ae a ligature for \ae by changing the ligature table for the font:

  1. find cmr10.tfm using kpsewhich, then copy it to the working directory under a different name.
  2. convert the file to a .pl file (which is human readable) using tftopl
  3. find the line (LABEL C a) within the LIGTABLE portion of the .pl file, then add below it (LIG C e O 32). (\ae is at octal position 32 in the cmr10 font).
  4. convert the .pl file back to a .tfm file using pltotf

What I am not sure of is how to move a particular character to a given position within a font (which is apparently necessary to produce \aa and \AA using ligatures).

20
  • This is a place where Knuth was wrong. But Unicode came later, unfortunately.
    – egreg
    Commented Aug 25, 2015 at 8:31
  • @egreg your comment is intriguing. I think you're saying that prior to Unicode, it was not possible to switch around the positions of glyphs on a font table; but that it became possible with Unicode, which is unfortunate.
    – user16581
    Commented Aug 29, 2015 at 13:51
  • I didn't mean that; it's quite easy (conceptually, but long to do) to create a virtual font with glyphs wherever you wish and with extended ligature set. What I meant is that inputting special characters or diacritics with ligatures is the wrong approach.
    – egreg
    Commented Aug 29, 2015 at 13:53
  • @egreg OK, understood. In my application I have a long plain text file that I'd like to typeset for easier reading, with some sequences (such as CO2) that should be rendered with subscripts (CO$_2$). My idea was to write handle the subscripts through a ligature to minimize the amount of pre-processing that would need to be done on the text file.
    – user16581
    Commented Aug 29, 2015 at 13:58
  • 1
    Unless you are using Windows, a little sed and/or awk seems a whole lot easier. (If you are using Windows, my sympathies.)
    – cfr
    Commented Nov 6, 2015 at 0:36

2 Answers 2

5

You can do some ligature-like shorthands on the fly without virtual fonts with the encTeX extension of tex and pdftex. It is built-in in most modern TeX distros through a command line switch at format compilation time. Assuming the bash shell, you could do the following...

  1. You must activate the encTeX extension at format generation, saying something like: pdftex -ini -enc -jobname=enctex plain.tex \\pdfoutput=1 \\dump. That should create a new enctex.fmt file for pdfTeX for you.

  2. You may define your personal reencodings on your source code or a dedicated tex file, like the following:

\mubyte\oii O2\endmubyte 
\mubytein=1 
\def\oii{O$_2$} 
It is suspected that CO2 is the main source of air pollution. 
\bye

the pair \mubyte ... \endmubyte defines a reencoding scheme, defining the first token as the result of the following byte sequence, up to \endmubyte; \mubytein=1 activates the substitution (and you can turn it off stating \mubytein=0 anywhere in your source file[s]), and the definition should yield the expected result.

  1. Run your document by calling the special format saying, e.g. pdftex \&enctex mydoc.

encTeX was designed to do reencoding of input files on the fly, with the goal of allowing 8bit fonts to be mapped in from multibyte (UTF8 in particular) input, so it may be missing in TeX engines designed to work directly with multibyte UTF8 strings (XeTeX and LuaTeX specifically); but the euroTeX paper, §§3-4 says that it may be used to do tricks like this one.

1
  • thanks. this is an interesting-looking extension. going to read up on it.
    – user16581
    Commented Nov 6, 2015 at 2:17
0

Unless you really need raw Tex for some reason, you're better off using XeLateX (or LuaTex?, I haven't actually used that flavor) and using the actual unicode letters for things like ø, å, æ, etc. (in other words, just type normally with correct european keyboard).

For example, I currently have a quite large document that is a mix of english/danish/icelandic and I don't use any of the old "tricks", I just type (or copy) all the text in directly. This is exactly what XeLateX was designed for - unicode support for direct use with any language.

1
  • 1
    This won't work for the OP. Take a look at the comments discussing it. There's no direct input for chemical formulae.... Anyway, the concern is compiling an existing document.
    – cfr
    Commented Nov 6, 2015 at 1:36

You must log in to answer this question.