2

I'm having trouble with \mintinline, because I am using a black background for it, and the characters render in a way that I find unpleasing. Namely, when doing something like:

\documentclass{article}

\usepackage{minted}
\usemintedstyle{monokai}

\setminted{
  bgcolor=black,
}

\begin{document}

Hello, \mintinline{coq}{+}, \mintinline{coq}{*}, \mintinline{coq}{-}, can you have the same height?

\end{document}

I would like each character's background to take the same height, as I find the difference jarring:

enter image description here

IS there a trick I can use to force the height to be fixed?

Marijn
  • 37,699
Ptival
  • 145
  • What version of the minted package do you use (see log file)? I can't reproduce this behaviour with version 2.5, all boxes have the same height here – siracusa Aug 19 '18 at 03:18
  • Fairly sure I'm also on 2.5... Might be relevant: I'm using xetex. – Ptival Aug 19 '18 at 08:53

1 Answers1

2

The documentation of minted states that the bgcolor option puts \mintinline inside a \colorbox. Therefore, as a solution, you can define your own \colorbox with a fixed height and use that instead of the automatic colorbox used by minted.

To set the height of the colorbox, a \parbox can be used within the colorbox (as in, for example, https://tex.stackexchange.com/a/232491/).

MWE:

\documentclass{article}
\usepackage{minted}
\usemintedstyle{monokai}
\begin{document}

\newcommand{\inlinebg}[1]{%
\colorbox{black}{%
\parbox[b][0.6em]{\widthof{\mintinline{coq}{#1}}}{\mintinline{coq}{#1}}%
}%
}

\setminted{bgcolor=black}
Without custom colorbox/parbox:

Hello, \mintinline{coq}{+}, \mintinline{coq}{*}, \mintinline{coq}{-}, can you have the same height?

\setminted{bgcolor={}}
\vspace{1cm}
With custom colorbox/parbox:

Hello, \inlinebg{+}, \inlinebg{*}, \inlinebg{-}, can you have the same height?
\end{document}

Result:

enter image description here

Marijn
  • 37,699
  • Great! Had to bump it from 0.6em to ~1em because I have some tall glyphs in there, but it did the trick! – Ptival Aug 22 '18 at 04:23
  • I realized that \widthof on \mintinline returns a width that contains some left-and-right margins, making the parbox slightly larger horizontally than the original. Any workaround? – Ptival Sep 25 '18 at 02:16
  • You can subtract a small amount (maybe 1pt) from the width, see for example https://tex.stackexchange.com/questions/149045/how-to-calculate-a-new-length (two answers with different approaches, but both of them should work). – Marijn Sep 25 '18 at 07:18