latex3 / fontspec

Font selection in LaTeX for XeTeX and LuaTeX
http://latex3.github.io/fontspec/
LaTeX Project Public License v1.3c
273 stars 32 forks source link

shrinkability and stretchability of interword space in tt family #139

Closed jfbu closed 8 years ago

jfbu commented 11 years ago

Hi, as explained to me by Enrico Gregorio, the default typewriter family font (after \usepackage{fontspec}) has both shrinkability and stretchability in its interword space. This results in a perhaps non user expected behavior in a verbatim environment in the case of long lines. To reduce the overfull box XeTeX shifts the offending line to the left (when it started with spaces), thus breaking the alignment with other lines of the same verbatim block. I signaled the issue in a c.t.tex posting: NNTP-Posting-Date: 17 Oct 2012 23:26:09 CEST Newsgroups: comp.text.tex Subject: an interaction between fontspec and verbatim Enrico advised I should raise the question here. Best wishes, Jean-Francois PS Here is a the mwe from my c.t.tex post: \documentclass[12pt,a4paper]{article} \usepackage{fontspec} \begin{document} \begin{verbatim} hello thisisaveryveryveryveryveryveryveryveryllllllllooooooooooooooonnnnnngline \end{verbatim} \end{document} [Please add 4 spaces at the start of both the hello and the veryverylong line]

khaledhosny commented 11 years ago

That is an engine issue, fontspec has nothing to do with it/can’t help much here.

wspr commented 8 years ago

Whether engine issue or otherwise, I can no longer reproduce this; I think the defaults in how mono fonts are loaded might be helping.

jfbu commented 8 years ago

Hi Will,

sorry my post was badly formatted, back then in 2012.

(cf the last sentence Please add 4 spaces at the start of both the hello and the veryverylong line).

With the four spaces added, I can reproduce the issue with:

\documentclass[12pt,a4paper]{article}
\usepackage{fontspec}
\begin{document}
\hrule
\begin{verbatim}
    hello
    thisisaveryveryveryveryveryveryveryveryllllllllooooooooooooooonnnnnngline
\end{verbatim}
\hrule
\end{document}

and XeLaTeX. I added also \hrule's for easier visualization.

I don't see the issue with LuaLaTeX.

Tested on a somewhat up-to-date TL2015. Maybe this is more of a XeTeX issue ?

jfbu commented 8 years ago

@wspr

Here is an image:

tempverbatimxetex

jfbu commented 8 years ago

@wspr

Perhaps this code snippet is more revealing:

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\ttfamily
\fontname\font

\the\fontdimen2\font

\the\fontdimen3\font

\the\fontdimen4\font
\end{document}

Output with xetex:

ttfontdimenxetex

Output with luatex:

ttfontdimenluatex

Does fontspec play any rôle at all in this ? Should I raise the issue on xetex mailing list ?

davidcarlisle commented 8 years ago

you see the same in plain tex without fontspec at all

\tracingonline1 \ifx\directlua\undefined \font\ltt="[lmmono12-regular]" at 12pt \else \input luaotfload.sty \font\ltt=file:lmmono12-regular.otf:script=latn \fi

\ltt

\showthe\fontdimen2\font

\showthe\fontdimen3\font

\showthe\fontdimen4\font

\bye

luatex shows no stretch/shrink xetex does, which looks wrong.

jfbu commented 8 years ago

@davidcarlisle I just wrote to xetex mailing list.

wspr commented 8 years ago

I can’t speak for what the engines are doing, but fontspec explicitly (by default) sets these values to zero when it loads a font via \setmonofont:

\documentclass{article}
\usepackage{fontspec}
\setmonofont{Inconsolata}
\begin{document}
\ttfamily
\fontname\font\\
\the\fontdimen2\font\\
\the\fontdimen3\font\\
\the\fontdimen4\font
\end{document}
jfbu commented 8 years ago

ah ok. But it does not do it by default for default monotype font ?

wspr commented 8 years ago

fontspec doesn’t try to guess what it’s given. The relevant lines in fontspec.cfg that enable this behaviour are:

\defaultfontfeatures
 [\ttfamily]
 {WordSpace={1,0,0},
  PunctuationSpace=WordSpace}

So presumably you know when you’re loading a monospace font and can apply the same :)

jfbu commented 8 years ago

@wspr Thanks. I guess this pretty much tells me all I need to know about fontspec in this regard ;-) ...