-1

I have seen similar questions (a, b, c) but this one is a bit different.

Yesterday I was so excited to start learning latex and quick enough I discovered packages that can render any source code. But in my program, there are some Unicode (multibyte) characters that are not rendered with standard font families. So I used emoji package for this. And soon after that I couldn't render these special characters inside (TypeScript) string which is inside minted block.

Surely I can escape by using the same type of quotes around the latex code inside string: "string "|\escaped|" string", but this will render another pair of quotes in PDF, so this won't work.

AFAIK, I should use another package, but minted is soo good. How can I solve the problem without ditching minted package?

Here is a short example:

\documentclass[a4paper]{article}
\usepackage[cachedir=../.cache, outputdir=output]{minted}
\usepackage{emoji}

\def\done{\emoji{check-mark-button}}

\begin{document} \noindent It shows here (outside minted) -> \done \begin{minted}[escapeinside=||]{typescript} ... hbs.registerHelper("list", function(this: any) { ... entries.forEach(entry => { |It shows here (inside minted) -> \done| rows += |But not in here (inside minted and backticks) -> \done| ... }) ... }); ... \end{minted} \end{document}

And the output:
enter image description here

1 Answers1

0

Not sure what you're after, but how about this?

An indirect (=meta) command for the backtick (grave accent), option1; or mixing in some Pygment metacommands, option2.

back tick

In both cases, the special character is "hidden" from the lexer, and is inserted "manually", so to speak.

Fonts and red colour arbitrarily chosen for demonstration purposes for 1 and 2. Option 3 is the minted colour scheme.

MWE

\documentclass{article}
\usepackage{minted}
\usepackage{fontspec}
\newfontface\fsym{Noto Sans Symbols2}
\newfontface\fsymb{Noto Emoji}
\def\done{{\fsym ☑✓✔}{\fsymb ✅}}

%Adapted from %https://tex.stackexchange.com/questions/384468/minted-escapeinside-doesnt-work-within-a-string: \newcommand{\metastring}[1]{\PYG{l+s}{\Uchar96}\PYG{l+s}{\textcolor{red}{#1}}\PYG{l+s}{\Uchar96}} \newcommand{\metastringb}[1]{\PYG{l+s}{\Uchar96}\PYG{l+s}{#1}\PYG{l+s}{\Uchar96}}

\begin{document} \noindent It shows here (outside minted) -> \done \begin{minted}[escapeinside=||]{typescript} ... hbs.registerHelper("list", function(this: any) { ... entries.forEach(entry => { |It shows here (inside minted) -> \done| rows += |\Uchar96| |{\color{red}1. But not in here (inside minted and backticks) -> \done}| |\Uchar96| ...

|\metastring{2. But not in here (inside minted and backticks) -> \done}|

|\metastringb{3. But not in here (inside minted and backticks) -> \done}|

}) ... }); ... \end{minted} \end{document}

Cicada
  • 10,129
  • The big problem that I encountered, after trying using several methods (and including this one), is that the coloring is not applied to things such as \${this}`` (putting variables inside interpolated string). – Andrew15_5 Oct 07 '22 at 13:46