EDITED to better demonstrate the technique, using txtt
as the ttfont.
FIX for lstlisting
and \verb
(and \texttt
and \ttfamily
) given in FOLLOW UP at end:
Here, I show how a simple \scalebox
can be used to invert the slash through a defined macro \0
. I also show how making the 0
active allows one to use the reversed version of the zero inside verbatim
environments.
Obviously, one would not want 0 active all the time, but turning it on for verbatim
environments is a viable way to remedy the issue cited by the OP. Alternately, in normal text, one could just invoke the reflected image as \0
.
\documentclass{article}
\renewcommand*\ttdefault{txtt}
\renewcommand*\familydefault{\ttdefault} %% Only if the base font of the document is to be typewriter style
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\newcommand\0{\scalebox{-1}[1]{0}}
\begin{document}
Default look of zero: 0
\begin{verbatim}
\verbatim 0123456789
\end{verbatim}
Setting zero to its mirror image
\catcode`0=\active
\def0{\0}
Revised look of zero: 0
\begin{verbatim}
\verbatim 0123456789
\end{verbatim}
\catcode`0=12% RESET MEANING OF 0
0 restored to original, but\\
I can still call on \0 at will.
\end{document}
FOLLOW UP:
Using egreg's answer at email symbol while using package listings, I can automagically replace the reverse 0 with its mirror image in lstlisting
(by using literate
) and in \verb
arguments (through a patch) as such.
EDITED to fix \ttfamily
and \texttt
, as well. Note, though, that use of ttfamily
should be grouped, or the active 0
could break other things.
\documentclass{article}
\usepackage{marvosym,listings,etoolbox}
% THIS REPLACES 0 with \0 IN lstings
\lstset{literate={0}{\0}1{0\ }{\0\ }2}
% THIS REPLACES 0 WITH \0 IN verb
\patchcmd{\verb}{\dospecials}{\dospecials\atspecial}{}{}
\def\atspecial{\begingroup\lccode`~=`0%
\lowercase{\endgroup\let~}\0%
\catcode`0=\active}
%
\renewcommand*\ttdefault{txtt}
% COMMENT THE NEXT LINE TO TURN OFF texttt AS DEFAULT FONT FAMILY
\renewcommand*\familydefault{\ttdefault} % makes base font typewriter style
\usepackage[T1]{fontenc}
\usepackage{graphicx}
% DEFINE \0 AS MIRROR OF 0
\newcommand\0{\scalebox{-1}[1]{0}}
% FIX FOR \texttt AND \ttfamily
\let\svttfamily\ttfamily
\let\svtexttt\texttt
\catcode`0=\active
\def0{\0}
\renewcommand\ttfamily{\svttfamily\catcode`0=\active }
\renewcommand\texttt{\bgroup\ttfamily\texttthelp}
\def\texttthelp#1{#1\egroup}
\catcode`0=12 %
%
\begin{document}
Here is the font's normal 0 (which is reverse sense)\par
But it is fixed (un-reversed) in lstlisting:
\begin{lstlisting}[framexleftmargin=0mm,
basicstyle=\ttfamily\small,
breaklines,
columns=fullflexible]
' 0000 having 1=1--
' or 1 in (select @@version)--
' union all select @@version 0.0--
' OR 'unusual' = 'unusual'
\end{lstlisting}\par
as well as in verb:~\verb|declare @s0 varchar(8000)|
\noindent\hrulefill
%Now we try it in texttt: \texttt{foo0bar} or this {\ttfamily foo0bar},
texttt: \texttt{foo0bar}
or back to 0
ttfamily: {\ttfamily foo0bar}
or back to 0 again
\noindent\hrulefill
I didn't break verb, did I? \verb|declare @s0 varchar(8000)|
\end{document}
By commenting out the \familydefault
redefinition, the result is basically what the OP is asking for: normal text unaltered in \rmfamily
, but in listings, verbatim, ttfamily, and texttt, the reverse 0 is un-reversed.
\usepackage[T1]{fontenc} \usepackage[ttdefault=true]{AnonymousPro}