10

I am using minted to display my source code and the Inconsolata package to set the output font. Unfortunately, this produces the following ugly result (note the direction of the quote marks:

Example string with badly-shaped quote marks

Figuring this was a bad attempt on LaTeX's part to use smart quotes, I tried using the upquote package. This produced the following:

Example string which erroneously displays no quotes, using Inconsolata font

Using this MWE:

\documentclass{article}
\usepackage{minted}
\usepackage{inconsolata}
\usepackage{upquote}
\begin{document}

\begin{minted}{matlab}
    disp('This string should have straight quotes!');
\end{minted}
\end{document}

Removing the Inconsolata package produces a typographically-acceptable result, but, alas, not in the Inconsolata font:

Example string with straight quotes, using tt font

I'm not sure what's going on.

Why can't I have the font I want AND the appropriate quotes? Any thoughts?

8
  • 4
    The Inconsolata font doesn't have a straight quote character. :(
    – egreg
    Commented Dec 7, 2012 at 13:25
  • ... which the log file produced by your MWE tells you: Missing character: There is no ' in font ts1-inconsolata!. Commented Dec 7, 2012 at 13:26
  • An alternative is the Droid Sans Mono font (provided by droidmono package) which has straight quotes and looks somewhat similar. Commented Dec 7, 2012 at 13:29
  • 7
    What the hell, Inconsolata! That font was designed for typesetting code. No straight quotes? The font designer was a master troll. Commented Dec 8, 2012 at 12:36
  • 1
    There's an Inconsolata fork with straight quotes, which you could use with XeLaTeX/LuaLaTeX.
    – doncherry
    Commented Dec 8, 2012 at 16:18

2 Answers 2

10

The Inconsolata font doesn't have a straight quote character, as testified by the lines

Missing character: There is no ' in font ts1-inconsolata!

in your .log file. You can work around this by using the cmtt font and doing similarly to what upquote does:

\documentclass{article}
\usepackage{minted}
\usepackage{inconsolata}

\begingroup
\makeatletter
\catcode`'=\active
\catcode``=\active
\g@addto@macro\@noligs
   {\def'{{\fontencoding{TS1}\fontfamily{cmtt}\selectfont\textquotesingle}}%
    \def`{{\fontencoding{TS1}\fontfamily{cmtt}\selectfont\textasciigrave}}%
    }
\endgroup

\begin{document}

\begin{minted}{matlab}
    disp('This string should have straight quotes!');
\end{minted}
\end{document}

enter image description here

Maybe the quotes should be raised a bit:

\documentclass{article}
\usepackage{minted}
\usepackage{inconsolata}

\begingroup
\makeatletter
\catcode`'=\active
\catcode``=\active
\gdef\raise@quotes#1{\raisebox{.1ex}{\fontencoding{TS1}\fontfamily{cmtt}\selectfont#1}}
\g@addto@macro\@noligs
   {\def'{\raise@quotes{\textquotesingle}}%
    \def`{\raise@quotes{\textasciigrave}}%
    }
\endgroup

\begin{document}

\begin{minted}{matlab}
    disp('This string should have straight quotes!');
\end{minted}
\end{document}

enter image description here

3
  • 1
    May I know what inconsolata.sty doing here?
    – MadyYuvi
    Commented Jun 26, 2020 at 6:40
  • 1
    @MadyYuvi It’s not necessary, but it loads the font used by the OP.
    – egreg
    Commented Jun 26, 2020 at 9:00
  • 1
    Much thanks for the reply...
    – MadyYuvi
    Commented Jun 26, 2020 at 9:48
6

There is (as of 2013-06-14) a new version of the inconsolata package by Michael Sharpe, called inconsolata-zi4, that provides a font with a straight quote which can be automatically used in verbatim environments (using upquote). (Currently, the new package has replaced inconsolata on CTAN, so use caution in updating; see this question.) With the new package, this works as expected:

\documentclass{article}
\usepackage{minted}
\usepackage[varqu]{zi4}%   updated inconsolata with variant upquotes
\AtBeginDocument{%         needed for pygmentize 1.6
\def\PYZsq{\textquotesingle}%
}
\begin{document}
\begin{minted}[fontfamily=zi4]{matlab}
    disp('This string should have straight quotes!');
\end{minted}
\end{document}

enter image description here

(The \def to make upquote work with recent pygments is taken from this answer.)

2
  • 2
    Good news! However, I'd have preferred if the package name had been kept, for backward compatibility.
    – egreg
    Commented Jun 24, 2013 at 17:26
  • 1
    The latest version (2013-07-13) now comes with an inconsolata.sty file for backward compatibility. Commented Aug 12, 2013 at 19:56

You must log in to answer this question.

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