3

Context: In my document (compiled with pdfLaTeX), I use the libertine package and eponymous font. At some point, I want to use a monospaced font (for in-line code snippets, and URLs).

Problem: Even after scaling, the Libertine mono font appear too large:

enter image description here

Both the serif and the mono fonts match pretty well, but I find that the "grey" of mono-snippets is way too light compared to the serif font.

In Which typewriter font fits to Linux Libertine and supports bold letters?, two other fonts are suggested to pair with Libertine and Biolinum. However, as I scarcely ever use the mono-font in my document, the contrast is too conspicuous.

Question: Daring to brave basic standard rules of good typography, I'd like to "squish" the monospaced font horizontally (so that the length of one serif-alphabet more or less equals the length of one mono-alphabet).
How to do it when compiling with pdfLaTeX and without editing the font with FontForge?


\documentclass{scrartcl}

    \usepackage[
        osf,
        ttscale=0.875,
    ]{libertine}

\begin{document}
    \begin{itemize}
        \item[normal font:] {\normalfont abcdefghijklmnopqrstuvwxyz}
        \item[monospaced font:] {\ttfamily abcdefghijklmnopqrstuvwxyz}
        \item[x-height comparison:] {\ttfamily x}{\normalfont x}{\ttfamily x} {\ttfamily X}{\normalfont X}{\ttfamily X}
    \end{itemize}

    \addsec{Testing the grey}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim velit nunc, sit amet bibendum ante venenatis vel. Suspendisse ultrices lectus et ex bibendum, in vehicula lectus auctor. Etiam at maximus felis, ac blandit ex. Phasellus vitae ultrices nulla. Praesent viverra velit ullamcorper, sagittis mauris sit amet, posuere tellus. {\ttfamily Mauris ac sem ullamcorper,} euismod sem eleifend, ultricies metus. Aenean enim diam, tristique et maximus id, ultricies et nulla. Cras augue nibh, interdum ac aliquet sed, ultrices vitae lacus. Nulla rutrum nulla suscipit odio varius luctus.

    Vivamus ullamcorper elit in nibh pharetra posuere. Sed ut enim ornare ex tincidunt aliquet et vel lacus. Etiam vel sagittis urna. {\ttfamily Suspendisse felis lorem, elementum id pharetra eget, pulvinar sed justo.} Maecenas sit amet consectetur dolor, in vestibulum tortor. Morbi maximus nulla nec augue rutrum, non egestas neque molestie. Phasellus non feugiat ex, a condimentum ante. Praesent porta metus dui, quis euismod ante lacinia a. Nunc diam nulla, tempus et diam sed, eleifend iaculis neque. Morbi id arcu ornare, feugiat tellus eu, venenatis odio. Cras dignissim laoreet mauris a ultricies. Aliquam in orci erat. Mauris malesuada nisi ut nunc tincidunt, non luctus metus auctor. Suspendisse venenatis dolor ac ante accumsan, eu aliquet odio accumsan.

    Fusce non ipsum eget ipsum hendrerit vestibulum non et elit. Morbi finibus ornare dignissim. Cras vitae lacus eros. Mauris in egestas purus. Nullam vulputate felis vulputate dolor lacinia, at cursus eros sagittis. {\ttfamily Phasellus sed mauris metus. Aenean eget felis sapien.} Maecenas id ligula neque. Pellentesque vitae odio sed nulla venenatis molestie eu sit amet ipsum. Maecenas massa lorem, semper in maximus a, dictum vel neque. Nunc a tellus ligula. Pellentesque commodo interdum bibendum. Suspendisse elit ipsum, varius in justo id, hendrerit ornare nisi. Curabitur ut rutrum augue.
\end{document}
  • Mixing monospaced text with serifed text in this way is just plain silly IMHO. Trying to enforce consistency by "horizontal squashing" is even worse. Use displays, not in-line code snippets and URLs. – user51830 Jun 1 '17 at 16:52
  • @user51830 it's standard practice when writing books about code (see for example Numerical Recipes in C -- the second of these 2 sample pages) – Chris H Jun 2 '17 at 14:12
  • I like latin modern tt condensed for listings, but that may be going too far in your case. The ordinary latin modern tt looks -- to me -- to have narrower proportions than libertine tt – Chris H Jun 2 '17 at 14:17
4

You can use ExtendFont in the map-declaration. But as this changes only the glyphs and not their metrics you will probably have to combine it with some negative tracking (unless you want to create new tfm-files). 0.55 is an exagerated value, it should only show the effect better:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}

