2

I have a custom monospace font. I want to write the whole document using it. The output from doing Lorem Ipsum shows that my monospaced font is not being rendered as monospaced (i.e. some character widths are squished, probably due to the line-rendering algorithms). What do I need to configure on LaTeX's end to make this work right? I am using XeLaTeX.

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{fullpage}
\setmainfont{MyFont}
\begin{document}
Hello world hello world Hello world hello world Hello world hello world Hello world hello worldHello world hello world Hello world hello worldHello world hello worldHello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello world.
\end{document}

I would like to customize how many lines exactly per page, and how many characters per line (since it is monospaced), or at least to set a font size and have the whole document be monospaced at that size.

  • 1
    TeX engines (including XeLaTeX) don't “squish” character widths. – egreg Aug 21 at 8:37
5

Using fullpage will not give you the possibility to set the number of characters per line nor the number of lines per page. This can be done with geometry instead.

However, justification will make characters not align vertically, because it's usually impossible that lines contain the exact number of characters (including spaces). If you want vertical alignment, you need \raggedright and \frenchspacing.

In the example, I set 72 characters (maximum) per line and 48 lines per page.

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{geometry}

\usepackage{kantlipsum}

\setmainfont{Latin Modern Mono}

\newlength{\characterwidth}
\settowidth{\characterwidth}{\normalfont x}
\geometry{textwidth=72\characterwidth,lines=48}
\AtBeginDocument{\raggedright\setlength{\parindent}{3\characterwidth}}
\frenchspacing

\begin{document}

\kant[1-4]

\end{document}

enter image description here

The first lines with a frame around the text block to show more clearly where the problem is:

enter image description here

As you see, the first two lines end at the margin, but the third one is two character short of 72; even with hyphenation on, the next word cannot fit, because the space would count for a character and the hyphen for another.

  • How do I change the number of characters that fit on a single line? Changing the font size and then changing the textwidth doesn't always align to the available page space. – Lance Pollard Aug 21 at 9:45
  • If I do this, monospace is no longer working :/ \fontsize{10pt}{12pt}\settowidth{\characterwidth}{\normalfont x}\geometry{margin=0.7in,textwidth=96\characterwidth,lines=48}. – Lance Pollard Aug 21 at 9:48
  • @LancePollard Remove the 12pt option, if you want 10pt. – egreg Aug 21 at 9:49
  • It errors without it, not sure how... – Lance Pollard Aug 21 at 9:49
  • Your example isn't monospaced either it looks like... imgur.com/ugsynvZ Phenomena and paralogisms are not aligned at the na and ms. – Lance Pollard Aug 21 at 9:52
0

Please, be more specific. At least with respect to spacing, flushleft avoids uneven spacing.

%!TEX program=xelatex
\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{fullpage}
\setmainfont{DejaVu Sans Mono}
\begin{document}
\begin{flushleft}
Hello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello worldHello world hello worldHello world hello world Hello world hello world Hello world hello world Hello world hello world Hello world hello world.
\end{flushleft}
\end{document}

enter image description here

Wrt lines per page, this may be worth your attention: How can I limit the maximum number of lines in a page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.