7

For part of my documentation I want my \texttt to use a fixed-spacing font that slashes its zeroes. The default font LaTeX uses for the purpose (Courier New, I suppose) does not. I'm used to Consolas for this purpose, but I don't suppose it matters much. How do I set the default tt font?

(I looked up this question and found a reference to \setmonofont, but \setmonofont{Consolas} generates an error message about an undefined control sequence; I suspect \setmonofont is for lua only.)

1
  • Welcome to LaTeX! I think most monospaced fonts let you choose whether or not you use slashed zeroes. It is usually an available OpenType feature. Commented Jan 8, 2023 at 22:23

3 Answers 3

5

You could use inconsolata.

\documentclass{article}
\usepackage{inconsolata}
\begin{document}
\texttt{0123456789}
\end{document}
3
  • 1
    Hey, that looks good! Only one problem: It doesn't respond to \textit, which I need to use for variables. Sigh. (But thanks anyway.) Commented Jan 8, 2023 at 22:29
  • 1
    Is your text in math mode? If so, try \mathit. Commented Jan 8, 2023 at 22:36
  • You can also try the iosevka font with lualatex (be warned, that font is a monster. Expect a lot of delay the first time you compile to build the caches...)
    – Rmano
    Commented Jan 9, 2023 at 7:42
4

The \setmonofont command works in either LuaLaTeX or XeLaTeX if you

\usepackage{fontspec}

You probably want

\setmonofont{Consolas}[Scale=MatchLowercase]

or possibly

\setmonofont{Consolas}[Scale=MatchUppercase]

But be aware, Consolas is not a free font. If you do this, other people will only be able to recompile your document from source on a machine with Microsoft Windows or Microsoft Office installed.

4

As illustration of using OTF font features with fontspec, TeX Gyre Cursor font is a fixed-width font which has the slashed-zero OpenType font feature.

TexGyreCursor

You can use any suitable font instead.

MWE

\documentclass{article}

\usepackage{fontspec}
\setmonofont{Tex Gyre Cursor}[Numbers=SlashedZero]
\newfontfamily\fontcons{Tex Gyre Cursor}[Numbers=SlashedZero]

\newcommand\digits{0123456789}
\newcommand\sample[1]{{\fontcons#1abc \digits\ xyz iiii mmmm}}

\begin{document}
As document mono-spaced font: 

\texttt{\digits}

\texttt{\textit{\digits}}

\texttt{\textbf{\digits}}

\texttt{\textit{\textbf{\digits}}}

\bigskip
As custom font family

A. \sample{}

B. \sample{\itshape}

C. \sample{\bfseries}

D. \sample{\itshape\bfseries}

\end{document}

You must log in to answer this question.

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