3

I'm now making a documentation of a small LaTeX package with documentation library from the tcolorbox package, and having difficulty in printing sample codes without any syntax highlighting.

According to G. Poore's answer, we can set the language as text to turn off the coloring, which can be specified via /tcb/minted language key. Thus, I tried to redefine the corresponding value like the following MWE (the first two are just for comparison).

\documentclass{article}
\usepackage[all]{tcolorbox}
\tcbset{listing engine=minted}
\begin{document}
\begin{tcblisting}{minted language=text}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{tcblisting}
\begin{dispExample}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{dispExample}
\tcbset{
  docexample/.add style={}{
    fontlower=\normalsize,
    minted language=text,
    documentation minted options={
      autogobble=true,
      fontsize=\small
    }
  }
}
\begin{dispExample}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{dispExample}
\end{document}

Typesetting this with pdflatex -shell-escape gave me

output of the MWE

As you can see, the option minted language=text seems to be invalid in the third box while other key-value settings (e.g., fontlower=\normalsize) works. Also, minted language=text is valid in the normal tcblisting environment.

How can I .add style the minted language key to the docexample style? What am I doing wrong?

I could have directly asked this question at Prof. Thomas F. Sturm's GitHub repository, but I use TeX.SX expecting more people will have a look.

Update:

Thanks to @egreg's answer, I found that my issue lies in the combination of tcolorbox and newtxtt (after some investigation, the same behaviour was confirmed with other monospaced fonts). Consider this MWE:

\documentclass{article}
\usepackage[all]{tcolorbox}
\usepackage{newtxtt}
\tcbset{
  listing engine=minted,
  docexample/.add style={}{
    fontlower=\normalsize,
    minted language=latex,
    documentation minted options={
      autogobble=true,
      fontsize=\small,
      style=bw,
    }
  }
}
\begin{document}
\begin{dispExample}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{dispExample}
\end{document}

This gives control sequences in boldface, which I don't like, although style=bw is specified.

output of the second MWE

Monospaced fonts that reproduce this problem include

  • Courier (\usepackage{courier}),
  • DejaVu (\usepackage{dejavu}),
  • Fira (\usepackage{firamono}),
  • Incondolata (\usepackage{zi4}), and
  • Source Code Pro (\usepackage{sourcecodepro}),

while Latin Modern and Droid don't trigger the problem.

Yet Another Update:

The second part of this question now has its own thread.

4

Currently, the documentation library assumes all (minted) texts to be of latex language. Therefore, minted language has deliberately no effect on dispExample environments.

Nevertheless, I take it as a feature request to make this configurable in the same way as documentation minted options.

The following patch introduces a new option documentation minted language which will be integrated into tcolorbox version 4.03 and higher:

\documentclass{article}
\usepackage[all]{tcolorbox}
\begin{document}

\makeatletter

\tcbset{
  documentation minted language/.store in=\kvtcb@docminted@language,
  documentation minted language=latex,
}

\def\tcb@minted@doc@usetemplisting{%
  \tcb@minted@input@listing{\kvtcb@docmintoptions}{\kvtcb@docminted@language}{\kvtcb@tempfile}{\kvtcb@docmintstyle}%
}

\tcbset{listing engine=minted}

\makeatother

\begin{tcblisting}{minted language=text}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{tcblisting}

\begin{dispExample}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{dispExample}

\tcbset{
  docexample/.add style={}{
    fontlower=\normalsize,
    documentation minted language=text,
    documentation minted options={
      autogobble=true,
      fontsize=\small
    }
  }
}

\begin{dispExample}
  \begin{equation}
    \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
  \end{equation}
\end{dispExample}

\end{document}

enter image description here

  • Thank you for your explanation and the patch works well also. Regarding the font weight problem, which still remains, I'll open another question with a reduced MWE later. – yudai-nkt Apr 24 '17 at 17:20
1

You want to pass style=bw to pygmentize:

\documentclass{article}
\usepackage[all]{tcolorbox}
\tcbset{
  listing engine=minted,
  docexample/.add style={}{
    fontlower=\normalsize,
    minted language=latex, % <--------
    documentation minted options={
      autogobble=true,
      fontsize=\small,
      style=bw, % <-------
    }
  }
}
\begin{document}

\begin{dispExample}
\begin{equation}
  \int_{-\infty}^{\infty} \exp (-x^2) \, dx = \sqrt{\pi}
\end{equation}
\end{dispExample}

\end{document}

enter image description here

  • I know the style key but it didn't give me a desired result neither. My actual case is like this, where some control sequences are in boldface. This is why I next tried the minted language. That being said, your code works on my end as well. I'll update the question after investigating a true cause and making a new MWE. – yudai-nkt Dec 28 '16 at 12:59
  • I updated the question. – yudai-nkt Dec 28 '16 at 13:20

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.