5

Background

Using LMTX to typeset an XML document that has been converted from Markdown. Users may type emojis directly into the document without using TeX macros.

Problem

The emojis don't appear when defined as a fallback font. One of the linked answers notes:

You don't want to use the Emoji font as fallback.

It may be that what I'm trying to do won't work.

Code

The following document shows how the fallback is used:

\enabletrackers [fonts.missing]

\definefallbackfamily [FontBody] [serif] [Noto Emoji] [range={miscellaneoussymbols,dingbats}] \definefontfamily [FontBody] [serif] [Noto Serif] \setupbodyfont[FontBody]

\starttext Emoji:

\stoptext

Neither MuPDF nor Evince show the emojis. Deleting the ~/luametatex-cache/ directory doesn't help. Using the font directly sort of works:

\enabletrackers [fonts.missing]

\definefontfamily [FontBody] [serif] [Noto Emoji] \setupbodyfont[FontBody]

\starttext Emoji:

\stoptext

This produces the glyphs, but no longer shows any text, page header notwithstanding:

Glyphs

Errors

When trying to use the fallback, ConTeXt outputs the following errors:

fonts           > 'fallback modern-designsize mm 12pt' is loaded
fonts           > preloading modern-designsize (mono)
fonts           > 'fallback modern-designsize tt 12pt' is loaded
fonts           > checking > char  (U+1F468) in font 'LMRoman10-Regular' with id 1: missing

Not sure why it's trying to find the glyphs in LMRoman10-Regular when the code was defining the fallback as Noto Emoji. Using an explicit range also didn't work:

\definefallbackfamily
  [FontBody] [serif] [Noto Emoji] [range={0x1F400-0x1F600}]

It is possible to use \definefont[EmojiFont] and a variation upon:

\starttext
  Emoji: \EmojiFont{}
\stoptext

However, that would mean introducing TeX markup into the Markdown source document, which I'd like to avoid.

Question

Without modifying the document body (i.e., no changes between \starttext and \stoptext), how do you get the emojis and text to appear in the PDF at the same time?

Related

Similar questions:

Addendum

The main ConTeXt font setup I'm using resembles:

% Greek letters aren't defined by Baskerville, first try Source Serif Pro.
% Source Serif Pro pairs well with Libre Baskerville in terms of font weight
% and rounded accents.
\definefallbackfamily [TextFont] [serif] [Source Serif Pro] [
  range=greekandcoptic,
  rscale=1.17
]

\definefontfamily [TextFont] [rm] [LibreBaskerville] [features=TextFontFeature] \definefontfamily [TextFont] [ss] [Archivo Narrow] \definefontfamily [TextFont] [tt] [Inconsolata] \definefontfamily [TextFont] [mm] [TeX Gyre Pagella Math]

\setupbodyfont[TextFont]

This works flawlessly to put Greek letters into the document. I thought that emojis would be similar.

Dave Jarvis
  • 11,809

2 Answers2

3

You can use \setups in TypeScript to generate the desired text with emoji fonts as fallback. As you can see you can use several font fallback together by defining your fallback fonts with multiple \definefontfallback, they should have the same name that here is "myfallback". Also you can simultaneously specify different ranges for various emoji fonts with their own special features.

Explanation about the parameters "force" and "check" taken from the messages on the mail list:

check: only replace when present in the replacement font (default: no) force: force replacement even when the base font has the glyph (default: yes)

%defint font fallback with its features:
\startsetups [fallbackfonts]
\definefontfeature  [Emojiuse][default][ccmp=yes,colr=yes,dist=yes]
\definefontfeature  [mycolored][default][cmcp=yes,dist=yes,colr=yes,svg=yes,sbix=yes]
\definefontfallback [myfallback][file:seguiemj.ttf*Emojiuse] [0x01F345-0x01FAD8] [force=no,check=no]
\definefontfallback [myfallback][OtsutomeEmojiSvgRegular*mycolored][0x01F600-0x01F61B][force=yes,check=no]
\stopsetups

%defining our typescript: \starttypescript [serif] [ptsans] \setups[fallbackfonts] \definefontsynonym [SerifRegular] [file:PTSans-Regular] [features=default] \definefontsynonym [SerifBold] [file:PTSans-Bold] [features=default] \stoptypescript

\starttypescript [serif] [ptsans] \definebodyfont [default] [rm] [tf= SerifRegular sa 1, bf= SerifBold sa 1,] \stoptypescript

\starttypescript [ptsans] \definetypeface [ptsans] [rm] [serif] [ptsans] [default] [fallbacks=myfallback] \stoptypescript

\setupbodyfont[ptsans] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \starttext koalla

\stoptext

  • Also, to convert the Unicode code point such as U+1F600 to the hexadecimal format like 0x01F600, you can follow these steps:

    1. Remove the "U+" from the Unicode code point.
    2. Prepend "0x" to indicate it as a hexadecimal number.
    3. Pad with zeros to make the total length 6 (since the code point is always 6 digits).
JamesT
  • 3,169
seyal
  • 43
0

The solution entails:

  • Use the TTF version of OpenSansEmoji, not the OTF version.
  • Use \definefont alongside style arguments.

Consider:

\definefont [TextFontEmoji] [OpenSansEmoji]

\defineframedtext[TextBubbleFrame][ style=TextFontEmoji, frame=on, width=.618\textwidth, autowidth=force, offset=.75em, after={\blank[2*big]}, ]

This switches the font to OpenSansEmoji within any TextBubbleFrame environment. The OpenSansEmoji font includes Latin characters and most of the common Unicode emojis.

Dave Jarvis
  • 11,809