0

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

6
  • Same cause as italic - Minted escapeinside doesn't work within a string - TeX - LaTeX Stack Exchange but I don't know how generalizable is the answer because I didn't look at the manual to see what \PYG does
    – user202729
    Oct 6, 2022 at 12:01
  • @user202729, yes. But in my case, I have a lot of characters on multiple lines between quotes (backticks) and escapeinside=|| doesn't seem to work when escape characters (start | and end |) are placed on different lines.
    – Andrew15_5
    Oct 6, 2022 at 14:25
  • escapeinside comments and strings is a GitHub issue, according to the documentation.
    – Cicada
    Oct 7, 2022 at 9:46
  • @Cicada, can you provide a link to the issue? I can't find it (or the issue covers a slightly different problem).
    – Andrew15_5
    Oct 7, 2022 at 13:55
  • minted doc p24 links to: GitHub
    – Cicada
    Oct 7, 2022 at 14:05

1 Answer 1

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}
1
  • 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 7, 2022 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .