3
\documentclass{article}

\usepackage{minted}

\begin{document}

    This is a python
    \begin{minted}[escapeinside=||]{py}
    def f(x):
      y = x|\colorbox{green}{**}|2
      return y
    \end{minted}

    This is a json
    \begin{minted}[escapeinside=||]{json}
      {
        "hello":"world|\colorbox{green}{**}|"
      }
    \end{minted}
\end{document}

Got a problem that i can show the green box in python code, but i cannot get green box in json code. My guess is because the curly braces of json. I tried \{ \} but doesn't work. enter image description here

Got another problem about the color of the json.

    This is a normal json
    \begin{minted}{json}
{
  "hello":"world",
  "hell":"worl",
  "hello1":"world1"
}
    \end{minted}

    This is a json with color problem
    \begin{minted}[escapeinside=||]{json}
{
  "hello":|\colorbox{green}{**}|"world",
  "hell":"worl",
  "hello1":"world1"
}
    \end{minted}

    This is a json with color problem but without green box
    \begin{minted}[escapeinside=||]{json}
{
  "hello":"world",
  "hell":"worl",
  "hello1":"world1"
}
    \end{minted}

Note the color of these three json color problem

1

1 Answer 1

2

The minted documentation says "Note that escapeinside does not work within strings." (p. 20). Since "world" is a string you can't put any escaped code there.

It does work outside of the string. However, escapeinside still (incorrectly) causes the closing } to be highlighted as a syntax error. You can switch off the color box for errors by redefining the \fcolorbox command within minted environments.

\documentclass{article}
% from https://tex.stackexchange.com/questions/14166/red-box-drawn-around-question-mark-operator-in-minted-erlang-code
\usepackage{etoolbox}
\AtBeginEnvironment{minted}{%
  \renewcommand{\fcolorbox}[4][]{#4}}

\usepackage{minted}
\begin{document}
    This is a python
    \begin{minted}[escapeinside=||]{py}
    def f(x):
      y = x|\colorbox{green}{**}|2
      return y
    \end{minted}

    This is a json
    \begin{minted}[escapeinside=||]{json}
      {
        "hello":|\colorbox{green}{**}|"world"
      }
    \end{minted}
\end{document}

enter image description here

1
  • 1
    I tried this, and I can put a green box in a json. But the color of the json is wrong. I post the code in the question. May 25, 2020 at 10:09

You must log in to answer this question.

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