3

When I render the following document with xelatex...

\documentclass{scrbook}
\usepackage{fontspec}
\usepackage{listings}
\newfontface{\emojifont}{Symbola_hint.ttf}

\begin{document}
\emojifont{The emoji end up in front of the punctuation: \lstinline`<😀,🤔/🎨+`}
\end{document}

I end up with the content of the inline code span looking like 😀🤔🎨<,/+—the Emoji are moved across the punctuation, to the start of the span. This doesn't happen (or at least happens differently) with non-punctuation characters.

The same happens in code listing blocks, and since I have to typeset some programs with emoji in them, this is rather disruptive. Any ideas on why this is happening and whether there's a way to work around it?

Using \texttt instead of \lstinline removes the issue, but I really prefer to keep using listings, since it does several things that I need.

  • 1
  • That means I have to manually add every Unicode character I want to use in my listings in to cryptic list? That's beyond terrible. – Marijn Feb 2 '18 at 22:12
  • That doesn't seem to have been it—even with the extra invocations (with appropriate character codes) shown in that answer, the rearranging still happens. – Marijn Feb 2 '18 at 22:33
  • @Marijn Unless you want a gigantic macro to be executed each time listings is processed… – egreg Feb 3 '18 at 10:34
2

The method shown in The 'listings' package and UTF-8 works here fine for me too (I had to use another emoji font as I don't have yours installed). I tested both with xelatex and lualatex on a current texlive 2017:

\documentclass{scrbook}
\usepackage{fontspec}
\usepackage{listings}
\newfontface{\emojifont}{seguiemj.ttf}
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  😀🤔🎨%
% ^^^^^1f600^^^^^1f914^^^^^1f3a8%alternative for xelatex, doesn't work in lualatex 
  ^^00}
\lst@RestoreCatcodes
\makeatother

\begin{document}

\emojifont{The emoji end up in front of the punctuation: \lstinline`<😀,🤔/🎨+`}
\end{document}

enter image description here

  • I think that in LuaTeX you have to use six hats, with a padding 0 (it should also work in XeTeX). – egreg Feb 3 '18 at 10:21
  • @egreg Yes, thanks David just told me in the chat too, I will correct the example later. – Ulrike Fischer Feb 3 '18 at 10:43
  • Thank you, it really does work (not sure what I did wrong when testing). I'm still sad to have to include a hack like this to get basic Unicode support, but I can automate the extraction of characters used so I guess I'll survive. – Marijn Feb 3 '18 at 20:59
  • As egreg already commented: Do you really expect listings to add support for over 100.000 symbols by default? And even if it would extend the range of supported symbols why on earth should it add emojis? – Ulrike Fischer Feb 3 '18 at 23:12

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.