# Proper typewriter font for math symbols (∀, ∃, →), e.g. in verbatim environment

I have a listing to be used in verbatim (acutally Verbatim) that uses unicode characters such as ∀, ∃, →, ∨. Using

\DeclareUnicodeCharacter{2203}{\ensuremath\exists}


they do appear in the listing, but obviously in the wrong font.

For → I got the desired result using

\usepackage{textcomp}
\DeclareUnicodeCharacter{2192}{\ifmmode\to\else\textrightarrow\fi}


but I do not see how to do it for ∃, ∀ and ∨.

MWE:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\DeclareUnicodeCharacter{2192}{\ifmmode\to\else\textrightarrow\fi}
\DeclareUnicodeCharacter{2203}{\ensuremath\exists}
\begin{document}
\begin{verbatim}
Make this → ∃ look nice!
\end{verbatim}
\end{document}


I’d like to stick to latex (i.e. not xetex). I would prefer to stick to the default type writer font (Computer Modern Typewriter), but if it only works with a different font (such as DejaVu Sans Mono), then that would be ok as well.

• Related: I have tried to find ∀ in DejaVu Sans Mono using the fonttable package, but could not find it in either T1 or TS1 font encoding. Which encoding is used for such symbols? – Joachim Breitner Jan 13 '16 at 12:31
• Do you have an example document? – Alenanno Jan 13 '16 at 12:38
• Added an example. – Joachim Breitner Jan 13 '16 at 12:43

You can use the cmtex10 font, that has several math symbols and is compatible with cmtt. The code below assumes you use the characters either in math mode or in Verbatim.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyvrb}
\usepackage{newunicodechar}

\DeclareFontFamily{U}{cmtex}{}
\DeclareFontShape{U}{cmtex}{m}{n}{
<-> cmtex10
}{}
\newcommand{\cmtex}[1]{{%
\usefont{U}{cmtex}{m}{n}\symbol{#1}%
}}

\newcommand{\ttexists}{\cmtex{"15}}
\newcommand{\ttforall}{\cmtex{"14}}
\newcommand{\ttrightarrow}{\cmtex{"19}}
\newcommand{\ttlor}{\cmtex{"1F}}
\newcommand{\ttland}{\cmtex{"04}}

\newunicodechar{∃}{\ifmmode\exists\else\ttexists\fi}
\newunicodechar{∀}{\ifmmode\forall\else\ttforall\fi}
\newunicodechar{→}{\ifmmode\expandafter\rightarrow\else\ttrightarrow\fi}
\newunicodechar{∨}{\ifmmode\lor\else\ttlor\fi}
\newunicodechar{∧}{\ifmmode\land\else\ttland\fi}

\begin{document}

$∃∀→∨∧$

\begin{Verbatim}
∃∀→∨∧
abcde
\end{Verbatim}

\end{document}


This is the font table, so you can extend the set in the same fashion.

• Great! Could you also add the precise command to get that font table? – Joachim Breitner Jan 13 '16 at 13:01
• @JoachimBreitner I typed pdflatex nfssfont from a terminal window and, at the prompt, cmtex10; at the next prompt, \table\bye. The reference for cmtex10 is the TeXbook, table at page 369. – egreg Jan 13 '16 at 13:02
• Alignment can be slightly incorrect. I've found that with the character δ in boxes by using the pmboxdraw package. So I needed \ifmmode\delta\else\makebox[0pt][l]{\ttdelta} \fi. Not sure whether there is a better solution. – vinc17 Sep 27 '17 at 12:15
• @vinc17 I'm not sure at all about the zero width box. Without an example with the pmboxdraw package it's difficult to say. Please, ask a new question referencing this one. – egreg Sep 27 '17 at 12:25
• The issue actually comes from the use of scalefont from the scalefnt package. It seems that cmtex10 doesn't like it. With article, I get a warning, but with beamer, the breakage is silent. I can ask a new question later if need be. – vinc17 Sep 27 '17 at 15:17