# True fixed-width font for standalone mathematical expressions

I'd like the following to be in a fixed-width (i.e. monospace) font, so I can get the various expressions lined up nicely in order to (probably with a bit of manipulation) make their similarities and differences more obvious and immediately apparent.

I do like the font though, so if there is something similar, that is monospaced, or maybe some kind of quantization method; a way to force each character to occupy the same space; that would be ideal. Not getting my hopes up, just saying it would be nice.

\documentclass[border=5mm,varwidth]{standalone}

\begin{document}

$(x+y)'=x'y'$\\
$\neg(p\vee q)\leftrightarrow\neg p\wedge\neg q$\\
$(A\cup B)^c=A^c\cap$ $B^c$\\
\\
$(xy)'=x'+y'$\\
$\neg(p\wedge q)\leftrightarrow\neg p\vee\neg q$\\
$(A\cap B)^c=A^c\cup B^c$\\

\end{document}

• Would a align environment be a good first step? What is your exact aim (what should line up)? – TeXnician Jul 4 '18 at 17:14

If I understand your aim correctly you want it to be easily comparable. So here are two suggestions (if you don't like any of them I'll delete my post):

• use align and use them as in your post
• use a tabular to make the comparison more clear

Code:

\documentclass{article}

\usepackage{mathtools}

\usepackage{array}

\begin{document}
\begin{align*}
(x+y)' &= x'y'\\
\neg(p\vee q) &\leftrightarrow \neg p\wedge\neg q\\
(A\cup B)^c &= A^c\cap B^c\\[\baselineskip]
x' + y' &= (xy)'\\
\neg(p\wedge q) &\leftrightarrow \neg p\vee\neg q\\
(A\cap B)^c &= A^c\cup B^c
\end{align*}

\vfill

\begin{tabular}{*{2}{>{$$}r<{$$}@{\hskip.25em}>{$$}c<{$$}@{\hskip.25em}>{$$}l<{$$}}}
(x+y)' &=& x'y' & x' + y' &=& (xy)'\\
\neg(p\vee q) &\leftrightarrow& \neg p\wedge\neg q & \neg(p\wedge q) &\leftrightarrow& \neg p\vee\neg q\\
(A\cup B)^c &=& A^c\cap B^c & (A\cap B)^c &=& A^c\cup B^c
\end{tabular}
\end{document}

• Thanks, it's quite nice. And it's useful information. But it's not quite what I was looking for. Maybe if I could align the wedges and the caps and cups and various other operators it would be good, but that seems like it would get messy real quick. Anyway, please leave it up for our perusal. Thanks again. – voices Apr 9 '19 at 11:39

You might do like this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\fsmath}{m}
{
\tl_map_inline:nn { #1 } { \makebox[1.2em]{$##1$} }
}

\ExplSyntaxOff

\begin{document}

\begin{align*}
& \fsmath{(x+y)'=x'y'} \\
& \fsmath{\neg(p\vee q)\leftrightarrow\neg p\wedge\neg q} \\
& \fsmath{(A\cap B){^c}=A{^c}\cup B{^c}}
\end{align*}

\end{document}


A literal answer to your question: It is technically possible, using unicode-math, to load TeX Gyre DejaVu math as your math font and then the letters, numbers and symbols from DejaVu Sans Mono over it using the range= option of \setmathfont.

However, that won’t do what you want because subscripts, large operators, spacing and so on will not be monospaced. It’s an XY-problem.