4

Introduction

I am writing a document using the TeX Gyre Pagella font. Unfortunately, the glyph for the euro sign (UTF-8 character U+20AC) in this font does not comply with the official euro sign specification.

Luckily, the Martin Vogel symbol font does contain a symbol which glyph seems alright.

Minimum working example

euro glyphs

\setupbodyfontenvironment[default][em=italic]
\usemodule[simplefonts][size=14pt]
\setmainfontfallback[DejaVu Serif][range={greekandcoptic, greekextended}, force=yes, rscale=auto]
\setmainfont[TeX Gyre Pagella]

% Martin Vogel Symbol font for euro sign
\usesymbols[mvs]
%\definesymbol[€][{\symbol[europe][EUR]}]

\starttext
\startitemize[packed]
\item € is the glyph of the TeX Gyre Pagella font.
\item \symbol[europe][EUR]~is the glyph of the Martin Vogel symbol font.
\stopitemize
\stoptext

Question

How can I redefine the encoding for U+20AC (€) so that it corresponds to the Martin Vogel glyph?

In other words, I am looking for a preamble command so that the first line in the MWE also would show the Martin Vogel symbol glyph.

My commented-out \definesymbol[€] attempt did not work...

1 Answers1

4

The problem is that the Martin Vogel font does not contain the Euro symbol in the correct slot, so you can't just use a simple font fallback as described in this answer. I don't know if there's a simple way to map a font fallback to different slots of another font without messing with virtual fonts.

Solution 1

Here is a simple workaround, which just replaces all occurences of “€” with an instruction to insert a particular glyph from another font. This is not very robust and might break unexpectedly (for instance in verbatim environments).

\usemodule [translate]
\enableinputtranslation

\translateinput
  [€]
  [\getnamedglyphdirect{marvosym.ttf}{EUR}]

\starttext
  €
\stoptext

Solution 2

Here's a second solution which is more robust than the crude input translation. It uses a regular font fallback and the new simplefonts module which is part of the core as of 2013.09.30 20:05. The euro sign is taken from the Martin Vogel font. Because the euro sign uses a wrong slot, a font feature is created using a substitution to correct the font slot. The euro sign is taken from the Martin Vogel font, although it does exist in the main font.

\startluacode
    fonts.handlers.otf.addfeature {
        name    = "euro",
        type    = "substitution",
        nocheck = true,
        data    = { [0x20AC] = "EUR" },
    }
\stopluacode

\definefontfeature
    [euro]
    [mode=node,
     euro=yes]

\definefallbackfamily [mainface] [serif] [MarVoSym] [range=0x20AC, features=euro, force=yes]
\definefontfamily     [mainface] [serif] [TeX Gyre Pagella]

\setupbodyfont [mainface]

\starttext
    The euro sign (€) is the currency sign used for the euro.
    In Unicode it is encoded at \type{U+20AC €} euro sign.
\stoptext

result

Marco
  • 26,055
  • Are there other fonts which have the right Euro symbol? If so, they may be used as fallbacks. – Aditya Jan 30 '14 at 19:06
  • 6
    @Aditya -- the euro symbol was designed by a committee, a committee that apparently had no input from knowledgeable typographers. the shape as "designed" is found by font designers to be offensive, as it stands out from the text "background" more than necessary or desirable. therefore, most fonts do not follow the mandated design for the euro, but provide a version compatible with the style of the including font. – barbara beeton Jan 30 '14 at 19:25
  • @Marco Your solution is indeed good, but not perfect. Unfortunately, it breaks in the \type{} environment. However, I would not mind if it would be left untranslated in that environment. Perhaps you could extend your solution to account for that. That would make it perfect, at least for me. – Serge Stroobandt Jan 30 '14 at 19:59
  • 1
    @SergeStroobandt That's not possible using my hackish solution. It's like “search and replace” in your editor, just using Lua. When it reaches TeX, is has been substituted already. I have a second hack in mind (using regular fallback + feature file for marvosym to correct the slot), but no time at the moment to update my answer. – Marco Jan 30 '14 at 20:17
  • 1
    @Aditya Here is snippet of post-modern European history: "Typographers discuss the euro." Fascinating... – Serge Stroobandt Jan 30 '14 at 21:22
  • @Marco It would be great to have a kind of compartmentalised input translation. That way, one could single out \type{}. Just some wishful thinking... – Serge Stroobandt Jan 31 '14 at 08:30
  • @Marco Interesting... When I substitute uni0063 in your code with the correct euro glyph uni00A4, I receive !LuaTeX error (file .../marvosym.ttf): Invalid glyph index (gid 215). Why would that happen? – Serge Stroobandt Feb 02 '14 at 20:01
  • 1
    @SergeStroobandt The font does not have a glyph at index 0x00A4. I changed the example to use 0x00A7 instead. – Marco Feb 02 '14 at 21:36
  • @Marco Mystery solved: I am using ConTeXt Standalone version: 2014.02.01 14:22 with its own copy of the font in /opt/context/tex/texmf/fonts/truetype/public/marvosym. However, I was looking at the glyph chart of the Nov. 2007 version of the font as installed on my Debian GNU/Linux system under /usr/share/fonts/truetype/ttf-marvosym/. Could it be that the ConTeXt version of the font is outdated or perhaps of Windows origin? – Serge Stroobandt Feb 02 '14 at 21:59
  • @Marco According to the MarVoSym version history, the mapping of the font changed with version 3.10 to accommodate Windows users. – Serge Stroobandt Feb 02 '14 at 22:07
  • 1
    @SergeStroobandt ConTeXt standalone uses the current version 3.10. The unicode char U+00A7 is located in the font in slot 164 (decimal) or 0x00A4 (hex). – Marco Feb 02 '14 at 22:14
  • @Marco I was not aware that the hex code of the unicode character could differ from the hex code of the font slot. Thanks for pointing that out! – Serge Stroobandt Feb 02 '14 at 22:27
  • @SergeStroobandt Welcome to the m̶e̶s̶s̶y̶ beautiful world of fonts! :) – Marco Feb 02 '14 at 22:33
  • @Marco Your wonderful solution 2 no longer seems to work with ConTeXt ver: 2017.05.15; even when replacing [MarVoSym] by [marvosymwithtexsupport]. Could you have again a look at this? Thank you in advance. – Serge Stroobandt Oct 06 '18 at 22:35
  • @Marco FYI, ConTeXt documentation now also features \usesymbols, including [mvs]. However, none of that seems to be working. – Serge Stroobandt Oct 06 '18 at 22:41
  • 1
    @SergeStroobandt It's fixed. I also got rid of the external feature file and replaced the glyph slot with the glyph name. Should be working again. – Marco Oct 10 '18 at 09:02
  • @Marco I tested it and it works. Many thanks for that! Only in my setup (ConTeXt version: 2017.05.15 21:48 as included in the Ubuntu repository), I need to replace the font name [MarVoSym] by [MarVoSym with TeX Support]. Otherwise, I get the main font's Euro sign with the following warning selectfont > The name 'marvosym' is not a proper family name, use 'marvosymwithtexsupport' instead. – Serge Stroobandt Oct 10 '18 at 21:25
  • @Marco I have also deleted my outdated simplefonts answer. In my old code I also had rscale=auto. I cannot recall what it does. Is this still relevant? – Serge Stroobandt Oct 10 '18 at 21:27