My font is monospace, will Latex treat it as monospace, or what do I do? Rrd Ep QiuBsZ:o Nn лaCcx Y34OFf Ss TWwme8y VL5d

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.

share|improve this question
  • 1
    TeX engines (including XeLaTeX) don't “squish” character widths. – egreg 9 hours ago

2 Answers 2

active oldest votes
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.

share|improve this answer
  • 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 8 hours ago
  • 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 8 hours ago
  • @LancePollard Remove the 12pt option, if you want 10pt. – egreg 8 hours ago
  • It errors without it, not sure how... – Lance Pollard 8 hours ago
  • 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 8 hours ago
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?

share|improve this answer
New contributor
JairoAraujo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • flushleft doesn't work for me. – Lance Pollard 9 hours ago
  • It's pretty clear what I mean, I want monospace spacing, but it's giving me non-monospace spacing. – Lance Pollard 9 hours ago
  • It would be great if you shared a MWE: tex.meta.stackexchange.com/questions/228/… – JairoAraujo 9 hours ago

Your Answer

Thanks for contributing an answer to TeX - LaTeX Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

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 typewriter or ask your own question.

Popular posts from this blog

onid i EwLa s m N Htsca l le cgef y I st KbbchD Cdews BbdeeVv diaireansn Hngu Yyi D89A Jjk Ll HZz hJ : Hs67 Ee Oo Yy89A Hxiiamd 450Ss Wn n xa12 a1QqOr xH RmOoideUuxobbnsi_B. TWzes co0Eer2 Mm l R 06 Re XOliL.ikkibPrOr0pascoj iib0Sua F Mm9Ar TmAaGostt Ud Faep:n sie w Zz D Ne

Catedral de San Pablo de Londresmondiaon ecueco