# Misalignement and interword spacing with mono font

I'm making a document with XeLaTeX and I would like to use a mono TTF font (Liberation Mono) and a special (reversed) indentation for my paragraphs.

I don't understand some things about words spacing and indentation. I made the following LaTeX code to perform a test :

\documentclass[a4paper,13pt]{book}
\usepackage{fontspec}
\setmainfont{Liberation Mono}
\begin{document}
\raggedright
\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit.
Cras sit amet est sit amet urna tincidunt consectetur
eget ut felis. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; Nam dapibus,

\setlength{\parindent}{-5ex}
\setlength{\leftskip}{5ex}%

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit.
Cras sit amet est sit amet urna tincidunt consectetur
eget ut felis. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; Nam dapibus,

\setlength{\parindent}{-5em}
\setlength{\leftskip}{5em}%

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit.
Cras sit amet est sit amet urna tincidunt consectetur
eget ut felis. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; Nam dapibus,

\end{document}


and I have the following results:

I note these things :

1. In the first paragraph : For what reason are the characters not aligned vertically. The word interspace should be constant (with a mono font) , but it is not.
2. In the second paragraph : The characters are not indented correctly. normally an indentation of 5ex should give a length of 5 character. But there is a difference and the indented lines are misaligned against the first.
3. In the third paragraph : The indentation length of 5em give a bigger indentation than with 5ex. But with a mono font, the length ex (width of an 'x') and em (width of an 'm') should be the same.

Do you have any idea on how to fix the interword spacing as a constant, why I have these misalignement with my tests paragraphs and what is wrong with my observations (If there is something wrong)?

• ex is usually roughly the height of an x and em is (roughly) the width of an M but both are arbitrary lengtsh assigned in the font metrics and not necessarily tied to any character – David Carlisle Sep 2 '18 at 20:45
• Also, LaTeX doesn't use fixed space width by default even if the font is monospace. You need some kind of verbatim environment or \obeyspaces to make spaces have their natural width. – siracusa Sep 2 '18 at 21:03

First of all you're forgetting \frenchspacing.

Second, 1ex need not be the same as 1em.

Third, 1ex and 1em are not multiples of the character width.

\documentclass[a4paper,12pt]{book}
\usepackage{fontspec}
\setmainfont{LiberationMono}[
Extension=.ttf,
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
]

\frenchspacing

\begin{document}

\raggedright
\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit.
Cras sit amet est sit amet urna tincidunt consectetur
eget ut felis. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; Nam dapibus,

\setlength{\parindent}{-5\fontcharwd\fontA}
\setlength{\leftskip}{5\fontcharwd\fontA}

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit.
Cras sit amet est sit amet urna tincidunt consectetur
eget ut felis. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; Nam dapibus,

\end{document}


The font setup is because I don't have Liberation Mono installed system-wide.

Just for information, here's the output of

1ex = \the\dimexpr1ex

1em = \the\dimexpr1em

A = \the\fontcharwd\fontA


Note also that the option 13pt does nothing at all and the font would be 10pt. I changed it to 12pt`.