6

I have files containing fragments of Old English texts. These files use the letter wynn (ƿ (U+01BF) and Ƿ (U+01F7)) which I want to print as modern w (U+0077) and W (U+0057). This I have no problem doing using the a mapping file, which I’ve compiled using teckit_compile into .tec file (teckit_compile oldenglish.map -o oldenglish.tec). I also want the sequence ‘ ·’ (space (U+0020) followed by an interpunct) to be mapped into ‘ ·’ (non-breaking space (U+00A0) followed by an interpunct), but this for some reason do not work.

This is my .map file (oldenglish.map):

LHSName "old"
RHSName "new"

pass(Unicode)

U+01BF <> U+0077 ; ‘ƿ’→‘w’
U+01F7 <> U+0057 ; ‘Ƿ’→‘W’
U+0020 U+00B7 <> U+00A0 U+00B7 ; ‘ ·’→‘ ·’

And this is an example LaTeX file and it’s output:

\documentclass{article}

\usepackage{fontspec}
\setmainfont[Mapping=oldenglish]{Junicode}

\begin{document}
abcwxyz · ABCWXYZ

abcƿxyz · ABCǷXYZ
\end{document}

Output of the previous code

I know U+0020 U+00B7 isn’t being replaced by U+00A0 U+00B7 because when I test it with U+0020 U+00B7 <> U+00A0 U+0078 in the last line I don’t get ‘abcwxyz x ABCWXYZ’ but ‘abcwxyz · ABCWXYZ’.

I guess it’s the space (U+0020) that causes this problem. Am I doing something wrong?

Thank you very much! ☺

  • 1
    I don't think this can work, because XeTeX never uses the space character. The substitutions with the mapping file are performed when the box is being built and XeTeX has already transformed spaces into space tokens, which insert a skip, not a character. – egreg Dec 14 '14 at 16:18
  • @egreg: So the only solution would be manually replacing ‘ ·’ (U+0020) with ‘ ·’ (U+00A0) or ‘~·’ using my text editor or a program like sed? – Júda Ronén Dec 14 '14 at 16:23
7

The mapping substitutions work on a character basis, but XeTeX never uses the space character; rather, it changes space tokens into horizontal glue, so when the substitution stage is reached, there's never a combination U+0020 U+00B7.

You can use newunicodechar for this purpose:

\documentclass{article}

\usepackage{fontspec}
\setmainfont[Mapping=oldenglish]{Junicode}

\usepackage{newunicodechar}
\newunicodechar{·}{\ifhmode\ifdim\lastskip>0pt \unskip~\fi\fi·}

\begin{document}

abcwxyz · ABCWXYZ

abcƿxyz · ABCǷXYZ

\parbox{0pt}{
abcwxyz · ABCWXYZ

abcƿxyz · ABCǷXYZ
}
\end{document}

The interpunct character is made active; if it's found in horizontal mode and it's preceded by a space, it removes the space and inserts a nonbreaking space ~, then it prints itself.

I wouldn't use U+00A0, because this is a glyph and so doesn't participate to space stretching or shrinking on a line.

enter image description here

This assumes that · (U+00B7 MIDDLE DOT) is used only in this context. Something like \hspace{10pt}· would remove the space as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.