\usepackage{microtype}
\pdfmapline{=LinLibertineMT-tlf-t1--base LinLibertineMT ".55 ExtendFont AutoEnc_d6jdytwuqqz4y7d6afmjlfgx7d ReEncodeFont " <[lbtn_d6jdyt.enc <LinLibertineMT.pfb }    

    \usepackage[
        osf,
        ttscale=0.875,
    ]{libertine}



\begin{document}\pagestyle{empty}
    \begin{itemize}
        \item[normal font:] {\normalfont abcdefghijklmnopqrstuvwxyz}
        \item[monospaced font:]  {\ttfamily abcdefghijklmnopqrstuvwxyz}\\
                                 {\textls[-100]{\ttfamily abcdefghijklmnopqrstuvwxyz}}
        \item[x-height comparison:] {\ttfamily x}{\normalfont x}{\ttfamily x} {\ttfamily X}{\normalfont X}{\ttfamily X}
    \end{itemize}
\end{document}

enter image description here

  • Thank you! I tried to make these changes global through microtype's options. My guess is \SetTracking[spacing = {-250*,-100*,210}]{encoding=*, family = tt*}{-100}, but without any success... Any hint? (Note that .875 is a good factor for both scaling and squishing.) – ebosi Jun 1 '17 at 19:23
  • (I did not figure out how to solve this issue even after having read Set tracking amount with microtype) – ebosi Jun 1 '17 at 19:46
  • You need to add a \DeclareMicrotypeSet too, see here tex.stackexchange.com/a/320973/2388 (Robert is the author, so you can trust his answers ...). – Ulrike Fischer Jun 1 '17 at 20:20
0

Based on Ulrike's answer and comments, here is a take-away MWE of a solution that subjectively meets my requirements.

I used the .875 factor for both the global scaling of the typewriter font (as global option of the libertine package) and the ExtendFont in the map-declaration.

I then declare \DeclareMicrotypeSet for the ttfamily fonts (note that making encoding=* explicit seems to be required), and I adjust its tracking by reducing the inter-letter spacing by .1em (see {-100}), as well as the inter-word spacing by 50% (see -500*) plus increase shrinkability by 10% (100*).

The key is to set these settings after having loaded the libertine (here you are, o, two lost hours!)

enter image description here


\documentclass{scrartcl}

    \usepackage[T1]{fontenc}
    \usepackage[tracking]{microtype}
    \usepackage[ttscale=0.875]{libertine}

    \pdfmapline{=LinLibertineMT-tlf-t1--base LinLibertineMT ".875 ExtendFont AutoEnc_d6jdytwuqqz4y7d6afmjlfgx7d ReEncodeFont " <[lbtn_d6jdyt.enc <LinLibertineMT.pfb }    
    \DeclareMicrotypeSet*[tracking]{typewriter}{ encoding = *, family = tt* }
    \SetTracking[ spacing = {-500*,,100*} ]{ encoding=*, family = tt* }{-100}

\begin{document}

    \begin{itemize}
        \item[normal font:] {\normalfont abcdefghijklmnopqrstuvwxyz}
        \item[monospaced font:] {\ttfamily abcdefghijklmnopqrstuvwxyz}
        \item[x-height comparison:] {\ttfamily x}{\normalfont x}{\ttfamily x} {\ttfamily X}{\normalfont X}{\ttfamily X}
    \end{itemize}

    \addsec{Testing the grey}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim velit nunc, sit amet bibendum ante venenatis vel. Suspendisse ultrices lectus et ex bibendum, in vehicula lectus auctor. Etiam at maximus felis, ac blandit ex. Phasellus vitae ultrices nulla. Praesent viverra velit ullamcorper, sagittis mauris sit amet, posuere tellus. {\ttfamily Mauris ac sem ullamcorper,} euismod sem eleifend, ultricies metus. Aenean enim diam, tristique et maximus id, ultricies et nulla. Cras augue nibh, interdum ac aliquet sed, ultrices vitae lacus. Nulla rutrum nulla suscipit odio varius luctus.

    Vivamus ullamcorper elit in nibh pharetra posuere. Sed ut enim ornare ex tincidunt aliquet et vel lacus. Etiam vel sagittis urna. {\ttfamily Suspendisse felis lorem, elementum id pharetra eget, pulvinar sed justo.} Maecenas sit amet consectetur dolor, in vestibulum tortor. Morbi maximus nulla nec augue rutrum, non egestas neque molestie. Phasellus non feugiat ex, a condimentum ante. Praesent porta metus dui, quis euismod ante lacinia a. Nunc diam nulla, tempus et diam sed, eleifend iaculis neque. Morbi id arcu ornare, feugiat tellus eu, venenatis odio. Cras dignissim laoreet mauris a ultricies. Aliquam in orci erat. Mauris malesuada nisi ut nunc tincidunt, non luctus metus auctor. Suspendisse venenatis dolor ac ante accumsan, eu aliquet odio accumsan.

    Fusce non ipsum eget ipsum hendrerit vestibulum non et elit. Morbi finibus ornare dignissim. Cras vitae lacus eros. Mauris in egestas purus. Nullam vulputate felis vulputate dolor lacinia, at cursus eros sagittis. {\ttfamily Phasellus sed mauris metus. Aenean eget felis sapien.} Maecenas id ligula neque. Pellentesque vitae odio sed nulla venenatis molestie eu sit amet ipsum. Maecenas massa lorem, semper in maximus a, dictum vel neque. Nunc a tellus ligula. Pellentesque commodo interdum bibendum. {\ttfamily https://tex.stackexchange.com} Suspendisse elit ipsum, varius in justo id, hendrerit ornare nisi. Curabitur ut rutrum augue.
\end{document}

Note: all microtype's factors given here are ballpark numbers pleasing to my untrained eye. They would require a much finer tuning in a real document (i.e., I here guessed them, tried them, they were ok so I kept them. That is I didn't look for better alternatives. Suggestions welcome in comments!)

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.